Search in sources :

Example 1 with BlockComment

use of com.google.devtools.j2objc.ast.BlockComment in project j2objc by google.

the class TreeConverter method addNativeComments.

private static void addNativeComments(CompilationUnit unit, String delim, String endDelim) {
    // Can't use a regex because it will greedily include everything between
    // the first and last closing pattern, resulting in a single comment node.
    String source = unit.getSource();
    int startPos = 0;
    int endPos = 0;
    while ((startPos = source.indexOf(delim, endPos)) > -1) {
        endPos = source.indexOf(endDelim, startPos);
        if (endPos > startPos) {
            // Include closing delimiter.
            endPos += 4;
            BlockComment ocniComment = new BlockComment();
            ocniComment.setSourceRange(startPos, endPos - startPos);
            unit.getCommentList().add(ocniComment);
        }
    }
}
Also used : BlockComment(com.google.devtools.j2objc.ast.BlockComment)

Example 2 with BlockComment

use of com.google.devtools.j2objc.ast.BlockComment in project j2objc by google.

the class TreeConverter method convertAssociatedComment.

private Comment convertAssociatedComment(JCTree node, Element element) {
    boolean docCommentsEnabled = newUnit.getEnv().options().docCommentsEnabled();
    DocCommentTable docComments = unit.docComments;
    if (!docCommentsEnabled || docComments == null || !docComments.hasComment(node)) {
        return null;
    }
    com.sun.tools.javac.parser.Tokens.Comment javacComment = docComments.getComment(node);
    Comment comment;
    switch(javacComment.getStyle()) {
        case BLOCK:
            comment = new BlockComment();
            break;
        case JAVADOC:
            comment = docCommentsEnabled ? convertJavadocComment(element) : new Javadoc();
            break;
        case LINE:
            comment = new LineComment();
            break;
        default:
            throw new AssertionError("unknown comment type");
    }
    int startPos = javacComment.getSourcePos(0);
    int endPos = startPos + javacComment.getText().length();
    comment.setSourceRange(startPos, endPos);
    comment.setLineNumber(unit.getLineMap().getLineNumber(startPos));
    return comment;
}
Also used : LineComment(com.google.devtools.j2objc.ast.LineComment) BlockComment(com.google.devtools.j2objc.ast.BlockComment) Comment(com.google.devtools.j2objc.ast.Comment) BlockComment(com.google.devtools.j2objc.ast.BlockComment) DocCommentTable(com.sun.tools.javac.tree.DocCommentTable) Javadoc(com.google.devtools.j2objc.ast.Javadoc) LineComment(com.google.devtools.j2objc.ast.LineComment)

Aggregations

BlockComment (com.google.devtools.j2objc.ast.BlockComment)2 Comment (com.google.devtools.j2objc.ast.Comment)1 Javadoc (com.google.devtools.j2objc.ast.Javadoc)1 LineComment (com.google.devtools.j2objc.ast.LineComment)1 DocCommentTable (com.sun.tools.javac.tree.DocCommentTable)1