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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
13 import net.sourceforge.phpdt.core.IJavaElement;
16 * This class represents the recovered binding for a variable
18 class RecoveredVariableBinding implements IVariableBinding {
20 private VariableDeclaration variableDeclaration;
21 private BindingResolver resolver;
23 RecoveredVariableBinding(BindingResolver resolver, VariableDeclaration variableDeclaration) {
24 this.resolver = resolver;
25 this.variableDeclaration = variableDeclaration;
27 public Object getConstantValue() {
31 public ITypeBinding getDeclaringClass() {
32 ASTNode parent = this.variableDeclaration.getParent();
33 while (parent != null && parent.getNodeType() != ASTNode.TYPE_DECLARATION) {
34 parent = parent.getParent();
37 return ((TypeDeclaration) parent).resolveBinding();
42 public IMethodBinding getDeclaringMethod() {
43 ASTNode parent = this.variableDeclaration.getParent();
44 while (parent != null && parent.getNodeType() != ASTNode.METHOD_DECLARATION) {
45 parent = parent.getParent();
48 return ((MethodDeclaration) parent).resolveBinding();
53 public String getName() {
54 return this.variableDeclaration.getName().getIdentifier();
57 public ITypeBinding getType() {
58 return this.resolver.getTypeBinding(this.variableDeclaration);
61 public IVariableBinding getVariableDeclaration() {
65 public int getVariableId() {
69 public boolean isEnumConstant() {
73 public boolean isField() {
74 return this.variableDeclaration.getParent() instanceof FieldDeclaration;
77 public boolean isParameter() {
78 return this.variableDeclaration instanceof SingleVariableDeclaration;
81 public IAnnotationBinding[] getAnnotations() {
82 return AnnotationBinding.NoAnnotations;
85 public IJavaElement getJavaElement() {
89 public String getKey() {
90 StringBuffer buffer = new StringBuffer();
91 buffer.append("Recovered#"); //$NON-NLS-1$
92 if (variableDeclaration != null) {
94 .append("variableDeclaration") //$NON-NLS-1$
95 .append(this.variableDeclaration.getClass())
96 .append(this.variableDeclaration.getName().getIdentifier())
97 .append(this.variableDeclaration.getExtraDimensions());
99 return String.valueOf(buffer);
102 public int getKind() {
103 return IBinding.VARIABLE;
106 public int getModifiers() {
110 public boolean isDeprecated() {
114 public boolean isEqualTo(IBinding binding) {
115 if (binding.isRecovered() && binding.getKind() == IBinding.VARIABLE) {
116 return this.getKey().equals(binding.getKey());
121 public boolean isRecovered() {
125 public boolean isSynthetic() {