Example usage for org.eclipse.jdt.core.dom IMethodBinding getName

List of usage examples for org.eclipse.jdt.core.dom IMethodBinding getName

Introduction

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

Prototype

@Override
public String getName();

Source Link

Document

Returns the name of the method declared in this binding.

Usage

From source file:astview.Binding.java

License:Open Source License

@Override
public String getLabel() {
    StringBuffer buf = new StringBuffer(fLabel);
    buf.append(": "); //$NON-NLS-1$
    if (fBinding != null) {
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            if (!variableBinding.isField()) {
                buf.append(variableBinding.getName());
            } else {
                if (variableBinding.getDeclaringClass() == null) {
                    buf.append("<some array type>"); //$NON-NLS-1$
                } else {
                    buf.append(variableBinding.getDeclaringClass().getName());
                }//from   w  w  w. j a  v  a 2  s . c o  m
                buf.append('.');
                buf.append(variableBinding.getName());
            }
            break;
        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            buf.append(packageBinding.getName());
            break;
        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            appendAnnotatedQualifiedName(buf, typeBinding);
            break;
        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            buf.append(methodBinding.getDeclaringClass().getName());
            buf.append('.');
            buf.append(methodBinding.getName());
            buf.append('(');
            ITypeBinding[] parameters = methodBinding.getParameterTypes();
            for (int i = 0; i < parameters.length; i++) {
                if (i > 0) {
                    buf.append(", "); //$NON-NLS-1$
                }
                ITypeBinding parameter = parameters[i];
                buf.append(parameter.getName());
            }
            buf.append(')');
            break;
        case IBinding.ANNOTATION:
        case IBinding.MEMBER_VALUE_PAIR:
            buf.append(fBinding.toString());
            break;
        }

    } else {
        buf.append("null"); //$NON-NLS-1$
    }
    return buf.toString();

}

From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java

License:Open Source License

/**
 * Gets the soot method sub signature./*from ww w. ja va  2  s .c o m*/
 * 
 * @return the soot method sub signature
 */
public String getSootMethodSubSignature() {
    IMethodBinding methodBinding = methodDeclaration.resolveBinding();
    ITypeBinding[] argumentsBinding = methodBinding.getParameterTypes();
    ITypeBinding returnBinding = methodBinding.getReturnType();

    StringBuilder stringMethodBuilder = new StringBuilder();

    stringMethodBuilder.append(returnBinding.getQualifiedName());
    stringMethodBuilder.append(" ");
    if (methodDeclaration.isConstructor()) {
        stringMethodBuilder.append("<init>");
    } else {
        stringMethodBuilder.append(methodBinding.getName());
    }
    stringMethodBuilder.append("(");

    for (int index = 0; index < argumentsBinding.length; index++) {
        stringMethodBuilder.append(argumentsBinding[index].getQualifiedName());
        if (!(index == argumentsBinding.length - 1)) {
            stringMethodBuilder.append(",");
        }
    }

    stringMethodBuilder.append(")");
    return stringMethodBuilder.toString();
}

From source file:br.ufal.cideei.util.MethodDeclarationSootMethodBridge.java

License:Open Source License

/**
 * Gets the soot method signature.//from   w w  w .  java  2  s . c o  m
 * 
 * @return the soot method signature
 */
public String getSootMethodSignature() {
    IMethodBinding methodBinding = methodDeclaration.resolveBinding();
    ITypeBinding[] argumentsBinding = methodBinding.getParameterTypes();
    ITypeBinding declaringTypeBinding = methodBinding.getDeclaringClass();
    ITypeBinding returnBinding = methodBinding.getReturnType();

    StringBuilder stringMethodBuilder = new StringBuilder("<");
    stringMethodBuilder.append(declaringTypeBinding.getQualifiedName());
    stringMethodBuilder.append(": ");
    stringMethodBuilder.append(returnBinding.getQualifiedName());
    stringMethodBuilder.append(" ");
    stringMethodBuilder.append(methodBinding.getName());
    stringMethodBuilder.append("(");

    for (int index = 0; index < argumentsBinding.length; index++) {
        stringMethodBuilder.append(argumentsBinding[index].getQualifiedName());
        if (!(index == argumentsBinding.length - 1)) {
            stringMethodBuilder.append(",");
        }
    }

    stringMethodBuilder.append(")>");
    return stringMethodBuilder.toString();
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean processReference(MethodDeclaration method, IMethodBinding methodBinding, Annotation annotation,
        IAnnotationBinding annotationBinding, IDSDocumentFactory factory, Collection<IDSReference> collector,
        Map<String, Annotation> names, Collection<DSAnnotationProblem> problems) {
    HashMap<String, Object> params = new HashMap<String, Object>();
    for (IMemberValuePairBinding pair : annotationBinding.getDeclaredMemberValuePairs()) {
        params.put(pair.getName(), pair.getValue());
    }/* w w  w . jav  a  2s  . c o  m*/

    boolean requiresV12 = false;

    ITypeBinding[] argTypes = methodBinding.getParameterTypes();

    ITypeBinding serviceType;
    Object value;
    if ((value = params.get("service")) instanceof ITypeBinding) { //$NON-NLS-1$
        serviceType = (ITypeBinding) value;
        if (!errorLevel.isNone() && argTypes.length > 0) {
            ITypeBinding[] typeArgs;
            if (!(ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName())
                    && ((typeArgs = argTypes[0].getTypeArguments()).length == 0
                            || serviceType.isAssignmentCompatible(typeArgs[0])))
                    && !serviceType.isAssignmentCompatible(argTypes[0]))
                reportProblem(annotation, "service", problems, //$NON-NLS-1$
                        NLS.bind(Messages.AnnotationProcessor_invalidReferenceService, argTypes[0].getName(),
                                serviceType.getName()),
                        serviceType.getName());
        }
    } else if (argTypes.length > 0) {
        if (ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName())) {
            ITypeBinding[] typeArgs = argTypes[0].getTypeArguments();
            if (typeArgs.length > 0)
                serviceType = typeArgs[0];
            else
                serviceType = null;
        } else {
            serviceType = argTypes[0].isPrimitive() ? getObjectType(method.getAST(), argTypes[0]) : argTypes[0];
        }
    } else {
        serviceType = null;
    }

    if (serviceType == null) {
        reportProblem(annotation, null, problems, Messages.AnnotationProcessor_invalidReferenceServiceUnknown);

        serviceType = method.getAST().resolveWellKnownType(Object.class.getName());
    }

    validateReferenceBindMethod(annotation, serviceType, methodBinding, problems);

    String service = serviceType == null ? null : serviceType.getBinaryName();

    String methodName = methodBinding.getName();
    String name;
    if ((value = params.get("name")) instanceof String) { //$NON-NLS-1$
        name = (String) value;
    } else if (methodName.startsWith("bind")) { //$NON-NLS-1$
        name = methodName.substring("bind".length()); //$NON-NLS-1$
    } else if (methodName.startsWith("set")) { //$NON-NLS-1$
        name = methodName.substring("set".length()); //$NON-NLS-1$
    } else if (methodName.startsWith("add")) { //$NON-NLS-1$
        name = methodName.substring("add".length()); //$NON-NLS-1$
    } else {
        name = methodName;
    }

    if (!errorLevel.isNone()) {
        if (names.containsKey(name)) {
            reportProblem(annotation, "name", problems, //$NON-NLS-1$
                    NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name);
            Annotation duplicate = names.put(name, null);
            if (duplicate != null)
                reportProblem(duplicate, "name", problems, //$NON-NLS-1$
                        NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name);
        } else {
            names.put(name, annotation);
        }
    }

    String cardinality = null;
    if ((value = params.get("cardinality")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding cardinalityBinding = (IVariableBinding) value;
        ReferenceCardinality cardinalityLiteral = ReferenceCardinality.valueOf(cardinalityBinding.getName());
        if (cardinalityLiteral != null)
            cardinality = cardinalityLiteral.toString();
    }

    String policy = null;
    if ((value = params.get("policy")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding policyBinding = (IVariableBinding) value;
        ReferencePolicy policyLiteral = ReferencePolicy.valueOf(policyBinding.getName());
        if (policyLiteral != null)
            policy = policyLiteral.toString();
    }

    String target = null;
    if ((value = params.get("target")) instanceof String) { //$NON-NLS-1$
        target = (String) value;
        validateReferenceTarget(annotation, target, problems);
    }

    String unbind;
    if ((value = params.get("unbind")) instanceof String) { //$NON-NLS-1$
        String unbindValue = (String) value;
        if ("-".equals(unbindValue)) { //$NON-NLS-1$
            unbind = null;
        } else {
            unbind = unbindValue;
            if (!errorLevel.isNone() && serviceType != null) {
                IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(),
                        serviceType, unbind);
                if (unbindMethod == null)
                    reportProblem(annotation, "unbind", problems, //$NON-NLS-1$
                            NLS.bind(Messages.AnnotationProcessor_invalidReferenceUnbind, unbind), unbind);
            }
        }
    } else if (serviceType != null) {
        String unbindCandidate;
        if (methodName.startsWith("add")) { //$NON-NLS-1$
            unbindCandidate = "remove" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            unbindCandidate = "un" + methodName; //$NON-NLS-1$
        }

        IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType,
                unbindCandidate);
        if (unbindMethod == null)
            unbind = null;
        else
            unbind = unbindMethod.getName();
    } else {
        unbind = null;
    }

    String policyOption = null;
    if ((value = params.get("policyOption")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding policyOptionBinding = (IVariableBinding) value;
        ReferencePolicyOption policyOptionLiteral = ReferencePolicyOption
                .valueOf(policyOptionBinding.getName());
        if (policyOptionLiteral != null) {
            policyOption = policyOptionLiteral.toString();
            requiresV12 = true;
        }
    }

    String updated;
    if ((value = params.get("updated")) instanceof String) { //$NON-NLS-1$
        String updatedValue = (String) value;
        if ("-".equals(updatedValue)) { //$NON-NLS-1$
            updated = null;
        } else {
            updated = updatedValue;
            if (!errorLevel.isNone() && serviceType != null) {
                IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(),
                        serviceType, updated);
                if (updatedMethod == null)
                    reportProblem(annotation, "updated", problems, //$NON-NLS-1$
                            NLS.bind(Messages.AnnotationProcessor_invalidReferenceUpdated, updated), updated);
            }
        }

        requiresV12 = true;
    } else if (serviceType != null) {
        String updatedCandidate;
        if (methodName.startsWith("bind")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("bind".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (methodName.startsWith("set")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("set".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (methodName.startsWith("add")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            updatedCandidate = "updated" + methodName; //$NON-NLS-1$
        }

        IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType,
                updatedCandidate);
        if (updatedMethod == null)
            updated = null;
        else
            updated = updatedMethod.getName();
    } else {
        updated = null;
    }

    IDSReference reference = factory.createReference();
    collector.add(reference);

    reference.setReferenceBind(methodName);

    if (name != null)
        reference.setReferenceName(name);

    if (service != null)
        reference.setReferenceInterface(service);

    if (cardinality != null)
        reference.setReferenceCardinality(cardinality);

    if (policy != null)
        reference.setReferencePolicy(policy);

    if (target != null)
        reference.setReferenceTarget(target);

    if (unbind != null)
        reference.setReferenceUnbind(unbind);

    if (policyOption != null)
        reference.setXMLAttribute("policy-option", policyOption); //$NON-NLS-1$

    if (updated != null)
        reference.setXMLAttribute("updated", updated); //$NON-NLS-1$

    return requiresV12;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private IMethodBinding findReferenceMethod(ITypeBinding componentClass, ITypeBinding serviceType, String name) {
    ITypeBinding testedClass = componentClass;

    IMethodBinding candidate = null;/*from  ww w.j  a  va  2  s  . c o  m*/
    int priority = 0;
    // priority:
    // 0: <assignment-compatible-type>, Map
    // 1: <exact-type>, Map
    // 2: <assignment-compatible-type>
    // 3: <exact-type>
    do {
        for (IMethodBinding declaredMethod : testedClass.getDeclaredMethods()) {
            if (name.equals(declaredMethod.getName())
                    && Void.TYPE.getName().equals(declaredMethod.getReturnType().getName())
                    && (testedClass.isEqualTo(componentClass)
                            || Modifier.isPublic(declaredMethod.getModifiers())
                            || Modifier.isProtected(declaredMethod.getModifiers())
                            || (!Modifier.isPrivate(declaredMethod.getModifiers())
                                    && testedClass.getPackage().isEqualTo(componentClass.getPackage())))) {
                ITypeBinding[] paramTypes = declaredMethod.getParameterTypes();
                if (paramTypes.length == 1) {
                    if (ServiceReference.class.getName().equals(paramTypes[0].getErasure().getQualifiedName()))
                        // we have the winner
                        return declaredMethod;

                    if (priority < 3 && serviceType.isEqualTo(paramTypes[0]))
                        priority = 3;
                    else if (priority < 2 && serviceType.isAssignmentCompatible(paramTypes[0]))
                        priority = 2;
                    else
                        continue;

                    // we have a (better) candidate
                    candidate = declaredMethod;
                } else if (paramTypes.length == 2) {
                    if (priority < 1 && serviceType.isEqualTo(paramTypes[0])
                            && Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName()))
                        priority = 1;
                    else if (candidate != null || !serviceType.isAssignmentCompatible(paramTypes[0])
                            || !Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName()))
                        continue;

                    // we have a candidate
                    candidate = declaredMethod;
                }
            }
        }
    } while ((testedClass = testedClass.getSuperclass()) != null);

    return candidate;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * Converts a method binding to a method element.
 * /*from   www . java2s  .c  o m*/
 * @param pBinding
 *            The binding to covert. Cannot be null.
 * @return A method element corresponding to pBinding. Never null.
 */
private static IElement convertBinding(final IMethodBinding pBinding) {
    ASTCrawler.checkForNull(pBinding);
    String lReturn = null;
    try {
        lReturn = ASTCrawler.convertBinding(pBinding.getDeclaringClass()).getId() + ".";
    } catch (final NullPointerException E) {
        E.printStackTrace();
        throw E;
    }
    if (pBinding.isConstructor())
        lReturn += "<init>";
    else
        lReturn += pBinding.getName();
    lReturn += "(";
    final ITypeBinding lParamBindings[] = pBinding.getParameterTypes();
    for (int i = 0; i < lParamBindings.length - 1; i++) {
        lReturn += ASTCrawler.convertParameterTypeBinding(lParamBindings[i]).getId();
        lReturn += ",";
    }
    if (lParamBindings.length > 0)
        lReturn += ASTCrawler.convertParameterTypeBinding(lParamBindings[lParamBindings.length - 1]).getId();
    lReturn += ")";

    return FlyweightElementFactory.getElement(Category.METHOD, lReturn);
}

From source file:ca.mcgill.cs.swevo.ppa.ui.ASTUtil.java

License:Open Source License

private static void getMethodBindingHandle(IBinding binding, boolean augmented, StringBuffer handle) {
    IMethodBinding methodBinding = (IMethodBinding) binding;
    handle.append(METHOD_KIND);//from   w  w w  . j  a  v a2  s. c  o  m
    if (augmented) {
        handle.append(AUGMENTED_HANDLE_SEPARATOR);
        if (methodBinding.isAnnotationMember()) {
            handle.append(ANNOTATION_PARAMETER_KIND);
        } else {
            handle.append(METHOD_KIND);
        }
    }
    handle.append(HANDLE_SEPARATOR);
    handle.append(getNonEmptyTypeString(getTypeString(methodBinding.getDeclaringClass())));
    handle.append(HANDLE_SEPARATOR);
    handle.append(getNonEmptyName(methodBinding.getName()));
    for (ITypeBinding param : methodBinding.getParameterTypes()) {
        handle.append(HANDLE_SEPARATOR);
        handle.append(getNonEmptyTypeString(getTypeString(param)));
    }
}

From source file:ca.mcgill.cs.swevo.ppa.ui.NameMapVisitor.java

License:Open Source License

private String addBindingText(IBinding binding, ASTNode node, boolean isDeclaration) {
    String bindingText = "";
    if (binding != null) {
        if (binding instanceof IMethodBinding) {
            IMethodBinding mBinding = (IMethodBinding) binding;
            String methodName = mBinding.getName();
            if (!filterUnknown || methodName == null || !methodName.equals(SnippetUtil.SNIPPET_METHOD)) {
                if (encoded) {
                    bindingText = ASTUtil.getHandle(binding, augmented);
                } else {
                    bindingText = PPABindingsUtil.getFullMethodSignature(mBinding);

                }//  w ww .  ja v  a2s  .c  o  m
                bindings.add(bindingText);
                bindingsType.add(METHOD_TYPE);
                declarations.add(isDeclaration);
                nodes.add(node);
            }
        } else if (binding instanceof IVariableBinding) {
            IVariableBinding vBinding = (IVariableBinding) binding;
            if (vBinding.isField()) {
                if (encoded) {
                    bindingText = ASTUtil.getHandle(binding, augmented);
                } else {
                    String type = "nil";
                    if (vBinding.getType() != null) {
                        type = PPABindingsUtil.getTypeString(vBinding.getType());
                    }

                    String decType = "nil";
                    if (vBinding.getDeclaringClass() != null) {
                        decType = PPABindingsUtil.getTypeString(vBinding.getDeclaringClass());
                    }
                    bindingText = type + " " + decType + ":" + vBinding.getName();
                }
                bindings.add(bindingText);
                bindingsType.add(FIELD_TYPE);
                declarations.add(isDeclaration);
                nodes.add(node);
            }
        } else if (binding instanceof ITypeBinding) {
            ITypeBinding typeBinding = (ITypeBinding) binding;
            bindingText = typeBinding.getName();
            // TODO Change SNIPPET FOR SOMETHING THAT WON't BREAK ANYTHING
            // AND HANDLE
            // SUPERSNIPPET!!!
            if (!filterUnknown || (!bindingText.contains(PPATypeRegistry.UNKNWON_CLASS)
                    && !bindingText.contains(SnippetUtil.SNIPPET_CLASS)
                    && !bindingText.contains(SnippetUtil.SNIPPET_SUPER_CLASS))) {
                if (encoded) {
                    bindingText = ASTUtil.getHandle(binding, augmented);
                }
                bindings.add(bindingText);
                bindingsType.add(TYPE_TYPE);
                declarations.add(isDeclaration);
                nodes.add(node);
            }
        }
    }
    return bindingText;
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

private static String methodNameHelper(MethodDeclaration methodNode, IMethodBinding method, boolean override) {
    if (override && hasOverrideAnnotation(method)) {
        getSuperMethodNames(method);/* w  ww .j a  v  a 2  s .co m*/
    }

    StringBuilder sb = new StringBuilder();

    sb.append(modifierHelper(method));

    sb.append("[");

    String declaringClass = BindingFactory.getBindingName(method.getDeclaringClass());
    if (method.isConstructor()) {
        sb.append(CsTypeName.newTypeName(declaringClass).getIdentifier());
    } else {
        String returnType = BindingFactory.getBindingName(method.getReturnType());
        sb.append(CsTypeName.newTypeName(returnType).getIdentifier());
    }

    sb.append("] [");
    sb.append(CsTypeName.newTypeName(declaringClass).getIdentifier());
    sb.append("].");

    if (method.isConstructor()) {
        sb.append(".ctor");
    } else {
        sb.append(method.getName());
    }

    sb.append("(");

    String[] parameterNames = createParameterNames(methodNode, method);

    for (int i = 0; i < parameterNames.length; i++) {
        sb.append(parameterNames[i]);

        if (i < parameterNames.length - 1) {
            sb.append(", ");
        }
    }

    sb.append(")");

    return sb.toString();
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

/**
 * /*from  www.  j a  v a 2 s  .  com*/
 * @param method
 *            The method binding whose superclasses are searched trough for
 *            this bindings super method
 * @return Returns an array with two MethodName. They can be null if they do
 *         not exist.
 */
protected static MethodName[] getSuperMethodNames(IMethodBinding method) {
    MethodName[] methodNames = new CsMethodName[2];
    IMethodBinding firstMethod = null, topLevelMethod = null;

    List<ITypeBinding> types = getTypeHierarchy(method);

    for (int i = 0; i < types.size(); i++) {
        IMethodBinding[] declaredMethods = types.get(i).getDeclaredMethods();
        for (int j = 0; j < declaredMethods.length; j++) {
            if (declaredMethods[j].getName().equals(method.getName()) && method.overrides(declaredMethods[j])) {
                if (firstMethod == null) {
                    firstMethod = declaredMethods[j];
                } else {
                    topLevelMethod = declaredMethods[j];
                }
            }
        }
    }

    methodNames[0] = CsMethodName.newMethodName(methodNameHelper(null, firstMethod, false));

    if (topLevelMethod != null) {
        methodNames[1] = CsMethodName.newMethodName(methodNameHelper(null, topLevelMethod, false));
    }

    return methodNames;
}