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.BlockScope; 16 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; 17 import org.eclipse.jdt.internal.compiler.lookup.Scope; 18 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 19 20 public class ArrayTypeReference extends SingleTypeReference { 21 public int dimensions; 22 public int originalSourceEnd; 23 24 30 public ArrayTypeReference(char[] source, int dimensions, long pos) { 31 32 super(source, pos); 33 this.originalSourceEnd = this.sourceEnd; 34 this.dimensions = dimensions ; 35 } 36 37 public int dimensions() { 38 39 return dimensions; 40 } 41 44 public char [][] getParameterizedTypeName(){ 45 int dim = this.dimensions; 46 char[] dimChars = new char[dim*2]; 47 for (int i = 0; i < dim; i++) { 48 int index = i*2; 49 dimChars[index] = '['; 50 dimChars[index+1] = ']'; 51 } 52 return new char[][]{ CharOperation.concat(token, dimChars) }; 53 } 54 protected TypeBinding getTypeBinding(Scope scope) { 55 56 if (this.resolvedType != null) return this.resolvedType; 57 if (dimensions > 255) { 58 scope.problemReporter().tooManyDimensions(this); 59 } 60 TypeBinding leafComponentType = scope.getType(token); 61 return scope.createArrayType(leafComponentType, dimensions); 62 63 } 64 65 public StringBuffer printExpression(int indent, StringBuffer output){ 66 67 super.printExpression(indent, output); 68 if ((this.bits & IsVarArgs) != 0) { 69 for (int i= 0 ; i < dimensions - 1; i++) { 70 output.append("[]"); } 72 output.append("..."); } else { 74 for (int i= 0 ; i < dimensions; i++) { 75 output.append("[]"); } 77 } 78 return output; 79 } 80 81 public void traverse(ASTVisitor visitor, BlockScope scope) { 82 83 visitor.visit(this, scope); 84 visitor.endVisit(this, scope); 85 } 86 87 public void traverse(ASTVisitor visitor, ClassScope scope) { 88 89 visitor.visit(this, scope); 90 visitor.endVisit(this, scope); 91 } 92 } 93 | Popular Tags |