01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13: import org.eclipse.jdt.internal.compiler.ASTVisitor;
14: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
15: import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
16: import org.eclipse.jdt.internal.compiler.lookup.Scope;
17: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
18:
19: public class ArrayTypeReference extends SingleTypeReference {
20: public int dimensions;
21: public int originalSourceEnd;
22:
23: /**
24: * ArrayTypeReference constructor comment.
25: * @param source char[]
26: * @param dimensions int
27: * @param pos int
28: */
29: public ArrayTypeReference(char[] source, int dimensions, long pos) {
30:
31: super (source, pos);
32: this .originalSourceEnd = this .sourceEnd;
33: this .dimensions = dimensions;
34: }
35:
36: public int dimensions() {
37:
38: return dimensions;
39: }
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:
55: protected TypeBinding getTypeBinding(Scope scope) {
56:
57: if (this .resolvedType != null)
58: return this .resolvedType;
59: if (dimensions > 255) {
60: scope.problemReporter().tooManyDimensions(this );
61: }
62: TypeBinding leafComponentType = scope.getType(token);
63: return scope.createArrayType(leafComponentType, dimensions);
64:
65: }
66:
67: public StringBuffer printExpression(int indent, StringBuffer output) {
68:
69: super .printExpression(indent, output);
70: if ((this .bits & IsVarArgs) != 0) {
71: for (int i = 0; i < dimensions - 1; i++) {
72: output.append("[]"); //$NON-NLS-1$
73: }
74: output.append("..."); //$NON-NLS-1$
75: } else {
76: for (int i = 0; i < dimensions; i++) {
77: output.append("[]"); //$NON-NLS-1$
78: }
79: }
80: return output;
81: }
82:
83: public void traverse(ASTVisitor visitor, BlockScope scope) {
84:
85: visitor.visit(this , scope);
86: visitor.endVisit(this , scope);
87: }
88:
89: public void traverse(ASTVisitor visitor, ClassScope scope) {
90:
91: visitor.visit(this, scope);
92: visitor.endVisit(this, scope);
93: }
94: }
|