Package uk.co.badgersinfoil.metaas.impl.antlr

Examples of uk.co.badgersinfoil.metaas.impl.antlr.LinkedListToken


  }

  public static LinkedListTree newDescendantExpression(LinkedListTree target,
                                                       LinkedListTree selector)
  {
    LinkedListToken op = TokenBuilder.newE4XDescendant();
    LinkedListTree ast = ASTUtils.newAST(op);
    assertNoParent("left-hand expression", target);
    // TODO: is this needed..?
    if (precidence(ast) < precidence(target)) {
      target = parenthise(target);
View Full Code Here


  private static final LinkedListTreeAdaptor TREE_ADAPTOR = new LinkedListTreeAdaptor();

  private DocCommentUtils() { /* hide ctor */ }

  public static String getDocComment(LinkedListTree node) {
    LinkedListToken tok = findDocCommentToken(node);
    if (tok == null) {
      return null;
    }
    return commentToString(tok);
  }
View Full Code Here

    }
    return commentToString(tok);
  }

  public static LinkedListToken findDocCommentToken(LinkedListTree node) {
    LinkedListToken tok=node.getStartToken();
    if (tok == null) {
      return null;
    }
    // find the first proper token,
    outer: while (true) {
      switch (tok.getType()) {
          case AS3Parser.WS:
          case AS3Parser.NL:
          case AS3Parser.ML_COMMENT:
          case AS3Parser.SL_COMMENT:
        tok = tok.getNext();
        break;
          default:
        break outer;
      }
    }
    // search backwards from the first proper token until we reach the first ML_COMMENT
    for (tok=tok.getPrev(); tok!=null; tok=tok.getPrev()) {
      switch (tok.getType()) {
          case AS3Parser.WS:
          case AS3Parser.NL:
        continue;
          case AS3Parser.ML_COMMENT:
        if (tok.getText().startsWith("/**")) {
          return tok;
        }
        // fall though,
          default:
        return null;
View Full Code Here

                        .replaceFirst("(?:(?<=[\n\r])[ \t]+)?\\*+/\\Z", "")
                        .replaceAll("([\n\r])\\s*\\*", "$1");
  }

  public static void setDocComment(LinkedListTree node, String text) {
    LinkedListToken tok = findDocCommentToken(node);
    if (text == null) {
      if (tok != null) {
        LinkedListToken next = tok.getNext();
        LinkedListToken prev = tok.getPrev();
        tok.delete();
        // TODO: looks like I didn't finish here,
        if (next.getType() == AS3Parser.NL) {
          next.getNext();
        }
        if (prev.getType() == AS3Parser.WS) {
          prev.getPrev();
        }
      }
      return;
    }
    assertValidContent(text);
    String indent = ASTUtils.findIndent(node);
    text = "/**" + text.replaceAll("(\n|\r\n|\r)", "$1"+indent+" *");
    if (!text.endsWith("*")) {
       text += "*";
    }
    text += "/";
    if (tok == null) {
      LinkedListToken comment = TokenBuilder.newMLComment(text);

      insertDocComment(node, indent, comment);
    } else {
      tok.setText(text);
    }
View Full Code Here

      tok.setText(text);
    }
  }

  private static void insertDocComment(LinkedListTree node, String indent, LinkedListToken comment) {
    LinkedListToken nl = TokenBuilder.newNewline();

    // TODO: try harder to find the right place/line to
    // insert the comment
    findTokenToInsertCommentBefore(node).beforeInsert(comment);
    comment.afterInsert(nl);
    if (indent.length() > 0) {
      LinkedListToken indentTok = TokenBuilder.newWhiteSpace(indent);
      nl.afterInsert(indentTok);
    }
  }
View Full Code Here

      nl.afterInsert(indentTok);
    }
  }

  private static LinkedListToken findTokenToInsertCommentBefore(LinkedListTree node) {
    LinkedListToken tok = node.getStartToken();
    outer: while (true) {
      switch (tok.getType()) {
        case AS3Parser.WS:
        case AS3Parser.NL:
          tok = tok.getNext();
          break;
        default:
          break outer;
      }
    }
View Full Code Here

    LinkedListTree desc = javadoc.getFirstChild();
    return stringify(desc);
  }

  public static LinkedListTree buildJavadoc(LinkedListTree ast) {
    LinkedListToken doc = findDocCommentToken(ast);
    if (doc == null) {
      return null;
    }
    String body = getCommentBody(doc);
    LinkedListTree javadoc = parse(body);
View Full Code Here

        return tok.getText();
    }
  }

  public static void setDescriptionString(LinkedListTree ast, String description) {
    LinkedListToken doc = findDocCommentToken(ast);
    LinkedListTree javadoc = null;
    LinkedListTree desc = null;
    if (doc != null) {
      javadoc = parse(getCommentBody(doc));
      trimEOF(javadoc);
      desc = javadoc.getFirstChild();
    }
    if (description == null) {
      if (desc != null) {
        ASTUtils.deleteAllChildren(desc);
        doc.setText("/**"+ASTUtils.stringifyNode(javadoc)+"*/");
      }
      return;
    }
    assertValidContent(description);
    String newline = getNewlineText(ast, javadoc);
    if (!description.startsWith("\n")) {
      description = "\n" + description;
    }
    description = description.replaceAll("\n", newline);
    LinkedListTree newDesc = parseDescription(description);
    if (doc == null) {
      String indent = ASTUtils.findIndent(ast);
      doc = TokenBuilder.newMLComment("/**"+ASTUtils.stringifyNode(newDesc)+"\n"+indent+" */");
      insertDocComment(ast, indent, doc);
    } else {
      newDesc.appendToken(new LinkedListToken(JavadocParser.NL, newline));
      javadoc.setChildWithTokens(0, newDesc);
      doc.setText("/**"+ASTUtils.stringifyNode(javadoc)+"*/");
    }
  }
 
View Full Code Here

    }
    return newline;
  }

  public static String findNewline(LinkedListTree javadoc) {
    LinkedListToken tok=javadoc.getStopToken();
    if (tok.getType() == JavadocParser.NL) {
      // Skip the very-last NL, since this will precede the
      // closing-comment marker, and therefore will lack the
      // '*' that should be present at the start of every
      // other line,
      tok=tok.getPrev();
    }
    for (; tok!=null; tok=tok.getPrev()) {
      if (tok.getType() == JavadocParser.NL) {
        return tok.getText();
      }
    }
    return null;
  }
View Full Code Here

  private static LinkedListTree parseDescription(String description) {
    try {
      JavadocParser parser = parserOn(description);
      LinkedListTree desc = (LinkedListTree)parser.description().getTree();
      LinkedListToken after = (LinkedListToken)parser.getTokenStream().LT(1);
      if (!isEOF(after)) {
        throw new SyntaxException("trailing content after description: "+ActionScriptFactory.str(after.getText()));
      }
      trimEOF(desc);
      return desc;
    } catch (IOException e) {
      throw new SyntaxException(e);
View Full Code Here

TOP

Related Classes of uk.co.badgersinfoil.metaas.impl.antlr.LinkedListToken

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.