List of usage examples for org.eclipse.jdt.core.dom Comment isDocComment
public final boolean isDocComment()
Javadoc). From source file:org.autorefactor.refactoring.rules.CommentsRefactoring.java
License:Open Source License
@Override public boolean visit(CompilationUnit node) { this.astRoot = node; for (Comment comment : getCommentList(astRoot)) { comments.add(Pair.of(new SourceLocation(comment), comment)); }// w w w.java2 s.c o m 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; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public void convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, BodyDeclaration bodyDeclaration) { if (bodyDeclaration.getJavadoc() == null) { if (javadoc != null) { if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) { this.commentMapper = new DefaultCommentMapper(this.commentsTable); }/*from w w w . j av a2 s .c o m*/ Comment comment = this.commentMapper.getComment(javadoc.sourceStart); if (comment != null && comment.isDocComment() && comment.getParent() == null) { Javadoc 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()); } } bodyDeclaration.setJavadoc(docComment); } } } }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public void convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, PackageDeclaration packageDeclaration) { switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: return;// ww w .j av a2 s .c o m } if (packageDeclaration.getJavadoc() == 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) { Javadoc 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()); } } packageDeclaration.setJavadoc(docComment); } } } }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.CompilationUnit node) { CompilationUnit element = (CompilationUnit) this.binding.get(node); // if any type of this cu already exists in the model, we don't // visit this cu if (this.isAlreadyVisited) { return;// w w w . jav a 2s . c o m } this.jdtModel.getCompilationUnits().add(element); ITypeRoot rootType = node.getTypeRoot(); if (rootType != null) { if (rootType instanceof IClassFile) { // type comes from a .class file ClassFile classFile = this.factory.createClassFile(); classFile.setName(rootType.getElementName()); classFile.setAttachedSource(element); classFile.setOriginalFilePath(this.currentFilePath); Archive ar = LibraryReader.getArchive((IClassFile) rootType, this.factory, this.jdtModel); if (ar == null) { this.jdtModel.getClassFiles().add(classFile); } else { ar.getClassFiles().add(classFile); } } else if (rootType instanceof ICompilationUnit) { // type comes a .java file IPath absolutePath = null; try { absolutePath = rootType.getCorrespondingResource().getLocation(); } catch (JavaModelException e) { absolutePath = ResourcesPlugin.getWorkspace().getRoot().getRawLocation() .append(rootType.getPath()); } element.setOriginalFilePath(absolutePath.toOSString()); } else { element.setOriginalFilePath(""); //$NON-NLS-1$ } element.setName(rootType.getElementName()); } else { element.setProxy(true); } Package packageDeclaration = (Package) this.binding.get(node.getPackage()); element.setPackage(packageDeclaration); for (Object importNode : node.imports()) { ImportDeclaration importDeclaration = (ImportDeclaration) this.binding.get(importNode); element.getImports().add(importDeclaration); } for (Object typeNode : node.types()) { AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) this.binding.get(typeNode); element.getTypes().add(typeDeclaration); } try { // accessing BlockComment and LineComment // (https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=84528) List<?> comments = node.getCommentList(); for (Object name : comments) { org.eclipse.jdt.core.dom.Comment aComment = (org.eclipse.jdt.core.dom.Comment) name; Comment commentElement = null; if (aComment.isLineComment()) { commentElement = this.factory.createLineComment(); initializeNode(commentElement, aComment); String content = CommentsManager.extractCommentContent(aComment, this.javaContent); commentElement.setContent(content); this.binding.put(aComment, commentElement); } else if (aComment.isBlockComment()) { commentElement = this.factory.createBlockComment(); initializeNode(commentElement, aComment); String content = CommentsManager.extractCommentContent(aComment, this.javaContent); commentElement.setContent(content); this.binding.put(aComment, commentElement); } else if (aComment.isDocComment()) { // one javadoc node (and its tag elements) should have been // already visited commentElement = (Javadoc) this.binding.get(aComment); if (commentElement == null) { // happen if more than one javadoc // for a node commentElement = this.factory.createJavadoc(); initializeNode(commentElement, aComment); } commentElement.setContent(aComment.toString()); } getCommentsBinding().put(aComment, commentElement); // initialisation of element CompilationUnit element.getCommentList().add(commentElement); } CommentsManager.resolveCommentPositions(this); } catch (StringIndexOutOfBoundsException e) { // IGNORE hub, sam, markus } }
From source file:org.eclipse.xtend.core.javaconverter.JavaASTFlattener.java
License:Open Source License
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))); };//from w ww . ja v a 2 s .co m return IterableExtensions.<Comment>filter(cu.getCommentList(), _function); }
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>/* ww w.j a v a 2 s. c om*/ * Comment: * LineComment * BlockComment * Javadoc * </pre> * * @param comment the comment being recorded (cannot be <code>null</code>) * @param parentNode the {@link Node parent node} (cannot be <code>null</code>) * @throws Exception if there is a problem */ protected void record(final Comment comment, final Node parentNode) throws Exception { Node commentNode = null; 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 { assert false; LOGGER.error(JavaFileI18n.unhandledCommentType, comment.getClass().getName()); } commentNode.setProperty(ClassFileSequencerLexicon.COMMENT_TYPE, commentType); } final String code = getSourceCode(comment.getStartPosition(), comment.getLength()); if (!StringUtil.isBlank(code)) { commentNode.setProperty(ClassFileSequencerLexicon.COMMENT, code); } recordSourceReference(comment, commentNode); }
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>/*from w w w. j av a2s . c o m*/ * 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); } } } }