/** * Generecized version of the equivalent JDT method. * * @param node the node on which to call the equivalent JDT method * @return a List of expressions * @see CompilationUnit#getCommentList() */ @SuppressWarnings("unchecked") public static List<Comment> getCommentList(CompilationUnit node) { return node.getCommentList(); }
/** * @param compilationUnit to use to get a list of comments and node positions * @param source original source used to create compilation unit */ public CommentAwareSourceRangeComputer(CompilationUnit compilationUnit, String source) { this.compilationUnit = compilationUnit; this.source = source; List<?> commentList = compilationUnit.getCommentList(); if (commentList != null) { this.commentArray = commentList.toArray(new Comment[commentList.size()]); this.commentStartPositions = new int [commentList.size()]; this.commentEndPositions = new int [commentList.size()]; int i = 0; for (Iterator<?> iter = commentList.iterator(); iter.hasNext();) { Comment comment = (Comment)iter.next(); commentStartPositions[i] = comment.getStartPosition(); commentEndPositions[i] = commentStartPositions[i] + comment.getLength(); i++; } } else { this.commentArray = new Comment [0]; this.commentStartPositions = new int [0]; this.commentEndPositions = new int [0]; } }
public void run() { if (null == warningHandler() || null == _ast) { throw new IllegalStateException(); } _ast.accept(this); visit(_ast.getCommentList()); }
/** * @param compilationUnit to use to get a list of comments and node positions * @param source original source used to create compilation unit */ public CommentAwareSourceRangeComputer(CompilationUnit compilationUnit, String source) { this.compilationUnit = compilationUnit; this.source = source; List<?> commentList = compilationUnit.getCommentList(); if (commentList != null) { this.commentArray = (Comment[])commentList.toArray(); this.commentStartPositions = new int [commentList.size()]; this.commentEndPositions = new int [commentList.size()]; int i = 0; for (Iterator<?> iter = commentList.iterator(); iter.hasNext();) { Comment comment = (Comment)iter.next(); commentStartPositions[i] = comment.getStartPosition(); commentEndPositions[i] = commentStartPositions[i] + comment.getLength(); i++; } } else { this.commentArray = new Comment [0]; this.commentStartPositions = new int [0]; this.commentEndPositions = new int [0]; } }
/** * <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); } } } }
/** * <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); } } } }
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); }
/** * 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; }
/** * 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; }
/** * 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; }
private void prepareComments() { CommentsPreparator commentsPreparator = new CommentsPreparator(this.tokenManager, this.workingOptions, this.sourceLevel); List<Comment> comments = ((CompilationUnit) this.astRoot.getRoot()).getCommentList(); for (Comment comment : comments) { comment.accept(commentsPreparator); } commentsPreparator.finishUp(); }
private void prepareComments() { CommentsPreparator commentsPreparator = new CommentsPreparator(this.tokenManager, this.workingOptions, this.sourceLevel); List<Comment> comments = ((CompilationUnit) this.astRoot.getRoot()).getCommentList(); for (Comment comment : comments) { comment.accept(commentsPreparator); } commentsPreparator.finishUp(); }
private void prepareComments() { CommentsPreparator commentsPreparator = new CommentsPreparator(this.tokenManager, this.workingOptions, this.sourceLevel); List<Comment> comments = ((CompilationUnit) this.astRoot.getRoot()).getCommentList(); for (Comment comment : comments) { comment.accept(commentsPreparator); } commentsPreparator.finishUp(); }
private void prepareComments() { CommentsPreparator commentsPreparator = new CommentsPreparator(this.tokenManager, this.workingOptions, this.sourceLevel); List<Comment> comments = ((CompilationUnit) this.astRoot.getRoot()).getCommentList(); for (Comment comment : comments) { comment.accept(commentsPreparator); } commentsPreparator.finishUp(); }
public void ensureCommentFromBodyDeclaration(SourcedEntity entity, BodyDeclaration node) { if (node.getJavadoc() != null) createBasicComment(entity, node.getJavadoc().toString()); else { // if there is no javadoc, we look for single line or multi line comments before // the node CompilationUnit root = (CompilationUnit) node.getRoot(); int firstLeadingCommentIndex = root.firstLeadingCommentIndex(node); if (firstLeadingCommentIndex >= 0) // There seems to be a problem here: JDT does not seem to provide the contents // of the comments. // Only the types (one line or multi line). createBasicComment(entity, root.getCommentList().get(firstLeadingCommentIndex).toString()); } }
protected IValue convertToM3(LimitedTypeStore store, Map<String, ISourceLocation> cache, ISourceLocation loc, CompilationUnit cu) { SourceConverter converter = new SourceConverter(store, cache); converter.convert(cu, cu, loc); for (Object cm: cu.getCommentList()) { Comment comment = (Comment)cm; // Issue 720: changed condition to only visit comments without a parent (includes line, block and misplaced javadoc comments). if (comment.getParent() != null) continue; converter.convert(cu, comment, loc); } return converter.getModel(true); }
List commentNodes= astRoot instanceof CompilationUnit ? ((CompilationUnit) astRoot).getCommentList() : null; Map currentOptions = options == null ? JavaCore.getOptions() : options; return internalRewriteAST(content, lineInfo, lineDelim, commentNodes, currentOptions, rootNode, (RecoveryScannerData)((CompilationUnit) astRoot).getStatementsRecoveryData());
LineInformation lineInfo= LineInformation.create(document); String lineDelim= TextUtilities.getDefaultLineDelimiter(document); List comments= rootNode.getCommentList();
LineInformation lineInfo= LineInformation.create(document); String lineDelim= TextUtilities.getDefaultLineDelimiter(document); List comments= rootNode.getCommentList();
LineInformation lineInfo= LineInformation.create(document); String lineDelim= TextUtilities.getDefaultLineDelimiter(document); List comments= rootNode.getCommentList();