Package com.google.collide.codemirror2

Examples of com.google.collide.codemirror2.Parser


    SimpleStringBag excluded = new SimpleStringBag();
    assertEquals(1, htmlAttributes.searchAttributes("html", excluded, sampleAttribute).size());
    excluded.add(sampleAttribute);

    JsonArray<Token> tokens1 = JsonCollections.createArray();
    tokens1.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<html"));
    tokens1.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));
    String line1 = tokensToText(tokens1);
    parsedLines.put(line1, tokens1);

    JsonArray<Token> tokens2 = JsonCollections.createArray();
    tokens2.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, sampleAttribute));
    String line2 = tokensToText(tokens2);
    parsedLines.put(line2, tokens2);

    JsonArray<Token> tokens3 = JsonCollections.createArray();
    tokens3.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));
    String line3 = tokensToText(tokens3);
    parsedLines.put(line3, tokens3);

    String text = line1 + "\n" + line2 + "\n ";
    helper.setup(path, text, 0, line1.length(), false);
View Full Code Here


  /**
   * Tests that find autocompletions do not ruin existing "clean" results.
   */
  public void testFindDoNotRuinResults() {
    String id = "id";
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<html"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));

    prepareAutocompleter();
    HtmlTagWithAttributes before = helper.editor.getDocument().getFirstLine().getTag(
        XmlCodeAnalyzer.TAG_END_TAG);
    assertNotNull(before);

    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, id));
    helper.autocompleter.htmlAutocompleter.findAutocompletions(
        helper.editor.getSelection(), CTRL_SPACE);
    HtmlTagWithAttributes after = helper.editor.getDocument().getFirstLine().getTag(
        XmlCodeAnalyzer.TAG_END_TAG);

View Full Code Here

    HtmlTagsAndAttributes htmlAttributes = HtmlTagsAndAttributes.getInstance();
    SimpleStringBag excluded = new SimpleStringBag();
    assertEquals(1, htmlAttributes.searchAttributes("ol", excluded, reversed).size());
    excluded.add(reversed);

    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<ol"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, reversed));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATOM, "="));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.STRING, "\"\""));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));
    AutocompleteProposals proposals = findAutocompletions();

    assertEquals(htmlAttributes.searchAttributes("ol", excluded, "").size(), proposals.size());
    assertEquals("accesskey", proposals.get(0).getName());
    assertNull(TestUtils.selectProposalByName(proposals, reversed));
View Full Code Here

  /**
   * Tests the proposals for ELEMENT.
   */
  public void testAutocompleteHtmlElements() {
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<a"));
    AutocompleteProposals proposals = findAutocompletions();

    assertEquals(7, proposals.size());
    assertEquals("abbr", proposals.get(1).getName());

    lineTokens.clear();
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<bod"));
    proposals = findAutocompletions();
    assertEquals(1, proposals.size());
    assertEquals("body", proposals.get(0).getName());

    lineTokens.clear();
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<body"));
    assertEquals(1, findAutocompletions().size());

    lineTokens.clear();
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<body"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, ">"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "</body"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, ">"));
    assertTrue(findAutocompletions().isEmpty());

    lineTokens.clear();
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<"));
    assertEquals(
        HtmlTagsAndAttributes.getInstance().searchTags("").size(), findAutocompletions().size());
  }
View Full Code Here

  /**
   * Tests the autocompletion of self-closing tag.
   */
  public void testAutocompleteSelfClosingTag() {
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<lin"));
    AutocompleteProposals autocompletions = findAutocompletions();
    assertNotNull(autocompletions);
    ProposalWithContext linkProposal = TestUtils.selectProposalByName(autocompletions, "link");
    assertNotNull(linkProposal);
    AutocompleteResult commonResult =
View Full Code Here

  /**
   * Tests full autocompletion for ATTRIBUTE.
   */
  public void testJumpLengthAndFullAutocompletionHtmlAttribute() {
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<body"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));
    AutocompleteProposals autocompletions = findAutocompletions();
    assertNotNull(autocompletions);
    ProposalWithContext onloadProposal = TestUtils.selectProposalByName(autocompletions, "onload");
    assertNotNull(onloadProposal);
    AutocompleteResult commonResult =
View Full Code Here

  /**
   * Tests full autocompletion for ELEMENT.
   */
  public void testJumpLengthAndFullAutocompletionHtmlElement() {
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<bod"));
    AutocompleteProposals autocompletions = findAutocompletions();
    assertNotNull(autocompletions);
    ProposalWithContext bodyProposal = TestUtils.selectProposalByName(autocompletions, "body");
    assertNotNull(bodyProposal);

View Full Code Here

      tokens.add(JsonCollections.<Token>createArray());
    }
    JsonArray<Token> lineTokens;

    lineTokens = tokens.get(1);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<html"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "first"));

    lineTokens = tokens.get(2);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "second"));

    lineTokens = tokens.get(3);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "third"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, ">"));

    codeAnalyzer.onBeforeParse();
    for (int i = 1; i <= 3; i++) {
      codeAnalyzer.onParseLine(lines.get(i - 1), lines.get(i), tokens.get(i));
    }
View Full Code Here

      tokens.add(JsonCollections.<Token>createArray());
    }
    JsonArray<Token> lineTokens;

    lineTokens = tokens.get(1);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, "<html"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "first"));

    lineTokens = tokens.get(2);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "second"));

    lineTokens = tokens.get(3);
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "third"));
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.TAG, ">"));

    codeAnalyzer.onBeforeParse();
    for (int i = 1; i <= 3; i++) {
      codeAnalyzer.onParseLine(lines.get(i - 1), lines.get(i), tokens.get(i));
    }
    codeAnalyzer.onAfterParse();

    lineTokens = tokens.get(2);
    lineTokens.clear();
    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.ATTRIBUTE, "fixed"));

    codeAnalyzer.onBeforeParse();
    for (int i = 2; i <= 3; i++) {
      codeAnalyzer.onParseLine(lines.get(i - 1), lines.get(i), tokens.get(i));
    }
View Full Code Here

      }

      StringMultiset tagAttributes = tag.getAttributes();

      while (index < size) {
        Token token = tokens.get(index);
        index++;
        TokenType tokenType = token.getType();
        if (ATTRIBUTE == tokenType) {
          String attribute = token.getValue();
          attribute = ignoreCase ? attribute.toLowerCase() : attribute;
          attributes.add(attribute);
          tagAttributes.add(attribute);
        } else if (TAG == tokenType) {
          // Tag closing token
          tag.setDirty(false);
          inTag = false;
          break;
        }
      }
      if (newAttributes && attributes.size() != 0) {
        line.putTag(TAG_ATTRIBUTES, attributes);
      } else if (!newAttributes && attributes.size() == 0) {
        line.putTag(TAG_ATTRIBUTES, null);
      }
    } else {
      line.putTag(TAG_ATTRIBUTES, null);
    }

    while (index < size) {
      Token token = tokens.get(index);
      index++;
      TokenType tokenType = token.getType();
      if (TAG == tokenType) {
        if (inTag) {
          if (">".equals(token.getValue()) || "/>".equals(token.getValue())) {
            // If type is "tag" and content is ">", this is HTML token.
            inTag = false;
          }
        } else {
          // Check that we are in html mode.
          if (CodeMirror2.HTML.equals(token.getMode())) {
            lastTagTokenIndex = index - 1;
            inTag = true;
          }
        }
      }
    }

    if (inTag) {
      if (lastTagTokenIndex != -1) {
        index = lastTagTokenIndex;
        Token token = tokens.get(index);
        index++;
        String tagName = token.getValue().substring(1).trim();
        tag = new HtmlTagWithAttributes(tagName);
        StringMultiset tagAttributes = tag.getAttributes();
        while (index < size) {
          token = tokens.get(index);
          index++;
          TokenType tokenType = token.getType();
          if (ATTRIBUTE == tokenType) {
            String attribute = token.getValue();
            tagAttributes.add(ignoreCase ? attribute.toLowerCase() : attribute);
          }
        }
      }
View Full Code Here

TOP

Related Classes of com.google.collide.codemirror2.Parser

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.