Package com.google.collide.client.documentparser

Examples of com.google.collide.client.documentparser.DocumentParser


    editor.setDocument(document);

    editor.getInput().getActionExecutor().addDelegate(TextActions.INSTANCE);

    PathUtil path = new PathUtil("test.css");
    DocumentParser documentParser = createDocumentParser(path);
    Autoindenter autoindenter = Autoindenter.create(documentParser, editor);

    LineFinder lineFinder = editor.getDocument().getLineFinder();
    editor.getSelection().setSelection(
        lineFinder.findLine(line1), column1, lineFinder.findLine(line2), column2);
View Full Code Here


  }

  private static void checkAutoindenter(String text, int line1, int column1, int line2, int column2,
      final SignalEvent trigger, String expected, boolean allowScheduling) {
    PathUtil path = new PathUtil("test.js");
    DocumentParser documentParser = createDocumentParser(path);
    Document document = Document.createFromString(text);
    Editor editor = Editor.create(new MockAppContext());
    editor.setDocument(document);
    checkAutoindenter(line1, column1, line2, column2, trigger, expected, allowScheduling,
        documentParser, document, editor);
View Full Code Here

  private static void checkAutoindenter(String text, int line1, int column1, int line2, int column2,
      final SignalEvent trigger, String expected, boolean allowScheduling) {
    PathUtil path = new PathUtil("test.py");
    TestUtils.MockIncrementalScheduler parseScheduler = new TestUtils.MockIncrementalScheduler();
    Document document = Document.createFromString(text);
    DocumentParser documentParser = createDocumentParser(path, true, parseScheduler, document);
    Editor editor = Editor.create(new MockAppContext());
    editor.setDocument(document);

    documentParser.begin();
    assertEquals(1, parseScheduler.requests.size());
    parseScheduler.requests.pop().run(300);

    AutoindenterTest.checkAutoindenter(line1, column1, line2, column2, trigger, expected,
        allowScheduling, documentParser, document, editor);
View Full Code Here

    Position cursor = selection.getCursorPosition();
    final Line line = cursor.getLine();
    final int column = cursor.getColumn();

    DocumentParser parser = getParser();
    JsonArray<Token> tokens = parser.parseLineSync(line);
    if (tokens == null) {
      // This line has never been parsed yet. No variants.
      return AutocompleteProposals.EMPTY;
    }

    // We do not ruin parse results for "clean" lines.
    if (parser.isLineDirty(cursor.getLineNumber())) {
      // But "processing" of "dirty" line is harmless.
      XmlCodeAnalyzer.processLine(TaggableLineUtil.getPreviousLine(line), line, tokens);
    }
    String initialMode = parser.getInitialMode(line);
    JsonArray<Pair<Integer, String>> modes = TokenUtil.buildModes(initialMode, tokens);
    putModeAnchors(line, modes);
    String mode = TokenUtil.findModeForColumn(initialMode, modes, column);

    if (cssAutocompleter != null && CodeMirror2.CSS.equals(mode)) {
View Full Code Here

    putModeAnchors(line, modes);
  }

  @VisibleForTesting
  String getModeForColumn(Line line, int column) {
    DocumentParser parser = getParser();
    String mode = parser.getInitialMode(line);

    JsonArray<Anchor> anchors = AnchorManager.getAnchorsByTypeOrNull(line, MODE_ANCHOR_TYPE);
    if (anchors != null) {
      for (Anchor anchor : anchors.asIterable()) {
        if (anchor.getColumn() >= column) {
View Full Code Here

  }

  public void testCollectedAnchors() {
    PathUtil filePath = new PathUtil("index.html");
    Document document = Document.createFromString(SOURCE);
    DocumentParser parser = DocumentParser.create(
        document, CodeMirror2.getParser(filePath), new StubIncrementalScheduler(50, 50));
    AnchorTagParser anchorParser = new AnchorTagParser(parser);
    parser.begin();
    JsonArray<AnchorTagParser.AnchorTag> anchorTags = anchorParser.getAnchorTags();
    assertEquals(3, anchorTags.size());
    assertAnchorTag(anchorTags.get(0), "aName1", 4, 13);
    assertAnchorTag(anchorTags.get(1), "aName2", 5, 12);
    assertAnchorTag(anchorTags.get(2), "aId1", 6, 11);
View Full Code Here

    if (selectionModel.hasSelection()) {
      return ExplicitAction.DEFAULT;
    }

    DocumentParser parser = getParser();

    // 1) Check we are not in block already.
    ParseResult<CssState> parseResult = parser.getState(
        CssState.class, selectionModel.getCursorPosition(), " ");
    if (parseResult == null) {
      return ExplicitAction.DEFAULT;
    }
    JsonArray<Token> tokens = parseResult.getTokens();
    Preconditions.checkNotNull(tokens);
    Preconditions.checkState(tokens.size() > 0);
    CssToken lastToken = (CssToken) tokens.peek();
    if ("{".equals(lastToken.getContext())) {
      return ExplicitAction.DEFAULT;
    }

    // 2) Check we will enter block.
    parseResult = parser.getState(CssState.class, selectionModel.getCursorPosition(), "{");
    if (parseResult == null) {
      return ExplicitAction.DEFAULT;
    }
    tokens = parseResult.getTokens();
    Preconditions.checkNotNull(tokens);
View Full Code Here

TOP

Related Classes of com.google.collide.client.documentparser.DocumentParser

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.