summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Metchev2013-08-14 02:06:19 (EDT)
committer Noopur Gupta2013-08-14 02:06:19 (EDT)
commit158c786fed25c1146fc5d390724079908d091994 (patch)
tree8c5c209ea1ddad2fd18bf2416ab20f3dee43d2d1
parent6bdcff2ffb9524d5a63e7832b8175643a587d85c (diff)
downloadeclipse.jdt.ui-158c786fed25c1146fc5d390724079908d091994.zip
eclipse.jdt.ui-158c786fed25c1146fc5d390724079908d091994.tar.gz
eclipse.jdt.ui-158c786fed25c1146fc5d390724079908d091994.tar.bz2
Fixed bug 269401: [inline] Anonymous class using final parameter breaks
method inlining. Signed-off-by: Nikolay Metchev <nikolaymetchev@gmail.com>
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter1.java14
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter2.java14
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter3.java14
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter1.java18
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter2.java19
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter3.java17
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java18
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java15
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java8
9 files changed, 131 insertions, 6 deletions
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter1.java
new file mode 100644
index 0000000..ad63d3b
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter1.java
@@ -0,0 +1,14 @@
+package argument_in;
+
+class Bug {
+ {
+ int y=4;
+ /*]*/foo(y);/*[*/
+ }
+ void foo(final int x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x);
+ }};
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter2.java
new file mode 100644
index 0000000..840d7ad
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter2.java
@@ -0,0 +1,14 @@
+package argument_in;
+
+class Bug {
+ void m(String y) {
+ /*]*/foo(y.substring(3, 10));/*[*/
+ }
+ void foo(final String x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x.trim());
+ }};
+ x.trim();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter3.java
new file mode 100644
index 0000000..1581012
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_in/TestFinalParameter3.java
@@ -0,0 +1,14 @@
+package argument_in;
+
+class Bug {
+ {
+ final int y=4;
+ /*]*/foo(y);/*[*/
+ }
+ void foo(final int x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x);
+ }};
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter1.java
new file mode 100644
index 0000000..aa90ee5
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter1.java
@@ -0,0 +1,18 @@
+package argument_out;
+
+class Bug {
+ {
+ int y=4;
+ final int x = y;
+ new Runnable(){
+ public void run(){
+ System.out.println(x);
+ }};
+ }
+ void foo(final int x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x);
+ }};
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter2.java
new file mode 100644
index 0000000..e11c108
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter2.java
@@ -0,0 +1,19 @@
+package argument_out;
+
+class Bug {
+ void m(String y) {
+ final String x = y.substring(3, 10);
+ new Runnable(){
+ public void run(){
+ System.out.println(x.trim());
+ }};
+ x.trim();
+ }
+ void foo(final String x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x.trim());
+ }};
+ x.trim();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter3.java
new file mode 100644
index 0000000..dad517a
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineMethodWorkspace/TestCases/argument_out/TestFinalParameter3.java
@@ -0,0 +1,17 @@
+;
+
+class Bug {
+ {
+ final int y=4;
+ new Runnable(){
+ public void run(){
+ System.out.println(y);
+ }};
+ }
+ void foo(final int x){
+ new Runnable(){
+ public void run(){
+ System.out.println(x);
+ }};
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java
index 15f096b..536f0ed 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 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
@@ -20,6 +20,7 @@
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=44417)
* o Allow 'this' constructor to be inlined
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38093)
+ * Nikolay Metchev <nikolaymetchev@gmail.com> - Anonymous class using final parameter breaks method inlining - https://bugs.eclipse.org/269401
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;
@@ -503,7 +504,22 @@ public class InlineMethodTests extends AbstractSelectionTestCase {
public void test91470() throws Exception {
performArgumentTest();
}
+
+ //see bug 269401
+ public void testFinalParameter1() throws Exception {
+ performArgumentTest();
+ }
+ //see bug 269401
+ public void testFinalParameter2() throws Exception {
+ performArgumentTest();
+ }
+
+ //see bug 269401
+ public void testFinalParameter3() throws Exception {
+ performArgumentTest();
+ }
+
/* *********************** Name Conflict Tests ******************************* */
private void performNameConflictTest() throws Exception {
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java
index 9d5b0b1..063360f 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 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
@@ -18,6 +18,7 @@
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=44417)
* o Allow 'this' constructor to be inlined
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38093)
+ * Nikolay Metchev <nikolaymetchev@gmail.com> - Anonymous class using final parameter breaks method inlining - https://bugs.eclipse.org/269401
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.code;
@@ -65,6 +66,7 @@ import org.eclipse.jdt.core.dom.LabeledStatement;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.ParenthesizedExpression;
import org.eclipse.jdt.core.dom.ReturnStatement;
@@ -163,6 +165,9 @@ public class CallInliner {
IBinding binding= node.resolveBinding();
if (binding instanceof IVariableBinding) {
int accessMode = fFormalArgument.getSimplifiedAccessMode();
+ if (fFormalArgument.isFinal() && !Modifier.isFinal(binding.getModifiers())) {
+ return setResult(false);
+ }
if (accessMode == FlowInfo.READ || accessMode == FlowInfo.UNUSED)
return setResult(true);
// from now on we only have write accesses.
@@ -515,9 +520,11 @@ public class CallInliner {
} else {
String name= fInvocationScope.createName(parameter.getName(), true);
realArguments[i]= ast.newSimpleName(name);
- fLocals.add(createLocalDeclaration(
- parameter.getTypeBinding(), name,
- (Expression)fRewrite.createCopyTarget(expression)));
+ VariableDeclarationStatement local= createLocalDeclaration(parameter.getTypeBinding(), name, (Expression) fRewrite.createCopyTarget(expression));
+ if (parameter.isFinal()) {
+ local.modifiers().add(fInvocation.getAST().newModifier(ModifierKeyword.FINAL_KEYWORD));
+ }
+ fLocals.add(local);
}
}
if (needsVarargBoxing) {
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java
index b4a3994..4db6bad 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Nikolay Metchev <nikolaymetchev@gmail.com> - Anonymous class using final parameter breaks method inlining - https://bugs.eclipse.org/269401
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.code;
@@ -14,6 +15,7 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
@@ -59,6 +61,10 @@ import org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowInfo;
public boolean isUnused() {
return fAccessMode == FlowInfo.UNUSED;
}
+
+ public boolean isFinal() {
+ return Modifier.isFinal(fDeclaration.getModifiers());
+ }
public boolean isReadOnly() {
return (fAccessMode & (FlowInfo.READ | FlowInfo.READ_POTENTIAL)) != 0;