|
44 | 44 | import com.google.devtools.j2objc.util.BindingUtil;
|
45 | 45 |
|
46 | 46 | import com.google.devtools.j2objc.util.ErrorUtil;
|
47 |
| -import org.eclipse.jdt.core.dom.IMethodBinding; |
48 |
| -import org.eclipse.jdt.core.dom.ITypeBinding; |
49 |
| -import org.eclipse.jdt.core.dom.IVariableBinding; |
50 |
| -import org.eclipse.jdt.core.dom.Modifier; |
| 47 | +import org.eclipse.jdt.core.dom.*; |
51 | 48 |
|
52 | 49 | import java.util.ArrayList;
|
53 | 50 | import java.util.List;
|
@@ -209,47 +206,54 @@ private IVariableBinding getOrCreateOuterField(Scope scope) {
|
209 | 206 | ITypeBinding type = scope.type;
|
210 | 207 | IVariableBinding outerField = outerVars.get(type);
|
211 | 208 | if (outerField == null) {
|
212 |
| - GeneratedTypeBinding newType = new GeneratedTypeBinding( |
213 |
| - type.getName(), type.getPackage(), |
214 |
| - type.getComponentType(), false, type.getComponentType(), |
215 |
| - type.getDeclaringClass() |
216 |
| - ); |
217 |
| - |
218 |
| - if (type.isAnonymous()) { |
219 |
| - Scope preScope = preScope(scope); |
220 |
| - |
221 |
| - boolean isField = false; |
222 |
| - if (type.getDeclaringMethod() == null) { |
223 |
| - isField = true; |
224 |
| - } else { |
225 |
| - isField = false; |
226 |
| - } |
| 209 | + if (type.isAnonymous() && (getOrCreateWeakOuterOuterField(scope) != null)) { |
| 210 | + outerField = getOrCreateWeakOuterOuterField(scope); |
| 211 | + } else { |
| 212 | + outerField = new GeneratedVariableBinding( |
| 213 | + getOuterFieldName(type), Modifier.PRIVATE | Modifier.FINAL, type.getDeclaringClass(), |
| 214 | + true, false, type, null); |
| 215 | + } |
| 216 | + } |
| 217 | + outerVars.put(type, outerField); |
| 218 | + return outerField; |
| 219 | + } |
227 | 220 |
|
228 |
| - for (IVariableBinding theVariableBinding : preScope.declaredVars) { |
229 |
| - if (!(theVariableBinding.isField() ^ isField)) { |
230 |
| - if (scope.node != null) { |
231 |
| - TreeNode parent = scope.node.getParent().getParent(); |
232 |
| - if (parent instanceof VariableDeclarationFragment) { |
233 |
| - VariableDeclarationFragment newParent = (VariableDeclarationFragment) parent; |
234 |
| - if (theVariableBinding.getName().equals(newParent.getVariableBinding().getName())) { |
235 |
| - newType.addAnnotation(BindingUtil.getAnnotation(theVariableBinding, com.google.j2objc.annotations.WeakOuter.class)); |
236 |
| - break; |
237 |
| - } |
| 221 | + private IVariableBinding getOrCreateWeakOuterOuterField(Scope scope) { |
| 222 | + Scope preScope = preScope(scope); |
| 223 | + ITypeBinding type = scope.type; |
| 224 | + GeneratedTypeBinding newType = new GeneratedTypeBinding( |
| 225 | + type.getName(), type.getPackage(), |
| 226 | + type.getComponentType(), false, type.getComponentType(), |
| 227 | + type.getDeclaringClass() |
| 228 | + ); |
| 229 | + |
| 230 | + boolean isField = false; |
| 231 | + if (type.getDeclaringMethod() == null) { |
| 232 | + isField = true; |
| 233 | + } else { |
| 234 | + isField = false; |
| 235 | + } |
| 236 | + |
| 237 | + for (IVariableBinding theVariableBinding : preScope.declaredVars) { |
| 238 | + if (!(theVariableBinding.isField() ^ isField)) { |
| 239 | + if (scope.node != null) { |
| 240 | + TreeNode parent = scope.node.getParent().getParent(); |
| 241 | + if (parent instanceof VariableDeclarationFragment) { |
| 242 | + VariableDeclarationFragment newParent = (VariableDeclarationFragment) parent; |
| 243 | + if (theVariableBinding.getName().equals(newParent.getVariableBinding().getName())) { |
| 244 | + IAnnotationBinding weakOuterAnnotation = BindingUtil.getAnnotation(theVariableBinding, com.google.j2objc.annotations.WeakOuter.class); |
| 245 | + if (weakOuterAnnotation != null) { |
| 246 | + newType.addAnnotation(BindingUtil.getAnnotation(theVariableBinding, com.google.j2objc.annotations.WeakOuter.class)); |
| 247 | + return new GeneratedVariableBinding( |
| 248 | + getOuterFieldName(newType), Modifier.PRIVATE | Modifier.FINAL, newType.getDeclaringClass(), |
| 249 | + true, false, newType, null); |
238 | 250 | }
|
239 | 251 | }
|
240 | 252 | }
|
241 | 253 | }
|
242 |
| - outerField = new GeneratedVariableBinding( |
243 |
| - getOuterFieldName(newType), Modifier.PRIVATE | Modifier.FINAL, newType.getDeclaringClass(), |
244 |
| - true, false, newType, null); |
245 |
| - } else { |
246 |
| - outerField = new GeneratedVariableBinding( |
247 |
| - getOuterFieldName(type), Modifier.PRIVATE | Modifier.FINAL, newType.getDeclaringClass(), |
248 |
| - true, false, newType, null); |
249 | 254 | }
|
250 | 255 | }
|
251 |
| - outerVars.put(type, outerField); |
252 |
| - return outerField; |
| 256 | + return null; |
253 | 257 | }
|
254 | 258 |
|
255 | 259 | private IVariableBinding getOrCreateInnerField(IVariableBinding var, ITypeBinding declaringType) {
|
|
0 commit comments