Example usage for org.eclipse.jdt.core.dom LineComment getLength

List of usage examples for org.eclipse.jdt.core.dom LineComment getLength

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom LineComment getLength.

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:ASTParser.ParseJavaFile.java

public boolean visit(LineComment node) {
    int start = node.getStartPosition();
    int end = start + node.getLength();
    String comment = source.substring(start, end);
    allComments.append(comment);// ww w.  ja va 2s  .c o m
    allComments.append("\r\n");
    return true;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(LineComment node) {
    boa.types.Ast.Comment.Builder b = boa.types.Ast.Comment.newBuilder();
    buildPosition(node);/*w ww.  j  av a  2s.  co  m*/
    b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Comment.CommentKind.LINE);
    b.setValue(src.substring(node.getStartPosition(), node.getStartPosition() + node.getLength()));
    comments.add(b.build());
    return false;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(LineComment node) {
    int beginLine = cu.getLineNumber(node.getStartPosition());
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = cu.getColumnNumber(node.getStartPosition());
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    languageConstructs.add(/*  w  w w .  j  a va2  s  .com*/
            new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn));

    return true;
}

From source file:edu.buffalo.cse.Sapphire.JavaModelListener.java

License:Open Source License

/**
 * This function deals with the changes of comments since comments can't 
 * be obtained via ASTNodes, it has to be done by accepting ASTVisitor.
 * //w  w w .j  a v a2  s .com
 * @author Chern Yee Chua
 */

@SuppressWarnings("unchecked")
public static void parse(final String strA) {
    ASTParser parserA = ASTParser.newParser(AST.JLS8);
    parserA.setSource(strA.toCharArray());
    parserA.setKind(ASTParser.K_COMPILATION_UNIT);
    final CompilationUnit cuA = (CompilationUnit) parserA.createAST(null);

    for (Comment comment : (List<Comment>) cuA.getCommentList()) {
        comment.accept(new ASTVisitor() {

            public boolean visit(LineComment node) {
                int start = node.getStartPosition();
                int end = start + node.getLength();
                String comment = strA.substring(start, end);
                int lineNumber;

                if (isTempLarger) {
                    lineNumber = astRootTemp.getLineNumber(node.getStartPosition());
                } else {
                    lineNumber = astRoot.getLineNumber(node.getStartPosition());
                }

                if (isTempLarger) {
                    if (!commentListTemp.contains(lineNumber + " # " + "[LINE_COMMENT] " + comment)) {
                        commentListTemp.add(lineNumber + " # " + "[LINE_COMMENT] " + comment);
                        commentListTempContent.add("[LINE_COMMENT] " + comment);
                    }
                } else {
                    if (!commentList.contains(lineNumber + " # " + "[LINE_COMMENT] " + comment)) {
                        commentList.add(lineNumber + " # " + "[LINE_COMMENT] " + comment);
                        commentListContent.add("[LINE_COMMENT] " + comment);
                    }
                }

                return true;
            }

            public boolean visit(BlockComment node) {
                int start = node.getStartPosition();
                int end = start + node.getLength();
                String comment = strA.substring(start, end);
                int lineNumber;

                if (isTempLarger) {
                    lineNumber = astRootTemp.getLineNumber(node.getStartPosition());
                } else {
                    lineNumber = astRoot.getLineNumber(node.getStartPosition());
                }

                if (isTempLarger) {
                    if (!commentListTemp.contains(lineNumber + " # " + "[BLOCK_COMMENT] \n" + comment)) {
                        commentListTemp.add(lineNumber + " # " + "[BLOCK_COMMENT] \n" + comment);
                        commentListTempContent.add("[BLOCK_COMMENT] \n" + comment);
                    }
                } else {
                    if (!commentList.contains(lineNumber + " # " + "[BLOCK_COMMENT] \n" + comment)) {
                        commentList.add(lineNumber + " # " + "[BLOCK_COMMENT] \n" + comment);
                        commentListContent.add("[BLOCK_COMMENT] \n" + comment);
                    }
                }
                return true;
            }

            public boolean visit(Javadoc node) {

                int start = node.getStartPosition();
                int end = start + node.getLength();
                String comment = strA.substring(start, end);
                int lineNumber;

                if (isTempLarger) {
                    lineNumber = astRootTemp.getLineNumber(node.getStartPosition());
                } else {
                    lineNumber = astRoot.getLineNumber(node.getStartPosition());
                }

                if (isTempLarger) {
                    if (!commentListTemp.contains(lineNumber + " # " + "[JAVADOC] \n" + comment)) {
                        commentListTemp.add(lineNumber + " # " + "[JAVADOC] \n" + comment);
                        commentListTempContent.add("[JAVADOC] \n" + comment);
                    }
                } else {
                    if (!commentList.contains(lineNumber + " # " + "[JAVADOC] \n" + comment)) {
                        commentList.add(lineNumber + " # " + "[JAVADOC] \n" + comment);
                        commentListContent.add("[JAVADOC] \n" + comment);
                    }
                }
                return true;
            }
        });
    }
}

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/*  w w  w . j av a  2 s  .c  o m*/
 *<ul>
 *  <li>For any line comment:
 *  <ul>
 *    <li>Comment to <code>ICommentWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(LineComment node) {
    // Write the comment entity
    commentWriter.writeLineComment(compilationUnitPath, node.getStartPosition(), node.getLength());
    return true;
}

From source file:org.autorefactor.refactoring.ASTCommentRewriter.java

License:Open Source License

private void deleteLineCommentAfterNode(List<TextEdit> commentEdits, String source, LineComment lineComment) {
    final int commentStart = lineComment.getStartPosition();
    final int commentLength = lineComment.getLength();
    final int nbWhiteSpaces = nbTrailingSpaces(source, commentStart);
    commentEdits.add(new DeleteEdit(commentStart - nbWhiteSpaces, nbWhiteSpaces + commentLength));
}

From source file:sharpen.core.CSharpBuilder.java

License:Open Source License

@Override
public boolean visit(LineComment node) {
    _compilationUnit.addComment(/*from   ww  w . j av a  2  s. co m*/
            new CSLineComment(node.getStartPosition(), getText(node.getStartPosition(), node.getLength())));
    return false;
}