Example usage for org.eclipse.jdt.core.dom MethodDeclaration getJavadoc

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration getJavadoc

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MethodDeclaration getJavadoc.

Prototype

public Javadoc getJavadoc() 

Source Link

Document

Returns the doc comment node.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(MethodDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//w  w w.  ja v a 2 s .c  o  m
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
        if (!node.typeParameters().isEmpty()) {
            this.fBuffer.append("<");//$NON-NLS-1$
            for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.fBuffer.append(", ");//$NON-NLS-1$
                }
            }
            this.fBuffer.append("> ");//$NON-NLS-1$
        }
    }
    if (!node.isConstructor()) {
        if (node.getReturnType2() != null) {
            node.getReturnType2().accept(this);
        } else {
            // methods really ought to have a return type
            this.fBuffer.append("void");//$NON-NLS-1$
        }
        this.fBuffer.append(" ");//$NON-NLS-1$
    }
    node.getName().accept(this);
    this.fBuffer.append("(");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS8) {
        Type receiverType = node.getReceiverType();
        if (receiverType != null) {
            receiverType.accept(this);
            this.fBuffer.append(' ');
            SimpleName qualifier = node.getReceiverQualifier();
            if (qualifier != null) {
                qualifier.accept(this);
                this.fBuffer.append('.');
            }
            this.fBuffer.append("this"); //$NON-NLS-1$
            if (node.parameters().size() > 0) {
                this.fBuffer.append(',');
            }
        }
    }
    for (Iterator<SingleVariableDeclaration> it = node.parameters().iterator(); it.hasNext();) {
        SingleVariableDeclaration v = it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(", ");//$NON-NLS-1$
        }
    }
    this.fBuffer.append(")");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS8) {
        List<Dimension> dimensions = node.extraDimensions();
        for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext();) {
            Dimension e = it.next();
            e.accept(this);
        }
    } else {
        for (int i = 0; i < node.getExtraDimensions(); i++) {
            this.fBuffer.append("[]"); //$NON-NLS-1$
        }
    }
    List<? extends ASTNode> thrownExceptions = node.getAST().apiLevel() >= AST.JLS8
            ? node.thrownExceptionTypes()
            : getThrownExceptions(node);
    if (!thrownExceptions.isEmpty()) {
        this.fBuffer.append(" throws ");//$NON-NLS-1$
        for (Iterator<? extends ASTNode> it = thrownExceptions.iterator(); it.hasNext();) {
            ASTNode n = it.next();
            n.accept(this);
            if (it.hasNext()) {
                this.fBuffer.append(", ");//$NON-NLS-1$
            }
        }
        this.fBuffer.append(" ");//$NON-NLS-1$
    }
    if (node.getBody() == null) {
        this.fBuffer.append(";");//$NON-NLS-1$
    } else {
        node.getBody().accept(this);
    }
    return false;
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w ww.  j a v  a 2  s .c  om*/
public boolean visit(MethodDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }
    fInMethodDeclaration = true;

    // @Inria
    pushNode(node, node.getName().toString());
    //

    visitListAsNode(EntityType.MODIFIERS, node.modifiers());
    if (node.getReturnType2() != null) {
        node.getReturnType2().accept(this);
    }
    visitListAsNode(EntityType.TYPE_ARGUMENTS, node.typeParameters());
    visitListAsNode(EntityType.PARAMETERS, node.parameters());
    visitListAsNode(EntityType.THROW, node.thrownExceptions());

    // @Inria
    // The body can be null when the method declaration is from a interface
    if (node.getBody() != null) {
        node.getBody().accept(this);
    }
    return false;

}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(MethodDeclaration node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }// ww  w  . ja  va 2  s  .  c om
    printIndent();
    hook_beforeVisitMethodDeclaration(node);
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
        if (!node.typeParameters().isEmpty()) {
            this.buffer.append("<");//$NON-NLS-1$
            for (Iterator it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = (TypeParameter) it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(",");//$NON-NLS-1$
                }
            }
            this.buffer.append(">");//$NON-NLS-1$
        }
    }
    if (!node.isConstructor()) {
        if (node.getReturnType2() != null) {
            node.getReturnType2().accept(this);
        } else {
            // methods really ought to have a return type
            this.buffer.append("void");//$NON-NLS-1$
        }

        this.buffer.append(" ");//$NON-NLS-1$
    }
    node.getName().accept(this);
    this.buffer.append("(");//$NON-NLS-1$
    for (Iterator it = node.parameters().iterator(); it.hasNext();) {
        SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
        v.accept(this);
        if (it.hasNext()) {
            this.buffer.append(",");//$NON-NLS-1$
        }
    }
    this.buffer.append(")");//$NON-NLS-1$
    for (int i = 0; i < node.getExtraDimensions(); i++) {
        this.buffer.append("[]"); //$NON-NLS-1$
    }
    if (!node.thrownExceptions().isEmpty()) {
        this.buffer.append(" throws ");//$NON-NLS-1$
        for (Iterator it = node.thrownExceptions().iterator(); it.hasNext();) {
            Name n = (Name) it.next();
            n.accept(this);
            if (it.hasNext()) {
                this.buffer.append(", ");//$NON-NLS-1$
            }
        }
        this.buffer.append(" ");//$NON-NLS-1$
    }
    if (node.getBody() == null) {
        this.buffer.append(";\n");//$NON-NLS-1$
    } else {
        node.getBody().accept(this);
    }
    return false;
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaClass_OwnedMethods.java

License:Open Source License

/**
 * @flowerModelElementId _zb9VX5iOEd6aNMdNFvR5WQ
 *///  w ww.java2 s  .c  o m
@Override
protected String getUIDForAstElement(MethodDeclaration astElement) {
    Javadoc docComment = astElement.getJavadoc();
    if (docComment == null)
        return null;
    else
        return SyncUtils.getFlowerModelElementID((String) docComment.getProperty("comment"));
}

From source file:com.google.gdt.eclipse.designer.builders.GwtBuilder.java

License:Open Source License

/**
 * Generates Async type for given <code>RemoteService</code>.
 *///from w w  w.j  a  v  a 2s  . co  m
private void generateAsync(IPackageFragment servicePackage, ICompilationUnit serviceUnit) throws Exception {
    IJavaProject javaProject = serviceUnit.getJavaProject();
    // parse service unit
    CompilationUnit serviceRoot = Utils.parseUnit(serviceUnit);
    // prepare AST and start modifications recording
    AST ast = serviceRoot.getAST();
    serviceRoot.recordModifications();
    // modify imports (-com.google.gwt.*, -*Exception, +AsyncCallback) 
    {
        List<ImportDeclaration> imports = DomGenerics.imports(serviceRoot);
        // remove useless imports
        for (Iterator<ImportDeclaration> I = imports.iterator(); I.hasNext();) {
            ImportDeclaration importDeclaration = I.next();
            String importName = importDeclaration.getName().getFullyQualifiedName();
            if (importName.startsWith("com.google.gwt.user.client.rpc.")
                    || importName.equals("com.google.gwt.core.client.GWT")
                    || importName.endsWith("Exception")) {
                I.remove();
            }
        }
    }
    // add Async to the name
    TypeDeclaration serviceType = (TypeDeclaration) serviceRoot.types().get(0);
    String remoteServiceAsyncName = serviceType.getName().getIdentifier() + "Async";
    serviceType.setName(serviceRoot.getAST().newSimpleName(remoteServiceAsyncName));
    // update interfaces
    updateInterfacesOfAsync(javaProject, serviceRoot, serviceType);
    // change methods, fields and inner classes
    {
        List<BodyDeclaration> bodyDeclarations = DomGenerics.bodyDeclarations(serviceType);
        for (Iterator<BodyDeclaration> I = bodyDeclarations.iterator(); I.hasNext();) {
            BodyDeclaration bodyDeclaration = I.next();
            if (bodyDeclaration instanceof MethodDeclaration) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
                // make return type void
                Type returnType;
                {
                    returnType = methodDeclaration.getReturnType2();
                    methodDeclaration.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
                }
                // process JavaDoc
                {
                    Javadoc javadoc = methodDeclaration.getJavadoc();
                    if (javadoc != null) {
                        List<TagElement> tags = DomGenerics.tags(javadoc);
                        for (Iterator<TagElement> tagIter = tags.iterator(); tagIter.hasNext();) {
                            TagElement tag = tagIter.next();
                            if ("@gwt.typeArgs".equals(tag.getTagName())) {
                                tagIter.remove();
                            } else if ("@return".equals(tag.getTagName())) {
                                if (!tag.fragments().isEmpty()) {
                                    tag.setTagName("@param callback the callback to return");
                                } else {
                                    tagIter.remove();
                                }
                            } else if ("@wbp.gwt.Request".equals(tag.getTagName())) {
                                tagIter.remove();
                                addImport(serviceRoot, "com.google.gwt.http.client.Request");
                                methodDeclaration.setReturnType2(ast.newSimpleType(ast.newName("Request")));
                            }
                        }
                        // remove empty JavaDoc
                        if (tags.isEmpty()) {
                            methodDeclaration.setJavadoc(null);
                        }
                    }
                }
                // add AsyncCallback parameter
                {
                    addImport(serviceRoot, "com.google.gwt.user.client.rpc.AsyncCallback");
                    // prepare "callback" type
                    Type callbackType;
                    {
                        callbackType = ast.newSimpleType(ast.newName("AsyncCallback"));
                        Type objectReturnType = getObjectType(returnType);
                        ParameterizedType parameterizedType = ast.newParameterizedType(callbackType);
                        DomGenerics.typeArguments(parameterizedType).add(objectReturnType);
                        callbackType = parameterizedType;
                    }
                    // prepare "callback" parameter
                    SingleVariableDeclaration asyncCallback = ast.newSingleVariableDeclaration();
                    asyncCallback.setType(callbackType);
                    asyncCallback.setName(ast.newSimpleName("callback"));
                    // add "callback" parameter
                    DomGenerics.parameters(methodDeclaration).add(asyncCallback);
                }
                // remove throws
                methodDeclaration.thrownExceptions().clear();
            } else if (bodyDeclaration instanceof FieldDeclaration
                    || bodyDeclaration instanceof TypeDeclaration) {
                // remove the fields and inner classes
                I.remove();
            }
        }
    }
    // apply modifications to prepare new source code
    String newSource;
    {
        String source = serviceUnit.getBuffer().getContents();
        Document document = new Document(source);
        // prepare text edits
        MultiTextEdit edits = (MultiTextEdit) serviceRoot.rewrite(document, javaProject.getOptions(true));
        removeAnnotations(serviceType, source, edits);
        // prepare new source code
        edits.apply(document);
        newSource = document.get();
    }
    // update compilation unit
    {
        ICompilationUnit unit = servicePackage.createCompilationUnit(remoteServiceAsyncName + ".java",
                newSource, true, null);
        unit.getBuffer().save(null, true);
    }
}

From source file:com.kodebeagle.javaparser.MethodInvocationResolver.java

License:Apache License

private void addMethodDoc(MethodDeclaration node) {
    if (node.getJavadoc() != null && node.getParent() instanceof AbstractTypeDeclaration) {
        String typeName = ((AbstractTypeDeclaration) node.getParent()).getName().getFullyQualifiedName();
        String fullTypeName = currentPackage + "." + removeSpecialSymbols(typeName);
        TypeJavadoc typeJavadoc = typeJavadocs.get(fullTypeName);
        if (typeJavadoc != null) {
            typeJavadoc.getMethodJavadocs().add(
                    new MethodJavadoc(node.getName().getFullyQualifiedName(), node.getJavadoc().toString()));
        }/*from  w  w  w.j a va2 s  . co m*/
    }
}

From source file:com.motorola.studio.android.model.java.JavaClass.java

License:Apache License

/**
 * Adds documentation reference to a method (the see tag to the javadoc)
 * /*from w w w.  ja v  a 2s  .c  o m*/
 * @param element The method declaration object
 * @param qualifiedClassName The full qualified class name to refer
 * @param methodName The method to refer
 * @param parameters The method parameters
 */
@SuppressWarnings("unchecked")
protected void addMethodReference(MethodDeclaration element, String qualifiedClassName, String methodName,
        Type[] parameters) {
    String[] fqnArray = getFQNAsArray(qualifiedClassName);

    MethodRef methodRef = ast.newMethodRef();
    methodRef.setQualifier(
            ast.newQualifiedName(ast.newName(getQualifier(fqnArray)), ast.newSimpleName(getName(fqnArray))));

    methodRef.setName(ast.newSimpleName(methodName));

    if ((parameters != null) && (parameters.length > 0)) {
        for (Type param : parameters) {
            MethodRefParameter methodParam = ast.newMethodRefParameter();
            methodParam.setType(param);
            methodRef.parameters().add(methodParam);
        }
    }

    Javadoc javadoc = element.getJavadoc();
    TagElement tagElement = ast.newTagElement();
    tagElement.setTagName(TagElement.TAG_SEE);

    if (javadoc == null) {
        javadoc = ast.newJavadoc();
        element.setJavadoc(javadoc);
    }

    tagElement.fragments().add(methodRef);
    javadoc.tags().add(tagElement);
}

From source file:com.t3.doccreator.MethodDefinition.java

License:Open Source License

public MethodDefinition(MethodDeclaration m) {
    this.name = m.getName().getIdentifier();
    this.returnType = m.getReturnType2().toString();
    parameters = new HashMap<String, ParameterDefinition>();
    for (Object o : m.parameters()) {
        SingleVariableDeclaration svd = (SingleVariableDeclaration) o;
        parameters.put(svd.getName().getIdentifier(),
                new ParameterDefinition(svd.getType().toString(), svd.getName().getIdentifier()));
    }//w  w  w . ja  v a2  s . c  om
    throwingException = !m.thrownExceptions().isEmpty();
    if (m.getJavadoc() != null)
        parseDoc(m.getJavadoc());
}

From source file:ctrus.pa.bow.java.token.MethodTokens.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void addTokens(ASTNode node) {
    // Check if the node is a MethodDeclaration 
    if (!(node instanceof MethodDeclaration))
        throw new IllegalArgumentException(
                "Expecting method declaration but found " + node.getClass().getName());

    MethodDeclaration mth = (MethodDeclaration) node;

    // Add method name
    String methodName = mth.getName().getFullyQualifiedName();
    addInterfaceToken(methodName);// ww w  .  j  a  v  a2s.  c  om

    // Add method declaration parameters and create unique method name
    String uniqueMethodName = "";
    uniqueMethodName = methodName;

    for (SingleVariableDeclaration param : (List<SingleVariableDeclaration>) mth.parameters()) {
        if (!_stateAnalysis) {
            addInterfaceToken(param.getName().getIdentifier());
            addInterfaceToken(param.getType().toString());
        }
        uniqueMethodName = uniqueMethodName + " " + param.getType().toString();
    }

    // Set the identifier of this token-set
    setIdentifier(uniqueMethodName);

    // Add return type
    if (!mth.isConstructor()) {
        boolean skipReturn = false;
        Type mthReturn = mth.getReturnType2();
        if (mthReturn == null) {
            skipReturn = true;
        } else if (mthReturn.isPrimitiveType()) {
            if (PrimitiveType.VOID.equals(((PrimitiveType) mthReturn).getPrimitiveTypeCode()))
                skipReturn = true;
        }
        if (!skipReturn)
            addInterfaceToken(mthReturn.toString());
    }

    // update method identifier position in the Java source text
    updateIdentifierPosition(mth);

    // Add exceptions thrown by method
    if (!_stateAnalysis) {
        for (Object exception : mth.thrownExceptionTypes()) {
            addInterfaceToken(((SimpleType) exception).getName().getFullyQualifiedName());
        }
    }

    // Visit the method body to collect terms           
    Block block = mth.getBody();
    if (_hasBody && block != null) { // Found method body
        block.accept(new ASTVisitor() {
            public boolean visit(StringLiteral node) {
                if (!_stateAnalysis) {
                    addToken(node.toString());
                }
                return true;
            }

            public boolean visit(SimpleName node) {
                addToken(node.toString());
                return true;
            }
        });
    }

    // Add java doc comment found for the method
    if (!_ignoreComments && !_stateAnalysis && mth.getJavadoc() != null) {
        List<TagElement> jDocComments = (List<TagElement>) mth.getJavadoc().tags();
        for (TagElement jDocComment : jDocComments) {
            addCommentToken(jDocComment.toString());
        }
    }
}

From source file:de.akra.idocit.java.services.JavaInterfaceGenerator.java

License:Apache License

/**
 * Apply the changes to the methods with the documentations for the parameters.
 * /*w  w w.j a v  a2  s.  com*/
 * @param methods
 *            The {@link JavaMethod} that should be processed.
 */
private static void updateMethods(List<JavaMethod> methods, IJavadocGenerator javadocGenerator)
        throws ParsingException {
    for (JavaMethod method : methods) {
        if (SignatureElementUtils.isOperationsDocChanged(method)) {
            List<JavadocTagElement> jDocTags = createMethodJavadocTagElements(method);

            MethodDeclaration methodDeclaration = method.getRefToASTNode();
            Javadoc javadoc = createOrUpdateJavadoc(jDocTags, method.getAdditionalTags(),
                    methodDeclaration.getJavadoc(), methodDeclaration.getAST(), method.getThematicGridName(),
                    javadocGenerator, method);

            // if an existing Javadoc was updated it must not be set again!
            if ((methodDeclaration.getJavadoc() == null && javadoc != null)
                    || (methodDeclaration.getJavadoc() != null && javadoc == null)) {
                methodDeclaration.setJavadoc(javadoc);
            }
        }
    }
}