KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > ArrayQualifiedTypeReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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     
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     /**
33      * @return char[][]
34      */

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 JavaDoc printExpression(int indent, StringBuffer JavaDoc 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("[]"); //$NON-NLS-1$
76
}
77             output.append("..."); //$NON-NLS-1$
78
} else {
79             for (int i= 0 ; i < dimensions; i++) {
80                 output.append("[]"); //$NON-NLS-1$
81
}
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