List of usage examples for org.eclipse.jdt.core.dom Javadoc getParent
public final ASTNode getParent()
null
if this is the root node. From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java
License:Open Source License
@Override public boolean visit(Javadoc node) { this.noFormatTagOpenStart = -1; this.formatCodeTagOpenEnd = -1; this.lastFormatCodeClosingTagIndex = -1; this.firstTagToken = null; this.ctm = null; int commentIndex = this.tm.firstIndexIn(node, TokenNameCOMMENT_JAVADOC); Token commentToken = this.tm.get(commentIndex); if (node.getParent() == null) { // not a proper javadoc, treat as block comment handleWhitespaceAround(commentIndex); }//from w w w. j av a 2 s.c om if (commentIndex < this.tm.size() - 1) commentToken.breakAfter(); if (handleFormatOnOffTags(commentToken)) return false; boolean isHeader = this.tm.isInHeader(commentIndex); boolean formattingEnabled = (this.options.comment_format_javadoc_comment && !isHeader) || (this.options.comment_format_header && isHeader); if (!formattingEnabled || !tokenizeMultilineComment(commentToken)) { commentToken.setInternalStructure(commentToLines(commentToken, -1)); return false; } this.commentStructure = commentToken.getInternalStructure(); this.commentIndent = this.tm.toIndent(commentToken.getIndent(), true); this.ctm = new TokenManager(commentToken.getInternalStructure(), this.tm); return true; }
From source file:com.google.currysrc.processors.ReplaceSelectedJavadoc.java
License:Apache License
@Override protected String processComment(Reporter reporter, Comment commentNode, String commentText) { if (!(commentNode instanceof Javadoc)) { return null; }//from w w w . j a va 2 s . c o m Javadoc javadoc = (Javadoc) commentNode; ASTNode declarationNode = javadoc.getParent(); if (declarationNode == null || !(declarationNode instanceof BodyDeclaration)) { return null; } BodyDeclaration bodyDeclaration = (BodyDeclaration) declarationNode; for (Replacement replacement : replacements) { if (replacement.locator.matches(bodyDeclaration)) { reporter.info(bodyDeclaration, "Replaced comment text"); return replacement.replacementText; } } return null; }
From source file:com.servoy.eclipse.docgenerator.parser.JavadocExtractor.java
License:Open Source License
@Override public void endVisit(Javadoc node) { if (isInterestingJavadoc(node)) { javadocsStack.pop();// w w w . j a v a2 s. c o m currentJavadoc.compress(); int parentType = node.getParent().getNodeType(); if (parentType == ASTNode.TYPE_DECLARATION) { typesStack.peek().setJavadoc(currentJavadoc); } else if (parentType == ASTNode.METHOD_DECLARATION || parentType == ASTNode.FIELD_DECLARATION) { for (MemberMetaModel memberMM : currentMembers) { memberMM.setJavadoc(currentJavadoc); } } currentJavadoc = null; lastNodeEnd = -1; } }
From source file:com.servoy.eclipse.docgenerator.parser.JavadocExtractor.java
License:Open Source License
private boolean isInterestingJavadoc(Javadoc node) { if (node.getParent() != null) { int parentType = node.getParent().getNodeType(); if (parentType == ASTNode.TYPE_DECLARATION || parentType == ASTNode.METHOD_DECLARATION || parentType == ASTNode.FIELD_DECLARATION) { return true; }//from w ww .j a va2s. com } return false; }
From source file:de.ovgu.featureide.munge.signatures.MungeSignatureBuilder.java
License:Open Source License
private static Collection<AbstractSignature> parse(ProjectSignatures projectSignatures, ASTNode root) { final HashMap<AbstractSignature, AbstractSignature> map = new HashMap<>(); final CompilationUnit cu = (CompilationUnit) root; final PackageDeclaration pckgDecl = cu.getPackage(); final String packageName = (pckgDecl == null) ? null : pckgDecl.getName().getFullyQualifiedName(); List<?> l = cu.getCommentList(); List<Javadoc> cl = new LinkedList<>(); for (Object object : l) { if (object instanceof Javadoc) { Javadoc comment = (Javadoc) object; cl.add(comment);// w ww .jav a2 s. com } } final ListIterator<Javadoc> it = cl.listIterator(); final FeatureDataConstructor featureDataConstructor = new FeatureDataConstructor(projectSignatures, FeatureDataConstructor.TYPE_PP); root.accept(new ASTVisitor() { private BodyDeclaration curDeclaration = null; private PreprocessorFeatureData curfeatureData = null; private String lastComment = null; private MethodDeclaration lastCommentedMethod = null; @Override public boolean visit(Javadoc node) { if (curDeclaration != null) { final StringBuilder sb = new StringBuilder(); while (it.hasNext()) { final Javadoc comment = it.next(); if (comment.getStartPosition() <= curDeclaration.getStartPosition()) { sb.append(comment); sb.append("\n"); } else { it.previous(); break; } } lastComment = sb.toString(); curfeatureData.setComment(lastComment); lastCommentedMethod = (curDeclaration instanceof MethodDeclaration) ? (MethodDeclaration) curDeclaration : null; } return false; } private void attachFeatureData(AbstractSignature curSignature, BodyDeclaration curDeclaration) { this.curDeclaration = curDeclaration; final Javadoc javadoc = curDeclaration.getJavadoc(); final int startPosition = (javadoc == null) ? curDeclaration.getStartPosition() : curDeclaration.getStartPosition() + javadoc.getLength(); curfeatureData = (PreprocessorFeatureData) featureDataConstructor.create(null, unit.getLineNumber(startPosition), unit.getLineNumber(curDeclaration.getStartPosition() + curDeclaration.getLength())); curSignature.setFeatureData(curfeatureData); map.put(curSignature, curSignature); } @Override public boolean visit(CompilationUnit unit) { this.unit = unit; return true; } CompilationUnit unit = null; @Override public boolean visit(MethodDeclaration node) { int pos = unit.getLineNumber(node.getBody().getStartPosition()); int end = unit.getLineNumber(node.getBody().getStartPosition() + node.getBody().getLength()); final MungeMethodSignature methodSignature = new MungeMethodSignature(getParent(node.getParent()), node.getName().getIdentifier(), node.getModifiers(), node.getReturnType2(), node.parameters(), node.isConstructor(), pos, end); attachFeatureData(methodSignature, node); if (node.getJavadoc() == null && lastCommentedMethod != null && lastCommentedMethod.getName().equals(node.getName())) { curfeatureData.setComment(lastComment); } else { lastCommentedMethod = null; } return true; } private AbstractClassSignature getParent(ASTNode astnode) { final AbstractClassSignature sig; if (astnode instanceof TypeDeclaration) { final TypeDeclaration node = (TypeDeclaration) astnode; sig = new MungeClassSignature(null, node.getName().getIdentifier(), node.getModifiers(), node.isInterface() ? "interface" : "class", packageName); } else { return null; } AbstractClassSignature uniqueSig = (AbstractClassSignature) map.get(sig); if (uniqueSig == null) { visit((TypeDeclaration) astnode); } return uniqueSig; } @Override public boolean visit(FieldDeclaration node) { for (Iterator<?> it = node.fragments().iterator(); it.hasNext();) { VariableDeclarationFragment fragment = (VariableDeclarationFragment) it.next(); final MungeFieldSignature fieldSignature = new MungeFieldSignature(getParent(node.getParent()), fragment.getName().getIdentifier(), node.getModifiers(), node.getType()); attachFeatureData(fieldSignature, node); } return true; } @Override public boolean visit(TypeDeclaration node) { final MungeClassSignature classSignature = new MungeClassSignature(getParent(node.getParent()), node.getName().getIdentifier(), node.getModifiers(), node.isInterface() ? "interface" : "class", packageName); attachFeatureData(classSignature, node); return super.visit(node); } }); return map.keySet(); }
From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://w w w . j a va 2 s . co m *<ul> * <li>For any javadoc comment: * <ul> * <li>Comment to <code>ICommentWriter</code>.</li> * </ul></li> *</ul> */ @Override public boolean visit(Javadoc node) { // Write the comment entity if (node.getParent() == null || node.getParent() instanceof PackageDeclaration) { commentWriter.writeUnassociatedJavadocComment(compilationUnitPath, node.getStartPosition(), node.getLength()); } else { commentWriter.writeJavadocComment(fqnStack.getFqn(), compilationUnitPath, node.getStartPosition(), node.getLength()); } return true; }
From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java
License:Open Source License
/** * This method writes://from www.j a va 2 s. c om *<ul> * <li>For any javadoc comment: * <ul> * <li>Comment to <code>ICommentWriter</code>.</li> * </ul></li> *</ul> */ @Override public boolean visit(Javadoc node) { // Write the comment entity if (node.getParent() == null || node.getParent() instanceof PackageDeclaration) { commentWriter.writeComment(Comment.UJAVADOC, createLocation(node)); } else { commentWriter.writeComment(Comment.JAVADOC, fqnStack.getFqn(), createLocation(node)); } return false; }
From source file:org.eclipse.pde.api.tools.internal.builder.TagValidator.java
License:Open Source License
@Override public boolean visit(Javadoc node) { if (!fScanTags) { return false; }// ww w.j av a 2 s . c om ASTNode parent = node.getParent(); if (parent != null) { List<TagElement> tags = node.tags(); validateTags(parent, tags); } return false; }
From source file:org.spoofax.interpreter.adapter.ecj.ECJFactory.java
License:LGPL
private Javadoc asJavadoc(IStrategoTerm term) { Javadoc x = ((WrappedJavadoc) term).getWrappee(); return x.getParent() == null && x.getAST() == ast ? x : (Javadoc) ASTNode.copySubtree(ast, x); }