Java 类org.eclipse.jdt.core.dom.IMethodBinding 实例源码

项目:SnowGraph    文件:APIMethodData.java   
public void initByIMethodBinding(IMethodBinding mBinding) {
    IMethod iMethod = (IMethod) mBinding.getJavaElement();
    try {
        key = iMethod.getKey().substring(0, iMethod.getKey().indexOf("("))
                + iMethod.getSignature();
        projectName = mBinding.getJavaElement().getJavaProject()
                .getElementName();
    } catch (Exception e) {
        projectName = "";
    }
    packageName = mBinding.getDeclaringClass().getPackage().getName();
    className = mBinding.getDeclaringClass().getName();
    name = mBinding.getName();

    parameters = new ArrayList<>();
    ITypeBinding[] parameterBindings = mBinding.getParameterTypes();
    for (int i = 0; i < parameterBindings.length; i++) {
        parameters.add(parameterBindings[i].getName());
    }
}
项目:bayou    文件:DOMClassInstanceCreation.java   
@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    // add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
    DSubTree Texp = new DOMExpression(creation.getExpression()).handle();
    tree.addNodes(Texp.getNodes());

    // evaluate arguments first
    for (Object o : creation.arguments()) {
        DSubTree Targ = new DOMExpression((Expression) o).handle();
        tree.addNodes(Targ.getNodes());
    }

    IMethodBinding binding = creation.resolveConstructorBinding();
    // get to the generic declaration, if this binding is an instantiation
    while (binding != null && binding.getMethodDeclaration() != binding)
        binding = binding.getMethodDeclaration();
    MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
    if (localMethod != null) {
        DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
        tree.addNodes(Tmethod.getNodes());
    }
    else if (Utils.isRelevantCall(binding))
        tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(creation)));
    return tree;
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (methodBinding != null) {
        handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
        handleMethodBinding(node, methodBinding);
    }
    return true;
}
项目:RefDiff    文件:AstUtils.java   
public static String getKeyFromMethodBinding(IMethodBinding binding) {
    StringBuilder sb = new StringBuilder();
    String className = binding.getDeclaringClass().getErasure().getQualifiedName();
    sb.append(className);
    sb.append('.');
    String methodName = binding.isConstructor() ? "" : binding.getName();
    sb.append(methodName);
    //if (methodName.equals("allObjectsSorted")) {
    //  System.out.println();
    //}
    sb.append('(');
    ITypeBinding[] parameters = binding.getParameterTypes();
    for (int i = 0; i < parameters.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        ITypeBinding type = parameters[i];
        sb.append(type.getErasure().getName());
    }
    sb.append(')');
    return sb.toString();
}
项目:RefDiff    文件:DependenciesAstVisitor.java   
@Override
public final boolean visit(MethodInvocation node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (methodBinding != null) {
        handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
        handleMethodBinding(node, methodBinding);
    }
    return true;
}
项目:RefDiff    文件:AstUtils.java   
public static String getKeyFromMethodBinding(IMethodBinding binding) {
    StringBuilder sb = new StringBuilder();
    String className = binding.getDeclaringClass().getErasure().getQualifiedName();
    sb.append(className);
    sb.append('#');
    String methodName = binding.isConstructor() ? "" : binding.getName();
    sb.append(methodName);
    //if (methodName.equals("allObjectsSorted")) {
    //  System.out.println();
    //}
    sb.append('(');
    ITypeBinding[] parameters = binding.getParameterTypes();
    for (int i = 0; i < parameters.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        ITypeBinding type = parameters[i];
        sb.append(type.getErasure().getName());
    }
    sb.append(')');
    return sb.toString();
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(CastExpression node) {
    if (mtbStack.isEmpty()) // not part of a method
        return true;

    Expression expression = node.getExpression();
    ITypeBinding type = node.getType().resolveBinding();
    IMethodBinding mtb = mtbStack.peek();
    String exprStr = expression.toString();
    String typeStr = getQualifiedName(type);
    String methodStr = getQualifiedName(mtb);

    exprStr = edit_str(exprStr);

    facts.add(Fact.makeCastFact(exprStr, typeStr, methodStr));

    return true;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
private static String getSimpleName(IMethodBinding imb) {
    try {
        // imb = imb.getMethodDeclaration();
        String name = imb.getName();
        if (imb.isConstructor())
            name = "<init>";
        String args = "";
        /*
         * for (ITypeBinding itb : imb.getParameterTypes()) { if
         * (args.length()>0) args+=","; args += getQualifiedName(itb); }
         */
        args = "(" + args + ")";
        return name + args;
    } catch (NullPointerException e) {
        return "";
    }
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(SuperMethodInvocation node) {
    IMethodBinding mmtb = node.resolveMethodBinding();

    if (mtbStack.isEmpty()) // not part of a method
        return true;

    // make field access fact
    try {
        facts.add(Fact.makeCallsFact(getQualifiedName(mtbStack.peek()),
                getQualifiedName(mmtb)));
    } catch (Exception e) {
        System.err.println("Cannot resolve method invocation \""
                + node.getName().toString() + "\"");
    }
    return true;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(ClassInstanceCreation node) {
    IMethodBinding mmtb = node.resolveConstructorBinding();

    if (mtbStack.isEmpty()) // not part of a method
        return true;

    // make field access fact
    try {
        facts.add(Fact.makeCallsFact(getQualifiedName(mtbStack.peek()),
                getQualifiedName(mmtb)));
    } catch (Exception e) {
        System.err.println("Cannot resolve class instance creation \""
                + node.getType().toString() + "\"");
    }
    return true;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(ConstructorInvocation node) {
    IMethodBinding mmtb = node.resolveConstructorBinding();

    if (mtbStack.isEmpty()) // not part of a method
        return true;

    // make field access fact
    try {
        facts.add(Fact.makeCallsFact(getQualifiedName(mtbStack.peek()),
                getQualifiedName(mmtb)));
    } catch (Exception e) {
        System.err.println("Cannot resolve constructor invocation in \""
                + "\"");
    }
    return true;
}
项目:RefDiff    文件:ASTVisitorAtomicChange.java   
public boolean visit(SuperConstructorInvocation node) {
    IMethodBinding mmtb = node.resolveConstructorBinding();

    if (mtbStack.isEmpty()) // not part of a method
        return true;

    // make field access fact
    try {
        facts.add(Fact.makeCallsFact(getQualifiedName(mtbStack.peek()),
                getQualifiedName(mmtb)));
    } catch (Exception e) {
        System.err
                .println("Cannot resolve super constructor invocation in \""
                        + "\"");
    }
    return true;
}
项目:code    文件:NodesOOGTransferFunctions.java   
/**
 * @return the list of formal domains for return type
 * */
// TODO: Move method elsewhere. to TraceUtils?
public static List<DomainP> getReturnDeclaredDomains(QualifiedClassName C, IMethodBinding mb, AnnotationDatabase annoDB) {
    AnnotationSummary methAnnots = annoDB.getSummaryForMethod(mb);
    List<DomainP> listP = new ArrayList<DomainP>();
    List<ICrystalAnnotation> annots = methAnnots.getReturn();
    // XXX. Why do we have this check here? We might read from cache! There could be another annotation, e.g., @Deprecated
    if (annots.size() > 0) {
        listP = getFormalDomains(C, mb, annots);
    } else {
        String key = mb.getMethodDeclaration().getKey();
        MethodAnnotationInfo methDecl = MethodAnnotationInfo.getBinding(key);
        if (methDecl != null) {
            AnnotationInfo anInfo = methDecl.getReturnAnnotation();
            if (anInfo.getAnnotation().isEmpty()) {
                anInfo = AnnotationInfo.Shared;
            }
            listP = Utils.getDomainP(C, anInfo);
        }
    }
    return listP;
}
项目:eclipse.jdt.ls    文件:BindingLabelProvider.java   
/**
 * Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}.
 * @param binding The binding to render.
 * @param flags The text flags as defined in {@link JavaElementLabels}
 * @return the label of the binding
 */
public static String getBindingLabel(IBinding binding, long flags) {
    StringBuffer buffer= new StringBuffer(60);
    if (binding instanceof ITypeBinding) {
        getTypeLabel(((ITypeBinding) binding), flags, buffer);
    } else if (binding instanceof IMethodBinding) {
        getMethodLabel(((IMethodBinding) binding), flags, buffer);
    } else if (binding instanceof IVariableBinding) {
        final IVariableBinding variable= (IVariableBinding) binding;
        if (variable.isField()) {
            getFieldLabel(variable, flags, buffer);
        } else {
            getLocalVariableLabel(variable, flags, buffer);
        }
    }
    return Strings.markLTR(buffer.toString());
}
项目:eclipse.jdt.ls    文件:MethodsSourcePositionComparator.java   
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
    try {
        IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement();
        IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement();
        if (firstMethod == null || secondMethod == null) {
            return 0;
        }
        ISourceRange firstSourceRange= firstMethod.getSourceRange();
        ISourceRange secondSourceRange= secondMethod.getSourceRange();

        if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) {
            return firstMethod.getElementName().compareTo(secondMethod.getElementName());
        } else {
            return firstSourceRange.getOffset() - secondSourceRange.getOffset();
        }
    } catch (JavaModelException e) {
        return 0;
    }
}
项目:eclipse.jdt.ls    文件:Bindings.java   
private static String asString(IMethodBinding method) {
    StringBuffer result= new StringBuffer();
    result.append(method.getDeclaringClass().getName());
    result.append(':');
    result.append(method.getName());
    result.append('(');
    ITypeBinding[] parameters= method.getParameterTypes();
    int lastComma= parameters.length - 1;
    for (int i= 0; i < parameters.length; i++) {
        ITypeBinding parameter= parameters[i];
        result.append(parameter.getName());
        if (i < lastComma)
        {
            result.append(", "); //$NON-NLS-1$
        }
    }
    result.append(')');
    return result.toString();
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
 * the given <code>type</code>. Returns <code>null</code> if no such method exists.
 * @param type The type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only
 *  the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
    if (type.isPrimitive()) {
        return null;
    }
    IMethodBinding[] methods= type.getDeclaredMethods();
    for (int i= 0; i < methods.length; i++) {
        if (parameters == null) {
            if (methodName.equals(methods[i].getName())) {
                return methods[i];
            }
        } else {
            if (isEqualMethod(methods[i], methodName, parameters)) {
                return methods[i];
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
 * the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
 * exists. If the method is defined in more than one super type only the first match is
 * returned. First the super class is examined and then the implemented interfaces.
 *
 * @param type The type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
    IMethodBinding method= findMethodInType(type, methodName, parameters);
    if (method != null) {
        return method;
    }
    ITypeBinding superClass= type.getSuperclass();
    if (superClass != null) {
        method= findMethodInHierarchy(superClass, methodName, parameters);
        if (method != null) {
            return method;
        }
    }
    ITypeBinding[] interfaces= type.getInterfaces();
    for (int i= 0; i < interfaces.length; i++) {
        method= findMethodInHierarchy(interfaces[i], methodName, parameters);
        if (method != null) {
            return method;
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
 * the given <code>type</code>. Returns <code>null</code> if no such method exists.
 * @param type The type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodInType(ITypeBinding type, String methodName, String[] parameters) {
    if (type.isPrimitive()) {
        return null;
    }
    IMethodBinding[] methods= type.getDeclaredMethods();
    for (int i= 0; i < methods.length; i++) {
        if (parameters == null) {
            if (methodName.equals(methods[i].getName())) {
                return methods[i];
            }
        } else {
            if (isEqualMethod(methods[i], methodName, parameters)) {
                return methods[i];
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
 * the given <code>type</code>. Returns <code>null</code> if no such method exists.
 * <p>
 * This variant of {@link #findMethodInType(ITypeBinding, String, String[])} looks for a method
 * whose {@link IMethodBinding#getMethodDeclaration() declaration}'s parameters matches the
 * given parameters.
 * </p>
 *
 * @param type The type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodWithDeclaredParameterTypesInType(ITypeBinding type, String methodName, String[] parameters) {
    if (type.isPrimitive()) {
        return null;
    }
    IMethodBinding[] methods= type.getDeclaredMethods();
    for (int i= 0; i < methods.length; i++) {
        if (parameters == null) {
            if (methodName.equals(methods[i].getName())) {
                return methods[i];
            }
        } else {
            if (isEqualMethod(methods[i].getMethodDeclaration(), methodName, parameters)) {
                return methods[i];
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds the method specified by <code>methodName</code> and <code>parameters</code> in
 * the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
 * exists. If the method is defined in more than one super type only the first match is
 * returned. First the super class is examined and then the implemented interfaces.
 * @param type the type to search the method in
 * @param methodName The name of the method to find
 * @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
 * @return the method binding representing the method
 */
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, String[] parameters) {
    IMethodBinding method= findMethodInType(type, methodName, parameters);
    if (method != null) {
        return method;
    }
    ITypeBinding superClass= type.getSuperclass();
    if (superClass != null) {
        method= findMethodInHierarchy(superClass, methodName, parameters);
        if (method != null) {
            return method;
        }
    }
    ITypeBinding[] interfaces= type.getInterfaces();
    for (int i= 0; i < interfaces.length; i++) {
        method= findMethodInHierarchy(interfaces[i], methodName, parameters);
        if (method != null) {
            return method;
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Finds a method in the hierarchy of <code>type</code> that is overridden by <code>binding</code>.
 * Returns <code>null</code> if no such method exists. If the method is defined in more than one super type only the first match is
 * returned. First the super class is examined and then the implemented interfaces.
 * @param type The type to search the method in
 * @param binding The method that overrides
 * @return the method binding overridden the method
 */
public static IMethodBinding findOverriddenMethodInHierarchy(ITypeBinding type, IMethodBinding binding) {
    IMethodBinding method= findOverriddenMethodInType(type, binding);
    if (method != null) {
        return method;
    }
    ITypeBinding superClass= type.getSuperclass();
    if (superClass != null) {
        method= findOverriddenMethodInHierarchy(superClass, binding);
        if (method != null) {
            return method;
        }
    }
    ITypeBinding[] interfaces= type.getInterfaces();
    for (int i= 0; i < interfaces.length; i++) {
        method= findOverriddenMethodInHierarchy(interfaces[i], binding);
        if (method != null) {
            return method;
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:Bindings.java   
private static boolean sameParameters(IMethodBinding method, IMethod candidate) throws JavaModelException {
    ITypeBinding[] methodParamters= method.getParameterTypes();
    String[] candidateParameters= candidate.getParameterTypes();
    if (methodParamters.length != candidateParameters.length) {
        return false;
    }
    IType scope= candidate.getDeclaringType();
    for (int i= 0; i < methodParamters.length; i++) {
        ITypeBinding methodParameter= methodParamters[i];
        String candidateParameter= candidateParameters[i];
        if (!sameParameter(methodParameter, candidateParameter, scope)) {
            return false;
        }
    }
    return true;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
public static int getDimensions(VariableDeclaration declaration) {
    int dim= declaration.getExtraDimensions();
    if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
        LambdaExpression lambda= (LambdaExpression) declaration.getParent();
        IMethodBinding methodBinding= lambda.resolveMethodBinding();
        if (methodBinding != null) {
            ITypeBinding[] parameterTypes= methodBinding.getParameterTypes();
            int index= lambda.parameters().indexOf(declaration);
            ITypeBinding typeBinding= parameterTypes[index];
            return typeBinding.getDimensions();
        }
    } else {
        Type type= getType(declaration);
        if (type instanceof ArrayType) {
            dim+= ((ArrayType) type).getDimensions();
        }
    }
    return dim;
}
项目:code    文件:Utils.java   
public static boolean isMethodCompatible(IMethodBinding methodBinding) {

    Options options = Options.getInstance();
    if (!options.includeConstructors()
            && (methodBinding.isConstructor() || methodBinding
                    .isDefaultConstructor())) {
        return false;
    }
    if (!options.includeStaticMethods()
            && Modifier.isStatic(methodBinding.getModifiers())) {
        return false;
    }

    return true;

}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
private static Type newType(LambdaExpression lambdaExpression, VariableDeclarationFragment declaration, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
    IMethodBinding method= lambdaExpression.resolveMethodBinding();
    if (method != null) {
        ITypeBinding[] parameterTypes= method.getParameterTypes();
        int index= lambdaExpression.parameters().indexOf(declaration);
        ITypeBinding typeBinding= parameterTypes[index];
        if (importRewrite != null) {
            return importRewrite.addImport(typeBinding, ast, context);
        } else {
            String qualifiedName= typeBinding.getQualifiedName();
            if (qualifiedName.length() > 0) {
                return newType(ast, qualifiedName);
            }
        }
    }
    // fall-back
    return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
/**
 * Returns the new type node representing the return type of <code>lambdaExpression</code>
 * including the extra dimensions.
 *
 * @param lambdaExpression the lambda expression
 * @param ast the AST to create the return type with
 * @param importRewrite the import rewrite to use, or <code>null</code>
 * @param context the import rewrite context, or <code>null</code>
 * @return a new type node created with the given AST representing the return type of
 *         <code>lambdaExpression</code>
 *
 * @since 3.10
 */
public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
    IMethodBinding method= lambdaExpression.resolveMethodBinding();
    if (method != null) {
        ITypeBinding returnTypeBinding= method.getReturnType();
        if (importRewrite != null) {
            return importRewrite.addImport(returnTypeBinding, ast);
        } else {
            String qualifiedName= returnTypeBinding.getQualifiedName();
            if (qualifiedName.length() > 0) {
                return newType(ast, qualifiedName);
            }
        }
    }
    // fall-back
    return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
项目:eclipse.jdt.ls    文件:LinkedNodeFinder.java   
@Override
public boolean visit(SimpleName node) {
    IBinding binding= node.resolveBinding();
    if (binding == null) {
        return false;
    }
    binding= getDeclaration(binding);

    if (fBinding == binding) {
        fResult.add(node);
    } else if (binding.getKind() != fBinding.getKind()) {
        return false;
    } else if (binding.getKind() == IBinding.METHOD) {
        IMethodBinding curr= (IMethodBinding) binding;
        IMethodBinding methodBinding= (IMethodBinding) fBinding;
        if (methodBinding.overrides(curr) || curr.overrides(methodBinding)) {
            fResult.add(node);
        }
    }
    return false;
}
项目:eclipse.jdt.ls    文件:StubUtility2.java   
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) {
    ITypeBinding[] typeParams= binding.getTypeParameters();
    List<TypeParameter> typeParameters= decl.typeParameters();
    for (int i= 0; i < typeParams.length; i++) {
        ITypeBinding curr= typeParams[i];
        TypeParameter newTypeParam= ast.newTypeParameter();
        newTypeParam.setName(ast.newSimpleName(curr.getName()));
        ITypeBinding[] typeBounds= curr.getTypeBounds();
        if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$
            List<Type> newTypeBounds= newTypeParam.typeBounds();
            for (int k= 0; k < typeBounds.length; k++) {
                newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND));
            }
        }
        typeParameters.add(newTypeParam);
    }
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
    try {
        ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
        parser.setProject(overridden.getJavaProject());
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
        if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
            return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
        }
    } catch (IllegalStateException e) {
        // method does not exist
    }
    // fall back code. Not good for generic methods!
    String[] paramTypes = overridden.getParameterTypes();
    String[] paramTypeNames = new String[paramTypes.length];
    for (int i = 0; i < paramTypes.length; i++) {
        paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
    }
    return paramTypeNames;
}
项目:eclipse.jdt.ls    文件:UnusedCodeFix.java   
private String getDisplayString(IBinding binding) {
    switch (binding.getKind()) {
    case IBinding.TYPE:
        return FixMessages.UnusedCodeFix_RemoveUnusedType_description;
    case IBinding.METHOD:
        if (((IMethodBinding) binding).isConstructor()) {
            return FixMessages.UnusedCodeFix_RemoveUnusedConstructor_description;
        } else {
            return FixMessages.UnusedCodeFix_RemoveUnusedPrivateMethod_description;
        }
    case IBinding.VARIABLE:
        if (((IVariableBinding) binding).isField()) {
            return FixMessages.UnusedCodeFix_RemoveUnusedField_description;
        } else {
            return FixMessages.UnusedCodeFix_RemoveUnusedVariabl_description;
        }
    default:
        return ""; //$NON-NLS-1$
    }
}
项目:eclipse.jdt.ls    文件:UnusedCodeFix.java   
private static String getDisplayString(SimpleName simpleName, IBinding binding, boolean removeAllAssignements) {
    String name= BasicElementLabels.getJavaElementName(simpleName.getIdentifier());
    switch (binding.getKind()) {
    case IBinding.TYPE:
        return Messages.format(FixMessages.UnusedCodeFix_RemoveType_description, name);
    case IBinding.METHOD:
        if (((IMethodBinding) binding).isConstructor()) {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveConstructor_description, name);
        } else {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveMethod_description, name);
        }
    case IBinding.VARIABLE:
        if (removeAllAssignements) {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocalWithInitializer_description, name);
        } else {
            return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocal_description, name);
        }
    default:
        return ""; //$NON-NLS-1$
    }
}
项目:eclipse.jdt.ls    文件:ExceptionAnalyzer.java   
private boolean handleMethodReference(MethodReference node) {
    if (!isSelected(node)) {
        return false;
    }
    if (!fEnclosingNode.equals(node)) {
        return false;
    }
    IMethodBinding referredMethodBinding = node.resolveMethodBinding();
    if (referredMethodBinding == null) {
        return false;
    }
    IMethodBinding functionalMethod = QuickAssistProcessor.getFunctionalMethodForMethodReference(node);
    if (functionalMethod == null || functionalMethod.isGenericMethod()) { // generic lambda expressions are not allowed
        return false;
    }
    return handleExceptions(referredMethodBinding, node);
}
项目:code    文件:Utils.java   
public static boolean isMethodCompatible(MethodDeclaration methodDeclaration) {
    Crystal instance = Crystal.getInstance();
    TypeDeclaration enclosingType = methodDeclaration.enclosingType;
    if(enclosingType!=null){
        ITypeBinding typeBinding = instance
                .getTypeBindingFromName(enclosingType
                        .getFullyQualifiedName());
        for(IMethodBinding methodBinding : typeBinding.getDeclaredMethods()){
            if(methodDeclaration.methodName.compareTo(methodBinding.getName()) == 0){
                 if(!isMethodCompatible(methodBinding)){
                     return false;
                 }
            }
        }
    }

    return true;

}
项目:eclipse.jdt.ls    文件:TypeChangeCorrectionProposal.java   
private void sortTypes(ITypeBinding[] typeProposals) {
    ITypeBinding oldType;
    if (fBinding instanceof IMethodBinding) {
        oldType= ((IMethodBinding) fBinding).getReturnType();
    } else {
        oldType= ((IVariableBinding) fBinding).getType();
    }
    if (! oldType.isParameterizedType()) {
        return;
    }

    final ITypeBinding oldTypeDeclaration= oldType.getTypeDeclaration();
    Arrays.sort(typeProposals, new Comparator<ITypeBinding>() {
        @Override
        public int compare(ITypeBinding o1, ITypeBinding o2) {
            return rank(o2) - rank(o1);
        }

        private int rank(ITypeBinding type) {
            if (type.getTypeDeclaration().equals(oldTypeDeclaration)) {
                return 1;
            }
            return 0;
        }
    });
}
项目:jsr305CleanUp    文件:Jsr305CleanUp.java   
private boolean isDefinedInTypeOrSuperType(final IMethodBinding methodBinding, ITypeBinding declaringClass) {
    while (declaringClass != null) {
        for (final IMethodBinding method : declaringClass.getDeclaredMethods()) {
            if (methodBinding.overrides(method)) {
                return true;
            }
        }
        for (final ITypeBinding type : declaringClass.getInterfaces()) {
            if (isDefinedInTypeOrSuperType(methodBinding, type)) {
                return true;
            }
        }
        declaringClass = declaringClass.getSuperclass();
    }
    return false;
}
项目:eclipse.jdt.ls    文件:NewMethodCorrectionProposal.java   
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
    // for interface and annotation members copy the modifiers from an existing member
    if (targetTypeDecl instanceof TypeDeclaration) {
        TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
        MethodDeclaration[] methodDecls= type.getMethods();
        if (methodDecls.length > 0) {
            if (createAbstractMethod) {
                for (MethodDeclaration methodDeclaration : methodDecls) {
                    IMethodBinding methodBinding= methodDeclaration.resolveBinding();
                    if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
                        return methodDeclaration.getModifiers();
                    }
                }
            }
            return methodDecls[0].getModifiers() & Modifier.PUBLIC;
        }
        List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
        if (bodyDecls.size() > 0) {
            return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
        }
    }
    return 0;
}
项目:code    文件:TraceabilityFactory.java   
/**
 * returns the method Parameters as a list of ast.VariableDeclarataion 
 * */
public static List<ast.VariableDeclaration> getMethodParameters(MethodDeclaration md) {
    List<ast.VariableDeclaration> params = new ArrayList<ast.VariableDeclaration>();
    IMethodBinding methodBinding = md.resolveBinding();
    if(methodBinding != null ) {
        ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
        List<SingleVariableDeclaration> svdList = md.parameters();
        for (SingleVariableDeclaration svd : svdList) {
            ast.Type type = getType(svd.getType().resolveBinding());
            ast.VariableDeclaration vd = VariableDeclaration.createFrom(svd);
            vd.varType = type;
            vd.varName = svd.getName().getFullyQualifiedName();
            params.add(vd);
        }
    }
    return params;
}
项目:gw4e.project    文件:JDTManager.java   
public boolean visit(MethodInvocation node) {
    try {
        SimpleName simpleName = node.getName();
        IBinding bding = simpleName.resolveBinding();
        if (bding instanceof IMethodBinding) {
            IMethodBinding imb = (IMethodBinding) bding;
            if (isContext(imb.getReturnType())) {
                this.value = imb.getReturnType().getQualifiedName().toString();
            }
        }
    } catch (Throwable e) {
    }
    return false;
}
项目:bayou    文件:DOMMethodInvocation.java   
@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    // add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
    DSubTree Texp = new DOMExpression(invocation.getExpression()).handle();
    tree.addNodes(Texp.getNodes());

    // evaluate arguments first
    for (Object o : invocation.arguments()) {
        DSubTree Targ = new DOMExpression((Expression) o).handle();
        tree.addNodes(Targ.getNodes());
    }

    IMethodBinding binding = invocation.resolveMethodBinding();
    // get to the generic declaration, if this binding is an instantiation
    while (binding != null && binding.getMethodDeclaration() != binding)
        binding = binding.getMethodDeclaration();
    MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
    if (localMethod != null) {
        Stack<MethodDeclaration> callStack = Visitor.V().callStack;
        if (! callStack.contains(localMethod)) {
            callStack.push(localMethod);
            DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
            callStack.pop();
            tree.addNodes(Tmethod.getNodes());
        }
    }
    else if (Utils.isRelevantCall(binding))
        tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(invocation)));
    return tree;
}