View | Details | Raw Unified | Return to bug 212096
Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (+1 lines)
Lines 199-204 Link Here
199
		IMethodBinding declaringMethod = getDeclaringMethod();
199
		IMethodBinding declaringMethod = getDeclaringMethod();
200
		if (declaringMethod == null) return null;
200
		if (declaringMethod == null) return null;
201
		JavaElement method = (JavaElement) declaringMethod.getJavaElement();
201
		JavaElement method = (JavaElement) declaringMethod.getJavaElement();
202
		if (method == null) return null;
202
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
203
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
203
		VariableDeclaration localVar = (VariableDeclaration) ((DefaultBindingResolver) this.resolver).bindingsToAstNodes.get(this);
204
		VariableDeclaration localVar = (VariableDeclaration) ((DefaultBindingResolver) this.resolver).bindingsToAstNodes.get(this);
204
		if (localVar == null) return null;
205
		if (localVar == null) return null;
(-)src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java (+37 lines)
Lines 150-155 Link Here
150
				"}"
150
				"}"
151
			}, 
151
			}, 
152
			"1.5");
152
			"1.5");
153
		setUpWorkingCopy();
154
	}
155
156
	private void setUpWorkingCopy() throws JavaModelException {
157
		if (this.workingCopy != null)
158
			this.workingCopy.discardWorkingCopy();
153
		IProblemRequestor problemRequestor = new IProblemRequestor() {
159
		IProblemRequestor problemRequestor = new IProblemRequestor() {
154
			public void acceptProblem(IProblem problem) {}
160
			public void acceptProblem(IProblem problem) {}
155
			public void beginReporting() {}
161
			public void beginReporting() {}
Lines 1354-1359 Link Here
1354
	}
1360
	}
1355
1361
1356
	/*
1362
	/*
1363
	 * Ensures that the IJavaElement of an IBinding representing a local variable in an anonymous type
1364
	 * in a discarded working copy is null.
1365
	 * (regression test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=212096 )
1366
	 */
1367
	public void testLocalVariable4() throws JavaModelException {
1368
		try {
1369
			ASTNode node = buildAST(
1370
				"public class X {\n" +
1371
				"  void foo() {\n" +
1372
				"    new Object() {\n" +
1373
				"      void bar() {\n" +
1374
				"        int /*start*/local/*end*/;\n" +
1375
				"      }\n" +
1376
				"    };\n" +
1377
				"  }\n" +
1378
				"}"
1379
			);
1380
			IBinding binding = ((VariableDeclaration) node).resolveBinding();
1381
			this.workingCopy.discardWorkingCopy();
1382
			IJavaElement element = binding.getJavaElement();
1383
			assertEquals(
1384
				"Unexpected Java element",
1385
				null,
1386
				element
1387
			);
1388
		} finally {
1389
			setUpWorkingCopy();
1390
		}
1391
	}
1392
1393
	/*
1357
	 * Ensures that the IJavaElement of an IBinding representing a member type is correct.
1394
	 * Ensures that the IJavaElement of an IBinding representing a member type is correct.
1358
	 */
1395
	 */
1359
	public void testMemberType() throws JavaModelException {
1396
	public void testMemberType() throws JavaModelException {

Return to bug 212096