Example usage for org.eclipse.jdt.core IMethod getRawParameterNames

List of usage examples for org.eclipse.jdt.core IMethod getRawParameterNames

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IMethod getRawParameterNames.

Prototype

String[] getRawParameterNames() throws JavaModelException;

Source Link

Document

Returns the names of parameters in this method.

Usage

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

License:Open Source License

/**
 * Visit a {@code IMethod}./*from   ww w. j  a v a 2  s  . c o  m*/
 * 
 * @param method
 *            the {@code IMethod}
 * @return the {@link AbstractMethodDeclaration} object corresponding to the
 *         {@code IMethod}, or {@code null} if the method does not exist or
 *         is {@link org.eclipse.jdt.core.Flags#isSynthetic(int) synthetic}
 *         or is {@link org.eclipse.jdt.core.Flags#isBridge(int) bridge} or
 *         its name equals the special name <code>"&lt;clinit&gt;"</code>
 * @throws JavaModelException
 * @see org.eclipse.jdt.core.IMethod#getElementName()
 */
protected AbstractMethodDeclaration visitMethod(final IMethod method) throws JavaModelException {
    if (Flags.isSynthetic(method.getFlags()) || Flags.isBridge(method.getFlags())
            || method.getElementName().equals("<clinit>")) { //$NON-NLS-1$
        return null;
    }

    this.currentlyVisitedJavaElement = method;
    AbstractMethodDeclaration element = null;
    if (method.isConstructor()) {
        element = getFactory().createConstructorDeclaration();
    } else {
        element = getFactory().createMethodDeclaration();
    }
    initializeNode(element);

    element.setName(method.getElementName());

    // throwns exceptions
    for (String exc : method.getExceptionTypes()) {
        element.getThrownExceptions().add(getRefOnType(exc));
    }

    // return type
    if (!method.isConstructor()) {
        String returnType = method.getReturnType();
        ((MethodDeclaration) element).setReturnType(getRefOnType(returnType));
    }

    // type parameters
    ITypeParameter[] parameters = method.getTypeParameters();
    for (ITypeParameter parameter : parameters) {
        TypeParameter t = getFactory().createTypeParameter();
        element.getTypeParameters().add(t);
        visitTypeParameter(parameter, t);
    }

    // parameters
    for (int i = 0; i < method.getNumberOfParameters(); i++) {
        String parameterType = method.getParameterTypes()[i];
        String parameterName = method.getRawParameterNames()[i];

        SingleVariableDeclaration var = getFactory().createSingleVariableDeclaration();
        initializeNode(var);
        element.getParameters().add(var);
        var.setMethodDeclaration(element);
        var.setName(parameterName);
        var.setExtraArrayDimensions(0);
        // varargs option for the last argument
        if (i == method.getNumberOfParameters() - 1) {
            boolean isMethodVarargs = Flags.isVarargs(method.getFlags());
            var.setVarargs(isMethodVarargs);
        }

        var.setType(getRefOnType(parameterType));
    }

    // annotations
    for (IAnnotation annotation : method.getAnnotations()) {
        Annotation anno = getFactory().createAnnotation();
        element.getAnnotations().add(anno);
        visitAnnotation(annotation, anno);
    }

    // visibility modifier
    Modifier m = getFactory().createModifier();
    element.setModifier(m);
    m.setBodyDeclaration(element);
    manageModifier(m, method.getFlags(), method);

    ClassFileParserUtils.manageBindingDeclaration(element, method, this);

    return element;
}

From source file:org.eclipseguru.gwt.core.internal.codegen.AsyncServiceCodeGenerator.java

License:Open Source License

/**
 * Appends all existing parameters from the specified method to the
 * specified buffer//  ww w.  j a va  2 s .com
 * 
 * @param method
 * @param buffer
 * @throws JavaModelException
 */
private void appendMethodParameters(final IMethod method, final StringBuffer buffer) throws CoreException {
    final String[] parameterTypes = method.getParameterTypes();
    final String[] parameterNames = method.getRawParameterNames();
    final int flags = method.getFlags();
    final boolean varargs = Flags.isVarargs(flags);
    final int parameterLength = parameterTypes.length;
    for (int j = 0; j < parameterLength; j++) {
        if (j > 0) {
            buffer.append(","); //$NON-NLS-1$
        }
        buffer.append(Signature.toString(parameterTypes[j]));
        if (varargs && (j == parameterLength - 1)) {
            final int length = buffer.length();
            if ((length >= 2) && (buffer.indexOf("[]", length - 2) >= 0)) {
                buffer.setLength(length - 2);
            }
            buffer.append("..."); //$NON-NLS-1$
        }
        buffer.append(" "); //$NON-NLS-1$
        buffer.append(parameterNames[j]);
    }
}