1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.lookup;
13 import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
16 public class FieldBinding extends VariableBinding {
17 public ReferenceBinding declaringClass;
19 protected FieldBinding() {
22 public FieldBinding(char[] name, TypeBinding type, int modifiers,
23 ReferenceBinding declaringClass, Constant constant) {
24 this.modifiers = modifiers;
27 this.declaringClass = declaringClass;
28 this.constant = constant;
30 // propagate the deprecated modifier
31 if (this.declaringClass != null)
32 if (this.declaringClass.isViewedAsDeprecated() && !isDeprecated())
33 this.modifiers |= AccDeprecatedImplicitly;
36 public FieldBinding(FieldDeclaration field, TypeBinding type,
37 ReferenceBinding declaringClass) {
38 this(field.name, type, field.modifiers, declaringClass, null);
43 // special API used to change field declaring class for runtime visibility
45 public FieldBinding(FieldBinding initialFieldBinding,
46 ReferenceBinding declaringClass) {
47 this.modifiers = initialFieldBinding.modifiers;
48 this.type = initialFieldBinding.type;
49 this.name = initialFieldBinding.name;
50 this.declaringClass = declaringClass;
51 this.constant = initialFieldBinding.constant;
52 this.id = initialFieldBinding.id;
56 * API Answer the receiver's binding type from Binding.BindingID.
59 public final int bindingType() {
64 * Answer true if the receiver is visible to the type provided by the scope.
65 * InvocationSite implements isSuperAccess() to provide additional
66 * information if the receiver is protected.
68 * NOTE: Cannot invoke this method with a compilation unit scope.
71 public final boolean canBeSeenBy(TypeBinding receiverType,
72 InvocationSite invocationSite, Scope scope) {
76 SourceTypeBinding invocationType = scope.enclosingSourceType();
77 if (invocationType == declaringClass && invocationType == receiverType)
81 // answer true if the invocationType is the declaringClass or they
82 // are in the same package
83 // OR the invocationType is a subclass of the declaringClass
84 // AND the receiverType is the invocationType or its subclass
85 // OR the method is a static method accessed directly through a type
86 // OR previous assertions are true for one of the enclosing type
87 if (invocationType == declaringClass)
89 if (invocationType.fPackage == declaringClass.fPackage)
92 ReferenceBinding currentType = invocationType;
95 if (declaringClass.isSuperclassOf(currentType)) {
96 if (invocationSite.isSuperAccess()) {
99 // receiverType can be an array binding in one case... see
100 // if you can change it
101 if (receiverType instanceof ArrayBinding) {
105 return true; // see 1FMEPDL - return
106 // invocationSite.isTypeAccess();
108 if (currentType == receiverType
110 .isSuperclassOf((ReferenceBinding) receiverType)) {
112 invocationSite.setDepth(depth);
117 currentType = currentType.enclosingType();
118 } while (currentType != null);
123 // answer true if the receiverType is the declaringClass
124 // AND the invocationType and the declaringClass have a common
126 if (receiverType != declaringClass)
129 if (invocationType != declaringClass) {
130 ReferenceBinding outerInvocationType = invocationType;
131 ReferenceBinding temp = outerInvocationType.enclosingType();
132 while (temp != null) {
133 outerInvocationType = temp;
134 temp = temp.enclosingType();
137 ReferenceBinding outerDeclaringClass = declaringClass;
138 temp = outerDeclaringClass.enclosingType();
139 while (temp != null) {
140 outerDeclaringClass = temp;
141 temp = temp.enclosingType();
143 if (outerInvocationType != outerDeclaringClass)
150 if (invocationType.fPackage != declaringClass.fPackage)
153 // receiverType can be an array binding in one case... see if you can
155 if (receiverType instanceof ArrayBinding)
157 ReferenceBinding type = (ReferenceBinding) receiverType;
158 PackageBinding declaringPackage = declaringClass.fPackage;
160 if (declaringClass == type)
162 if (declaringPackage != type.fPackage)
164 } while ((type = type.superclass()) != null);
168 public final int getAccessFlags() {
169 return modifiers & AccJustFlag;
173 * Answer true if the receiver has default visibility
176 public final boolean isDefault() {
177 return !isPublic() && !isProtected() && !isPrivate();
181 * Answer true if the receiver is a deprecated field
184 public final boolean isDeprecated() {
185 return (modifiers & AccDeprecated) != 0;
189 * Answer true if the receiver has private visibility
192 public final boolean isPrivate() {
193 return (modifiers & AccPrivate) != 0;
197 * Answer true if the receiver has private visibility and is used locally
200 public final boolean isPrivateUsed() {
201 return (modifiers & AccPrivateUsed) != 0;
205 * Answer true if the receiver has protected visibility
208 public final boolean isProtected() {
209 return (modifiers & AccProtected) != 0;
213 * Answer true if the receiver has public visibility
216 public final boolean isPublic() {
217 return (modifiers & AccPublic) != 0;
221 * Answer true if the receiver is a static field
224 public final boolean isStatic() {
225 return (modifiers & AccStatic) != 0;
229 * Answer true if the receiver is not defined in the source of the
233 // public final boolean isSynthetic() {
234 // return (modifiers & AccSynthetic) != 0;
237 * Answer true if the receiver is a transient field
240 // public final boolean isTransient() {
241 // return (modifiers & AccTransient) != 0;
244 * Answer true if the receiver's declaring type is deprecated (or any of its
248 public final boolean isViewedAsDeprecated() {
249 return (modifiers & AccDeprecated) != 0
250 || (modifiers & AccDeprecatedImplicitly) != 0;
253 * Answer true if the receiver is a volatile field
256 // public final boolean isVolatile() {
257 // return (modifiers & AccVolatile) != 0;