Lines 156-183
Link Here
|
156 |
ClassScope classScope = initializationScope.enclosingClassScope(); |
156 |
ClassScope classScope = initializationScope.enclosingClassScope(); |
157 |
|
157 |
|
158 |
if (classScope != null) { |
158 |
if (classScope != null) { |
159 |
SourceTypeBinding declaringType = classScope.enclosingSourceType(); |
159 |
checkHiding: { |
160 |
boolean checkLocal = true; |
160 |
SourceTypeBinding declaringType = classScope.enclosingSourceType(); |
161 |
if (declaringType.superclass != null) { |
161 |
checkHidingSuperField: { |
162 |
Binding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/); |
162 |
if (declaringType.superclass == null) break checkHidingSuperField; |
163 |
if (existingVariable != null && this.binding != existingVariable && existingVariable.isValidBinding()){ |
163 |
Binding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/); |
|
|
164 |
if (existingVariable == null) break checkHidingSuperField; // keep checking outer scenario |
165 |
if (!existingVariable.isValidBinding()) break checkHidingSuperField; // keep checking outer scenario |
166 |
if (existingVariable instanceof FieldBinding) { |
167 |
FieldBinding existingField = (FieldBinding) existingVariable; |
168 |
if (existingField.original() == this.binding) break checkHidingSuperField; // keep checking outer scenario |
169 |
} |
170 |
// collision with supertype field |
164 |
initializationScope.problemReporter().fieldHiding(this, existingVariable); |
171 |
initializationScope.problemReporter().fieldHiding(this, existingVariable); |
165 |
checkLocal = false; // already found a matching field |
172 |
break checkHiding; // already found a matching field |
166 |
} |
173 |
} |
167 |
} |
|
|
168 |
if (checkLocal) { |
169 |
Scope outerScope = classScope.parent; |
170 |
// only corner case is: lookup of outer field through static declaringType, which isn't detected by #getBinding as lookup starts |
174 |
// only corner case is: lookup of outer field through static declaringType, which isn't detected by #getBinding as lookup starts |
171 |
// from outer scope. Subsequent static contexts are detected for free. |
175 |
// from outer scope. Subsequent static contexts are detected for free. |
172 |
if (outerScope.kind != Scope.COMPILATION_UNIT_SCOPE) { |
176 |
Scope outerScope = classScope.parent; |
173 |
Binding existingVariable = outerScope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); |
177 |
if (outerScope.kind == Scope.COMPILATION_UNIT_SCOPE) break checkHiding; |
174 |
if (existingVariable != null && this.binding != existingVariable && existingVariable.isValidBinding() |
178 |
Binding existingVariable = outerScope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); |
175 |
&& (!(existingVariable instanceof FieldBinding) |
179 |
if (existingVariable == null) break checkHiding; |
176 |
|| ((FieldBinding) existingVariable).isStatic() |
180 |
if (!existingVariable.isValidBinding()) break checkHiding; |
177 |
|| !declaringType.isStatic())) { |
181 |
if (existingVariable == this.binding) break checkHiding; |
178 |
initializationScope.problemReporter().fieldHiding(this, existingVariable); |
182 |
if (existingVariable instanceof FieldBinding) { |
179 |
} |
183 |
FieldBinding existingField = (FieldBinding) existingVariable; |
|
|
184 |
if (existingField.original() == this.binding) break checkHiding; |
185 |
if (!existingField.isStatic() && declaringType.isStatic()) break checkHiding; |
180 |
} |
186 |
} |
|
|
187 |
// collision with outer field or local variable |
188 |
initializationScope.problemReporter().fieldHiding(this, existingVariable); |
181 |
} |
189 |
} |
182 |
} |
190 |
} |
183 |
|
191 |
|