### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core.tests.model
diff --git src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 5dfb444..b810f03 100644
--- src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -3398,3 +3398,47 @@
assertTrue("binding is static", (binding.getModifiers() & Modifier.STATIC) != 0);
}
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=420660
+ */
+ public void testBug420660() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int p, int q) {\n" +
+ " int i = 0, j = 1;\n" +
+ " q = 0;\n" +
+ " j = 0;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ MethodDeclaration[] methods = ((TypeDeclaration) node).getMethods();
+ assertEquals("Incorrect no of methods", 1, methods.length);
+ MethodDeclaration method = methods[0];
+ List params = method.parameters();
+ assertEquals("Incorrect no of parameters", 2, params.size());
+ SingleVariableDeclaration param = (SingleVariableDeclaration) params.get(0);
+ IVariableBinding binding = param.resolveBinding();
+ assertTrue("Should be effectively final", binding.isEffectivelyFinal());
+ param = (SingleVariableDeclaration) params.get(1);
+ binding = param.resolveBinding();
+ assertFalse("Should not be effectively final", binding.isEffectivelyFinal());
+
+ List statements = method.getBody().statements();
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ binding = fragment.resolveBinding();
+ assertTrue("Should be effectively final", binding.isEffectivelyFinal());
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ binding = fragment.resolveBinding();
+ assertFalse("Should not be effectively final", binding.isEffectivelyFinal());
+ }
}
#P org.eclipse.jdt.core
diff --git compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
index fa24561..70113bf 100644
--- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
+++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java
@@ -198,5 +198,5 @@
}
LocalVariableBinding localVariableBinding = this.lhs.localVariableBinding();
- if (localVariableBinding != null && localVariableBinding.isCatchParameter()) {
+ if (localVariableBinding != null && (localVariableBinding.isCatchParameter() || localVariableBinding.isParameter())) {
localVariableBinding.tagBits &= ~TagBits.IsEffectivelyFinal; // as it is already definitely assigned, we can conclude already. Also note: catch parameter cannot be compound assigned.
}
diff --git dom/org/eclipse/jdt/core/dom/IVariableBinding.java dom/org/eclipse/jdt/core/dom/IVariableBinding.java
index 789b568..ab22078 100644
--- dom/org/eclipse/jdt/core/dom/IVariableBinding.java
+++ dom/org/eclipse/jdt/core/dom/IVariableBinding.java
@@ -1,8 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
@@ -158,4 +162,14 @@
*/
public IVariableBinding getVariableDeclaration();
-
+
+ /**
+ * Returns whether this binding corresponds to an effectively final variable.
+ * A variable is said to be effectively final if it is never assigned to after
+ * its initialization.
+ *
+ * @return true
if this is an effectively final variable and
+ * false
otherwise
+ * @since 3.9 BETA_JAVA8
+ */
+ public boolean isEffectivelyFinal();
}
diff --git dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java
index ba512fc..0e6ed50 100644
--- dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java
+++ dom/org/eclipse/jdt/core/dom/RecoveredVariableBinding.java
@@ -1,8 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
@@ -126,3 +130,6 @@
return false;
}
+ public boolean isEffectivelyFinal() {
+ return false;
+ }
}
diff --git dom/org/eclipse/jdt/core/dom/VariableBinding.java dom/org/eclipse/jdt/core/dom/VariableBinding.java
index c877900..c7fee74 100644
--- dom/org/eclipse/jdt/core/dom/VariableBinding.java
+++ dom/org/eclipse/jdt/core/dom/VariableBinding.java
@@ -1,8 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
*
* Contributors:
@@ -418,4 +422,12 @@
/*
+ * (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.IVariableBinding.isEffectivelyFinal()
+ */
+ public boolean isEffectivelyFinal() {
+ return this.binding.isEffectivelyFinal();
+ }
+
+ /*
* For debugging purpose only.
* @see java.lang.Object#toString()