KickJava   Java API By Example, From Geeks To Geeks.

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


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.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     /**
25      * ArrayTypeReference constructor comment.
26      * @param source char[]
27      * @param dimensions int
28      * @param pos int
29      */

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     /**
42      * @return char[][]
43      */

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 JavaDoc printExpression(int indent, StringBuffer JavaDoc 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("[]"); //$NON-NLS-1$
71
}
72             output.append("..."); //$NON-NLS-1$
73
} else {
74             for (int i= 0 ; i < dimensions; i++) {
75                 output.append("[]"); //$NON-NLS-1$
76
}
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