improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / SingleTypeReference.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.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
14 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
18 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
19 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
20
21 public class SingleTypeReference extends TypeReference {
22         public char[] token;
23         
24
25 public SingleTypeReference(char[] source, long pos) {
26                 token = source;
27                 sourceStart = (int) (pos>>>32)  ;
28                 sourceEnd = (int) (pos & 0x00000000FFFFFFFFL) ;
29         
30 }
31 public SingleTypeReference(char[] source ,TypeBinding type, long pos) {
32         this(source, pos) ;
33         this.resolvedType = type ;
34 }
35 public TypeReference copyDims(int dim){
36         //return a type reference copy of me with some dimensions
37         //warning : the new type ref has a null binding
38         
39         return new ArrayTypeReference(token,null,dim,(((long)sourceStart)<<32)+sourceEnd) ;
40 }
41 public TypeBinding getTypeBinding(Scope scope) {
42         if (this.resolvedType != null)
43                 return this.resolvedType;
44         return scope.getType(token);
45 }
46 public char [][] getTypeName() {
47         return new char[][] { token };
48 }
49 public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
50         ReferenceBinding memberTb = scope.getMemberType(token, enclosingType);
51         if (!memberTb.isValidBinding()) {
52                 scope.problemReporter().invalidEnclosingType(this, memberTb, enclosingType);
53                 return null;
54         }
55         if (isTypeUseDeprecated(memberTb, scope))
56                 scope.problemReporter().deprecatedType(memberTb, this);
57         return this.resolvedType = memberTb;
58 }
59 public StringBuffer printExpression(int indent, StringBuffer output){
60         
61         return output.append(token);
62 }
63 public String toStringExpression(int tab){
64         return new String(token) ;
65 }
66 public void traverse(ASTVisitor visitor, BlockScope scope) {
67         visitor.visit(this, scope);
68         visitor.endVisit(this, scope);
69 }
70 public void traverse(ASTVisitor visitor, ClassScope scope) {
71         visitor.visit(this, scope);
72         visitor.endVisit(this, scope);
73 }
74 }