1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ArrayTypeReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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 net.sourceforge.phpdt.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
17
18 public class ArrayTypeReference extends SingleTypeReference {
19         public int dimensions;
20
21         /**
22          * ArrayTypeReference constructor comment.
23          * 
24          * @param source
25          *            char[]
26          * @param dim
27          *            int
28          * @param pos
29          *            int
30          */
31         public ArrayTypeReference(char[] source, int dim, long pos) {
32                 super(source, pos);
33                 dimensions = dim;
34         }
35
36         public ArrayTypeReference(char[] source, TypeBinding tb, int dim, long pos) {
37                 super(source, tb, pos);
38                 dimensions = dim;
39         }
40
41         public int dimensions() {
42                 return dimensions;
43         }
44
45         public TypeBinding getTypeBinding(Scope scope) {
46                 if (this.resolvedType != null)
47                         return this.resolvedType;
48                 if (dimensions > 255) {
49                         scope.problemReporter().tooManyDimensions(this);
50                 }
51                 return scope.createArray(scope.getType(token), dimensions);
52
53         }
54
55         public String toStringExpression(int tab) {
56
57                 String s = super.toStringExpression(tab);
58                 if (dimensions == 1)
59                         return s + "[]"; //$NON-NLS-1$
60                 for (int i = 1; i <= dimensions; i++)
61                         s = s + "[]"; //$NON-NLS-1$
62                 return s;
63         }
64
65         public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
66                 visitor.visit(this, scope);
67                 visitor.endVisit(this, scope);
68         }
69 }