Search in sources :

Example 51 with Javadoc

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;
}
Also used : Javadoc(org.eclipse.jdt.core.dom.Javadoc) TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 52 with Javadoc

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;
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) NotImplementedException(org.autorefactor.util.NotImplementedException) Javadoc(org.eclipse.jdt.core.dom.Javadoc) LineComment(org.eclipse.jdt.core.dom.LineComment)

Example 53 with Javadoc

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();
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) Javadoc(org.eclipse.jdt.core.dom.Javadoc) NodeFinder(org.eclipse.jdt.core.dom.NodeFinder)

Example 54 with Javadoc

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());
}
Also used : AST(org.eclipse.jdt.core.dom.AST) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Javadoc(org.eclipse.jdt.core.dom.Javadoc) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) Name(org.eclipse.jdt.core.dom.Name) MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) StringLiteral(org.eclipse.jdt.core.dom.StringLiteral) TextEdit(org.eclipse.text.edits.TextEdit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) VariableDeclaration(org.eclipse.jdt.core.dom.VariableDeclaration) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration)

Example 55 with Javadoc

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;
}
Also used : ITypeRoot(org.eclipse.jdt.core.ITypeRoot) Javadoc(org.eclipse.jdt.core.dom.Javadoc) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

Javadoc (org.eclipse.jdt.core.dom.Javadoc)68 AST (org.eclipse.jdt.core.dom.AST)33 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)31 ASTNode (org.eclipse.jdt.core.dom.ASTNode)30 TagElement (org.eclipse.jdt.core.dom.TagElement)25 Type (org.eclipse.jdt.core.dom.Type)25 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)20 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)17 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)16 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)16 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)15 Block (org.eclipse.jdt.core.dom.Block)15 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)14 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)14 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)14 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)14 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)12 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)12 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)12 TextElement (org.eclipse.jdt.core.dom.TextElement)11