View | Details | Raw Unified | Return to bug 420660 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java (+44 lines)
Lines 3398-3400 Link Here
3398
		assertTrue("binding is static", (binding.getModifiers() & Modifier.STATIC) != 0);
3398
		assertTrue("binding is static", (binding.getModifiers() & Modifier.STATIC) != 0);
3399
	}
3399
	}
3400
3401
	/*
3402
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=420660
3403
	 */
3404
	public void testBug420660() throws JavaModelException {
3405
		String contents =
3406
			"public class X {\n" +
3407
			"		public void foo(int p, int q) {\n" +
3408
			"			int i = 0, j = 1;\n" +
3409
			"			q = 0;\n" +
3410
			"			j = 0;\n" +
3411
			"		}\n" +
3412
			"}";
3413
		this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
3414
		ASTNode node = buildAST(
3415
			contents,
3416
			this.workingCopy);
3417
		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
3418
		CompilationUnit compilationUnit = (CompilationUnit) node;
3419
		assertProblemsSize(compilationUnit, 0);
3420
		node = getASTNode(compilationUnit, 0);
3421
		assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
3422
		MethodDeclaration[] methods = ((TypeDeclaration) node).getMethods();
3423
		assertEquals("Incorrect no of methods", 1, methods.length);
3424
		MethodDeclaration method = methods[0];
3425
		List params = method.parameters();
3426
		assertEquals("Incorrect no of parameters", 2, params.size());
3427
		SingleVariableDeclaration param = (SingleVariableDeclaration) params.get(0);
3428
		IVariableBinding binding = param.resolveBinding();
3429
		assertTrue("Should be effectively final", binding.isEffectivelyFinal());
3430
		param = (SingleVariableDeclaration) params.get(1);
3431
		binding = param.resolveBinding();
3432
		assertFalse("Should not be effectively final", binding.isEffectivelyFinal());
3433
		
3434
		List statements = method.getBody().statements();
3435
		VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
3436
		List fragments = statement.fragments();
3437
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
3438
		binding = fragment.resolveBinding();
3439
		assertTrue("Should be effectively final", binding.isEffectivelyFinal());
3440
		fragment = (VariableDeclarationFragment) fragments.get(1);
3441
		binding = fragment.resolveBinding();
3442
		assertFalse("Should not be effectively final", binding.isEffectivelyFinal());
3443
	}
3400
}
3444
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java (-1 / +1 lines)
Lines 198-202 Link Here
198
	}
198
	}
199
	LocalVariableBinding localVariableBinding = this.lhs.localVariableBinding();
199
	LocalVariableBinding localVariableBinding = this.lhs.localVariableBinding();
200
	if (localVariableBinding != null && localVariableBinding.isCatchParameter()) { 
200
	if (localVariableBinding != null && (localVariableBinding.isCatchParameter() || localVariableBinding.isParameter())) { 
201
		localVariableBinding.tagBits &= ~TagBits.IsEffectivelyFinal;  // as it is already definitely assigned, we can conclude already. Also note: catch parameter cannot be compound assigned.
201
		localVariableBinding.tagBits &= ~TagBits.IsEffectivelyFinal;  // as it is already definitely assigned, we can conclude already. Also note: catch parameter cannot be compound assigned.
202
	}
202
	}
(-)dom/org/eclipse/jdt/core/dom/IVariableBinding.java (-2 / +16 lines)
Lines 1-8 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
Lines 158-161 Link Here
158
	 */
162
	 */
159
	public IVariableBinding getVariableDeclaration();
163
	public IVariableBinding getVariableDeclaration();
160
164
	
165
	/**
166
	 * Returns whether this binding corresponds to an effectively final variable. 
167
	 * A variable is said to be effectively final if it is never assigned to after 
168
	 * its initialization.
169
	 * 
170
	 * @return <code>true</code> if this is an effectively final variable and
171
	 * 			<code>false</code> otherwise
172
	 * @since 3.9 BETA_JAVA8
173
	 */
174
	public boolean isEffectivelyFinal();
161
}
175
}
(-)dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java (-1 / +8 lines)
Lines 1-8 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
2
 * Copyright (c) 2007, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
Lines 126-128 Link Here
126
		return false;
130
		return false;
127
	}
131
	}
132
	public boolean isEffectivelyFinal() {
133
		return false;
134
	}
128
}
135
}
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (-1 / +13 lines)
Lines 1-8 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * This is an implementation of an early-draft specification developed under the Java
9
 * Community Process (JCP) and is made available for testing and evaluation purposes
10
 * only. The code is not compatible with any specification of the JCP.
7
 *
11
 *
8
 * Contributors:
12
 * Contributors:
Lines 418-421 Link Here
418
422
419
	/*
423
	/*
424
	 * (non-Javadoc)
425
	 * @see org.eclipse.jdt.core.dom.IVariableBinding.isEffectivelyFinal()
426
	 */
427
	public boolean isEffectivelyFinal() {
428
		return this.binding.isEffectivelyFinal();
429
	}
430
431
	/*
420
	 * For debugging purpose only.
432
	 * For debugging purpose only.
421
	 * @see java.lang.Object#toString()
433
	 * @see java.lang.Object#toString()

Return to bug 420660