Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 245185 Details for
Bug 65875
[extract local] puts declaration at wrong position
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed Patch
bug_65875.patch (text/plain), 6.93 KB, created by
Nicolaj Hoess
on 2014-07-18 08:46:56 EDT
(
hide
)
Description:
Proposed Patch
Filename:
MIME Type:
Creator:
Nicolaj Hoess
Created:
2014-07-18 08:46:56 EDT
Size:
6.93 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_in.java >new file mode 100644 >index 0000000..4a19e40 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_in.java >@@ -0,0 +1,11 @@ >+package p; //6, 9, 6, 25 >+ >+class A { >+ void m() { >+ System.out.println(calculateCount()); >+ calculateCount(); >+ } >+ private int calculateCount() { >+ return 1; >+ } >+} >diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_out.java >new file mode 100644 >index 0000000..be4a6ad >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test110_out.java >@@ -0,0 +1,12 @@ >+package p; //6, 9, 6, 25 >+ >+class A { >+ void m() { >+ int temp= calculateCount(); >+ System.out.println(temp); >+ calculateCount(); >+ } >+ private int calculateCount() { >+ return 1; >+ } >+} >diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_in.java >new file mode 100644 >index 0000000..8e66744 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_in.java >@@ -0,0 +1,16 @@ >+package p; //11, 9, 11, 25 >+ >+class A { >+ void m() { >+ System.out.println(calculateCount()); >+ calculateCount(); >+ System.out.println(calculateCount()); >+ >+ int x= calculateCount(); >+ >+ calculateCount(); >+ } >+ private int calculateCount() { >+ return 1; >+ } >+} >diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_out.java >new file mode 100644 >index 0000000..44267a1 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractTemp/canExtract/A_test111_out.java >@@ -0,0 +1,17 @@ >+package p; //11, 9, 11, 25 >+ >+class A { >+ void m() { >+ int temp= calculateCount(); >+ System.out.println(temp); >+ calculateCount(); >+ System.out.println(temp); >+ >+ int x= temp; >+ >+ calculateCount(); >+ } >+ private int calculateCount() { >+ return 1; >+ } >+} >diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java >index d370241..c4dae0e 100644 >--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java >+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2013 IBM Corporation and others. >+ * Copyright (c) 2000, 2014 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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract local] Extract to local variable not replacing multiple occurrences in same statement - https://bugs.eclipse.org/406347 >+ * Nicolaj Hoess <nicohoess@gmail.com> - [extract local] puts declaration at wrong position - https://bugs.eclipse.org/65875 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.refactoring; > >@@ -681,6 +682,16 @@ > //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 > helper1(5, 20, 5, 29, true, false, "temp", "i"); > } >+ >+ public void test110() throws Exception { >+ //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65875 >+ helper1(6, 9, 6, 25, true, false, "temp", "calculateCount"); >+ } >+ >+ public void test111() throws Exception { >+ //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65875 >+ helper1(11, 9, 11, 25, true, false, "temp", "calculateCount"); >+ } > > public void test113() throws Exception { > //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=406347 >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java >index 101e074..0194a6b 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractTempRefactoring.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2013 IBM Corporation and others. >+ * Copyright (c) 2000, 2014 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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract local] Extract to local variable not replacing multiple occurrences in same statement - https://bugs.eclipse.org/406347 >+ * Nicolaj Hoess <nicohoess@gmail.com> - [extract local] puts declaration at wrong position - https://bugs.eclipse.org/65875 > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > >@@ -666,7 +667,8 @@ > Expression initializer= getSelectedExpression().createCopyTarget(fCURewrite.getASTRewrite(), true); > VariableDeclarationStatement vds= createTempDeclaration(initializer); > >- if ((!fReplaceAllOccurrences) || (retainOnlyReplacableMatches(getMatchingFragments()).length <= 1)) { >+ IASTFragment[] replacableMatches= retainOnlyReplacableMatches(getMatchingFragments()); >+ if ((!fReplaceAllOccurrences) || (replacableMatches.length == 0) || (replacableMatches.length == 1 && replacableMatches[0].equals(getSelectedExpression().getAssociatedExpression()))) { > insertAt(getSelectedExpression().getAssociatedNode(), vds); > return; > } >@@ -999,6 +1001,8 @@ > > private boolean shouldReplaceSelectedExpressionWithTempDeclaration() throws JavaModelException { > IExpressionFragment selectedFragment= getSelectedExpression(); >+ IExpressionFragment firstExpression= getFirstReplacedExpression(); >+ if (firstExpression.getStartPosition() < selectedFragment.getStartPosition()) return false; > return selectedFragment.getAssociatedNode().getParent() instanceof ExpressionStatement > && selectedFragment.matches(ASTFragmentFactory.createFragmentForFullSubtree(selectedFragment.getAssociatedNode())); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 65875
: 245185