Example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isStatic

List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding isStatic

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isStatic.

Prototype

public final boolean isStatic() 

Source Link

Usage

From source file:com.android.tools.lint.psi.EcjPsiManager.java

License:Apache License

/** Computes the super method, if any, given a method binding */
@SuppressWarnings("SameParameterValue")
@Nullable/* w w w  .ja v a  2 s. com*/
static MethodBinding findSuperMethodBinding(@NonNull MethodBinding binding, boolean allowStatic,
        boolean allowPrivate) {
    if (binding.isConstructor()) {
        return null;
    }
    if (!allowPrivate && binding.isPrivate()) {
        return null;
    }
    if (!allowStatic && binding.isStatic()) {
        return null;
    }
    try {
        ReferenceBinding superclass = binding.declaringClass.superclass();
        while (superclass != null) {
            MethodBinding[] methods = superclass.getMethods(binding.selector, binding.parameters.length);
            for (MethodBinding method : methods) {
                if (method.isStatic() != binding.isStatic()) {
                    continue;
                }
                if (method.areParameterErasuresEqual(binding)) {
                    if (method.isPrivate()) {
                        if (method.declaringClass.outermostEnclosingType() == binding.declaringClass
                                .outermostEnclosingType()) {
                            return method;
                        } else {
                            return null;
                        }
                    } else {
                        return method;
                    }
                }
            }

            // TODO: Check interfaces too!

            superclass = superclass.superclass();
        }
    } catch (Exception ignore) {
        // Work around ECJ bugs; see https://code.google.com/p/android/issues/detail?id=172268
    }

    return null;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

private void selectStaticMethodFromStaticImport(CompilationUnitDeclaration parsedUnit, char[] lastToken,
        ReferenceBinding ref) {//from   w  ww.j  a va2 s . com
    int methodLength = lastToken.length;
    MethodBinding[] methods = ref.availableMethods();
    next: for (int j = 0; j < methods.length; j++) {
        MethodBinding method = methods[j];

        if (method.isSynthetic())
            continue next;

        if (method.isDefaultAbstract())
            continue next;

        if (method.isConstructor())
            continue next;

        if (!method.isStatic())
            continue next;

        if (methodLength > method.selector.length)
            continue next;

        if (!CharOperation.equals(lastToken, method.selector, true))
            continue next;

        selectFrom(method, parsedUnit, false);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java

License:Open Source License

/**
 * Returns whether the code gen will use an invoke virtual for
 * this message send or not.//w  w w  .  jav a  2 s  .c  om
 */
protected boolean isVirtualInvoke(MethodBinding method, MessageSend messageSend) {
    return !method.isStatic() && !method.isPrivate() && !messageSend.isSuperAccess()
            && !(method.isDefault() && this.pattern.focus != null && !CharOperation
                    .equals(this.pattern.declaringPackageName, method.declaringClass.qualifiedPackageName()));
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java

License:Open Source License

protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) {
    if (!matchesName(this.pattern.selector, method.selector))
        return IMPOSSIBLE_MATCH;

    int level = ACCURATE_MATCH;
    // look at return type only if declaring type is not specified
    if (this.pattern.declaringSimpleName == null) {
        // TODO (frederic) use this call to refine accuracy on return type
        // int newLevel = resolveLevelForType(this.pattern.returnSimpleName, this.pattern.returnQualification, this.pattern.returnTypeArguments, 0, method.returnType);
        int newLevel = resolveLevelForType(this.pattern.returnSimpleName, this.pattern.returnQualification,
                method.returnType);/*w  w w.ja  v a  2s  . co  m*/
        if (level > newLevel) {
            if (newLevel == IMPOSSIBLE_MATCH)
                return IMPOSSIBLE_MATCH;
            level = newLevel; // can only be downgraded
        }
    }

    // parameter types
    int parameterCount = this.pattern.parameterSimpleNames == null ? -1
            : this.pattern.parameterSimpleNames.length;
    if (parameterCount > -1) {
        // global verification
        if (method.parameters == null)
            return INACCURATE_MATCH;
        if (parameterCount != method.parameters.length)
            return IMPOSSIBLE_MATCH;
        if (!method.isValidBinding()
                && ((ProblemMethodBinding) method).problemId() == ProblemReasons.Ambiguous) {
            // return inaccurate match for ambiguous call (bug 80890)
            return INACCURATE_MATCH;
        }
        boolean foundTypeVariable = false;
        // verify each parameter
        for (int i = 0; i < parameterCount; i++) {
            TypeBinding argType = method.parameters[i];
            int newLevel = IMPOSSIBLE_MATCH;
            if (argType.isMemberType()) {
                // only compare source name for member type (bug 41018)
                newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], argType.sourceName(),
                        this.isCaseSensitive) ? ACCURATE_MATCH : IMPOSSIBLE_MATCH;
            } else {
                // TODO (frederic) use this call to refine accuracy on parameter types
                //             newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, argType);
                newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i],
                        this.pattern.parameterQualifications[i], argType);
            }
            if (level > newLevel) {
                if (newLevel == IMPOSSIBLE_MATCH) {
                    if (skipImpossibleArg) {
                        // Do not consider match as impossible while finding declarations and source level >= 1.5
                        // (see  bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763)
                        newLevel = level;
                    } else if (argType.isTypeVariable()) {
                        newLevel = level;
                        foundTypeVariable = true;
                    } else {
                        return IMPOSSIBLE_MATCH;
                    }
                }
                level = newLevel; // can only be downgraded
            }
        }
        if (foundTypeVariable) {
            if (!method.isStatic() && !method.isPrivate()) {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123836, No point in textually comparing type variables, captures etc with concrete types.
                MethodBinding focusMethodBinding = this.matchLocator.getMethodBinding(this.pattern);
                if (focusMethodBinding != null) {
                    if (matchOverriddenMethod(focusMethodBinding.declaringClass, focusMethodBinding, method)) {
                        return ACCURATE_MATCH;
                    }
                }
            }
            return IMPOSSIBLE_MATCH;
        }
    }

    return level;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java

License:Open Source License

public int resolveLevel(Binding binding) {
    if (binding == null)
        return INACCURATE_MATCH;
    if (!(binding instanceof MethodBinding))
        return IMPOSSIBLE_MATCH;

    MethodBinding method = (MethodBinding) binding;
    boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric;
    int methodLevel = matchMethod(method, skipVerif);
    if (methodLevel == IMPOSSIBLE_MATCH) {
        if (method != method.original())
            methodLevel = matchMethod(method.original(), skipVerif);
        if (methodLevel == IMPOSSIBLE_MATCH) {
            return IMPOSSIBLE_MATCH;
        } else {/*w  w  w. j av  a 2  s .  c  om*/
            method = method.original();
        }
    }

    // declaring type
    if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null)
        return methodLevel; // since any declaring class will do

    boolean subType = !method.isStatic() && !method.isPrivate();
    if (subType && this.pattern.declaringQualification != null && method.declaringClass != null
            && method.declaringClass.fPackage != null) {
        subType = CharOperation.compareWith(this.pattern.declaringQualification,
                method.declaringClass.fPackage.shortReadableName()) == 0;
    }
    int declaringLevel = subType
            ? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification,
                    method.declaringClass, method.selector, null, method.declaringClass.qualifiedPackageName(),
                    method.isDefault())
            : resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification,
                    method.declaringClass);
    return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel
            : methodLevel; // return the weaker match
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.OrLocator.java

License:Open Source License

protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator)
        throws CoreException {

    // for static import, binding can be a field binding or a member type binding
    // verify that in this case binding is static and use declaring class for fields
    Binding refBinding = binding;
    if (importRef.isStatic()) {
        if (binding instanceof FieldBinding) {
            FieldBinding fieldBinding = (FieldBinding) binding;
            if (!fieldBinding.isStatic())
                return;
            refBinding = fieldBinding.declaringClass;
        } else if (binding instanceof MethodBinding) {
            MethodBinding methodBinding = (MethodBinding) binding;
            if (!methodBinding.isStatic())
                return;
            refBinding = methodBinding.declaringClass;
        } else if (binding instanceof MemberTypeBinding) {
            MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
            if (!memberBinding.isStatic())
                return;
        }/*from w w  w .  ja  va 2s .  com*/
    }

    // Look for closest pattern
    PatternLocator closestPattern = null;
    int level = IMPOSSIBLE_MATCH;
    for (int i = 0, length = this.patternLocators.length; i < length; i++) {
        PatternLocator patternLocator = this.patternLocators[i];
        int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH
                : patternLocator.resolveLevel(refBinding);
        if (newLevel > level) {
            closestPattern = patternLocator;
            if (newLevel == ACCURATE_MATCH)
                break;
            level = newLevel;
        }
    }
    if (closestPattern != null) {
        closestPattern.matchLevelAndReportImportRef(importRef, binding, locator);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PackageReferenceLocator.java

License:Open Source License

protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator)
        throws CoreException {
    Binding refBinding = binding;
    if (importRef.isStatic()) {
        // for static import, binding can be a field binding or a member type binding
        // verify that in this case binding is static and use declaring class for fields
        if (binding instanceof FieldBinding) {
            FieldBinding fieldBinding = (FieldBinding) binding;
            if (!fieldBinding.isStatic())
                return;
            refBinding = fieldBinding.declaringClass;
        } else if (binding instanceof MethodBinding) {
            MethodBinding methodBinding = (MethodBinding) binding;
            if (!methodBinding.isStatic())
                return;
            refBinding = methodBinding.declaringClass;
        } else if (binding instanceof MemberTypeBinding) {
            MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
            if (!memberBinding.isStatic())
                return;
        }/* w ww .  j a va 2s.  c  om*/
    }
    super.matchLevelAndReportImportRef(importRef, refBinding, locator);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java

License:Open Source License

protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator)
        throws CoreException {
    Binding refBinding = binding;
    if (importRef.isStatic()) {
        // for static import, binding can be a field binding or a member type binding
        // verify that in this case binding is static and use declaring class for fields
        if (binding instanceof FieldBinding) {
            FieldBinding fieldBinding = (FieldBinding) binding;
            if (!fieldBinding.isStatic())
                return;
            refBinding = fieldBinding.declaringClass;
        } else if (binding instanceof MethodBinding) {
            MethodBinding methodBinding = (MethodBinding) binding;
            if (!methodBinding.isStatic())
                return;
            refBinding = methodBinding.declaringClass;
        } else if (binding instanceof MemberTypeBinding) {
            MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
            if (!memberBinding.isStatic())
                return;
        }//from   w  w w . ja v  a2s. c  om
        // resolve and report
        int level = resolveLevel(refBinding);
        if (level >= INACCURATE_MATCH) {
            matchReportImportRef(importRef, binding, locator.createImportHandle(importRef),
                    level == ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE, locator);
        }
        return;
    }
    super.matchLevelAndReportImportRef(importRef, refBinding, locator);
}

From source file:com.google.gwt.dev.javac.JdtUtil.java

License:Apache License

public static String formatBinding(MethodBinding methodBinding) {
    String accessModifier = null;
    if (methodBinding.isProtected()) {
        accessModifier = "protected";
    } else if (methodBinding.isPrivate()) {
        accessModifier = "private";
    } else if (methodBinding.isPublic()) {
        accessModifier = "public";
    }/*from w w  w. ja  v a2s  .c o  m*/
    return Joiner.on(" ").skipNulls().join(accessModifier, methodBinding.isStatic() ? "static" : null,
            getSourceName(methodBinding.declaringClass) + "." + formatMethodSignature(methodBinding));
}

From source file:com.google.gwt.dev.javac.Shared.java

License:Open Source License

public static int bindingToModifierBits(MethodBinding binding) {
    int bits = 0;
    bits |= (binding.isPublic() ? MOD_PUBLIC : 0);
    bits |= (binding.isPrivate() ? MOD_PRIVATE : 0);
    bits |= (binding.isProtected() ? MOD_PROTECTED : 0);
    bits |= (binding.isStatic() ? MOD_STATIC : 0);
    bits |= (binding.isFinal() ? MOD_FINAL : 0);
    bits |= (binding.isNative() ? MOD_NATIVE : 0);
    bits |= (binding.isAbstract() ? MOD_ABSTRACT : 0);
    return bits;/*from  w  w w.  j  a v  a 2  s .c  o m*/
}