360e24b443101f9eb499c4395b510fc4351588ba
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / TypeReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.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.ClassScope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
18
19 public abstract class TypeReference extends Expression {
20         public TypeBinding binding;
21 public TypeReference() {
22                 super () ;
23                 }
24 // allows us to trap completion & selection nodes
25
26 public void aboutToResolve(Scope scope) {}
27 /*
28  * Answer a base type reference (can be an array of base type).
29  */
30 public static final TypeReference baseTypeReference(int baseType, int dim) {
31         
32         if (dim == 0) {
33                 switch (baseType) {
34                         case (T_void) :
35                                 return new SingleTypeReference(VoidBinding.simpleName, 0);
36                         case (T_boolean) :
37                                 return new SingleTypeReference(BooleanBinding.simpleName, 0);
38                         case (T_char) :
39                                 return new SingleTypeReference(CharBinding.simpleName, 0);
40                         case (T_float) :
41                                 return new SingleTypeReference(FloatBinding.simpleName, 0);
42                         case (T_double) :
43                                 return new SingleTypeReference(DoubleBinding.simpleName, 0);
44                         case (T_byte) :
45                                 return new SingleTypeReference(ByteBinding.simpleName, 0);
46                         case (T_short) :
47                                 return new SingleTypeReference(ShortBinding.simpleName, 0);
48                         case (T_int) :
49                                 return new SingleTypeReference(IntBinding.simpleName, 0);
50                         default : //T_long      
51                                 return new SingleTypeReference(LongBinding.simpleName, 0);
52                 }
53         }
54         switch (baseType) {
55                 case (T_void) :
56                         return new ArrayTypeReference(VoidBinding.simpleName, dim, 0);
57                 case (T_boolean) :
58                         return new ArrayTypeReference(BooleanBinding.simpleName, dim, 0);
59                 case (T_char) :
60                         return new ArrayTypeReference(CharBinding.simpleName, dim, 0);
61                 case (T_float) :
62                         return new ArrayTypeReference(FloatBinding.simpleName, dim, 0);
63                 case (T_double) :
64                         return new ArrayTypeReference(DoubleBinding.simpleName, dim, 0);
65                 case (T_byte) :
66                         return new ArrayTypeReference(ByteBinding.simpleName, dim, 0);
67                 case (T_short) :
68                         return new ArrayTypeReference(ShortBinding.simpleName, dim, 0);
69                 case (T_int) :
70                         return new ArrayTypeReference(IntBinding.simpleName, dim, 0);
71                 default : //T_long      
72                         return new ArrayTypeReference(LongBinding.simpleName, dim, 0);
73         }
74 }
75 public abstract TypeReference copyDims(int dim);
76 public int dimensions() {
77         return 0;
78 }
79 public abstract TypeBinding getTypeBinding(Scope scope);
80 /**
81  * @return char[][]
82  */
83 public abstract char [][] getTypeName() ;
84 public boolean isTypeReference() {
85         return true;
86 }
87 public TypeBinding resolveType(BlockScope scope) {
88         // handle the error here
89         constant = NotAConstant;
90         if (binding != null) { // is a shared type reference which was already resolved
91                 if (!binding.isValidBinding())
92                         return null; // already reported error
93         } else {
94                 binding = getTypeBinding(scope);
95                 if (!binding.isValidBinding()) {
96                         scope.problemReporter().invalidType(this, binding);
97                         return null;
98                 }
99                 if (isTypeUseDeprecated(binding, scope))
100                         scope.problemReporter().deprecatedType(binding, this);
101         }
102         return binding;
103 }
104 public abstract void traverse(IAbstractSyntaxTreeVisitor visitor, ClassScope classScope);
105 }