use of org.eclipse.jdt.core.dom.Javadoc in project generator by mybatis.
the class ExistingJavaFileVisitor method isGenerated.
@SuppressWarnings("unchecked")
private boolean isGenerated(BodyDeclaration node) {
boolean rc = false;
Javadoc jd = node.getJavadoc();
if (jd != null) {
List<TagElement> tags = jd.tags();
for (TagElement tag : tags) {
String tagName = tag.getTagName();
if (tagName == null) {
continue;
}
for (String javadocTag : javadocTags) {
if (tagName.equals(javadocTag)) {
String string = tag.toString();
if (string.contains("do_not_delete_during_merge")) {
if (node.getNodeType() == ASTNode.TYPE_DECLARATION) {
String name = ((TypeDeclaration) node).getName().getFullyQualifiedName();
generatedInnerClassesToKeep.add(name);
}
} else {
rc = true;
}
break;
}
}
}
}
return rc;
}
use of org.eclipse.jdt.core.dom.Javadoc in project AutoRefactor by JnRouvignac.
the class CommentsRefactoring method visit.
@Override
public boolean visit(CompilationUnit node) {
this.astRoot = node;
for (Comment comment : getCommentList(astRoot)) {
comments.add(Pair.of(new SourceLocation(comment), comment));
}
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;
}
use of org.eclipse.jdt.core.dom.Javadoc in project AutoRefactor by JnRouvignac.
the class CommentsRefactoring method getNextNode.
private ASTNode getNextNode(Comment node) {
final int nodeEndPosition = node.getStartPosition() + node.getLength();
final ASTNode coveringNode = getCoveringNode(node);
final int parentNodeEndPosition = coveringNode.getStartPosition() + coveringNode.getLength();
final NodeFinder finder = new NodeFinder(coveringNode, nodeEndPosition, parentNodeEndPosition - nodeEndPosition);
if (node instanceof Javadoc) {
return finder.getCoveringNode();
}
return finder.getCoveredNode();
}
use of org.eclipse.jdt.core.dom.Javadoc in project fabric8 by jboss-fuse.
the class AddSwaggerAnnotationMojo method addSwaggerApiAnnotation.
private void addSwaggerApiAnnotation(CompilationUnit unit, AnnotationVisitor visitor, File file, Document document) throws JavaModelException, IllegalArgumentException, MalformedTreeException, BadLocationException, IOException {
AST ast = unit.getAST();
ASTRewrite rewriter = ASTRewrite.create(ast);
ListRewrite listRewrite = rewriter.getListRewrite(unit, CompilationUnit.TYPES_PROPERTY);
NormalAnnotation normalAnnotation = rewriter.getAST().newNormalAnnotation();
Name name = ast.newName("com.wordnik.swagger.annotations.Api");
normalAnnotation.setTypeName(name);
MemberValuePair memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("value"));
StringLiteral stringLiteral = ast.newStringLiteral();
String rootPath = visitor.getRootPath();
rootPath = rootPath.substring(1, rootPath.length() - 1);
if (rootPath.endsWith("/")) {
rootPath = rootPath.substring(0, rootPath.length() - 1);
}
stringLiteral.setLiteralValue(rootPath);
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("description"));
stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue("Operations about " + visitor.getRestServiceClass());
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
listRewrite.insertAt(normalAnnotation, 0, null);
for (MethodDeclaration method : visitor.getRestMethod()) {
listRewrite = rewriter.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY);
normalAnnotation = rewriter.getAST().newNormalAnnotation();
name = ast.newName("com.wordnik.swagger.annotations.ApiOperation");
normalAnnotation.setTypeName(name);
memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("value"));
stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue(method.getName().toString());
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
Javadoc doc = method.getJavadoc();
String comment = null;
if (doc != null) {
comment = method.getJavadoc().toString();
}
if (comment != null && comment.length() > 0) {
// add notes from method java doc
memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("notes"));
stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue(comment);
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
}
listRewrite.insertAt(normalAnnotation, 0, null);
listRewrite = rewriter.getListRewrite((ASTNode) ((List) method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY)).get(0), SingleVariableDeclaration.MODIFIERS2_PROPERTY);
normalAnnotation = rewriter.getAST().newNormalAnnotation();
name = ast.newName("com.wordnik.swagger.annotations.ApiParam");
normalAnnotation.setTypeName(name);
((VariableDeclaration) ((List) method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY)).get(0)).getName();
memberValuePair = ast.newMemberValuePair();
memberValuePair.setName(ast.newSimpleName("value"));
stringLiteral = ast.newStringLiteral();
stringLiteral.setLiteralValue(((VariableDeclaration) ((List) method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY)).get(0)).getName().toString());
memberValuePair.setValue(stringLiteral);
normalAnnotation.values().add(memberValuePair);
listRewrite.insertAt(normalAnnotation, 0, null);
}
TextEdit edits = rewriter.rewriteAST(document, null);
edits.apply(document);
FileUtils.writeStringToFile(file, document.get());
}
use of org.eclipse.jdt.core.dom.Javadoc in project eclipse.jdt.ls by eclipse.
the class JavadocContentAccess method internalGetContentReader.
/**
* Gets a reader for an package fragment's Javadoc comment content from the source attachment.
* The content does contain only the text from the comment without the Javadoc leading star characters.
* Returns <code>null</code> if the package fragment does not contain a Javadoc comment or if no source is available.
* @param fragment The package fragment to get the Javadoc of.
* @return Returns a reader for the Javadoc comment content or <code>null</code> if the member
* does not contain a Javadoc comment or if no source is available
* @throws JavaModelException is thrown when the package fragment's javadoc can not be accessed
* @since 3.4
*/
private static Reader internalGetContentReader(IPackageFragment fragment) throws JavaModelException {
IPackageFragmentRoot root = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
// 1==> Handle the case when the documentation is present in package-info.java or package-info.class file
boolean isBinary = root.getKind() == IPackageFragmentRoot.K_BINARY;
ITypeRoot packageInfo;
if (isBinary) {
packageInfo = fragment.getClassFile(PACKAGE_INFO_CLASS);
} else {
packageInfo = fragment.getCompilationUnit(PACKAGE_INFO_JAVA);
}
if (packageInfo != null && packageInfo.exists()) {
String source = packageInfo.getSource();
// the source can be null for some of the class files
if (source != null) {
Javadoc javadocNode = getPackageJavadocNode(fragment, source);
if (javadocNode != null) {
int start = javadocNode.getStartPosition();
int length = javadocNode.getLength();
return new JavaDocCommentReader(source, start, start + length - 1);
}
}
}
return null;
}
Aggregations