242bd11e93bc20cb9d1e2a5b3cf4b48be127e64a
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / RecoveredVariableBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
12
13 import net.sourceforge.phpdt.core.IJavaElement;
14
15 /**
16  * This class represents the recovered binding for a variable
17  */
18 class RecoveredVariableBinding implements IVariableBinding {
19
20         private VariableDeclaration variableDeclaration;
21         private BindingResolver resolver;
22
23         RecoveredVariableBinding(BindingResolver resolver, VariableDeclaration variableDeclaration) {
24                 this.resolver = resolver;
25                 this.variableDeclaration = variableDeclaration;
26         }
27         public Object getConstantValue() {
28                 return null;
29         }
30
31         public ITypeBinding getDeclaringClass() {
32                 ASTNode parent = this.variableDeclaration.getParent();
33                 while (parent != null && parent.getNodeType() != ASTNode.TYPE_DECLARATION) {
34                         parent = parent.getParent();
35                 }
36                 if (parent != null) {
37                         return ((TypeDeclaration) parent).resolveBinding();
38                 }
39                 return null;
40         }
41
42         public IMethodBinding getDeclaringMethod() {
43                 ASTNode parent = this.variableDeclaration.getParent();
44                 while (parent != null && parent.getNodeType() != ASTNode.METHOD_DECLARATION) {
45                         parent = parent.getParent();
46                 }
47                 if (parent != null) {
48                         return ((MethodDeclaration) parent).resolveBinding();
49                 }
50                 return null;
51         }
52
53         public String getName() {
54                 return this.variableDeclaration.getName().getIdentifier();
55         }
56
57         public ITypeBinding getType() {
58                 return this.resolver.getTypeBinding(this.variableDeclaration);
59         }
60
61         public IVariableBinding getVariableDeclaration() {
62                 return this;
63         }
64
65         public int getVariableId() {
66                 return 0;
67         }
68
69         public boolean isEnumConstant() {
70                 return false;
71         }
72
73         public boolean isField() {
74                 return this.variableDeclaration.getParent() instanceof FieldDeclaration;
75         }
76
77         public boolean isParameter() {
78                 return this.variableDeclaration instanceof SingleVariableDeclaration;
79         }
80
81         public IAnnotationBinding[] getAnnotations() {
82                 return AnnotationBinding.NoAnnotations;
83         }
84
85         public IJavaElement getJavaElement() {
86                 return null;
87         }
88
89         public String getKey() {
90                 StringBuffer buffer = new StringBuffer();
91                 buffer.append("Recovered#"); //$NON-NLS-1$
92                 if (variableDeclaration != null) {
93                         buffer
94                                 .append("variableDeclaration") //$NON-NLS-1$
95                                 .append(this.variableDeclaration.getClass())
96                                 .append(this.variableDeclaration.getName().getIdentifier())
97                                 .append(this.variableDeclaration.getExtraDimensions());
98                 }
99                 return String.valueOf(buffer);
100         }
101
102         public int getKind() {
103                 return IBinding.VARIABLE;
104         }
105
106         public int getModifiers() {
107                 return 0;
108         }
109
110         public boolean isDeprecated() {
111                 return false;
112         }
113
114         public boolean isEqualTo(IBinding binding) {
115                 if (binding.isRecovered() && binding.getKind() == IBinding.VARIABLE) {
116                         return this.getKey().equals(binding.getKey());
117                 }
118                 return false;
119         }
120
121         public boolean isRecovered() {
122                 return true;
123         }
124
125         public boolean isSynthetic() {
126                 return false;
127         }
128 }