List of usage examples for org.eclipse.jdt.core.dom Javadoc accept
public final void accept(ASTVisitor visitor)
From source file:com.bsiag.eclipse.jdt.java.formatter.DefaultCodeFormatter.java
License:Open Source License
private TextEdit formatComments(String source, int kind, IRegion[] regions) { MultiTextEdit result = new MultiTextEdit(); if (!init(source)) return result; CommentsPreparator commentsPreparator = new CommentsPreparator(this.tokenManager, this.workingOptions, this.sourceLevel); CommentWrapExecutor commentWrapper = new CommentWrapExecutor(this.tokenManager, this.workingOptions); switch (kind) { case K_JAVA_DOC: ASTParser parser = ASTParser.newParser(AST.JLS8); for (Token token : this.tokens) { if (token.tokenType == TokenNameCOMMENT_JAVADOC) { parser.setSourceRange(token.originalStart, token.countChars()); CompilationUnit cu = (CompilationUnit) parseSourceCode(parser, ASTParser.K_COMPILATION_UNIT, true);// w ww .j av a2 s .c o m Javadoc javadoc = (Javadoc) cu.getCommentList().get(0); javadoc.accept(commentsPreparator); int startPosition = this.tokenManager.findSourcePositionInLine(token.originalStart); commentWrapper.wrapMultiLineComment(token, startPosition, false, false); } } break; case K_MULTI_LINE_COMMENT: for (int i = 0; i < this.tokens.size(); i++) { Token token = this.tokens.get(i); if (token.tokenType == TokenNameCOMMENT_BLOCK) { commentsPreparator.handleBlockComment(i); int startPosition = this.tokenManager.findSourcePositionInLine(token.originalStart); commentWrapper.wrapMultiLineComment(token, startPosition, false, false); } } break; case K_SINGLE_LINE_COMMENT: for (int i = 0; i < this.tokens.size(); i++) { Token token = this.tokens.get(i); if (token.tokenType == TokenNameCOMMENT_LINE) { commentsPreparator.handleLineComment(i); if (i >= this.tokens.size() || this.tokens.get(i) != token) { // current token has been removed and merged with previous one i--; token = this.tokens.get(i); } int startPosition = this.tokenManager.findSourcePositionInLine(token.originalStart); commentWrapper.wrapLineComment(token, startPosition); } } break; default: throw new AssertionError(String.valueOf(kind)); } this.tokenManager.applyFormatOff(); TextEditsBuilder resultBuilder = new TextEditsBuilder(source, regions, this.tokenManager, this.workingOptions); resultBuilder.setAlignChar(DefaultCodeFormatterOptions.SPACE); for (Token token : this.tokens) { List<Token> structure = token.getInternalStructure(); if (structure != null && !structure.isEmpty()) resultBuilder.processComment(token); } for (TextEdit edit : resultBuilder.getEdits()) { result.addChild(edit); } return result; }
From source file:com.google.currysrc.processors.BaseTagElementNodeScanner.java
License:Apache License
@Override protected final void visit(final Reporter reporter, Javadoc javadoc, final ASTRewrite rewrite) { javadoc.accept(new ASTVisitor(true /* visitDocTags */) { @Override/*ww w. ja v a 2 s. c o m*/ public boolean visit(TagElement node) { return visitTagElement(reporter, rewrite, node); } }); }
From source file:com.t3.doccreator.MethodDefinition.java
License:Open Source License
private void parseDoc(Javadoc javadoc) { javadoc.accept(new ASTVisitor(true) { @Override// w ww . j ava2 s . co m public boolean visit(TagElement node) { List<?> f = node.fragments(); if (node.getTagName() == null) for (Object o : f) { if (o instanceof TextElement) doc += ((TextElement) o).getText(); else if (o instanceof TagElement) { TagElement te = (TagElement) o; if (te.getTagName().equals("@link")) { if (te.fragments().size() == 2) doc += te.fragments().get(1).toString(); else if (te.fragments().size() == 1) doc += te.fragments().get(0).toString().substring(1); else throw new Error(); } else throw new Error(); } else throw new Error(); } else if (f.size() >= 2 && node.getTagName().equals("@param")) try { parameters.get(((SimpleName) f.get(0)).toString()).setComment(f.subList(1, f.size()) .stream().map(Object::toString).collect(Collectors.joining())); } catch (NullPointerException npe) { System.err.println("NPE for " + getName() + " -> " + ((SimpleName) f.get(0)).toString()); } else if (node.getTagName().equals("@return")) returnComment = f.stream().map(Object::toString).collect(Collectors.joining("\n")); else if (f.size() == 2 && node.getTagName().equals("@throws")) errorComment = ((TextElement) f.get(1)).getText(); else if (node.getTagName().equals("@author")) ; else if (node.getTagName().equals("@see")) ; else throw new Error(node.toString()); return false; } }); String[] lines = doc.split("\n"); doc = ""; for (String l : lines) { l = l.trim(); if (l.startsWith("*")) l = l.substring(1); if (l.startsWith("/**")) l = l.substring(3); if (l.startsWith("**/")) l = l.substring(3); if (l.endsWith("/")) l = l.substring(0, l.length() - 1); doc += l.trim() + "\n"; } }
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 ava 2 s . c om 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.pde.api.tools.ui.internal.completion.APIToolsJavadocCompletionProposalComputer.java
License:Open Source License
/** * Collects the existing tags on the {@link IJavaElement} we have been * activated on/*from ww w . ja v a 2 s . c om*/ * * @param element * @param jcontext * @throws JavaModelException * @throws BadLocationException */ private void collectExistingTags(IJavaElement element, JavaContentAssistInvocationContext jcontext) throws JavaModelException { if (element instanceof IMember) { IMember member = (IMember) element; ICompilationUnit cunit = jcontext.getCompilationUnit(); if (cunit != null) { if (cunit.isWorkingCopy()) { cunit.reconcile(ICompilationUnit.NO_AST, false, false, null, null); } fParser.setSource(member.getSource().toCharArray()); fParser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); Map<String, String> options = element.getJavaProject().getOptions(true); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); fParser.setCompilerOptions(options); fParser.setStatementsRecovery(false); fParser.setResolveBindings(false); fParser.setBindingsRecovery(false); ASTNode ast = fParser.createAST(null); TagCollector collector = new TagCollector(); if (ast.getNodeType() == ASTNode.TYPE_DECLARATION) { TypeDeclaration typeDeclaration = (TypeDeclaration) ast; List<BodyDeclaration> bodyDeclarations = typeDeclaration.bodyDeclarations(); if (bodyDeclarations.size() == 1) { // only one element should be there as we are parsing a // specific member BodyDeclaration bodyDeclaration = bodyDeclarations.iterator().next(); Javadoc javadoc = bodyDeclaration.getJavadoc(); if (javadoc != null) { javadoc.accept(collector); } } } } } }
From source file:ptolemy.backtrack.eclipse.ast.ASTFormatter.java
License:Open Source License
/** Visit an ast node, and return whether its children should be further * visited./* ww w. ja v a 2s .c o m*/ * * @param node The AST node. * @return Whether its children should be further visited. */ public boolean visit(TypeDeclaration node) { Javadoc javadoc = node.getJavadoc(); if (javadoc != null) { javadoc.accept(this); } _output(_indent); _outputModifiers(node.modifiers()); _output(node.isInterface() ? "interface " : "class "); //$NON-NLS-2$ node.getName().accept(this); if (node.getAST().apiLevel() >= AST.JLS3) { if (!node.typeParameters().isEmpty()) { _output("<"); Iterator it; for (it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = (TypeParameter) it.next(); t.accept(this); if (it.hasNext()) { _output(", "); } } _output(">"); } } _output(" "); if (node.getSuperclassType() != null) { _output("extends "); node.getSuperclassType().accept(this); _output(" "); } if (!node.superInterfaceTypes().isEmpty()) { _output(node.isInterface() ? "extends " : "implements "); //$NON-NLS-2$ Iterator it; for (it = node.superInterfaceTypes().iterator(); it.hasNext();) { Type t = (Type) it.next(); t.accept(this); if (it.hasNext()) { _output(", "); } } _output(" "); } _openBrace(); _output("\n"); BodyDeclaration prev = null; Iterator it; for (it = node.bodyDeclarations().iterator(); it.hasNext();) { BodyDeclaration d = (BodyDeclaration) it.next(); // FindBugs reports: A known null value is checked to see if it is an instance of a type // if (prev instanceof EnumConstantDeclaration) { // // enum constant declarations do not include punctuation // if (d instanceof EnumConstantDeclaration) { // // enum constant declarations are separated by commas // _output(", "); // } else { // // semicolon separates last enum constant declaration from // // first class body declarations // _output("; "); // } // } d.accept(this); } _checkComments((node.getStartPosition() + node.getLength()) - 1); _closeBrace(); _output("\n"); return false; }