1 /******************************************************************************* 2 * Copyright (c) 2000, 2004 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Common Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/cpl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 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 ArrayQualifiedTypeReference(char[][] sources , int dim, long[] poss)21 public ArrayQualifiedTypeReference(char[][] sources , int dim, long[] poss) { 22 23 super( sources , poss); 24 dimensions = dim ; 25 } 26 dimensions()27 public int dimensions() { 28 29 return dimensions; 30 } 31 32 /** 33 * @return char[][] 34 */ getParameterizedTypeName()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 getTypeBinding(Scope scope)50 protected TypeBinding getTypeBinding(Scope scope) { 51 52 if (this.resolvedType != null) 53 return this.resolvedType; 54 if (dimensions > 255) { 55 scope.problemReporter().tooManyDimensions(this); 56 } 57 try { 58 TypeBinding leafComponentType = scope.getType(this.tokens, this.tokens.length); 59 return scope.createArrayType(leafComponentType, dimensions); 60 } catch (AbortCompilation e) { 61 e.updateContext(this, scope.referenceCompilationUnit().compilationResult); 62 throw e; 63 } 64 } 65 printExpression(int indent, StringBuffer output)66 public StringBuffer printExpression(int indent, StringBuffer output){ 67 68 super.printExpression(indent, output); 69 for (int i = 0 ; i < dimensions ; i++) { 70 output.append("[]"); //$NON-NLS-1$ 71 } 72 return output; 73 } 74 traverse(ASTVisitor visitor, BlockScope scope)75 public void traverse(ASTVisitor visitor, BlockScope scope) { 76 77 visitor.visit(this, scope); 78 visitor.endVisit(this, scope); 79 } 80 traverse(ASTVisitor visitor, ClassScope scope)81 public void traverse(ASTVisitor visitor, ClassScope scope) { 82 83 visitor.visit(this, scope); 84 visitor.endVisit(this, scope); 85 } 86 } 87