Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5ae24c0120e82773b67f592065f9bf48b1410d33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
package org.eclipse.jdt.internal.compiler.ast;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
import org.eclipse.jdt.internal.compiler.IAbstractSyntaxTreeVisitor;
import org.eclipse.jdt.internal.compiler.impl.*;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.flow.*;
import org.eclipse.jdt.internal.compiler.lookup.*;

public class QualifiedNameReference extends NameReference {
	public char[][] tokens;
	public FieldBinding[] otherBindings;
	public int indexOfFirstFieldBinding; //points (into tokens) for the first token that corresponds to first FieldBinding
	
	SyntheticAccessMethodBinding syntheticWriteAccessor;
	SyntheticAccessMethodBinding[] syntheticReadAccessors;
	protected FieldBinding lastFieldBinding;
public QualifiedNameReference(char[][] sources, int sourceStart, int sourceEnd) {
	super();
	tokens = sources;
	this.sourceStart = sourceStart;
	this.sourceEnd = sourceEnd;
}
public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
	if (assignment.expression != null) {
		flowInfo = assignment.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
	}
	// determine the rank until which we now we do not need any actual value for the field access
	int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length;
	int indexOfFirstValueRequired = otherBindingsCount;
	while (indexOfFirstValueRequired > 0) {
		FieldBinding otherBinding = otherBindings[indexOfFirstValueRequired - 1];
		if (otherBinding.isStatic())
			break; // no longer need any value before this point
		indexOfFirstValueRequired--;
	}

	FieldBinding lastFieldBinding = null;
	if ((bits & FIELD) != 0) {
		// reading from a field
		// check if final blank field
		if ((lastFieldBinding = (FieldBinding) binding).isFinal() && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
			if (!flowInfo.isDefinitelyAssigned(lastFieldBinding)) {
				currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
			}
		}
	} else {
		if ((bits & LOCAL) != 0) {
			// first binding is a local variable
			LocalVariableBinding localBinding;
			if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
				currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
			}
			if (!flowInfo.isFakeReachable()) localBinding.used = true;			
		}
	}
	if (indexOfFirstValueRequired == 0) {
		manageEnclosingInstanceAccessIfNecessary(currentScope); // only for first binding
	}
	// all intermediate field accesses are read accesses
	if (otherBindings != null) {
		int start = indexOfFirstValueRequired == 0 ? 0 : indexOfFirstValueRequired - 1;
		for (int i = start; i < otherBindingsCount; i++) {
			if (lastFieldBinding != null) { // could be null if first was a local variable
				manageSyntheticReadAccessIfNecessary(currentScope, lastFieldBinding, i);
			}
			lastFieldBinding = otherBindings[i];
		}
	}
	if (isCompound) {
		if (binding == lastFieldBinding && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding) && (!flowInfo.isDefinitelyAssigned(lastFieldBinding))) {
			currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
		}
		manageSyntheticReadAccessIfNecessary(currentScope, lastFieldBinding, binding == lastFieldBinding ? 0 : otherBindings.length);
	}
	// the last field access is a write access
	if (lastFieldBinding.isFinal()) {
		// in a context where it can be assigned?
		if (currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
			if (flowInfo.isPotentiallyAssigned(lastFieldBinding)) {
				if (indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding
					currentScope.problemReporter().duplicateInitializationOfBlankFinalField(lastFieldBinding, this);
				} else {
					currentScope.problemReporter().cannotAssignToFinalField(lastFieldBinding, this); // attempting to assign a non implicit reference
				}
			}
			flowInfo.markAsDefinitelyAssigned(lastFieldBinding);
			flowContext.recordSettingFinal(lastFieldBinding, this);
		} else {
			currentScope.problemReporter().cannotAssignToFinalField(lastFieldBinding, this);
		}
	}
	// equivalent to valuesRequired[maxOtherBindings]
	manageSyntheticWriteAccessIfNecessary(currentScope, lastFieldBinding);
	return flowInfo;
}
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
	return analyseCode(currentScope, flowContext, flowInfo, true);
}
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {

	// determine the rank until which we now we do not need any actual value for the field access
	int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length;
	int indexOfFirstValueRequired;
	if (valueRequired) {
		indexOfFirstValueRequired = otherBindingsCount;
		while (indexOfFirstValueRequired > 0) {
			FieldBinding otherBinding = otherBindings[indexOfFirstValueRequired - 1];
			if (otherBinding.isStatic())
				break; // no longer need any value before this point
			indexOfFirstValueRequired--;
		}
	} else {
		indexOfFirstValueRequired = otherBindingsCount + 1;
	}
	switch (bits & RestrictiveFlagMASK) {
		case FIELD : // reading a field
			if (indexOfFirstValueRequired == 0) {
				manageSyntheticReadAccessIfNecessary(currentScope, (FieldBinding) binding, 0);
			}
			// check if reading a final blank field
			FieldBinding fieldBinding;
			if ((fieldBinding = (FieldBinding) binding).isFinal()
				&& (indexOfFirstFieldBinding == 1) // was an implicit reference to the first field binding
				&& currentScope.allowBlankFinalFieldAssignment(fieldBinding)
				&& (!flowInfo.isDefinitelyAssigned(fieldBinding))) {
					currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
			}
			break;
		case LOCAL : // reading a local variable
			LocalVariableBinding localBinding;
			if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
				currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
			}
			if (!flowInfo.isFakeReachable()) localBinding.used = true;			
	}
	if (indexOfFirstValueRequired == 0) { 
		manageEnclosingInstanceAccessIfNecessary(currentScope); // only for first binding
	}
	if (otherBindings != null) {
		int start = indexOfFirstValueRequired == 0 ? 0 : indexOfFirstValueRequired - 1;
		for (int i = start; i < otherBindingsCount; i++) {
			manageSyntheticReadAccessIfNecessary(currentScope, otherBindings[i], i + 1);
		}
	}
	return flowInfo;
}
/**
 * Check and/or redirect the field access to the delegate receiver if any
 */
public TypeBinding checkFieldAccess(BlockScope scope) {
	// check for forward references
	FieldBinding fieldBinding = (FieldBinding) binding;
	MethodScope methodScope = scope.methodScope();
	if (methodScope.enclosingSourceType() == fieldBinding.declaringClass
		&& methodScope.fieldDeclarationIndex != MethodScope.NotInFieldDecl
		&& fieldBinding.id >= methodScope.fieldDeclarationIndex) {
		if ((!fieldBinding.isStatic() || methodScope.isStatic)
			&& this.indexOfFirstFieldBinding == 1)
			scope.problemReporter().forwardReference(this, 0, scope.enclosingSourceType());
	}
	bits &= ~RestrictiveFlagMASK; // clear bits
	bits |= FIELD;
	return getOtherFieldBindings(scope);
}
public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
	generateReadSequence(currentScope, codeStream, true);
	// the last field access is a write access
	assignment.expression.generateCode(currentScope, codeStream, true);
	fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, valueRequired); // equivalent to valuesRequired[maxOtherBindings]
	if (valueRequired) {
		codeStream.generateImplicitConversion(assignment.implicitConversion);
	}
}
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
	int pc = codeStream.position;
	if (constant != NotAConstant) {
		if (valueRequired) {
			codeStream.generateConstant(constant, implicitConversion);
		}
	} else {
		generateReadSequence(currentScope, codeStream, valueRequired);
		if (valueRequired) {
			if (lastFieldBinding.declaringClass == null) { // array length
				codeStream.arraylength();
				codeStream.generateImplicitConversion(implicitConversion);
			} else {
				if (lastFieldBinding.constant != NotAConstant) {
					// inline the last field constant
					codeStream.generateConstant(lastFieldBinding.constant, implicitConversion);
				} else {					
					SyntheticAccessMethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[syntheticReadAccessors.length - 1];
					if (accessor == null) {
						if (lastFieldBinding.isStatic()) {
							codeStream.getstatic(lastFieldBinding);
						} else {
							codeStream.getfield(lastFieldBinding);
						}
					} else {
						codeStream.invokestatic(accessor);
					}
					codeStream.generateImplicitConversion(implicitConversion);
				}
			}
		}
	}
	codeStream.recordPositionsFrom(pc, this);
}
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
	
	generateReadSequence(currentScope, codeStream, true);
	SyntheticAccessMethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[syntheticReadAccessors.length - 1];
	
	if (lastFieldBinding.isStatic()){
		if (accessor == null) {
			codeStream.getstatic(lastFieldBinding);
		} else {
			codeStream.invokestatic(accessor);
		}
	} else {
		codeStream.dup();
		if (accessor == null) {
			codeStream.getfield(lastFieldBinding);
		} else {
			codeStream.invokestatic(accessor);
		}
	}
	// the last field access is a write access
	// perform the actual compound operation
	int operationTypeID;
	if ((operationTypeID = implicitConversion >> 4) == T_String) {
		codeStream.generateStringAppend(currentScope, null, expression);
	} else {
		// promote the array reference to the suitable operation type
		codeStream.generateImplicitConversion(implicitConversion);
		// generate the increment value (will by itself  be promoted to the operation value)
		if (expression == IntLiteral.One){ // prefix operation
			codeStream.generateConstant(expression.constant, implicitConversion);			
		} else {
			expression.generateCode(currentScope, codeStream, true);
		}
		// perform the operation
		codeStream.sendOperator(operator, operationTypeID);
		// cast the value back to the array reference type
		codeStream.generateImplicitConversion(assignmentImplicitConversion);
	}
	// actual assignment
	fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, valueRequired); // equivalent to valuesRequired[maxOtherBindings]
}
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
	generateReadSequence(currentScope, codeStream, true);
	SyntheticAccessMethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[syntheticReadAccessors.length - 1];

	if (lastFieldBinding.isStatic()){
		if (accessor == null) {
			codeStream.getstatic(lastFieldBinding);
		} else {
			codeStream.invokestatic(accessor);
		}
	} else {
		codeStream.dup();
		if (accessor == null) {
			codeStream.getfield(lastFieldBinding);
		} else {
			codeStream.invokestatic(accessor);
		}
	}	
	// duplicate the old field value
	if (valueRequired) {
		if (lastFieldBinding.isStatic()) {
			if ((lastFieldBinding.type == LongBinding) || (lastFieldBinding.type == DoubleBinding)) {
				codeStream.dup2();
			} else {
				codeStream.dup();
			}
		} else { // Stack:  [owner][old field value]  ---> [old field value][owner][old field value]
			if ((lastFieldBinding.type == LongBinding) || (lastFieldBinding.type == DoubleBinding)) {
				codeStream.dup2_x1();
			} else {
				codeStream.dup_x1();
			}
		}
	}
	codeStream.generateConstant(postIncrement.expression.constant, implicitConversion);
	codeStream.sendOperator(postIncrement.operator, lastFieldBinding.type.id);
	codeStream.generateImplicitConversion(postIncrement.assignmentImplicitConversion);
	
	fieldStore(codeStream, lastFieldBinding, syntheticWriteAccessor, false);
}
/*
 * Generate code for all bindings (local and fields) excluding the last one, which may then be generated code
 * for a read or write access.
 */
public void generateReadSequence(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {

	// determine the rank until which we now we do not need any actual value for the field access
	int otherBindingsCount = otherBindings == null ? 0 : otherBindings.length;
	int indexOfFirstValueRequired;
	if (valueRequired) {
		indexOfFirstValueRequired = otherBindingsCount;
		while (indexOfFirstValueRequired > 0) {
			FieldBinding otherBinding = otherBindings[indexOfFirstValueRequired - 1];
			if (otherBinding.isStatic() || otherBinding.constant != NotAConstant)
				break; // no longer need any value before this point
			indexOfFirstValueRequired--;
		}
	} else {
		indexOfFirstValueRequired = otherBindingsCount + 1;
	}
	if (indexOfFirstValueRequired == 0) {
		switch (bits & RestrictiveFlagMASK) {
			case FIELD :
				lastFieldBinding = (FieldBinding) binding;

				// if first field is actually constant, we can inline it
				if (lastFieldBinding.constant != NotAConstant) {
					codeStream.generateConstant(lastFieldBinding.constant, 0); // no implicit conversion
					lastFieldBinding = null; // will not generate it again
					break;
				}
				if (!lastFieldBinding.isStatic()) {
					if ((bits & DepthMASK) != 0) {
						Object[] emulationPath = currentScope.getExactEmulationPath(currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT));
						if (emulationPath == null) {
							// internal error, per construction we should have found it
							currentScope.problemReporter().needImplementation();
						} else {
							codeStream.generateOuterAccess(emulationPath, this, currentScope);
						}
					} else {
						generateReceiver(codeStream);
					}
				}
				break;
			case LOCAL : // reading the first local variable
				lastFieldBinding = null;
				LocalVariableBinding localBinding = (LocalVariableBinding) binding;

				// regular local variable read
				if (localBinding.constant != NotAConstant) {
					codeStream.generateConstant(localBinding.constant, 0); // no implicit conversion
				} else {
					// outer local?
					if ((bits & DepthMASK) != 0) {
						// outer local can be reached either through a synthetic arg or a synthetic field
						VariableBinding[] path = currentScope.getEmulationPath(localBinding);
						if (path == null) {
							// emulation was not possible (should not happen per construction)
							currentScope.problemReporter().needImplementation();
						} else {
							codeStream.generateOuterAccess(path, this, currentScope);
						}
					} else {
						codeStream.load(localBinding);
					}
				}
		}
	} else {
		lastFieldBinding = null;
	}
	// all intermediate field accesses are read accesses
	// only the last field binding is a write access
	if (otherBindings != null) {
		int start = indexOfFirstValueRequired == 0 ? 0 : indexOfFirstValueRequired - 1;
		for (int i = start; i < otherBindingsCount; i++) {
			if (lastFieldBinding != null) {
				MethodBinding accessor = syntheticReadAccessors == null ? null : syntheticReadAccessors[i];
				if (accessor == null)
					if (lastFieldBinding.isStatic())
						codeStream.getstatic(lastFieldBinding);
					else
						codeStream.getfield(lastFieldBinding);
				else
					codeStream.invokestatic(accessor);
			}
			lastFieldBinding = otherBindings[i];
		}
	}
}
public void generateReceiver(CodeStream codeStream) {
	codeStream.aload_0();
}
public TypeBinding getOtherFieldBindings(BlockScope scope) {
	// At this point restrictiveFlag may ONLY have two potential value : FIELD LOCAL (i.e cast <<(VariableBinding) binding>> is valid)

	if ((bits & FIELD) != 0) {
		if (!((FieldBinding) binding).isStatic()) { //must check for the static status....
			if (indexOfFirstFieldBinding == 1) {
				//the field is the first token of the qualified reference....
				if (scope.methodScope().isStatic) {
					scope.problemReporter().staticFieldAccessToNonStaticVariable(this, (FieldBinding) binding);
					return null;
				}
			} else { //accessing to a field using a type as "receiver" is allowed only with static field	
				scope.problemReporter().staticFieldAccessToNonStaticVariable(this, (FieldBinding) binding);
				return null;
			}
		}
		if (isFieldUseDeprecated((FieldBinding) binding, scope))
			scope.problemReporter().deprecatedField((FieldBinding) binding, this);

		// if the binding declaring class is not visible, need special action
		// for runtime compatibility on 1.2 VMs : change the declaring class of the binding
		FieldBinding fieldBinding = (FieldBinding)binding;
		if (fieldBinding.declaringClass != null
			&& fieldBinding.constant == NotAConstant
			&& !fieldBinding.declaringClass.canBeSeenBy(scope))
				binding = new FieldBinding(fieldBinding, scope.enclosingSourceType());
	}

	TypeBinding type = ((VariableBinding) binding).type;
	int index = indexOfFirstFieldBinding;
	int length = tokens.length;
	if (index == length) { //	restrictiveFlag == FIELD
		constant = FieldReference.getConstantFor((FieldBinding) binding, false, this, index - 1);
		return type;
	}

	// allocation of the fieldBindings array	and its respective constants
	int otherBindingsLength = length - index;
	otherBindings = new FieldBinding[otherBindingsLength];
	
	// fill the first constant (the one of the binding)
	constant =
		((bits & FIELD) != 0)
			? FieldReference.getConstantFor((FieldBinding) binding, false, this, index - 1)
			: ((VariableBinding) binding).constant;

	// iteration on each field	
	while (index < length) {
		char[] token = tokens[index];
		if (type == null) return null; // could not resolve type prior to this point
		FieldBinding field = scope.getField(type, token, this);
		int place = index - indexOfFirstFieldBinding;
		otherBindings[place] = field;
		if (field.isValidBinding()) {
			if (isFieldUseDeprecated(field, scope))
				scope.problemReporter().deprecatedField(field, this);
			Constant someConstant = FieldReference.getConstantFor(field, false, this, place);
			// constant propagation can only be performed as long as the previous one is a constant too.
			if (constant != NotAConstant){
				constant = someConstant;
			}
			// if the binding declaring class is not visible, need special action
			// for runtime compatibility on 1.2 VMs : change the declaring class of the binding
			if (field.declaringClass != type
				&& field.declaringClass != null // array.length
				&& field.constant == NotAConstant
				&& !field.declaringClass.canBeSeenBy(scope))
					otherBindings[place] = new FieldBinding(field, (ReferenceBinding)type);
			type = field.type;
			index++;
		} else {
			constant = NotAConstant; //don't fill other constants slots...
			scope.problemReporter().invalidField(this, field, index, type);
			return null;
		}
	}
	return (otherBindings[otherBindingsLength - 1]).type;
}
public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope) {
	//If inlinable field, forget the access emulation, the code gen will directly target it
	if (((bits & DepthMASK) == 0) || (constant != NotAConstant)) {
		return;
	}
	switch (bits & RestrictiveFlagMASK) {
		case FIELD :
			FieldBinding fieldBinding;
			if ((fieldBinding = (FieldBinding)binding).isStatic() || (fieldBinding.constant != NotAConstant)) return;		
			ReferenceBinding compatibleType = currentScope.enclosingSourceType();
			// the declaringClass of the target binding must be compatible with the enclosing
			// type at <depth> levels outside
			for (int i = 0, depth = (bits & DepthMASK) >> DepthSHIFT; i < depth; i++) {
				compatibleType = compatibleType.enclosingType();
			}
			currentScope.emulateOuterAccess(compatibleType, false); // request cascade of accesses
			break;
		case LOCAL :
			currentScope.emulateOuterAccess((LocalVariableBinding) binding);
	}
}
public void manageSyntheticReadAccessIfNecessary(BlockScope currentScope, FieldBinding fieldBinding, int index) {
	// index == 0 denotes the first fieldBinding, index > 0 denotes one of the 'otherBindings'

	if (fieldBinding.constant != NotAConstant) return;
	if (fieldBinding.isPrivate()) { // private access
		if (fieldBinding.declaringClass != currentScope.enclosingSourceType()) {
			if (syntheticReadAccessors == null) {
				if (otherBindings == null)
					syntheticReadAccessors = new SyntheticAccessMethodBinding[1];
				else
					syntheticReadAccessors = new SyntheticAccessMethodBinding[otherBindings.length + 1];
			}
			syntheticReadAccessors[index] = fieldBinding.getSyntheticReadAccess();
			currentScope.problemReporter().needToEmulateFieldReadAccess(fieldBinding, this);
		}
		return;
	}
	if (fieldBinding.isProtected() // implicit protected access (only for first one)
		&& index == 0
		&& (bits & DepthMASK) != 0
		&& (fieldBinding.declaringClass.getPackage() 
			!= currentScope.enclosingSourceType().getPackage())){	
			if (syntheticReadAccessors == null) {
				if (otherBindings == null)
					syntheticReadAccessors = new SyntheticAccessMethodBinding[1];
				else
					syntheticReadAccessors = new SyntheticAccessMethodBinding[otherBindings.length + 1];
			}
			syntheticReadAccessors[index] = 
				((SourceTypeBinding)currentScope.enclosingSourceType().
					enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT)).
						addSyntheticMethod(fieldBinding, true);
			currentScope.problemReporter().needToEmulateFieldReadAccess(fieldBinding, this);
	}
}
/*
 * No need to emulate access to protected fields since not implicitly accessed
 */
public void manageSyntheticWriteAccessIfNecessary(BlockScope currentScope, FieldBinding fieldBinding) {
	if (fieldBinding.isPrivate() && fieldBinding.declaringClass != currentScope.enclosingSourceType()) {
		syntheticWriteAccessor = fieldBinding.getSyntheticWriteAccess();
		currentScope.problemReporter().needToEmulateFieldWriteAccess(fieldBinding, this);
	}
}
/**
 * Normal field binding did not work, try to bind to a field of the delegate receiver.
 */
public TypeBinding reportError(BlockScope scope) {
	if (binding instanceof ProblemFieldBinding) {
		scope.problemReporter().invalidField(this, (FieldBinding) binding);
	} else if (binding instanceof ProblemReferenceBinding) {
		scope.problemReporter().invalidType(this, (TypeBinding) binding);
	} else {
		scope.problemReporter().unresolvableReference(this, binding);
	}
	return null;
}
public TypeBinding resolveType(BlockScope scope) {
	// field and/or local are done before type lookups

	// the only available value for the restrictiveFlag BEFORE
	// the TC is Flag_Type Flag_LocalField and Flag_TypeLocalField 
	this.receiverType = scope.enclosingSourceType();
	
	constant = Constant.NotAConstant;
	if ((binding = scope.getBinding(tokens, bits & RestrictiveFlagMASK, this)).isValidBinding()) {
		switch (bits & RestrictiveFlagMASK) {
			case VARIABLE : //============only variable===========
			case TYPE | VARIABLE :
				if (binding instanceof LocalVariableBinding) {
					if (!((LocalVariableBinding) binding).isFinal() && ((bits & DepthMASK) != 0))
						scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding) binding, this);
					bits &= ~RestrictiveFlagMASK;  // clear bits
					bits |= LOCAL;
					return getOtherFieldBindings(scope);
				}
				if (binding instanceof FieldBinding) {
					// check for forward references
					FieldBinding fieldBinding = (FieldBinding) binding;
					MethodScope methodScope = scope.methodScope() ;
					if (methodScope.enclosingSourceType() == fieldBinding.declaringClass
						&& methodScope.fieldDeclarationIndex != MethodScope.NotInFieldDecl
						&& fieldBinding.id >= methodScope.fieldDeclarationIndex) {
							if ((!fieldBinding.isStatic() || methodScope.isStatic) && this.indexOfFirstFieldBinding == 1)
								scope.problemReporter().forwardReference(this,0,scope.enclosingSourceType());
					}					
					bits &= ~RestrictiveFlagMASK;  // clear bits
					bits |= FIELD;					
					return getOtherFieldBindings(scope);
				}

				// thus it was a type
				bits &= ~RestrictiveFlagMASK;  // clear bits
				bits |= TYPE;				
			case TYPE : //=============only type ==============
				//deprecated test
				if (isTypeUseDeprecated((TypeBinding) binding, scope))
					scope.problemReporter().deprecatedType((TypeBinding) binding, this);
				return (TypeBinding) binding;
		}
	}

	//========error cases===============
	return this.reportError(scope);
}
public void setFieldIndex(int index){

	indexOfFirstFieldBinding = index ;
}
public String toStringExpression() {
	/* slow speed */
	StringBuffer buffer = new StringBuffer();
	for (int i = 0; i < tokens.length; i++) {
		buffer.append(tokens[i]);
		if (i < (tokens.length - 1)) {
			buffer.append("."/*nonNLS*/);
		}
	}
	return buffer.toString();
}
public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
	visitor.visit(this, scope);
	visitor.endVisit(this, scope);
}
public  String unboundReferenceErrorName(){

	return new String(tokens[0]);}
}

Back to the top