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