Skip to main content
summaryrefslogtreecommitdiffstats
blob: a8ac20a75020d7d2507d2dd7a82f2b28d56e7082 (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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/*******************************************************************************
 * Copyright (c) 2000, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * This is an implementation of an early-draft specification developed under the Java
 * Community Process (JCP) and is made available for testing and evaluation purposes
 * only. The code is not compatible with any specification of the JCP.
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Fraunhofer FIRST - extended API and implementation
 *     Technical University Berlin - extended API and implementation
 *     Stephan Herrmann - Contribution for
 *								bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis
 *								bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types
 *******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.codeassist.select.SelectionNodeFound;
import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.codegen.AnnotationContext;
import org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.flow.FlowContext;
import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.Constant;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel.FakeKind;
import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper;

/**
 * OTDT changes:
 *
 * What: new query isDeclaredLifting
 *
 * What: Support multiple strategies for resolve
 * 		 + base import scope
 *       + anchored role type
 *
 * What: Support baseclass decapsulation
 *
 * @version $Id: TypeReference.java 23404 2010-02-03 14:10:22Z stephan $
 */
public abstract class TypeReference extends Expression {

	public static final TypeReference[] NO_TYPE_ARGUMENTS = new TypeReference[0];
	static class AnnotationCollector extends ASTVisitor {
		List annotationContexts;
		TypeReference typeReference;
		int targetType;
		Annotation[] primaryAnnotations;
		int info = -1;
		int info2 = -1;
		LocalVariableBinding localVariable;
		Annotation[][] annotationsOnDimensions;
		Wildcard currentWildcard;

		public AnnotationCollector(
				TypeParameter typeParameter,
				int targetType,
				int typeParameterIndex,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = typeParameter.type;
			this.targetType = targetType;
			this.primaryAnnotations = typeParameter.annotations;
			this.info = typeParameterIndex;
		}

		public AnnotationCollector(
				LocalDeclaration localDeclaration,
				int targetType,
				LocalVariableBinding localVariable,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = localDeclaration.type;
			this.targetType = targetType;
			this.primaryAnnotations = localDeclaration.annotations;
			this.localVariable = localVariable;
		}

		public AnnotationCollector(
				LocalDeclaration localDeclaration,
				int targetType,
				int parameterIndex,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = localDeclaration.type;
			this.targetType = targetType;
			this.primaryAnnotations = localDeclaration.annotations;
			this.info = parameterIndex;
		}

		public AnnotationCollector(
				MethodDeclaration methodDeclaration,
				int targetType,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = methodDeclaration.returnType;
			this.targetType = targetType;
			this.primaryAnnotations = methodDeclaration.annotations;
		}

		public AnnotationCollector(
				FieldDeclaration fieldDeclaration,
				int targetType,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = fieldDeclaration.type;
			this.targetType = targetType;
			this.primaryAnnotations = fieldDeclaration.annotations;
		}
		public AnnotationCollector(
				TypeReference typeReference,
				int targetType,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = typeReference;
			this.targetType = targetType;
		}
		public AnnotationCollector(
				TypeReference typeReference,
				int targetType,
				int info,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = typeReference;
			this.info = info;
			this.targetType = targetType;
		}
		public AnnotationCollector(
				TypeReference typeReference,
				int targetType,
				int info,
				int typeIndex,
				List annotationContexts) {
			this.annotationContexts = annotationContexts;
			this.typeReference = typeReference;
			this.info = info;
			this.targetType = targetType;
			this.info2 = typeIndex;
		}
		public AnnotationCollector(
				TypeReference typeReference,
				int targetType,
				int info,
				List annotationContexts,
				Annotation[][] annotationsOnDimensions) {
			this.annotationContexts = annotationContexts;
			this.typeReference = typeReference;
			this.info = info;
			this.targetType = targetType;
			this.annotationsOnDimensions = annotationsOnDimensions;
		}
		private boolean internalVisit(Annotation annotation) {
			AnnotationContext annotationContext = null;
			if (annotation.isRuntimeTypeInvisible()) {
				annotationContext = new AnnotationContext(annotation, this.typeReference, this.targetType, this.primaryAnnotations, AnnotationContext.INVISIBLE, this.annotationsOnDimensions);
			} else if (annotation.isRuntimeTypeVisible()) {
				annotationContext = new AnnotationContext(annotation, this.typeReference, this.targetType, this.primaryAnnotations, AnnotationContext.VISIBLE, this.annotationsOnDimensions);
			}
			if (annotationContext != null) {
				annotationContext.wildcard = this.currentWildcard;
				switch(this.targetType) {
					case AnnotationTargetTypeConstants.THROWS :
					case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER :
					case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER :
					case AnnotationTargetTypeConstants.METHOD_PARAMETER :
					case AnnotationTargetTypeConstants.TYPE_CAST :
					case AnnotationTargetTypeConstants.TYPE_INSTANCEOF :
					case AnnotationTargetTypeConstants.OBJECT_CREATION :
					case AnnotationTargetTypeConstants.CLASS_LITERAL :
					case AnnotationTargetTypeConstants.CLASS_EXTENDS_IMPLEMENTS:
						annotationContext.info = this.info;
						break;
					case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND :
					case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND :
						annotationContext.info2 = this.info2;
						annotationContext.info = this.info;
						break;
					case AnnotationTargetTypeConstants.LOCAL_VARIABLE :
						annotationContext.variableBinding = this.localVariable;
						break;
					case AnnotationTargetTypeConstants.TYPE_ARGUMENT_METHOD_CALL :
					case AnnotationTargetTypeConstants.TYPE_ARGUMENT_CONSTRUCTOR_CALL :
						annotationContext.info2 = this.info2;
						annotationContext.info = this.info;
				}
				this.annotationContexts.add(annotationContext);
			}
			return true;
		}
		public boolean visit(MarkerAnnotation annotation, BlockScope scope) {
			return internalVisit(annotation);
		}
		public boolean visit(NormalAnnotation annotation, BlockScope scope) {
			return internalVisit(annotation);
		}
		public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) {
			return internalVisit(annotation);
		}
		public boolean visit(Wildcard wildcard, BlockScope scope) {
			this.currentWildcard = wildcard;
			return true;
		}
		public boolean visit(Argument argument, BlockScope scope) {
			if ((argument.bits & ASTNode.IsUnionType) == 0) {
				return true;
			}
			for (int i = 0, max = this.localVariable.initializationCount; i < max; i++) {
				int startPC = this.localVariable.initializationPCs[i << 1];
				int endPC = this.localVariable.initializationPCs[(i << 1) + 1];
				if (startPC != endPC) { // only entries for non zero length
					return true;
				}
			}
			return false;
		}
		public boolean visit(Argument argument, ClassScope scope) {
			if ((argument.bits & ASTNode.IsUnionType) == 0) {
				return true;
			}
			for (int i = 0, max = this.localVariable.initializationCount; i < max; i++) {
				int startPC = this.localVariable.initializationPCs[i << 1];
				int endPC = this.localVariable.initializationPCs[(i << 1) + 1];
				if (startPC != endPC) { // only entries for non zero length
					return true;
				}
			}
			return false;
		}
		public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) {
			for (int i = 0, max = this.localVariable.initializationCount; i < max; i++) {
				int startPC = this.localVariable.initializationPCs[i << 1];
				int endPC = this.localVariable.initializationPCs[(i << 1) + 1];
				if (startPC != endPC) { // only entries for non zero length
					return true;
				}
			}
			return false;
		}
		public void endVisit(Wildcard wildcard, BlockScope scope) {
			this.currentWildcard = null;
		}
	}

//{ObjectTeams: for baseclass decapsulation (implement interface from Expression):
private DecapsulationState baseclassDecapsulation = DecapsulationState.NONE;
public void setBaseclassDecapsulation(DecapsulationState state) {
	this.baseclassDecapsulation = state;
}
@Override
public DecapsulationState getBaseclassDecapsulation() {
	return this.baseclassDecapsulation;
}
@Override
public void tagReportedBaseclassDecapsulation() {
	setBaseclassDecapsulation(DecapsulationState.REPORTED);
}
public int deprecationProblemId = IProblem.UsingDeprecatedType;
// SH}

/*
 * Answer a base type reference (can be an array of base type).
 */
public static final TypeReference baseTypeReference(int baseType, int dim, Annotation[][] dimAnnotations) {

	if (dim == 0) {
		switch (baseType) {
			case (TypeIds.T_void) :
				return new SingleTypeReference(TypeBinding.VOID.simpleName, 0);
			case (TypeIds.T_boolean) :
				return new SingleTypeReference(TypeBinding.BOOLEAN.simpleName, 0);
			case (TypeIds.T_char) :
				return new SingleTypeReference(TypeBinding.CHAR.simpleName, 0);
			case (TypeIds.T_float) :
				return new SingleTypeReference(TypeBinding.FLOAT.simpleName, 0);
			case (TypeIds.T_double) :
				return new SingleTypeReference(TypeBinding.DOUBLE.simpleName, 0);
			case (TypeIds.T_byte) :
				return new SingleTypeReference(TypeBinding.BYTE.simpleName, 0);
			case (TypeIds.T_short) :
				return new SingleTypeReference(TypeBinding.SHORT.simpleName, 0);
			case (TypeIds.T_int) :
				return new SingleTypeReference(TypeBinding.INT.simpleName, 0);
			default : //T_long
				return new SingleTypeReference(TypeBinding.LONG.simpleName, 0);
		}
	}
	switch (baseType) {
		case (TypeIds.T_void) :
			return new ArrayTypeReference(TypeBinding.VOID.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_boolean) :
			return new ArrayTypeReference(TypeBinding.BOOLEAN.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_char) :
			return new ArrayTypeReference(TypeBinding.CHAR.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_float) :
			return new ArrayTypeReference(TypeBinding.FLOAT.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_double) :
			return new ArrayTypeReference(TypeBinding.DOUBLE.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_byte) :
			return new ArrayTypeReference(TypeBinding.BYTE.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_short) :
			return new ArrayTypeReference(TypeBinding.SHORT.simpleName, dim, dimAnnotations, 0);
		case (TypeIds.T_int) :
			return new ArrayTypeReference(TypeBinding.INT.simpleName, dim, dimAnnotations, 0);
		default : //T_long
			return new ArrayTypeReference(TypeBinding.LONG.simpleName, dim, dimAnnotations, 0);
	}
}

// JSR308 type annotations...
public Annotation[][] annotations = null;

// allows us to trap completion & selection nodes
public void aboutToResolve(Scope scope) {
	// default implementation: do nothing
}
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
	return flowInfo;
}
public void checkBounds(Scope scope) {
	// only parameterized type references have bounds
}
public abstract TypeReference copyDims(int dim);
public abstract TypeReference copyDims(int dim, Annotation[][] annotationsOnDimensions);
public int dimensions() {
	return 0;
}
//{ObjectTeams: synthetic AST can use TypeReference as receiver for static method:
@Override
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
	// nop
}
// SH}
public AnnotationContext[] getAllAnnotationContexts(int targetType) {
	List allAnnotationContexts = new ArrayList();
	AnnotationCollector collector = new AnnotationCollector(this, targetType, allAnnotationContexts);
	this.traverse(collector, (BlockScope) null);
	return (AnnotationContext[]) allAnnotationContexts.toArray(new AnnotationContext[allAnnotationContexts.size()]);
}
/**
 * info can be either a type index (superclass/superinterfaces) or a pc into the bytecode
 * @param targetType
 * @param info
 * @param allAnnotationContexts
 */
public void getAllAnnotationContexts(int targetType, int info, List allAnnotationContexts) {
	AnnotationCollector collector = new AnnotationCollector(this, targetType, info, allAnnotationContexts);
	this.traverse(collector, (BlockScope) null);
}
/**
 * info can be either a type index (superclass/superinterfaces) or a pc into the bytecode
 * @param targetType
 * @param info
 * @param allAnnotationContexts
 */
public void getAllAnnotationContexts(int targetType, int info, List allAnnotationContexts, Annotation[][] annotationsOnDimensions) {
	AnnotationCollector collector = new AnnotationCollector(this, targetType, info, allAnnotationContexts, annotationsOnDimensions);
	this.traverse(collector, (BlockScope) null);
	if (annotationsOnDimensions != null) {
		for (int i = 0, max = annotationsOnDimensions.length; i < max; i++) {
			Annotation[] annotationsOnDimension = annotationsOnDimensions[i];
			if (annotationsOnDimension != null) {
				for (int j = 0, max2 = annotationsOnDimension.length; j< max2; j++) {
					annotationsOnDimension[j].traverse(collector, (BlockScope) null);
				}
			}
		}
	}
}
public void getAllAnnotationContexts(int targetType, int info, int typeIndex, List allAnnotationContexts) {
	AnnotationCollector collector = new AnnotationCollector(this, targetType, info, typeIndex, allAnnotationContexts);
	this.traverse(collector, (BlockScope) null);
}
public void getAllAnnotationContexts(int targetType, List allAnnotationContexts) {
	AnnotationCollector collector = new AnnotationCollector(this, targetType, allAnnotationContexts);
	this.traverse(collector, (BlockScope) null);
}
public Annotation[][] getAnnotationsOnDimensions() {
	return null;
}

public void setAnnotationsOnDimensions(Annotation [][] annotationsOnDimensions) {
	// nothing to do. Subtypes should react suitably.
}

public abstract char[] getLastToken();

/**
 * @return char[][]
 * TODO (jerome) should merge back into #getTypeName()
 */
public char [][] getParameterizedTypeName(){
	return getTypeName();
}
protected abstract TypeBinding getTypeBinding(Scope scope);
/**
 * @return char[][]
 */
public abstract char [][] getTypeName() ;

protected TypeBinding internalResolveType(Scope scope) {
	// handle the error here
	this.constant = Constant.NotAConstant;
	if (this.resolvedType != null) { // is a shared type reference which was already resolved
		if (this.resolvedType.isValidBinding()) {
			return this.resolvedType;
		} else {
			switch (this.resolvedType.problemId()) {
				case ProblemReasons.NotFound :
				case ProblemReasons.NotVisible :
				case ProblemReasons.InheritedNameHidesEnclosingName :
					TypeBinding type = this.resolvedType.closestMatch();
					if (type == null) return null;
					return scope.environment().convertToRawType(type, false /*do not force conversion of enclosing types*/);
				default :
					return null;
			}
		}
	}
	boolean hasError;
//{ObjectTeams: don't let SelectionNodeFound(null) prevent alternate searching strategies:
  SelectionNodeFound caughtException = null;
  TypeBinding type = null;
  try {
	// base import scope first:
	CompilationResult compilationResult = scope.referenceCompilationUnit().compilationResult();
	CompilationResult.CheckPoint cp = compilationResult.getCheckPoint(scope.referenceContext());
	try {
	  type = checkResolveUsingBaseImportScope(scope, false); // apply TOLERATE strategy only as a last resort below
	  // copied from below:
	  if (type != null && type.isValidBinding()) {
		type = scope.environment().convertToRawType(type, false /*do not force conversion of enclosing types*/);
		if (type.leafComponentType().isRawType()
				&& (this.bits & ASTNode.IgnoreRawTypeCheck) == 0
				&& scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
			scope.problemReporter().rawTypeReference(this, type);
		}
		return type;
	  }
	} catch (SelectionNodeFound snf) {
		if (snf.binding != null)
			throw snf; // found a valid node.
		caughtException = snf;
	} finally {
		if (   caughtException != null
			|| (type == null)
			|| !type.isValidBinding())
			compilationResult.rollBack(cp);
	}
// ~orig~:
	type = this.resolvedType = getTypeBinding(scope);
	if (type == null) {
		return null; // detected cycle while resolving hierarchy
	}
// :~giro~
  } catch (SelectionNodeFound snf) {
	if (snf.binding != null)
		throw snf; // found a valid node.
	caughtException = snf;
  }
// a third chance trying an anchored type:
  try {
    if (   (caughtException != null)
    	|| (this.resolvedType.problemId() == ProblemReasons.NotFound))
	{
    	// anchored type
	    TypeBinding result = resolveAnchoredType(scope);
	    if (result != null)             // did we do any better than before?
	    	type = this.resolvedType = result; // if non-null but ProblemBinding report below.
    }
  } catch (SelectionNodeFound snf2) {
	  caughtException = snf2; // throw the newer exception instead.
  }
//a forth chance trying a TOLERATED base imported type:
 try {
   if (   (caughtException != null)
	   || (this.resolvedType.problemId() == ProblemReasons.NotFound))
	{
   		if (this.baseclassDecapsulation == DecapsulationState.TOLERATED) {
   			TypeBinding result = checkResolveUsingBaseImportScope(scope, true);
   			if (result != null)             // did we do any better than before?
   				type = this.resolvedType = result; // if non-null but ProblemBinding report below.
   		}
   }
 } catch (SelectionNodeFound snf2) {
	  caughtException = snf2; // throw the newer exception instead.
 } finally {
	  // the attempt to prevent an exception failed:
	  if (caughtException != null)
		  throw caughtException;
 }
// SH}
	if ((hasError = !type.isValidBinding()) == true) {
		reportInvalidType(scope);
		switch (type.problemId()) {
			case ProblemReasons.NotFound :
			case ProblemReasons.NotVisible :
			case ProblemReasons.InheritedNameHidesEnclosingName :
				type = type.closestMatch();
				if (type == null) return null;
				break;
			default :
				return null;
		}
	}
//{ObjectTeams: Split method to make tail accessible:
	return checkResolvedType(type, scope, hasError);
}
public TypeBinding checkResolvedType(TypeBinding type, Scope scope, boolean hasError) {
// SH}
	if (type.isArrayType() && ((ArrayBinding) type).leafComponentType == TypeBinding.VOID) {
		scope.problemReporter().cannotAllocateVoidArray(this);
		return null;
	}
	if (!(this instanceof QualifiedTypeReference)   // QualifiedTypeReference#getTypeBinding called above will have already checked deprecation
			&& isTypeUseDeprecated(type, scope)) {
		reportDeprecatedType(type, scope);
	}
	type = scope.environment().convertToRawType(type, false /*do not force conversion of enclosing types*/);
	if (type.leafComponentType().isRawType()
			&& (this.bits & ASTNode.IgnoreRawTypeCheck) == 0
			&& scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
		scope.problemReporter().rawTypeReference(this, type);
	}
	if (hasError) {
		resolveAnnotations(scope);		
		return type;
	} else {
		// store the computed type only if no error, otherwise keep the problem type instead
		this.resolvedType = type;
		resolveAnnotations(scope);
		return this.resolvedType; // pick up value that may have been changed in resolveAnnotations(..)
	}
}

//{ObjectTeams: alternative strategies for resolving:
/** Try to resolve this reference from base imports. */
public TypeBinding checkResolveUsingBaseImportScope(Scope scope, boolean tolerate) {
	return null; // override to do something useful (only in SingleTypeReference).
}
/**
 * Try to resolve this type reference as an anchored type "t.R".
 */
TypeBinding resolveAnchoredType(Scope scope) {
	return null; // override to do something useful
}
protected boolean shouldAnalyzeRoleReference() {
	if ((this.bits & ASTNode.InsideJavadoc) != 0)
		return false; // don't complain about role encapsulation in java doc
	return   this.resolvedType.isRole()  // no need to check non-role inner of role: either inherited (non-rolish) or local (cannot be referenced)
		  && !TSuperHelper.isMarkerInterface(this.resolvedType);
}
/* check for use of protected role (for parameterized/qualified type references). */
protected boolean isIllegalQualifiedUseOfProtectedRole(Scope scope)
{
	  // implies ReferenceBinding
	if (   ((ReferenceBinding)this.resolvedType).isProtected() // here we only check protected roles
		&& !this.getBaseclassDecapsulation().isAllowed())
	{
		scope.problemReporter().qualifiedProtectedRole(this, (ReferenceBinding)this.resolvedType);
		// keep a problem binding,  clients may be interested in this information, see CodeSelectionTests.testRoleCreation3
		this.resolvedType = new ProblemReferenceBinding(((ReferenceBinding)this.resolvedType).compoundName, (ReferenceBinding)this.resolvedType, ProblemReasons.NotVisible);
		return true;
	}
	return false;
}
// SH}
public boolean isTypeReference() {
	return true;
}
//{ObjectTeams
public boolean isDeclaredLifting() {
	  return false;
}
//Markus Witte}
public boolean isWildcard() {
	return false;
}
public boolean isParameterizedTypeReference() {
	return false;
}

protected void reportDeprecatedType(TypeBinding type, Scope scope, int index) {
	scope.problemReporter().deprecatedType(type, this, index);
}

protected void reportDeprecatedType(TypeBinding type, Scope scope) {
//{ObjectTeams:
  if (this.deprecationProblemId == 0)
	return;
  if (this.deprecationProblemId == IProblem.DeprecatedBaseclass)
	scope.problemReporter().deprecatedBaseclass(this, type);
  else
// SH}
	scope.problemReporter().deprecatedType(type, this, Integer.MAX_VALUE);
}

protected void reportInvalidType(Scope scope) {
//{ObjectTeams: suppress this in role feature bridge (the same will be reported against the original, too):
	if (scope.isFakeMethod(FakeKind.ROLE_FEATURE_BRIDGE)) {
		scope.referenceContext().tagAsHavingErrors();
		return;
	}
	// did we misread an OT keyword as a type reference (during syntax recovery)?
	if (!scope.environment().globalOptions.isPureJava) {
		char[] token = getLastToken();
        for (int j = 0; j < IOTConstants.OT_KEYWORDS.length; j++) {
			if (CharOperation.equals(token, IOTConstants.OT_KEYWORDS[j])) {
				if (scope.referenceContext().compilationResult().hasErrors())
					return; // assume this is a secondary error
			}
		}
	}
// SH}
	scope.problemReporter().invalidType(this, this.resolvedType);
}

public TypeBinding resolveSuperType(ClassScope scope) {
	// assumes the implementation of resolveType(ClassScope) will call back to detect cycles
	TypeBinding superType = resolveType(scope);
	if (superType == null) return null;

	if (superType.isTypeVariable()) {
		if (this.resolvedType.isValidBinding()) {
			this.resolvedType = new ProblemReferenceBinding(getTypeName(), (ReferenceBinding)this.resolvedType, ProblemReasons.IllegalSuperTypeVariable);
			reportInvalidType(scope);
		}
		return null;
	}
	return superType;
}

public final TypeBinding resolveType(BlockScope blockScope) {
	return resolveType(blockScope, true /* checkbounds if any */);
}

public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
	return internalResolveType(scope);
}

public TypeBinding resolveType(ClassScope scope) {
	return internalResolveType(scope);
}

public TypeBinding resolveTypeArgument(BlockScope blockScope, ReferenceBinding genericType, int rank) {
    return resolveType(blockScope, true /* check bounds*/);
}

public TypeBinding resolveTypeArgument(ClassScope classScope, ReferenceBinding genericType, int rank) {
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294057, circularity is allowed when we are
	// resolving type arguments i.e interface A<T extends C> {}	interface B extends A<D> {}
	// interface D extends C {}	interface C extends B {}
	ReferenceBinding ref = classScope.referenceContext.binding;
	boolean pauseHierarchyCheck = false;
	try {
		if (ref.isHierarchyBeingConnected()) {
			ref.tagBits |= TagBits.PauseHierarchyCheck;
			pauseHierarchyCheck = true;
		}
	    return resolveType(classScope);
	} finally {
		if (pauseHierarchyCheck) {
			ref.tagBits &= ~TagBits.PauseHierarchyCheck;
		}
	}
}

public abstract void traverse(ASTVisitor visitor, BlockScope scope);

public abstract void traverse(ASTVisitor visitor, ClassScope scope);

protected void resolveAnnotations(Scope scope) {
	Annotation[][] annotationsOnDimensions = getAnnotationsOnDimensions();
	if (this.annotations != null || annotationsOnDimensions != null) {
		BlockScope resolutionScope = Scope.typeAnnotationsResolutionScope(scope);
		if (resolutionScope != null) {
			long[] tagBitsPerDimension = null;
			int dimensions = this.dimensions();
			boolean shouldAnalyzeArrayNullAnnotations = scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && this instanceof ArrayTypeReference;
			if (this.annotations != null) {
				int annotationsLevels = this.annotations.length;
				for (int i = 0; i < annotationsLevels; i++) {
					Annotation[] currentAnnotations = this.annotations[i];
					if (currentAnnotations != null) {
						resolveAnnotations(resolutionScope, currentAnnotations, new Annotation.TypeUseBinding(isWildcard() ? Binding.TYPE_PARAMETER : Binding.TYPE_USE));
						if (shouldAnalyzeArrayNullAnnotations) {
							int len = currentAnnotations.length;
							for (int j=0; j<len; j++) {
								Binding recipient = currentAnnotations[j].recipient;
								if (recipient instanceof Annotation.TypeUseBinding) {
									if (tagBitsPerDimension == null)
										tagBitsPerDimension = new long[dimensions+1]; // each dimension plus leaf component type at last position
									// @NonNull Foo [][][] means the leaf component type is @NonNull:
									tagBitsPerDimension[dimensions] = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK;
								}
							}
						}
					}
				}
			}

			if (annotationsOnDimensions != null) {
				for (int i = 0, length = annotationsOnDimensions.length; i < length; i++) {
					Annotation [] dimensionAnnotations = annotationsOnDimensions[i];
					if (dimensionAnnotations  != null) {
						resolveAnnotations(resolutionScope, dimensionAnnotations, new Annotation.TypeUseBinding(Binding.TYPE_USE));
						if (shouldAnalyzeArrayNullAnnotations) {
							int len = dimensionAnnotations.length;
							for (int j=0; j<len; j++) {
								Binding recipient = dimensionAnnotations[j].recipient;
								if (recipient instanceof Annotation.TypeUseBinding) {
									if (tagBitsPerDimension == null)
										tagBitsPerDimension = new long[dimensions+1];
									tagBitsPerDimension[i] = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK;
								}
							}
						}
					}
				}
			}
			if (tagBitsPerDimension != null && this.resolvedType.isValidBinding()) {
				// TODO(stephan): wouldn't it be more efficient to store the array bindings inside the type binding rather than the environment?
				// cf. LocalTypeBinding.createArrayType()
				this.resolvedType = scope.environment().createArrayType(this.resolvedType.leafComponentType(), dimensions, tagBitsPerDimension);
			}
		}
	}
}
public int getAnnotatableLevels() {
	return 1;
}
// If typeArgumentAnnotations contain any that are evaluated by the compiler
// create/retrieve a parameterized type binding
// capturing the effect of these annotations into the resolved type binding.
protected TypeBinding captureTypeAnnotations(Scope scope, ReferenceBinding enclosingType, TypeBinding argType, Annotation[] typeArgumentAnnotations) {
	if (!scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled
			|| typeArgumentAnnotations == null 
			|| !(argType instanceof ReferenceBinding))
	{
		return argType;
	}
    int annotLen = typeArgumentAnnotations.length;
    long annotationBits = 0L;
    for (int i = 0; i < annotLen; i++) {
		if (typeArgumentAnnotations[i] instanceof MarkerAnnotation) {
			AnnotationBinding compilerAnnotation = ((MarkerAnnotation)typeArgumentAnnotations[i]).getCompilerAnnotation();
			if (compilerAnnotation != null) {
				switch (compilerAnnotation.getAnnotationType().id) {
					case TypeIds.T_ConfiguredAnnotationNonNull :
						annotationBits |= TagBits.AnnotationNonNull;
						break;
					case TypeIds.T_ConfiguredAnnotationNullable :
						annotationBits |= TagBits.AnnotationNullable;
						break;
					default: // no other annotations are currently handled
				}
			}
		}
	}
    if (annotationBits == 0L)
    	return argType;
	return scope.environment().createParameterizedType((ReferenceBinding) argType, Binding.NO_TYPES, annotationBits, enclosingType);
}
}

Back to the top