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 235603 Details for
Bug 413967
[extract method] Compilation error on extracting to outer type
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]
Starting point
eclipse.jdt.ui.413967.patch (text/plain), 14.67 KB, created by
Nikolay Metchev
on 2013-09-18 11:06:00 EDT
(
hide
)
Description:
Starting point
Filename:
MIME Type:
Creator:
Nikolay Metchev
Created:
2013-09-18 11:06:00 EDT
Size:
14.67 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/nested_in/A_test655.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/nested_in/A_test655.java >new file mode 100644 >index 0000000..52c1462 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/nested_in/A_test655.java >@@ -0,0 +1,12 @@ >+package nested_in; >+ >+public class A_test655 { >+ class Inner { >+ void foo() { >+ } >+ public void test() { >+ /*[*/foo();/*]*/ >+ } >+ } >+ } >+} >diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java >index 6d649d8..634801e 100644 >--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java >+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java >@@ -11,10 +11,11 @@ > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Missing return value, while extracting code out of a loop - https://bugs.eclipse.org/bugs/show_bug.cgi?id=213519 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] missing return type when code can throw exception - https://bugs.eclipse.org/bugs/show_bug.cgi?id=97413 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] extracting return value results in compile error - https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 >+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract method] Compilation error on extracting to outer type > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.refactoring; > > import java.lang.reflect.Modifier; > import java.util.ArrayList; >@@ -161,10 +162,14 @@ > performTest(fgTestSetup.getExpressionPackage(), "A", COMPARE_WITH_OUTPUT, "expression_out"); > } > > protected void nestedTest() throws Exception { > performTest(fgTestSetup.getNestedPackage(), "A", COMPARE_WITH_OUTPUT, "nested_out"); >+ } >+ >+ protected void nestedTest(int mode, int destination) throws Exception { >+ performTest(fgTestSetup.getNestedPackage(), "A", mode, "nested_out", null, null, destination); > } > > protected void returnTest() throws Exception { > performTest(fgTestSetup.getReturnPackage(), "A", COMPARE_WITH_OUTPUT, "return_out"); > } >@@ -1497,10 +1502,15 @@ > > public void test654() throws Exception { > nestedTest(); > } > >+ // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=413967 >+ public void test655() throws Exception { >+ nestedTest(INVALID_SELECTION, 1); >+ } >+ > //---- Extracting method containing a return statement. > > public void test700() throws Exception { > returnTest(); > } >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >index 2c6aef5..045a849 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java >@@ -6,10 +6,11 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 >+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract method] Compilation error on extracting to outer type > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring; > > import org.eclipse.osgi.util.NLS; > >@@ -539,10 +540,12 @@ > > public static String ExtractMethodAnalyzer_cannot_extract_from_annotation; > > public static String ExtractMethodAnalyzer_cannot_extract_method_name_reference; > >+ public static String ExtractMethodAnalyzer_cannot_extract_method_accesibility; >+ > public static String ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name; > > public static String ExtractMethodAnalyzer_cannot_extract_name_in_declaration; > > public static String ExtractMethodAnalyzer_cannot_extract_null_type; >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java >index 54bde91..ed8155f 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java >@@ -7,10 +7,11 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Name ambiguous return value in error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=50607 >+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract method] Compilation error on extracting to outer type > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > > import java.util.ArrayList; > import java.util.HashSet; >@@ -50,10 +51,12 @@ > import org.eclipse.jdt.core.dom.IVariableBinding; > import org.eclipse.jdt.core.dom.Initializer; > import org.eclipse.jdt.core.dom.LabeledStatement; > import org.eclipse.jdt.core.dom.Message; > 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.Name; > import org.eclipse.jdt.core.dom.PrimitiveType; > import org.eclipse.jdt.core.dom.QualifiedName; > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.Statement; >@@ -62,10 +65,11 @@ > import org.eclipse.jdt.core.dom.SwitchCase; > import org.eclipse.jdt.core.dom.SwitchStatement; > import org.eclipse.jdt.core.dom.ThisExpression; > import org.eclipse.jdt.core.dom.TryStatement; > import org.eclipse.jdt.core.dom.Type; >+import org.eclipse.jdt.core.dom.TypeDeclaration; > import org.eclipse.jdt.core.dom.VariableDeclaration; > import org.eclipse.jdt.core.dom.VariableDeclarationExpression; > import org.eclipse.jdt.core.dom.VariableDeclarationFragment; > import org.eclipse.jdt.core.dom.VariableDeclarationStatement; > import org.eclipse.jdt.core.dom.WhileStatement; >@@ -92,10 +96,74 @@ > > import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels; > import org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider; > > /* package */ class ExtractMethodAnalyzer extends CodeAnalyzer { >+ >+ private static final class AccesibilityVisitor extends ASTVisitor { >+ private static final class ClassFinder extends ASTVisitor { >+ private final ITypeBinding fDeclaringClass; >+ >+ private boolean fFound= false; >+ >+ private ClassFinder(ITypeBinding declaringClass) { >+ fDeclaringClass= declaringClass; >+ } >+ >+ @Override >+ public boolean visit(ClassInstanceCreation node) { >+ if (node.resolveTypeBinding().isSubTypeCompatible(fDeclaringClass)) { >+ fFound = true; >+ return false; >+ } >+ return true; >+ } >+ } >+ >+ private ASTNode fDestination; >+ private RefactoringStatus fStatus= new RefactoringStatus(); >+ >+ private ASTNode[] fSelectedNodes; >+ >+ public AccesibilityVisitor(ASTNode destination, ASTNode[] selectedNodes) { >+ fDestination= destination; >+ fSelectedNodes= selectedNodes; >+ } >+ >+ @Override >+ public boolean visit(MethodInvocation node) { >+ IMethodBinding resolvedMethodBinding= node.resolveMethodBinding(); >+ if (!Modifier.isStatic(resolvedMethodBinding.getModifiers())) { >+ Expression expression= node.getExpression(); >+ if (expression != null) { >+ return true; >+ } >+ final ITypeBinding declaringClass= resolvedMethodBinding.getDeclaringClass(); >+ ClassFinder classFinder= new ClassFinder(declaringClass); >+ for (ASTNode selectedNode : fSelectedNodes) { >+ selectedNode.accept(classFinder); >+ if (classFinder.fFound) { >+ return true; >+ } >+ } >+ if (fDestination.getNodeType() == ASTNode.TYPE_DECLARATION) { >+ TypeDeclaration destination= (TypeDeclaration) fDestination; >+ ITypeBinding binding= destination.resolveBinding(); >+ if (binding != null && !declaringClass.isSubTypeCompatible(binding)) { >+ fStatus.addFatalError( >+ Messages.format( >+ RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_method_accesibility, new Object[] { resolvedMethodBinding.getName(), binding.getName() })); >+ } >+ } >+ } >+ return true; >+ } >+ >+ public RefactoringStatus getStatus() { >+ return fStatus; >+ } >+ } > > public static final int ERROR= -2; > public static final int UNDEFINED= -1; > public static final int NO= 0; > public static final int EXPRESSION= 1; >@@ -319,10 +387,18 @@ > ITypeBinding type= ASTNodes.getEnclosingType(destination); > status.merge(Checks.checkMethodInType(type, methodName, arguments)); > status.merge(Checks.checkMethodInHierarchy(type.getSuperclass(), methodName, null, arguments)); > } > >+ public void checkAccesibility(RefactoringStatus result, ASTNode[] selectedNodes, ASTNode destination) { >+ AccesibilityVisitor visitor= new AccesibilityVisitor(destination, selectedNodes); >+ for (ASTNode node : selectedNodes) { >+ node.accept(visitor); >+ } >+ result.merge(visitor.getStatus()); >+ } >+ > private ITypeBinding[] getArgumentTypes() { > ITypeBinding[] result= new ITypeBinding[fArguments.length]; > for (int i= 0; i < fArguments.length; i++) { > result[i]= fArguments[i].getType(); > } >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java >index 0279d0b..2baad89 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.java >@@ -8,10 +8,11 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Does not replace similar code in parent class of anonymous class - https://bugs.eclipse.org/bugs/show_bug.cgi?id=160853 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 > * Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] should declare method static if extracted from anonymous in static method - https://bugs.eclipse.org/bugs/show_bug.cgi?id=152004 >+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract method] Compilation error on extracting to outer type > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > > import java.util.ArrayList; > import java.util.Arrays; >@@ -471,10 +472,12 @@ > throw new OperationCanceledException(); > > BodyDeclaration node= fAnalyzer.getEnclosingBodyDeclaration(); > if (node != null) { > fAnalyzer.checkInput(result, fMethodName, fDestination); >+ ASTNode[] selectedNodes= fAnalyzer.getSelectedNodes(); >+ fAnalyzer.checkAccesibility(result, selectedNodes, fDestination); > pm.worked(1); > } > pm.done(); > return result; > } >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >index ca77d2b..e3ad713 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties >@@ -7,10 +7,11 @@ > # > # Contributors: > # IBM Corporation - initial API and implementation > # Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Extract method and continue https://bugs.eclipse.org/bugs/show_bug.cgi?id=48056 > # Benjamin Muskalla <bmuskalla@eclipsesource.com> - [extract method] Name ambiguous return value in error message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=50607 >+# Nikolay Metchev <nikolaymetchev@gmail.com> - [extract method] Compilation error on extracting to outer type > ############################################################################### > # NLS properties for the Refactoring Core > > ####################################### > # org.eclipse.jdt.internal.core.refactoring >@@ -118,10 +119,11 @@ > ExtractMethodAnalyzer_cannot_extract_from_annotation=Cannot extract out of an annotation. > ExtractMethodAnalyzer_cannot_extract_variable_declaration=Cannot extract parts of a variable declaration. Select whole declaration. > ExtractMethodAnalyzer_cannot_extract_type_reference=Cannot extract a single type reference. > ExtractMethodAnalyzer_cannot_extract_switch_case=Cannot extract the expression of a case statement. > ExtractMethodAnalyzer_cannot_extract_method_name_reference=Cannot extract a single method name. >+ExtractMethodAnalyzer_cannot_extract_method_accesibility=Cannot extract because the method ''{0}'' is not visible from ''{1}''. > ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name=Can not extract part of a qualified name > ExtractMethodAnalyzer_cannot_extract_name_in_declaration=Cannot extract the name part of a declaration. > ExtractMethodAnalyzer_compile_errors_no_parent_binding=The selection cannot cannot be analyzed because of compilation errors in the enclosing type. To perform the operation you will need to fix the errors. > ExtractMethodAnalyzer_ambiguous_return_value=Ambiguous return value: Expression, access to local or return statement extracted. > ExtractMethodAnalyzer_compile_errors=The method''s body cannot be analyzed because of compilation errors in method ''{0}''. To perform the operation you will need to fix the errors.
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 413967
: 235603