1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.ASTVisitor; 15 import org.eclipse.jdt.internal.compiler.lookup.*; 16 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; 17 18 public class ArrayQualifiedTypeReference extends QualifiedTypeReference { 19 int dimensions; 20 21 public ArrayQualifiedTypeReference(char[][] sources , int dim, long[] poss) { 22 23 super( sources , poss); 24 dimensions = dim ; 25 } 26 27 public int dimensions() { 28 29 return dimensions; 30 } 31 32 35 public char [][] getParameterizedTypeName(){ 36 int dim = this.dimensions; 37 char[] dimChars = new char[dim*2]; 38 for (int i = 0; i < dim; i++) { 39 int index = i*2; 40 dimChars[index] = '['; 41 dimChars[index+1] = ']'; 42 } 43 int length = this.tokens.length; 44 char[][] qParamName = new char[length][]; 45 System.arraycopy(this.tokens, 0, qParamName, 0, length-1); 46 qParamName[length-1] = CharOperation.concat(this.tokens[length-1], dimChars); 47 return qParamName; 48 } 49 50 protected TypeBinding getTypeBinding(Scope scope) { 51 52 if (this.resolvedType != null) 53 return this.resolvedType; 54 if (this.dimensions > 255) { 55 scope.problemReporter().tooManyDimensions(this); 56 } 57 LookupEnvironment env = scope.environment(); 58 try { 59 env.missingClassFileLocation = this; 60 TypeBinding leafComponentType = super.getTypeBinding(scope); 61 return this.resolvedType = scope.createArrayType(leafComponentType, dimensions); 62 } catch (AbortCompilation e) { 63 e.updateContext(this, scope.referenceCompilationUnit().compilationResult); 64 throw e; 65 } finally { 66 env.missingClassFileLocation = null; 67 } 68 } 69 70 public StringBuffer printExpression(int indent, StringBuffer output){ 71 72 super.printExpression(indent, output); 73 if ((this.bits & IsVarArgs) != 0) { 74 for (int i= 0 ; i < dimensions - 1; i++) { 75 output.append("[]"); } 77 output.append("..."); } else { 79 for (int i= 0 ; i < dimensions; i++) { 80 output.append("[]"); } 82 } 83 return output; 84 } 85 86 public void traverse(ASTVisitor visitor, BlockScope scope) { 87 88 visitor.visit(this, scope); 89 visitor.endVisit(this, scope); 90 } 91 92 public void traverse(ASTVisitor visitor, ClassScope scope) { 93 94 visitor.visit(this, scope); 95 visitor.endVisit(this, scope); 96 } 97 } 98 | Popular Tags |