Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isPrivate()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.MethodBinding#isPrivate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean hides(Element hidden) { if (!(hidden instanceof ExecutableElementImpl)) { return false; } MethodBinding hiderBinding = (MethodBinding)_binding; MethodBinding hiddenBinding = (MethodBinding)((ExecutableElementImpl)hidden)._binding; if (hiderBinding == hiddenBinding) { return false; } if (hiddenBinding.isPrivate()) { return false; } // See JLS 8.4.8: hiding only applies to static methods if (!hiderBinding.isStatic() || !hiddenBinding.isStatic()) { return false; } // check names if (!CharOperation.equals(hiddenBinding.selector, hiderBinding.selector)) { return false; } // check parameters if (!_env.getLookupEnvironment().methodVerifier().isMethodSubsignature(hiderBinding, hiddenBinding)) { return false; } return null != hiderBinding.declaringClass.findSuperTypeOriginatingFrom(hiddenBinding.declaringClass); }
Example 2
Source File: ConstantPool.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public int literalIndexForMethodHandle(MethodBinding binding) { boolean isInterface = binding.declaringClass.isInterface(); int referenceKind = isInterface ? binding.isStatic() ? MethodHandleRefKindInvokeStatic : binding.isPrivate() ? MethodHandleRefKindInvokeSpecial : MethodHandleRefKindInvokeInterface : binding.isConstructor() ? MethodHandleRefKindNewInvokeSpecial : binding.isStatic() ? MethodHandleRefKindInvokeStatic : MethodHandleRefKindInvokeVirtual; return literalIndexForMethodHandle(referenceKind, binding.declaringClass, binding.selector, binding.signature(), isInterface); }
Example 3
Source File: ElementsImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Add the members of a type to the maps of subtypes, fields, and methods. Add only those * which are non-private and which are not overridden by an already-discovered member. * For fields, add them all; javac implementation does not take field hiding into account. * @param binding the type whose members will be added to the lists * @param ignoreVisibility if true, all members will be added regardless of whether they * are private, overridden, etc. * @param types a map of type simple name to type binding * @param fields a list of field bindings * @param methods a map of method simple name to set of method bindings with that name */ private void addMembers(ReferenceBinding binding, boolean ignoreVisibility, Map<String, ReferenceBinding> types, List<FieldBinding> fields, Map<String, Set<MethodBinding>> methods) { for (ReferenceBinding subtype : binding.memberTypes()) { if (ignoreVisibility || !subtype.isPrivate()) { String name = new String(subtype.sourceName()); if (null == types.get(name)) { types.put(name, subtype); } } } for (FieldBinding field : binding.fields()) { if (ignoreVisibility || !field.isPrivate()) { fields.add(field); } } for (MethodBinding method : binding.methods()) { if (!method.isSynthetic() && (ignoreVisibility || (!method.isPrivate() && !method.isConstructor()))) { String methodName = new String(method.selector); Set<MethodBinding> sameNamedMethods = methods.get(methodName); if (null == sameNamedMethods) { // New method name. Create a set for it and add it to the list. // We don't expect many methods with same name, so only 4 slots: sameNamedMethods = new HashSet<MethodBinding>(4); methods.put(methodName, sameNamedMethods); sameNamedMethods.add(method); } else { // We already have a method with this name. Is this method overridden? boolean unique = true; if (!ignoreVisibility) { for (MethodBinding existing : sameNamedMethods) { MethodVerifier verifier = _env.getLookupEnvironment().methodVerifier(); if (verifier.doesMethodOverride(existing, method)) { unique = false; break; } } } if (unique) { sameNamedMethods.add(method); } } } } }
Example 4
Source File: ExecutableElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Return true if this method overrides {@code overridden} in the context of {@code type}. For * instance, consider * <pre> * interface A { void f(); } * class B { void f() {} } * class C extends B implements I { } * </pre> * In the context of B, B.f() does not override A.f(); they are unrelated. But in the context of * C, B.f() does override A.f(). That is, the copy of B.f() that C inherits overrides A.f(). * This is equivalent to considering two questions: first, does C inherit B.f(); if so, does * the inherited C.f() override A.f(). If B.f() were private, for instance, then in the context * of C it would still not override A.f(). * * @see javax.lang.model.util.Elements#overrides(ExecutableElement, ExecutableElement, TypeElement) * @jls3 8.4.8 Inheritance, Overriding, and Hiding * @jls3 9.4.1 Inheritance and Overriding */ public boolean overrides(ExecutableElement overridden, TypeElement type) { MethodBinding overriddenBinding = (MethodBinding)((ExecutableElementImpl) overridden)._binding; ReferenceBinding overriderContext = (ReferenceBinding)((TypeElementImpl)type)._binding; if ((MethodBinding)_binding == overriddenBinding || overriddenBinding.isStatic() || overriddenBinding.isPrivate() || ((MethodBinding)_binding).isStatic()) { return false; } char[] selector = ((MethodBinding)_binding).selector; if (!CharOperation.equals(selector, overriddenBinding.selector)) return false; // Construct a binding to the equivalent of this (the overrider) as it would be inherited by 'type'. // Can only do this if 'type' is descended from the overrider. // Second clause of the AND is required to match a peculiar javac behavior. if (null == overriderContext.findSuperTypeOriginatingFrom(((MethodBinding)_binding).declaringClass) && null == ((MethodBinding)_binding).declaringClass.findSuperTypeOriginatingFrom(overriderContext)) { return false; } MethodBinding overriderBinding = new MethodBinding((MethodBinding)_binding, overriderContext); if (overriderBinding.isPrivate()) { // a private method can never override another method. The other method would either be // private itself, in which case it would not be visible; or this would be a restriction // of access, which is a compile-time error. return false; } TypeBinding match = overriderBinding.declaringClass.findSuperTypeOriginatingFrom(overriddenBinding.declaringClass); if (!(match instanceof ReferenceBinding)) return false; org.eclipse.jdt.internal.compiler.lookup.MethodBinding[] superMethods = ((ReferenceBinding)match).getMethods(selector); LookupEnvironment lookupEnvironment = _env.getLookupEnvironment(); if (lookupEnvironment == null) return false; MethodVerifier methodVerifier = lookupEnvironment.methodVerifier(); for (int i = 0, length = superMethods.length; i < length; i++) { if (superMethods[i].original() == overriddenBinding) { return methodVerifier.doesMethodOverride(overriderBinding, superMethods[i]); } } return false; }
Example 5
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(MethodBinding methodBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (methodBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (methodBinding.isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the receiverType is the invocationType or its subclass // OR the method is a static method accessed directly through a type if (TypeBinding.equalsEquals(invocationType, methodBinding.declaringClass)) return true; if (invocationType.fPackage == methodBinding.declaringClass.fPackage) return true; if (methodBinding.declaringClass.isSuperclassOf(invocationType)) { if (invocationSite.isSuperAccess()) return true; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; if (invocationType.isSuperclassOf((ReferenceBinding) receiverType)) return true; if (methodBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (methodBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, methodBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, methodBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = methodBinding.declaringClass; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } if (TypeBinding.notEquals(outerInvocationType, outerDeclaringClass)) return false; } return true; } // isDefault() if (invocationType.fPackage != methodBinding.declaringClass.fPackage) return false; // receiverType can be an array binding in one case... see if you can change it if (receiverType instanceof ArrayBinding) return false; ReferenceBinding type = (ReferenceBinding) receiverType; PackageBinding declaringPackage = methodBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = methodBinding.declaringClass .original(); do { if (type.isCapture()) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 if (TypeBinding.equalsEquals(originalDeclaringClass, type.erasure().original())) return true; } else { if (TypeBinding.equalsEquals(originalDeclaringClass, type.original())) return true; } if (declaringPackage != type.fPackage) return false; } while ((type = type.superclass()) != null); return false; }
Example 6
Source File: MessageSend.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * MessageSend code generation * * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream * @param valueRequired boolean */ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; // generate receiver/enclosing instance access MethodBinding codegenBinding = this.binding instanceof PolymorphicMethodBinding ? this.binding : this.binding.original(); boolean isStatic = codegenBinding.isStatic(); if (isStatic) { this.receiver.generateCode(currentScope, codeStream, false); } else if ((this.bits & ASTNode.DepthMASK) != 0 && this.receiver.isImplicitThis()) { // outer access ? // outer method can be reached through emulation if implicit access ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT); Object[] path = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/); codeStream.generateOuterAccess(path, this, targetType, currentScope); } else { this.receiver.generateCode(currentScope, codeStream, true); if ((this.bits & NeedReceiverGenericCast) != 0) { codeStream.checkcast(this.actualReceiverType); } } codeStream.recordPositionsFrom(pc, this.sourceStart); // generate arguments generateArguments(this.binding, this.arguments, currentScope, codeStream); pc = codeStream.position; // actual message invocation if (this.syntheticAccessor == null){ TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis()); if (isStatic){ codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass, this.typeArguments); } else if((this.receiver.isSuper()) || codegenBinding.isPrivate()){ codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass, this.typeArguments); } else if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass, this.typeArguments); } else { codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass, this.typeArguments); } } else { codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessor, null /* default declaringClass */, this.typeArguments); } // required cast must occur even if no value is required if (this.valueCast != null) codeStream.checkcast(this.valueCast); if (valueRequired){ // implicit conversion if necessary codeStream.generateImplicitConversion(this.implicitConversion); } else { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; // conversion only generated if unboxing if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion); switch (isUnboxing ? postConversionType(currentScope).id : codegenBinding.returnType.id) { case T_long : case T_double : codeStream.pop2(); break; case T_void : break; default : codeStream.pop(); } } codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector }