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

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

Introduction

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

Prototype

public Type getReturnType() 

Source Link

Document

Returns the return type of the method declared in this method declaration, exclusive of any extra array dimensions (JLS2 API only).

Usage

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(MethodDeclaration node) {
    sb.printIndent();/*from   ww w  .j  a  va2  s .  co m*/
    printModifiers(node.getModifiers());
    IMethodBinding meth = node.getMethodBinding();
    printTypeParameters(meth.getTypeParameters());
    if (!node.isConstructor()) {
        if (node.getReturnType() != null) {
            node.getReturnType().accept(this);
        }
        sb.print(' ');
    }
    node.getName().accept(this);
    sb.print("(");
    for (Iterator<SingleVariableDeclaration> it = node.getParameters().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            sb.print(',');
        }
    }
    sb.print(")");
    ITypeBinding[] exceptions = meth.getExceptionTypes();
    if (exceptions.length > 0) {
        sb.print(" throws ");
        for (int i = 0; i < exceptions.length;) {
            sb.print(exceptions[i].getName());
            if (++i < exceptions.length) {
                sb.print(',');
            }
        }
        sb.print(' ');
    }
    if (node.getBody() == null) {
        sb.println(';');
    } else {
        node.getBody().accept(this);
    }
    return false;
}

From source file:com.j2swift.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(MethodDeclaration node) {
    sb.printIndent();/*w w  w.  j  a va 2s .  c o  m*/
    printAnnotations(node.getAnnotations());
    printModifiers(node.getModifiers());
    IMethodBinding meth = node.getMethodBinding();
    printTypeParameters(meth.getTypeParameters());
    if (!node.isConstructor()) {
        if (node.getReturnType() != null) {
            node.getReturnType().accept(this);
        }
        sb.print(' ');
    }
    node.getName().accept(this);
    sb.print("(");
    for (Iterator<SingleVariableDeclaration> it = node.getParameters().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            sb.print(',');
        }
    }
    sb.print(")");
    ITypeBinding[] exceptions = meth.getExceptionTypes();
    if (exceptions.length > 0) {
        sb.print(" throws ");
        for (int i = 0; i < exceptions.length;) {
            sb.print(exceptions[i].getName());
            if (++i < exceptions.length) {
                sb.print(',');
            }
        }
        sb.print(' ');
    }
    if (node.getBody() == null) {
        sb.println(';');
    } else {
        node.getBody().accept(this);
    }
    return false;
}

From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java

License:Open Source License

public boolean visit(MethodDeclaration node) {
    java.util.Map.Entry<IValueList, IValueList> extendedModifiers = parseExtendedModifiers(node);

    IValueList genericTypes = new IValueList(values);
    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (!node.typeParameters().isEmpty()) {
            for (Iterator it = node.typeParameters().iterator(); it.hasNext();) {
                TypeParameter t = (TypeParameter) it.next();
                genericTypes.add(visitChild(t));
            }//www . ja  v a 2 s .co  m
        }
    }

    IValue returnType = null;
    if (!node.isConstructor()) {
        if (node.getAST().apiLevel() == AST.JLS2) {
            returnType = visitChild(node.getReturnType());
        } else if (node.getReturnType2() != null) {
            returnType = visitChild(node.getReturnType2());
        } else {
            // methods really ought to have a return type
            returnType = values.constructor(Java.CONS_VOID);
        }
    }

    IValue name = values.string(node.getName().getFullyQualifiedName());

    IValueList parameters = new IValueList(values);
    for (Iterator it = node.parameters().iterator(); it.hasNext();) {
        SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
        parameters.add(visitChild(v));
    }

    /*
     * for (int i = 0; i < node.getExtraDimensions(); i++) {
     * //this.buffer.append("[]"); //$NON-NLS-1$ // TODO: Do these need to be included in the node tree? 
     * }
     */

    IValueList possibleExceptions = new IValueList(values);
    if (!node.thrownExceptions().isEmpty()) {

        for (Iterator it = node.thrownExceptions().iterator(); it.hasNext();) {
            Name n = (Name) it.next();
            possibleExceptions.add(visitChild(n));
        }
    }

    IValue body = node.getBody() == null ? null : visitChild(node.getBody());

    ownValue = constructRascalNode(node, extendedModifiers.getKey().asList(),
            extendedModifiers.getValue().asList(), genericTypes.asList(), optional(returnType), name,
            parameters.asList(), possibleExceptions.asList(), optional(body));
    return false;
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

/**
 * Internal synonym for {@link MethodDeclaration#getReturnType()}. Use to
 * alleviate deprecation warnings./*from   ww w.  java  2  s .c o m*/
 * 
 * @deprecated
 * @since 3.4
 */
private static Type getReturnType(MethodDeclaration node) {
    return node.getReturnType();
}

From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java

License:Open Source License

@Override
public void endVisit(final org.eclipse.jdt.core.dom.MethodDeclaration node) {
    AbstractMethodDeclaration element = (AbstractMethodDeclaration) this.binding.get(node);
    initializeNode(element, node);/*from   w w  w  .  j a  v  a2 s. c o m*/

    if (!node.isConstructor()) {
        ((MethodDeclaration) element).setExtraArrayDimensions(node.getExtraDimensions());
    }

    for (Iterator<?> i = node.parameters().iterator(); i.hasNext();) {
        SingleVariableDeclaration itElement = (SingleVariableDeclaration) this.binding.get(i.next());
        if (itElement != null) {
            itElement.setProxy(false);
            itElement.setMethodDeclaration(element);
            element.getParameters().add(itElement);
        }
    }

    if (this.binding.get(node.getBody()) != null) {
        element.setBody((Block) this.binding.get(node.getBody()));
    }
    if (this.isINCREMENTALDISCOVERING) {
        // To avoid to re-create an existing access type
        List<TypeAccess> thrownExceptionsList = new ArrayList<TypeAccess>(element.getThrownExceptions());
        Iterator<TypeAccess> thrownExceptions = thrownExceptionsList.iterator();
        while (thrownExceptions.hasNext()) {
            TypeAccess typeAccess = thrownExceptions.next();
            element.getThrownExceptions().remove(typeAccess);
            deepRemove(typeAccess);
        }
    }
    for (Iterator<?> i = node.thrownExceptions().iterator(); i.hasNext();) {
        ASTNode itElement = this.binding.get(i.next());
        if (itElement != null) {
            element.getThrownExceptions().add(JDTVisitorUtils.completeTypeAccess(itElement, this));
        }
    }

    element.setName(node.getName().getIdentifier());

    if (this.binding.get(node.getReturnType2()) != null) {
        MethodDeclaration methodDeclaration = (MethodDeclaration) element;
        if (this.isINCREMENTALDISCOVERING && methodDeclaration.getReturnType() != null) {
            // To avoid to re-create an existing access type
            deepRemove(methodDeclaration.getReturnType());
            methodDeclaration.setReturnType(null);
        }
        methodDeclaration.setReturnType(
                JDTVisitorUtils.completeTypeAccess(this.binding.get(node.getReturnType2()), this));
    }

    for (Iterator<?> i = node.typeParameters().iterator(); i.hasNext();) {
        TypeParameter itElement = (TypeParameter) this.binding.get(i.next());
        if (itElement != null) {
            element.getTypeParameters().add(itElement);
        }
    }
    endVisitBD(node, element);

    // long debut = System.currentTimeMillis();

    getLocalBindings().resolveBindings();

    // long fin = System.currentTimeMillis();
    // TimeResults.resolveBindings += fin - debut;

    // localBindings should be kept if method is declared in anonymous class
    // declared in a method body
    if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.AnonymousClassDeclaration
            || node.getParent().getParent() instanceof org.eclipse.jdt.core.dom.TypeDeclarationStatement)) {
        setLocalBindings(null);
    }

    JDTVisitorUtils.manageBindingDeclaration(element, node.getName(), this);
}

From source file:processing.mode.java.pdex.CompletionCandidate.java

License:Open Source License

public CompletionCandidate withRegeneratedCompString() {
    if (wrappedObject instanceof MethodDeclaration) {
        MethodDeclaration method = (MethodDeclaration) wrappedObject;

        @SuppressWarnings("unchecked")
        List<ASTNode> params = (List<ASTNode>) method
                .getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);

        StringBuilder label = new StringBuilder(elementName + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < params.size(); i++) {
            label.append(params.get(i).toString());
            if (i < params.size() - 1) {
                label.append(",");
                cstr.append(",");
            }/*from w ww  .  ja v  a  2 s .co  m*/
        }
        if (params.size() == 1) {
            cstr.append(' ');
        }
        label.append(")");
        if (method.getReturnType2() != null)
            label.append(" : " + method.getReturnType2());
        cstr.append(")");
        return this.withLabelAndCompString(label.toString(), cstr.toString());
    } else if (wrappedObject instanceof Method) {
        Method method = (Method) wrappedObject;
        StringBuilder label = new StringBuilder("<html>" + method.getName() + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < method.getParameterTypes().length; i++) {
            label.append(method.getParameterTypes()[i].getSimpleName());
            if (i < method.getParameterTypes().length - 1) {
                label.append(",");
                cstr.append(",");
            }
        }
        if (method.getParameterTypes().length == 1) {
            cstr.append(' ');
        }
        label.append(")");
        if (method.getReturnType() != null)
            label.append(" : " + method.getReturnType().getSimpleName());
        label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
        cstr.append(")");
        return this.withLabelAndCompString(label.toString(), cstr.toString());
        /*
         * StringBuilder label = new StringBuilder("<html>"+method.getName() + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < method.getParameterTypes().length; i++) {
         label.append(method.getParameterTypes()[i].getSimpleName());
         if (i < method.getParameterTypes().length - 1) {
           label.append(",");
           cstr.append(",");
         }
        }
        if(method.getParameterTypes().length == 1) {
         cstr.append(' ');
        }
        label.append(")");
        if(method.getReturnType() != null)
         label.append(" : " + method.getReturnType().getSimpleName());
        label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
         * */
    }
    return this;
}