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

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

Introduction

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

Prototype

public final boolean isPrivate() 

Source Link

Usage

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

License:Apache License

@SuppressWarnings("SameParameterValue")
private PsiAnnotation[] findAnnotations(boolean includeSuper) {
    List<PsiAnnotation> all = Lists.newArrayListWithExpectedSize(4);
    ExternalAnnotationRepository manager = mManager.getAnnotationRepository();

    MethodBinding binding = this.mMethodBinding;
    while (binding != null) {
        //noinspection VariableNotUsedInsideIf
        if (binding.declaringClass != null) { // prevent NPE in binding.getAnnotations()
            AnnotationBinding[] annotations = binding.getAnnotations();
            int count = annotations.length;
            if (count > 0) {
                for (AnnotationBinding annotation : annotations) {
                    if (annotation != null) {
                        all.add(new EcjPsiBinaryAnnotation(mManager, this, annotation));
                    }/*  w w w  .  j av  a 2s .  c  o m*/
                }
            }
        }

        // Look for external annotations
        if (manager != null) {
            Collection<PsiAnnotation> external = manager.getAnnotations(binding);
            if (external != null) {
                all.addAll(external);
            }
        }

        if (!includeSuper) {
            break;
        }

        binding = EcjPsiManager.findSuperMethodBinding(binding, false, false);
        if (binding != null && binding.isPrivate()) {
            break;
        }
    }

    return EcjPsiManager.ensureUnique(all);
}

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 .  j av a  2s .  c  o m
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.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 ww  .ja v a2  s .c o m
 */
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);//from   w  w  w  . ja v  a2  s.c om
        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 {//from w  w w. jav a  2s . c  o m
            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.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  ww .j a  va 2 s.  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;/*w  ww.  j a va  2  s .  c  o  m*/
}

From source file:com.google.gwt.dev.jjs.ast.AccessModifier.java

License:Apache License

public static AccessModifier fromMethodBinding(MethodBinding methodBinding) {
    if (methodBinding.isPublic()) {
        return PUBLIC;
    } else if (methodBinding.isProtected()) {
        return PROTECTED;
    } else if (methodBinding.isPrivate()) {
        return PRIVATE;
    }/*  ww w  .j av a 2 s  . c om*/
    assert methodBinding.isDefault();
    return DEFAULT;
}

From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java

License:Apache License

private void processExternalMethod(MethodBinding binding, JDeclaredType type) {
    if (binding.isPrivate()
            || (type.getName().startsWith("java.") && !binding.isPublic() && !binding.isProtected())) {
        return;/*  w w w  .  j ava  2  s .  c o  m*/
    }
    if (binding.isConstructor()) {
        processConstructor(binding, null, type.getSourceInfo());
    } else {
        createMethod(binding, type.getSourceInfo());
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java

License:Open Source License

@Override
public List<MethodMirror> getDirectMethods() {
    if (methods == null) {
        doWithBindings(new ActionOnClassBinding() {
            @Override/*  ww  w  .  ja  va 2  s.c om*/
            public void doWithBinding(IType classModel, ReferenceBinding klass) {
                MethodBinding[] directMethods;
                directMethods = klass.methods();
                methods = new ArrayList<MethodMirror>(directMethods.length);
                for (MethodBinding method : directMethods) {
                    if (!method.isBridge() && !method.isSynthetic() && !method.isPrivate())
                        methods.add(new JDTMethod(JDTClass.this, method));
                }
            }
        });
    }
    return methods;
}