private String commentContent(final Comment comment) { int _startPosition = comment.getStartPosition(); int _startPosition_1 = comment.getStartPosition(); int _length = comment.getLength(); int _plus = (_startPosition_1 + _length); return this.javaSources.substring(_startPosition, _plus); }
for (Comment comment : (List<Comment>) compilationUnit.getCommentList()) { comment.accept(new CommentVisitor(compilationUnit, classSource.split("\n"))); }
/** * Returns the root AST node that this comment occurs * within, or <code>null</code> if none (or not recorded). * <p> * </p> * * @param root the alternate root node, or <code>null</code> * if none * @see #getAlternateRoot() */ public final void setAlternateRoot(ASTNode root) { // alternate root is *not* considered a structural property // but we protect them nevertheless checkModifiable(); this.alternateRoot = root; }
String commentType = null; if (comment.isDocComment()) { commentNode = parentNode.addNode(ClassFileSequencerLexicon.JAVADOC, ClassFileSequencerLexicon.JAVADOC); } else { commentNode = parentNode.addNode(ClassFileSequencerLexicon.COMMENT, ClassFileSequencerLexicon.COMMENT); if (comment.isBlockComment()) { commentType = ClassFileSequencerLexicon.CommentType.BLOCK.toString(); } else if (comment.isLineComment()) { commentType = ClassFileSequencerLexicon.CommentType.LINE.toString(); } else { final String code = getSourceCode(comment.getStartPosition(), comment.getLength());
private Iterable<Comment> unAssignedComments(final CompilationUnit cu) { final Function1<Comment, Boolean> _function = (Comment c) -> { return Boolean.valueOf(((!(c.isDocComment() && (c.getParent() != null))) && this.notAssigned(c))); }; return IterableExtensions.<Comment>filter(cu.getCommentList(), _function); }
if (firstTrailingCommentIndex >= 0 && commentArray[firstTrailingCommentIndex].isLineComment()) int commentStartPos = commentArray[firstTrailingCommentIndex].getStartPosition(); int commentEndPos = commentStartPos + commentArray[firstTrailingCommentIndex].getLength(); if (compilationUnit.getLineNumber(commentStartPos) == compilationUnit.getLineNumber(nodeEnd))
int treeSize() { int size = memSize(); if (this.optionalPackageDeclaration != null) { size += getPackage().treeSize(); } size += this.imports.listSize(); size += this.types.listSize(); // include disconnected comments if (this.optionalCommentList != null) { for (int i = 0; i < this.optionalCommentList.size(); i++) { Comment comment = (Comment) this.optionalCommentList.get(i); if (comment != null && comment.getParent() == null) { size += comment.treeSize(); } } } return size; }
public int compare(Object o1, Object o2) { return ((Comment) o1).getStartPosition() - ((Comment) o2).getStartPosition(); } });
@Override public void preVisit(final ASTNode node) { if ((((node instanceof Comment) || (node instanceof TagElement)) || (node instanceof TextElement))) { return; } ASTNode _root = node.getRoot(); if ((_root instanceof CompilationUnit)) { ASTNode _root_1 = node.getRoot(); final CompilationUnit cu = ((CompilationUnit) _root_1); final Function1<Comment, Boolean> _function = (Comment it) -> { int _startPosition = it.getStartPosition(); int _startPosition_1 = node.getStartPosition(); return Boolean.valueOf((_startPosition < _startPosition_1)); }; final Consumer<Comment> _function_1 = (Comment it) -> { it.accept(this); this.assignedComments.add(it); }; IterableExtensions.<Comment>filter(this.unAssignedComments(cu), _function).forEach(_function_1); } }
@Override int memSize() { return super.memSize(); }
@Override public boolean visit(CompilationUnit node) { comments.clear(); this.astRoot = node; for (Comment comment : getCommentList(astRoot)) { comments.add(Pair.of(new SourceLocation(comment), comment)); } for (Comment comment : getCommentList(astRoot)) { if (comment.isBlockComment()) { final BlockComment bc = (BlockComment) comment; bc.accept(this); } else if (comment.isLineComment()) { final LineComment lc = (LineComment) comment; lc.accept(this); } else if (comment.isDocComment()) { final Javadoc jc = (Javadoc) comment; jc.accept(this); } else { throw new NotImplementedException(comment); } } return VISIT_SUBTREE; }
/** * Builds a NavigableMap containing all of the given compilation unit's top-level nodes * (package declaration, import declarations, type declarations, and non-doc comments), * keyed by start position. */ private static NavigableMap<Integer, ASTNode> mapTopLevelNodes(CompilationUnit compilationUnit) { NavigableMap<Integer, ASTNode> map = new TreeMap<Integer, ASTNode>(); Collection<ASTNode> nodes = new ArrayList<ASTNode>(); if (compilationUnit.getPackage() != null) { nodes.add(compilationUnit.getPackage()); } nodes.addAll(compilationUnit.imports()); nodes.addAll(compilationUnit.types()); for (Comment comment : ((List<Comment>) compilationUnit.getCommentList())) { // Include only top-level (non-doc) comments; // doc comments are contained within their parent nodes' ranges. if (comment.getParent() == null) { nodes.add(comment); } } for (ASTNode node : nodes) { map.put(node.getStartPosition(), node); } return map; }
@Override final List internalGetChildListProperty(ChildListPropertyDescriptor property) { if (property == TAGS_PROPERTY) { return tags(); } // allow default implementation to flag the error return super.internalGetChildListProperty(property); }
final Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, Object value) { if (property == COMMENT_PROPERTY) { if (get) { return getComment(); } else { setComment((String) value); return null; } } // allow default implementation to flag the error return super.internalGetSetObjectProperty(property, get, value); }
/** * @param compilationUnit * @param comments */ void buildCommentsTable(CompilationUnit compilationUnit, int[][] comments) { // Build comment table this.commentsTable = new Comment[comments.length]; int nbr = 0; for (int i = 0; i < comments.length; i++) { Comment comment = createComment(comments[i]); if (comment != null) { comment.setAlternateRoot(compilationUnit); this.commentsTable[nbr++] = comment; } } // Resize table if necessary if (nbr<comments.length) { Comment[] newCommentsTable = new Comment[nbr]; System.arraycopy(this.commentsTable, 0, newCommentsTable, 0, nbr); this.commentsTable = newCommentsTable; } compilationUnit.setCommentTable(this.commentsTable); }
/** * <pre> * Comment: * LineComment * BlockComment * Javadoc * </pre> * * @param compilationUnit the {@link CompilationUnit compilation unit} being recorded (cannot be <code>null</code>) * @param outputNode the parent {@link Node node} (cannot be <code>null</code>) * @throws Exception if there is a problem */ protected void recordComments( final CompilationUnit compilationUnit, final Node outputNode ) throws Exception { @SuppressWarnings( "unchecked" ) final List<Comment> comments = compilationUnit.getCommentList(); if ((comments != null) && !comments.isEmpty()) { final Node containerNode = outputNode.addNode(ClassFileSequencerLexicon.COMMENTS, ClassFileSequencerLexicon.COMMENTS); for (final Comment comment : comments) { // javadocs are stored with the object they pertain to if (!comment.isDocComment()) { record(comment, containerNode); } } } }
String commentType = null; if (comment.isDocComment()) { commentNode = parentNode.addNode(ClassFileSequencerLexicon.JAVADOC, ClassFileSequencerLexicon.JAVADOC); } else { commentNode = parentNode.addNode(ClassFileSequencerLexicon.COMMENT, ClassFileSequencerLexicon.COMMENT); if (comment.isBlockComment()) { commentType = ClassFileSequencerLexicon.CommentType.BLOCK.toString(); } else if (comment.isLineComment()) { commentType = ClassFileSequencerLexicon.CommentType.LINE.toString(); } else { final String code = getSourceCode(comment.getStartPosition(), comment.getLength());
private Javadoc convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc) { Javadoc docComment = null; if (javadoc != null) { if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) { this.commentMapper = new DefaultCommentMapper(this.commentsTable); } Comment comment = this.commentMapper.getComment(javadoc.sourceStart); if (comment != null && comment.isDocComment() && comment.getParent() == null) { docComment = (Javadoc) comment; if (this.resolveBindings) { recordNodes(docComment, javadoc); // resolve member and method references binding Iterator tags = docComment.tags().listIterator(); while (tags.hasNext()) { recordNodes(javadoc, (TagElement) tags.next()); } } } } return docComment; } public void convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, BodyDeclaration bodyDeclaration) {
int treeSize() { int size = memSize(); if (this.optionalPackageDeclaration != null) { size += getPackage().treeSize(); } size += this.imports.listSize(); size += this.types.listSize(); // include disconnected comments if (this.optionalCommentList != null) { for (int i = 0; i < this.optionalCommentList.size(); i++) { Comment comment = (Comment) this.optionalCommentList.get(i); if (comment != null && comment.getParent() == null) { size += comment.treeSize(); } } } return size; }
public int compare(Object o1, Object o2) { return ((Comment) o1).getStartPosition() - ((Comment) o2).getStartPosition(); } });