1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.lookup.*; 15 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; 16 17 public class QualifiedTypeReference extends TypeReference { 18 19 public char[][] tokens; 20 public long[] sourcePositions; 21 22 public QualifiedTypeReference(char[][] sources , long[] poss) { 23 24 tokens = sources ; 25 sourcePositions = poss ; 26 sourceStart = (int) (sourcePositions[0]>>>32) ; 27 sourceEnd = (int)(sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFFL ) ; 28 } 29 30 public TypeReference copyDims(int dim){ 31 return new ArrayQualifiedTypeReference(tokens, dim, sourcePositions); 34 } 35 36 protected TypeBinding findNextTypeBinding(int tokenIndex, Scope scope, PackageBinding packageBinding) { 37 LookupEnvironment env = scope.environment(); 38 try { 39 env.missingClassFileLocation = this; 40 if (this.resolvedType == null) { 41 this.resolvedType = scope.getType(this.tokens[tokenIndex], packageBinding); 42 } else { 43 this.resolvedType = scope.getMemberType(this.tokens[tokenIndex], (ReferenceBinding) this.resolvedType); 44 if (this.resolvedType instanceof ProblemReferenceBinding) { 45 ProblemReferenceBinding problemBinding = (ProblemReferenceBinding) this.resolvedType; 46 this.resolvedType = new ProblemReferenceBinding( 47 org.eclipse.jdt.core.compiler.CharOperation.subarray(this.tokens, 0, tokenIndex + 1), 48 problemBinding.closestMatch(), 49 this.resolvedType.problemId()); 50 } 51 } 52 return this.resolvedType; 53 } catch (AbortCompilation e) { 54 e.updateContext(this, scope.referenceCompilationUnit().compilationResult); 55 throw e; 56 } finally { 57 env.missingClassFileLocation = null; 58 } 59 } 60 61 public char[] getLastToken() { 62 return this.tokens[this.tokens.length-1]; 63 } 64 protected TypeBinding getTypeBinding(Scope scope) { 65 66 if (this.resolvedType != null) 67 return this.resolvedType; 68 69 Binding binding = scope.getPackage(this.tokens); 70 if (binding != null && !binding.isValidBinding()) 71 return (ReferenceBinding) binding; 73 PackageBinding packageBinding = binding == null ? null : (PackageBinding) binding; 74 boolean isClassScope = scope.kind == Scope.CLASS_SCOPE; 75 ReferenceBinding qualifiedType = null; 76 for (int i = packageBinding == null ? 0 : packageBinding.compoundName.length, max = this.tokens.length, last = max-1; i < max; i++) { 77 findNextTypeBinding(i, scope, packageBinding); 78 if (!this.resolvedType.isValidBinding()) 79 return this.resolvedType; 80 if (i == 0 && this.resolvedType.isTypeVariable() && ((TypeVariableBinding) this.resolvedType).firstBound == null) { scope.problemReporter().illegalAccessFromTypeVariable((TypeVariableBinding) this.resolvedType, this); 82 return this.resolvedType = null; 83 } 84 if (i < last && isTypeUseDeprecated(this.resolvedType, scope)) { 85 reportDeprecatedType(this.resolvedType, scope); 86 } 87 if (isClassScope) 88 if (((ClassScope) scope).detectHierarchyCycle(this.resolvedType, this)) return null; 90 ReferenceBinding currentType = (ReferenceBinding) this.resolvedType; 91 if (qualifiedType != null) { 92 boolean rawQualified; 93 if (currentType.isGenericType()) { 94 qualifiedType = scope.environment().createRawType(currentType, qualifiedType); 95 } else if ((rawQualified = qualifiedType.isRawType()) && !currentType.isStatic()) { 96 qualifiedType = scope.environment().createRawType((ReferenceBinding)currentType.erasure(), qualifiedType); 97 } else if ((rawQualified || qualifiedType.isParameterizedType()) && qualifiedType.erasure() == currentType.enclosingType().erasure()) { 98 qualifiedType = scope.environment().createParameterizedType((ReferenceBinding)currentType.erasure(), null, qualifiedType); 99 } else { 100 qualifiedType = currentType; 101 } 102 } else { 103 qualifiedType = currentType.isGenericType() ? (ReferenceBinding)scope.environment().convertToRawType(currentType) : currentType; 104 } 105 } 106 this.resolvedType = qualifiedType; 107 return this.resolvedType; 108 } 109 110 public char[][] getTypeName(){ 111 112 return tokens; 113 } 114 115 public StringBuffer printExpression(int indent, StringBuffer output) { 116 117 for (int i = 0; i < tokens.length; i++) { 118 if (i > 0) output.append('.'); 119 output.append(tokens[i]); 120 } 121 return output; 122 } 123 124 public void traverse(ASTVisitor visitor, BlockScope scope) { 125 126 visitor.visit(this, scope); 127 visitor.endVisit(this, scope); 128 } 129 130 public void traverse(ASTVisitor visitor, ClassScope scope) { 131 132 visitor.visit(this, scope); 133 visitor.endVisit(this, scope); 134 } 135 } 136 | Popular Tags |