Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.FieldBinding#isProtected()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.FieldBinding#isProtected() .
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: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; //If inlinable field, forget the access emulation, the code gen will directly target it if (this.constant != Constant.NotAConstant) return; if ((this.bits & Binding.FIELD) != 0) { FieldBinding fieldBinding = (FieldBinding) this.binding; FieldBinding codegenField = fieldBinding.original(); if (((this.bits & ASTNode.DepthMASK) != 0) && (codegenField.isPrivate() // private access || (codegenField.isProtected() // implicit protected access && codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) { if (this.syntheticAccessors == null) this.syntheticAccessors = new MethodBinding[2]; this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] = ((SourceTypeBinding)currentScope.enclosingSourceType(). enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT)).addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/); currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess); return; } } }
Example 2
Source File: CodeSnippetScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final boolean canBeSeenByForCodeSnippet(FieldBinding fieldBinding, TypeBinding receiverType, InvocationSite invocationSite, Scope scope) { if (fieldBinding.isPublic()) return true; ReferenceBinding invocationType = (ReferenceBinding) receiverType; if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (fieldBinding.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 field is a static field accessed directly through a type if (TypeBinding.equalsEquals(invocationType, fieldBinding.declaringClass)) return true; if (invocationType.fPackage == fieldBinding.declaringClass.fPackage) return true; if (fieldBinding.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 (fieldBinding.isStatic()) return true; // see 1FMEPDL - return invocationSite.isTypeAccess(); } return false; } if (fieldBinding.isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType if (TypeBinding.notEquals(receiverType, fieldBinding.declaringClass)) return false; if (TypeBinding.notEquals(invocationType, fieldBinding.declaringClass)) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = fieldBinding.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 != fieldBinding.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 = fieldBinding.declaringClass.fPackage; TypeBinding originalDeclaringClass = fieldBinding.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; }