Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.FieldBinding#isPrivate()

The following examples show how to use org.eclipse.jdt.internal.compiler.lookup.FieldBinding#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: VariableElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean hides(Element hiddenElement)
{
	if (_binding instanceof FieldBinding) {
		if (!(((ElementImpl)hiddenElement)._binding instanceof FieldBinding)) {
			return false;
		}
		FieldBinding hidden = (FieldBinding)((ElementImpl)hiddenElement)._binding;
		if (hidden.isPrivate()) {
			return false;
		}
		FieldBinding hider = (FieldBinding)_binding;
		if (hidden == hider) {
			return false;
		}
		if (!CharOperation.equals(hider.name, hidden.name)) {
			return false;
		}
		return null != hider.declaringClass.findSuperTypeOriginatingFrom(hidden.declaringClass);
	}
	// TODO: should we implement hides() for method parameters?
	return false;
}
 
Example 2
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 3
Source File: ElementsImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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: CodeSnippetScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
}