List of usage examples for org.eclipse.jdt.core.dom Comment isBlockComment
public final boolean isBlockComment()
BlockComment). 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)); }//from ww w . j a v a 2s . co 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.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 ww. ja v a2s .com*/ } 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.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>/*from w w w .java2 s. com*/ * 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); }