Package com.google.collide.shared.document

Examples of com.google.collide.shared.document.Line


        + "}\n"
        + "var e = {\n"
        + "  f : function ( ) {\n"
        + "    callMyFunctionWithCallback(function(/* Knock-knock! */) {\n";
    Document document = Document.createFromString(text);
    Line line = document.getFirstLine();
    TaggableLine previousLine;

    JsonArray<Token> tokens1 = JsonCollections.createArray();
    tokens1.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "a"));
    tokens1.add(new Token(mode, TokenType.NULL, "("));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "b"));
    tokens1.add(new Token(mode, TokenType.NULL, ","));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.VARIABLE, "c"));
    tokens1.add(new Token(mode, TokenType.NULL, ")"));
    tokens1.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens1.add(new Token(mode, TokenType.NULL, "{"));
    tokens1.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens2 = JsonCollections.createArray();
    tokens2.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens2.add(new Token(mode, TokenType.VARIABLE, "d"));
    tokens2.add(new Token(mode, TokenType.NULL, "."));
    tokens2.add(new Token(mode, TokenType.VARIABLE, "prototype"));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.NULL, "="));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens2.add(new Token(mode, TokenType.NULL, "("));
    tokens2.add(new Token(mode, TokenType.NULL, ")"));
    tokens2.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens2.add(new Token(mode, TokenType.NULL, "{"));
    tokens2.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens3 = JsonCollections.createArray();
    tokens3.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens3.add(new Token(mode, TokenType.NULL, "}"));
    tokens3.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens4 = JsonCollections.createArray();
    tokens4.add(new Token(mode, TokenType.NULL, "}"));
    tokens4.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens5 = JsonCollections.createArray();
    tokens5.add(new Token(mode, TokenType.KEYWORD, "var"));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.DEF, "e"));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.NULL, "="));
    tokens5.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens5.add(new Token(mode, TokenType.NULL, "{"));
    tokens5.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens6 = JsonCollections.createArray();
    tokens6.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens6.add(new Token(mode, TokenType.PROPERTY, "f"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, ":"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, "("));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, ")"));
    tokens6.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens6.add(new Token(mode, TokenType.NULL, "{"));
    tokens6.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsonArray<Token> tokens7 = JsonCollections.createArray();
    tokens7.add(new Token(mode, TokenType.WHITESPACE, "  "));
    tokens7.add(new Token(mode, TokenType.VARIABLE, "callMyFunctionWithCallback"));
    tokens7.add(new Token(mode, TokenType.NULL, "("));
    tokens7.add(new Token(mode, TokenType.KEYWORD, "function"));
    tokens7.add(new Token(mode, TokenType.NULL, "("));
    tokens7.add(new Token(mode, TokenType.COMMENT, "/* Knock-knock! */"));
    tokens7.add(new Token(mode, TokenType.NULL, ")"));
    tokens7.add(new Token(mode, TokenType.WHITESPACE, " "));
    tokens7.add(new Token(mode, TokenType.NULL, "{"));
    tokens7.add(new Token(mode, TokenType.NEWLINE, "\n"));

    JsIndexUpdater indexUpdater = new JsIndexUpdater();
    indexUpdater.onBeforeParse();

    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens1);
    JsCodeScope aScope = line.getTag(JsIndexUpdater.TAG_SCOPE);
    assertNotNull(aScope);
    assertEquals("a", aScope.getName());

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens2);
    JsCodeScope dProtoScope = line.getTag(JsIndexUpdater.TAG_SCOPE);
    assertNotNull(dProtoScope);
    assertEquals("d.prototype", dProtoScope.getName());
    assertTrue(dProtoScope.getParent() == aScope);
    assertEquals("a-d-prototype", JsCodeScope.buildPrefix(dProtoScope).join("-"));

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens3);
    assertTrue(line.getTag(JsIndexUpdater.TAG_SCOPE) == aScope);

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens4);
    assertFalse(line.getTag(JsIndexUpdater.TAG_SCOPE) == aScope);

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens5);
    JsCodeScope eScope = line.getTag(JsIndexUpdater.TAG_SCOPE);
    assertNotNull(eScope);
    assertEquals("e", eScope.getName());
    assertFalse(eScope.getParent() == aScope);

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens6);
    JsCodeScope fScope = line.getTag(JsIndexUpdater.TAG_SCOPE);
    assertNotNull(fScope);
    assertEquals("f", fScope.getName());
    assertTrue(fScope.getParent() == eScope);

    line = line.getNextLine();
    previousLine = TaggableLineUtil.getPreviousLine(line);
    indexUpdater.onParseLine(previousLine, line, tokens7);
    JsCodeScope namelessScope = line.getTag(JsIndexUpdater.TAG_SCOPE);
    assertNotNull(namelessScope);
    assertNull(namelessScope.getName());
    assertTrue(namelessScope.getParent() == fScope);

    indexUpdater.onAfterParse();
View Full Code Here


  public void testCssFindAutocompletions() {
    MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();

    setupHelper(helper, "<html><head><style>p {color:bl");
    Line line = helper.editor.getDocument().getLastLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("css", tokens.get(tokens.size() - 1).getMode());

    AutocompleteProposals proposals =
View Full Code Here

    String line1 = "";
    String line2 = "bl";
    String text = line0 + "\n" + line1 + "\n" + line2;
    helper.setup(new PathUtil("foo.html"), text, 2, line2.length(), true);
    helper.parser.begin();
    Line line = helper.editor.getDocument().getFirstLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("css", tokens.get(tokens.size() - 2).getMode());
    assertEquals("", tokens.get(tokens.size() - 1).getMode());
    line = helper.editor.getDocument().getLineFinder().findLine(1).line();
View Full Code Here

  public void testCssGetExplicitAutocompletion() {
    MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();

    setupHelper(helper, "<html><head><style>p ");
    Line line = helper.editor.getDocument().getLastLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("css", tokens.get(tokens.size() - 1).getMode());
    helper.autocompleter.htmlAutocompleter.updateModeAnchors(line, tokens);
View Full Code Here

  public void testJavascriptFindAutocompletions() {
    MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();

    setupHelper(helper,
        "<html><body><script type=\"text/javascript\">function a() { var abba, apple, arrow; a");
    Line line = helper.editor.getDocument().getLastLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("javascript", tokens.get(tokens.size() - 1).getMode());
    TaggableLine previousLine = TaggableLineUtil.getPreviousLine(line);
    helper.autocompleter.htmlAutocompleter.updateModeAnchors(line, tokens);
View Full Code Here

    helper.cubeClient.api.collectedCallbacks.get(0).onMessageReceived(response);

    setupHelper(helper,
        "<html><body><script type=\"text/javascript\">function a() { var abba, apple, arrow; a");

    Line line = helper.editor.getDocument().getLastLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("javascript", tokens.get(tokens.size() - 1).getMode());
    TaggableLine previousLine = TaggableLineUtil.getPreviousLine(line);
    helper.autocompleter.htmlAutocompleter.updateModeAnchors(line, tokens);
View Full Code Here

  public void testJavascriptGetExplicitAutocompletion() {
    MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();

    setupHelper(helper, "<html><body><script type=\"text/javascript\">foo");
    Line line = helper.editor.getDocument().getLastLine();
    JsonArray<Token> tokens = helper.parser.parseLineSync(line);
    assertEquals("html", tokens.get(0).getMode());
    assertEquals("javascript", tokens.get(tokens.size() - 1).getMode());
    TaggableLine previousLine = TaggableLineUtil.getPreviousLine(line);
    helper.autocompleter.htmlAutocompleter.updateModeAnchors(line, tokens);
View Full Code Here

        helper.editor.getSelection(), CTRL_SPACE);
    AutocompleteProposals.ProposalWithContext proposal = TestUtils.selectProposalByName(
        proposals, "barBeQue");
    assertNotNull(proposal);
    helper.autocompleter.reallyFinishAutocompletion(proposal);
    Line thirdLine = helper.editor.getDocument().getLineFinder().findLine(2).line();
    assertEquals("  barBeQue\n", thirdLine.getText());
  }
View Full Code Here

        output.clear();
        output.addAll(nodes);
      }
    };

    Line line = helper.editor.getDocument().getFirstLine();
    JsonArray<Token> tokens = helper.parser
        .parseLineSync(line);

    CssOutlineParser cssOutlineParser = new CssOutlineParser(registrar, consumer);
View Full Code Here

    helper.parser.begin();
    helper.parseScheduler.requests.get(0).run(20);

    //# Comment
    Line line = helper.editor.getDocument().getFirstLine();
    PyCodeScope scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNull(scope);

    //class Foo:
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNotNull(scope);
    assertEquals(PyCodeScope.Type.CLASS, scope.getType());
    assertEquals("Foo", PyCodeScope.buildPrefix(scope).join("#"));
    PyCodeScope prevScope = scope;

    //  "Foo is very clever and open-minded"
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //  def goo(self, dwarf):
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNotNull(scope);
    assertEquals(PyCodeScope.Type.DEF, scope.getType());
    assertEquals("Foo#goo", PyCodeScope.buildPrefix(scope).join("#"));
    prevScope = scope;

    //    whatever = [
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //"whenever"
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //               ]
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //    # Fais ce que dois, advienne que pourra
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //  def roo(gnome):
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNotNull(scope);
    assertEquals(PyCodeScope.Type.DEF, scope.getType());
    assertEquals("Foo#roo", PyCodeScope.buildPrefix(scope).join("#"));
    prevScope = scope;

    //    self.this = def class
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //    # La culture, c'est ce qui reste quand on a tout oublié.
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    //class Bar:
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNotNull(scope);
    assertEquals(PyCodeScope.Type.CLASS, scope.getType());
    assertEquals("Bar", PyCodeScope.buildPrefix(scope).join("#"));
    prevScope = scope;

    // "Bar is a unit of pressure, roughly equal to the atmospheric pressure on Earth"
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);

    // def far(self):
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertNotNull(scope);
    assertEquals(PyCodeScope.Type.DEF, scope.getType());
    assertEquals("Bar#far", PyCodeScope.buildPrefix(scope).join("#"));
    prevScope = scope;

    //  The kingdom of FAR FAR Away, Donkey? That's where we're going! FAR! FAR!... away.
    line = line.getNextLine();
    scope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    assertTrue(scope == prevScope);
  }
View Full Code Here

TOP

Related Classes of com.google.collide.shared.document.Line

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.