first scanner /parser copied from the jdt java version
[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.*;
15
16 public abstract class TypeReference extends Expression {
17         public TypeBinding binding;
18 public TypeReference() {
19                 super () ;
20                 }
21 // allows us to trap completion & selection nodes
22
23 public void aboutToResolve(Scope scope) {}
24 /*
25  * Answer a base type reference (can be an array of base type).
26  */
27 public static final TypeReference baseTypeReference(int baseType, int dim) {
28         
29         if (dim == 0) {
30                 switch (baseType) {
31                         case (T_void) :
32                                 return new SingleTypeReference(VoidBinding.simpleName, 0);
33                         case (T_boolean) :
34                                 return new SingleTypeReference(BooleanBinding.simpleName, 0);
35                         case (T_char) :
36                                 return new SingleTypeReference(CharBinding.simpleName, 0);
37                         case (T_float) :
38                                 return new SingleTypeReference(FloatBinding.simpleName, 0);
39                         case (T_double) :
40                                 return new SingleTypeReference(DoubleBinding.simpleName, 0);
41                         case (T_byte) :
42                                 return new SingleTypeReference(ByteBinding.simpleName, 0);
43                         case (T_short) :
44                                 return new SingleTypeReference(ShortBinding.simpleName, 0);
45                         case (T_int) :
46                                 return new SingleTypeReference(IntBinding.simpleName, 0);
47                         default : //T_long      
48                                 return new SingleTypeReference(LongBinding.simpleName, 0);
49                 }
50         }
51         switch (baseType) {
52                 case (T_void) :
53                         return new ArrayTypeReference(VoidBinding.simpleName, dim, 0);
54                 case (T_boolean) :
55                         return new ArrayTypeReference(BooleanBinding.simpleName, dim, 0);
56                 case (T_char) :
57                         return new ArrayTypeReference(CharBinding.simpleName, dim, 0);
58                 case (T_float) :
59                         return new ArrayTypeReference(FloatBinding.simpleName, dim, 0);
60                 case (T_double) :
61                         return new ArrayTypeReference(DoubleBinding.simpleName, dim, 0);
62                 case (T_byte) :
63                         return new ArrayTypeReference(ByteBinding.simpleName, dim, 0);
64                 case (T_short) :
65                         return new ArrayTypeReference(ShortBinding.simpleName, dim, 0);
66                 case (T_int) :
67                         return new ArrayTypeReference(IntBinding.simpleName, dim, 0);
68                 default : //T_long      
69                         return new ArrayTypeReference(LongBinding.simpleName, dim, 0);
70         }
71 }
72 public abstract TypeReference copyDims(int dim);
73 public int dimensions() {
74         return 0;
75 }
76 public abstract TypeBinding getTypeBinding(Scope scope);
77 /**
78  * @return char[][]
79  */
80 public abstract char [][] getTypeName() ;
81 public boolean isTypeReference() {
82         return true;
83 }
84 public TypeBinding resolveType(BlockScope scope) {
85         // handle the error here
86         constant = NotAConstant;
87         if (binding != null) { // is a shared type reference which was already resolved
88                 if (!binding.isValidBinding())
89                         return null; // already reported error
90         } else {
91                 binding = getTypeBinding(scope);
92                 if (!binding.isValidBinding()) {
93                         scope.problemReporter().invalidType(this, binding);
94                         return null;
95                 }
96                 if (isTypeUseDeprecated(binding, scope))
97                         scope.problemReporter().deprecatedType(binding, this);
98         }
99         return binding;
100 }
101 public abstract void traverse(IAbstractSyntaxTreeVisitor visitor, ClassScope classScope);
102 }