1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.impl.*;
15 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16 import org.eclipse.jdt.internal.compiler.codegen.*;
17 import org.eclipse.jdt.internal.compiler.flow.*;
18 import org.eclipse.jdt.internal.compiler.lookup.*;
19 import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
21 public class QualifiedNameReference extends NameReference {
23 public char[][] tokens;
24 public long[] sourcePositions;
25 public FieldBinding[] otherBindings, otherCodegenBindings;
27 public int indexOfFirstFieldBinding;//points (into tokens) for the first token that corresponds to first FieldBinding
28 SyntheticAccessMethodBinding syntheticWriteAccessor;
29 SyntheticAccessMethodBinding[] syntheticReadAccessors;
30 protected FieldBinding lastFieldBinding;
31 public QualifiedNameReference(
37 this.tokens = sources;
38 this.sourcePositions = positions;
39 this.sourceStart = sourceStart;
40 this.sourceEnd = sourceEnd;
42 public FlowInfo analyseAssignment(
43 BlockScope currentScope,
44 FlowContext flowContext,
46 Assignment assignment,
49 // determine the rank until which we now we do not need any actual value for the field access
50 int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length;
51 boolean needValue = otherBindingsCount == 0 || !this.otherBindings[0].isStatic();
52 switch (bits & RestrictiveFlagMASK) {
53 case FIELD : // reading a field
54 lastFieldBinding = (FieldBinding) binding;
56 manageSyntheticReadAccessIfNecessary(currentScope, lastFieldBinding, this.actualReceiverType, 0, flowInfo);
57 } // check if final blank field
58 if (lastFieldBinding.isBlankFinal()
59 && this.otherBindings != null // the last field binding is only assigned
60 && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
61 if (!flowInfo.isDefinitelyAssigned(lastFieldBinding)) {
62 currentScope.problemReporter().uninitializedBlankFinalField(
69 // first binding is a local variable
70 LocalVariableBinding localBinding;
72 .isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
73 currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
75 if (flowInfo.isReachable()) {
76 localBinding.useFlag = LocalVariableBinding.USED;
77 } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
78 localBinding.useFlag = LocalVariableBinding.FAKE_USED;
83 manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
84 // only for first binding
86 // all intermediate field accesses are read accesses
87 if (otherBindings != null) {
88 for (int i = 0; i < otherBindingsCount-1; i++) {
89 lastFieldBinding = otherBindings[i];
90 needValue = !otherBindings[i+1].isStatic();
92 manageSyntheticReadAccessIfNecessary(
96 ? ((VariableBinding)binding).type
97 : otherBindings[i-1].type,
102 lastFieldBinding = otherBindings[otherBindingsCount-1];
106 if (binding == lastFieldBinding
107 && lastFieldBinding.isBlankFinal()
108 && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)
109 && (!flowInfo.isDefinitelyAssigned(lastFieldBinding))) {
110 currentScope.problemReporter().uninitializedBlankFinalField(
114 TypeBinding lastReceiverType;
115 if (lastFieldBinding == binding){
116 lastReceiverType = this.actualReceiverType;
117 } else if (otherBindingsCount == 1){
118 lastReceiverType = ((VariableBinding)this.binding).type;
120 lastReceiverType = this.otherBindings[otherBindingsCount-2].type;
122 manageSyntheticReadAccessIfNecessary(
126 lastFieldBinding == binding
128 : otherBindingsCount,
132 if (assignment.expression != null) {
136 .analyseCode(currentScope, flowContext, flowInfo)
137 .unconditionalInits();
140 // the last field access is a write access
141 if (lastFieldBinding.isFinal()) {
142 // in a context where it can be assigned?
143 if (lastFieldBinding.isBlankFinal()
145 && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)
146 && indexOfFirstFieldBinding == 1) {
147 if (flowInfo.isPotentiallyAssigned(lastFieldBinding)) {
148 currentScope.problemReporter().duplicateInitializationOfBlankFinalField(lastFieldBinding, this);
150 flowContext.recordSettingFinal(lastFieldBinding, this, flowInfo);
152 flowInfo.markAsDefinitelyAssigned(lastFieldBinding);
154 currentScope.problemReporter().cannotAssignToFinalField(lastFieldBinding, this);
155 if (currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) { // pretend it got assigned
156 flowInfo.markAsDefinitelyAssigned(lastFieldBinding);
160 // equivalent to valuesRequired[maxOtherBindings]
161 TypeBinding lastReceiverType;
162 if (lastFieldBinding == binding){
163 lastReceiverType = this.actualReceiverType;
164 } else if (otherBindingsCount == 1){
165 lastReceiverType = ((VariableBinding)this.binding).type;
167 lastReceiverType = this.otherBindings[otherBindingsCount-2].type;
169 manageSyntheticWriteAccessIfNecessary(currentScope, lastFieldBinding, lastReceiverType, flowInfo);
174 public FlowInfo analyseCode(
175 BlockScope currentScope,
176 FlowContext flowContext,
179 return analyseCode(currentScope, flowContext, flowInfo, true);
182 public FlowInfo analyseCode(
183 BlockScope currentScope,
184 FlowContext flowContext,
186 boolean valueRequired) {
188 // determine the rank until which we now we do not need any actual value for the field access
189 int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length;
191 boolean needValue = otherBindingsCount == 0 ? valueRequired : !this.otherBindings[0].isStatic();
192 switch (bits & RestrictiveFlagMASK) {
193 case FIELD : // reading a field
195 manageSyntheticReadAccessIfNecessary(currentScope, (FieldBinding) binding, this.actualReceiverType, 0, flowInfo);
197 // check if reading a final blank field
198 FieldBinding fieldBinding;
199 if ((fieldBinding = (FieldBinding) binding).isBlankFinal()
200 && (indexOfFirstFieldBinding == 1)
201 // was an implicit reference to the first field binding
202 && currentScope.allowBlankFinalFieldAssignment(fieldBinding)
203 && (!flowInfo.isDefinitelyAssigned(fieldBinding))) {
204 currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
207 case LOCAL : // reading a local variable
208 LocalVariableBinding localBinding;
210 .isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
211 currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
213 if (flowInfo.isReachable()) {
214 localBinding.useFlag = LocalVariableBinding.USED;
215 } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
216 localBinding.useFlag = LocalVariableBinding.FAKE_USED;
220 manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
221 // only for first binding
223 if (otherBindings != null) {
224 for (int i = 0; i < otherBindingsCount; i++) {
225 needValue = i < otherBindingsCount-1 ? !otherBindings[i+1].isStatic() : valueRequired;
227 manageSyntheticReadAccessIfNecessary(
231 ? ((VariableBinding)binding).type
232 : otherBindings[i-1].type,
241 * Check and/or redirect the field access to the delegate receiver if any
243 public TypeBinding checkFieldAccess(BlockScope scope) {
244 // check for forward references
245 FieldBinding fieldBinding = (FieldBinding) binding;
246 MethodScope methodScope = scope.methodScope();
247 if (methodScope.enclosingSourceType() == fieldBinding.declaringClass
248 && methodScope.lastVisibleFieldID >= 0
249 && fieldBinding.id >= methodScope.lastVisibleFieldID) {
250 if ((!fieldBinding.isStatic() || methodScope.isStatic)
251 && this.indexOfFirstFieldBinding == 1)
252 scope.problemReporter().forwardReference(this, 0, scope.enclosingSourceType());
254 bits &= ~RestrictiveFlagMASK; // clear bits
256 return getOtherFieldBindings(scope);
258 public void generateAssignment(
259 BlockScope currentScope,
260 CodeStream codeStream,
261 Assignment assignment,
262 boolean valueRequired) {
264 generateReadSequence(currentScope, codeStream);
265 assignment.expression.generateCode(currentScope, codeStream, true);
266 fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, valueRequired);
267 // equivalent to valuesRequired[maxOtherBindings]
269 codeStream.generateImplicitConversion(assignment.implicitConversion);
272 public void generateCode(
273 BlockScope currentScope,
274 CodeStream codeStream,
275 boolean valueRequired) {
277 int pc = codeStream.position;
278 if (constant != NotAConstant) {
280 codeStream.generateConstant(constant, implicitConversion);
283 generateReadSequence(currentScope, codeStream);
285 if (lastFieldBinding.declaringClass == null) { // array length
286 codeStream.arraylength();
287 codeStream.generateImplicitConversion(implicitConversion);
289 if (lastFieldBinding.constant != NotAConstant) {
290 if (!lastFieldBinding.isStatic()){
291 codeStream.invokeObjectGetClass();
294 // inline the last field constant
295 codeStream.generateConstant(lastFieldBinding.constant, implicitConversion);
297 SyntheticAccessMethodBinding accessor =
298 syntheticReadAccessors == null
300 : syntheticReadAccessors[syntheticReadAccessors.length - 1];
301 if (accessor == null) {
302 if (lastFieldBinding.isStatic()) {
303 codeStream.getstatic(lastFieldBinding);
305 codeStream.getfield(lastFieldBinding);
308 codeStream.invokestatic(accessor);
310 codeStream.generateImplicitConversion(implicitConversion);
314 if (lastFieldBinding != null && !lastFieldBinding.isStatic()){
315 codeStream.invokeObjectGetClass(); // perform null check
321 codeStream.recordPositionsFrom(pc, this.sourceStart);
323 public void generateCompoundAssignment(
324 BlockScope currentScope,
325 CodeStream codeStream,
326 Expression expression,
328 int assignmentImplicitConversion,
329 boolean valueRequired) {
331 generateReadSequence(currentScope, codeStream);
332 SyntheticAccessMethodBinding accessor =
333 syntheticReadAccessors == null
335 : syntheticReadAccessors[syntheticReadAccessors.length - 1];
336 if (lastFieldBinding.isStatic()) {
337 if (accessor == null) {
338 codeStream.getstatic(lastFieldBinding);
340 codeStream.invokestatic(accessor);
344 if (accessor == null) {
345 codeStream.getfield(lastFieldBinding);
347 codeStream.invokestatic(accessor);
350 // the last field access is a write access
351 // perform the actual compound operation
353 if ((operationTypeID = implicitConversion >> 4) == T_String) {
354 codeStream.generateStringAppend(currentScope, null, expression);
356 // promote the array reference to the suitable operation type
357 codeStream.generateImplicitConversion(implicitConversion);
358 // generate the increment value (will by itself be promoted to the operation value)
359 if (expression == IntLiteral.One) { // prefix operation
360 codeStream.generateConstant(expression.constant, implicitConversion);
362 expression.generateCode(currentScope, codeStream, true);
364 // perform the operation
365 codeStream.sendOperator(operator, operationTypeID);
366 // cast the value back to the array reference type
367 codeStream.generateImplicitConversion(assignmentImplicitConversion);
370 fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, valueRequired);
371 // equivalent to valuesRequired[maxOtherBindings]
373 public void generatePostIncrement(
374 BlockScope currentScope,
375 CodeStream codeStream,
376 CompoundAssignment postIncrement,
377 boolean valueRequired) {
378 generateReadSequence(currentScope, codeStream);
379 SyntheticAccessMethodBinding accessor =
380 syntheticReadAccessors == null
382 : syntheticReadAccessors[syntheticReadAccessors.length - 1];
383 if (lastFieldBinding.isStatic()) {
384 if (accessor == null) {
385 codeStream.getstatic(lastFieldBinding);
387 codeStream.invokestatic(accessor);
391 if (accessor == null) {
392 codeStream.getfield(lastFieldBinding);
394 codeStream.invokestatic(accessor);
397 // duplicate the old field value
399 if (lastFieldBinding.isStatic()) {
400 if ((lastFieldBinding.type == LongBinding)
401 || (lastFieldBinding.type == DoubleBinding)) {
406 } else { // Stack: [owner][old field value] ---> [old field value][owner][old field value]
407 if ((lastFieldBinding.type == LongBinding)
408 || (lastFieldBinding.type == DoubleBinding)) {
409 codeStream.dup2_x1();
415 codeStream.generateConstant(
416 postIncrement.expression.constant,
418 codeStream.sendOperator(postIncrement.operator, lastFieldBinding.type.id);
419 codeStream.generateImplicitConversion(
420 postIncrement.assignmentImplicitConversion);
421 fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, false);
424 * Generate code for all bindings (local and fields) excluding the last one, which may then be generated code
425 * for a read or write access.
427 public void generateReadSequence(
428 BlockScope currentScope,
429 CodeStream codeStream) {
431 // determine the rank until which we now we do not need any actual value for the field access
432 int otherBindingsCount = this.otherCodegenBindings == null ? 0 : otherCodegenBindings.length;
434 boolean needValue = otherBindingsCount == 0 || !this.otherBindings[0].isStatic();
435 switch (bits & RestrictiveFlagMASK) {
437 lastFieldBinding = (FieldBinding) this.codegenBinding;
438 // if first field is actually constant, we can inline it
439 if (lastFieldBinding.constant != NotAConstant) {
442 if (needValue && !lastFieldBinding.isStatic()) {
443 if ((bits & DepthMASK) != 0) {
444 ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
445 Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
446 codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
448 generateReceiver(codeStream);
452 case LOCAL : // reading the first local variable
453 lastFieldBinding = null;
454 if (!needValue) break; // no value needed
455 LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
456 // regular local variable read
457 if (localBinding.constant != NotAConstant) {
458 codeStream.generateConstant(localBinding.constant, 0);
459 // no implicit conversion
462 if ((bits & DepthMASK) != 0) {
463 // outer local can be reached either through a synthetic arg or a synthetic field
464 VariableBinding[] path = currentScope.getEmulationPath(localBinding);
465 codeStream.generateOuterAccess(path, this, localBinding, currentScope);
467 codeStream.load(localBinding);
472 // all intermediate field accesses are read accesses
473 // only the last field binding is a write access
474 if (this.otherCodegenBindings != null) {
475 for (int i = 0; i < otherBindingsCount; i++) {
476 FieldBinding nextField = this.otherCodegenBindings[i];
477 if (lastFieldBinding != null) {
478 needValue = !nextField.isStatic();
480 MethodBinding accessor =
481 syntheticReadAccessors == null ? null : syntheticReadAccessors[i];
482 if (accessor == null) {
483 if (lastFieldBinding.constant != NotAConstant) {
484 if (this.lastFieldBinding != this.codegenBinding && !this.lastFieldBinding.isStatic()) {
485 codeStream.invokeObjectGetClass(); // perform null check
488 codeStream.generateConstant(lastFieldBinding.constant, 0);
489 } else if (lastFieldBinding.isStatic()) {
490 codeStream.getstatic(lastFieldBinding);
492 codeStream.getfield(lastFieldBinding);
495 codeStream.invokestatic(accessor);
498 if (this.codegenBinding != this.lastFieldBinding && !this.lastFieldBinding.isStatic()){
499 codeStream.invokeObjectGetClass(); // perform null check
504 this.lastFieldBinding = nextField;
508 public void generateReceiver(CodeStream codeStream) {
509 codeStream.aload_0();
511 public TypeBinding getOtherFieldBindings(BlockScope scope) {
512 // At this point restrictiveFlag may ONLY have two potential value : FIELD LOCAL (i.e cast <<(VariableBinding) binding>> is valid)
513 int length = tokens.length;
514 if ((bits & FIELD) != 0) {
515 FieldBinding fieldBinding = (FieldBinding) binding;
516 if (!fieldBinding.isStatic()) {
517 //must check for the static status....
518 if (indexOfFirstFieldBinding > 1 //accessing to a field using a type as "receiver" is allowed only with static field
519 || scope.methodScope().isStatic) { // the field is the first token of the qualified reference....
520 scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
524 // indirect static reference ?
525 if (indexOfFirstFieldBinding > 1
526 && fieldBinding.declaringClass != actualReceiverType) {
527 scope.problemReporter().indirectAccessToStaticField(this, fieldBinding);
530 // only last field is actually a write access if any
531 if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & IsStrictlyAssignedMASK) !=0 && indexOfFirstFieldBinding == length))
532 scope.problemReporter().deprecatedField(fieldBinding, this);
534 TypeBinding type = ((VariableBinding) binding).type;
535 int index = indexOfFirstFieldBinding;
536 if (index == length) { // restrictiveFlag == FIELD
537 this.constant = FieldReference.getConstantFor((FieldBinding) binding, this, false, scope);
540 // allocation of the fieldBindings array and its respective constants
541 int otherBindingsLength = length - index;
542 otherCodegenBindings = otherBindings = new FieldBinding[otherBindingsLength];
543 otherDepths = new int[otherBindingsLength];
545 // fill the first constant (the one of the binding)
547 ((bits & FIELD) != 0)
548 ? FieldReference.getConstantFor((FieldBinding) binding, this, false, scope)
549 : ((VariableBinding) binding).constant;
550 // save first depth, since will be updated by visibility checks of other bindings
551 int firstDepth = (bits & DepthMASK) >> DepthSHIFT;
552 // iteration on each field
553 while (index < length) {
554 char[] token = tokens[index];
556 return null; // could not resolve type prior to this point
558 bits &= ~DepthMASK; // flush previous depth if any
559 FieldBinding field = scope.getField(type, token, this);
560 int place = index - indexOfFirstFieldBinding;
561 otherBindings[place] = field;
562 otherDepths[place] = (bits & DepthMASK) >> DepthSHIFT;
563 if (field.isValidBinding()) {
564 // only last field is actually a write access if any
565 if (isFieldUseDeprecated(field, scope, (this.bits & IsStrictlyAssignedMASK) !=0 && index+1 == length)) {
566 scope.problemReporter().deprecatedField(field, this);
568 Constant someConstant = FieldReference.getConstantFor(field, this, false, scope);
569 // constant propagation can only be performed as long as the previous one is a constant too.
570 if (this.constant != NotAConstant) {
571 this.constant = someConstant;
574 if (field.isStatic()) {
575 // static field accessed through receiver? legal but unoptimal (optional warning)
576 scope.problemReporter().nonStaticAccessToStaticField(this, field);
577 // indirect static reference ?
578 if (field.declaringClass != type) {
579 scope.problemReporter().indirectAccessToStaticField(this, field);
585 constant = NotAConstant; //don't fill other constants slots...
586 scope.problemReporter().invalidField(this, field, index, type);
587 setDepth(firstDepth);
591 setDepth(firstDepth);
592 return (otherBindings[otherBindingsLength - 1]).type;
594 public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
595 if (!flowInfo.isReachable()) return;
596 //If inlinable field, forget the access emulation, the code gen will directly target it
597 if (((bits & DepthMASK) == 0) || (constant != NotAConstant)) {
600 if ((bits & RestrictiveFlagMASK) == LOCAL) {
601 currentScope.emulateOuterAccess((LocalVariableBinding) binding);
604 public void manageSyntheticReadAccessIfNecessary(
605 BlockScope currentScope,
606 FieldBinding fieldBinding,
607 TypeBinding lastReceiverType,
610 if (!flowInfo.isReachable()) return;
611 // index == 0 denotes the first fieldBinding, index > 0 denotes one of the 'otherBindings'
612 if (fieldBinding.constant != NotAConstant)
614 if (fieldBinding.isPrivate()) { // private access
615 if (fieldBinding.declaringClass != currentScope.enclosingSourceType()) {
616 if (syntheticReadAccessors == null) {
617 if (otherBindings == null)
618 syntheticReadAccessors = new SyntheticAccessMethodBinding[1];
620 syntheticReadAccessors =
621 new SyntheticAccessMethodBinding[otherBindings.length + 1];
623 syntheticReadAccessors[index] = ((SourceTypeBinding) fieldBinding.declaringClass).addSyntheticMethod(fieldBinding, true);
624 currentScope.problemReporter().needToEmulateFieldReadAccess(fieldBinding, this);
627 } else if (fieldBinding.isProtected()){
628 int depth = index == 0 ? (bits & DepthMASK) >> DepthSHIFT : otherDepths[index-1];
629 // implicit protected access (only for first one)
630 if (depth > 0 && (fieldBinding.declaringClass.getPackage()
631 != currentScope.enclosingSourceType().getPackage())) {
632 if (syntheticReadAccessors == null) {
633 if (otherBindings == null)
634 syntheticReadAccessors = new SyntheticAccessMethodBinding[1];
636 syntheticReadAccessors =
637 new SyntheticAccessMethodBinding[otherBindings.length + 1];
639 syntheticReadAccessors[index] =
640 ((SourceTypeBinding) currentScope.enclosingSourceType().enclosingTypeAt(depth))
641 .addSyntheticMethod(fieldBinding, true);
642 currentScope.problemReporter().needToEmulateFieldReadAccess(fieldBinding, this);
646 // if the binding declaring class is not visible, need special action
647 // for runtime compatibility on 1.2 VMs : change the declaring class of the binding
648 // NOTE: from target 1.2 on, field's declaring class is touched if any different from receiver type
649 if (fieldBinding.declaringClass != lastReceiverType
650 && !lastReceiverType.isArrayType()
651 && fieldBinding.declaringClass != null
652 && fieldBinding.constant == NotAConstant
653 && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2
654 && (index > 0 || indexOfFirstFieldBinding > 1 || !fieldBinding.isStatic())
655 && fieldBinding.declaringClass.id != T_Object)
656 || !fieldBinding.declaringClass.canBeSeenBy(currentScope))){
658 this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)lastReceiverType);
660 if (this.otherCodegenBindings == this.otherBindings){
661 int l = this.otherBindings.length;
662 System.arraycopy(this.otherBindings, 0, this.otherCodegenBindings = new FieldBinding[l], 0, l);
664 this.otherCodegenBindings[index-1] = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)lastReceiverType);
669 * No need to emulate access to protected fields since not implicitly accessed
671 public void manageSyntheticWriteAccessIfNecessary(
672 BlockScope currentScope,
673 FieldBinding fieldBinding,
674 TypeBinding lastReceiverType,
676 if (!flowInfo.isReachable()) return;
677 if (fieldBinding.isPrivate()) {
678 if (fieldBinding.declaringClass != currentScope.enclosingSourceType()) {
679 syntheticWriteAccessor = ((SourceTypeBinding) fieldBinding.declaringClass)
680 .addSyntheticMethod(fieldBinding, false);
681 currentScope.problemReporter().needToEmulateFieldWriteAccess(fieldBinding, this);
684 } else if (fieldBinding.isProtected()){
685 int depth = fieldBinding == binding ? (bits & DepthMASK) >> DepthSHIFT : otherDepths[otherDepths.length-1];
686 if (depth > 0 && (fieldBinding.declaringClass.getPackage()
687 != currentScope.enclosingSourceType().getPackage())) {
688 syntheticWriteAccessor = ((SourceTypeBinding) currentScope.enclosingSourceType().enclosingTypeAt(depth))
689 .addSyntheticMethod(fieldBinding, false);
690 currentScope.problemReporter().needToEmulateFieldWriteAccess(fieldBinding, this);
694 // if the binding declaring class is not visible, need special action
695 // for runtime compatibility on 1.2 VMs : change the declaring class of the binding
696 // NOTE: from target 1.2 on, field's declaring class is touched if any different from receiver type
697 if (fieldBinding.declaringClass != lastReceiverType
698 && !lastReceiverType.isArrayType()
699 && fieldBinding.declaringClass != null
700 && fieldBinding.constant == NotAConstant
701 && ((currentScope.environment().options.targetJDK >= ClassFileConstants.JDK1_2
702 && (fieldBinding != binding || indexOfFirstFieldBinding > 1 || !fieldBinding.isStatic())
703 && fieldBinding.declaringClass.id != T_Object)
704 || !fieldBinding.declaringClass.canBeSeenBy(currentScope))){
705 if (fieldBinding == binding){
706 this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)lastReceiverType);
708 if (this.otherCodegenBindings == this.otherBindings){
709 int l = this.otherBindings.length;
710 System.arraycopy(this.otherBindings, 0, this.otherCodegenBindings = new FieldBinding[l], 0, l);
712 this.otherCodegenBindings[this.otherCodegenBindings.length-1] = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)lastReceiverType);
718 public StringBuffer printExpression(int indent, StringBuffer output) {
720 for (int i = 0; i < tokens.length; i++) {
721 if (i > 0) output.append('.');
722 output.append(tokens[i]);
728 * Normal field binding did not work, try to bind to a field of the delegate receiver.
730 public TypeBinding reportError(BlockScope scope) {
731 if (binding instanceof ProblemFieldBinding) {
732 scope.problemReporter().invalidField(this, (FieldBinding) binding);
733 } else if (binding instanceof ProblemReferenceBinding) {
734 scope.problemReporter().invalidType(this, (TypeBinding) binding);
736 scope.problemReporter().unresolvableReference(this, binding);
740 public TypeBinding resolveType(BlockScope scope) {
741 // field and/or local are done before type lookups
742 // the only available value for the restrictiveFlag BEFORE
743 // the TC is Flag_Type Flag_LocalField and Flag_TypeLocalField
744 this.actualReceiverType = this.receiverType = scope.enclosingSourceType();
745 constant = Constant.NotAConstant;
746 if ((this.codegenBinding = this.binding = scope.getBinding(tokens, bits & RestrictiveFlagMASK, this, true /*resolve*/)).isValidBinding()) {
747 switch (bits & RestrictiveFlagMASK) {
748 case VARIABLE : //============only variable===========
749 case TYPE | VARIABLE :
750 if (binding instanceof LocalVariableBinding) {
751 if (!((LocalVariableBinding) binding).isFinal() && ((bits & DepthMASK) != 0))
752 scope.problemReporter().cannotReferToNonFinalOuterLocal(
753 (LocalVariableBinding) binding,
755 bits &= ~RestrictiveFlagMASK; // clear bits
757 return this.resolvedType = getOtherFieldBindings(scope);
759 if (binding instanceof FieldBinding) {
760 // check for forward references
761 FieldBinding fieldBinding = (FieldBinding) binding;
762 MethodScope methodScope = scope.methodScope();
763 if (methodScope.enclosingSourceType() == fieldBinding.declaringClass
764 && methodScope.lastVisibleFieldID >= 0
765 && fieldBinding.id >= methodScope.lastVisibleFieldID) {
766 if ((!fieldBinding.isStatic() || methodScope.isStatic)
767 && this.indexOfFirstFieldBinding == 1) {
768 scope.problemReporter().forwardReference(this, 0, scope.enclosingSourceType());
771 if (!fieldBinding.isStatic()
772 && this.indexOfFirstFieldBinding == 1
773 && scope.environment().options.getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) {
774 scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
776 bits &= ~RestrictiveFlagMASK; // clear bits
779 // check for deprecated receiver type
780 // deprecation check for receiver type if not first token
781 if (indexOfFirstFieldBinding > 1) {
782 if (isTypeUseDeprecated(this.actualReceiverType, scope))
783 scope.problemReporter().deprecatedType(this.actualReceiverType, this);
786 return this.resolvedType = getOtherFieldBindings(scope);
788 // thus it was a type
789 bits &= ~RestrictiveFlagMASK; // clear bits
791 case TYPE : //=============only type ==============
792 if (isTypeUseDeprecated((TypeBinding) binding, scope))
793 scope.problemReporter().deprecatedType((TypeBinding) binding, this);
794 return this.resolvedType = (TypeBinding) binding;
797 //========error cases===============
798 return this.resolvedType = this.reportError(scope);
801 public void setFieldIndex(int index) {
802 this.indexOfFirstFieldBinding = index;
805 public void traverse(ASTVisitor visitor, BlockScope scope) {
806 visitor.visit(this, scope);
807 visitor.endVisit(this, scope);
809 public String unboundReferenceErrorName() {
810 return new String(tokens[0]);