Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when renaming overridden method in enum constant #389

Closed
mauromol opened this issue Nov 16, 2017 · 9 comments
Closed

Error when renaming overridden method in enum constant #389

mauromol opened this issue Nov 16, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@mauromol
Copy link

This was (in part) GRECLIPSE-1538.

Consider the following:

package b; 

enum R { 
	A() { 
		@Override 
		String getFoo() { 
			
		} 
	}, 
	B() {
		 @Override 
		 String getFoo() { 
			 "bar" 
		 } 
	} 
	
	String getFoo() { 
		
	} 
} 

Now, select getFoo in either A or B definition and hit Ctrl+Shift+R to rename. Change it to getBar and hit enter: the following error dialog is shown:

Could not create a method handle for project 'null' with handle identifier '=MyGroovyProject/src/main/groovy<b{R.groovy[R[b.R$1~getFoo'

However, if you issue the same refactoring from the base getFoo() declaration, it works correctly.

@mauromol
Copy link
Author

After #390 has been fixed, the exact same behaviour exists if R is annotated with @CompileStatic.

@mauromol
Copy link
Author

By the way, when I work with this enum class, sometimes I get the following exception from Eclipse:

pluginId            org.eclipse.jdt.core
pluginVersion       3.12.3.xx-201711162156-e46
code                4
severity            4
message             Error reporting search match inside of enum R [in [Working copy] R.groovy [in b [in src/main/groovy [in TestGroovy]]]]
  R A
  R B
  String getBar() in resource L/TestGroovy/src/main/groovy/b/R.groovy
fingerprint         96b5bb26a8914153fb2fb342b3b0ece8

Exception:java.lang.ClassCastException: org.eclipse.jdt.internal.core.SourceType cannot be cast to org.eclipse.jdt.core.IMethod
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder2$1MethodRequestor.acceptSearchMatch(RippleMethodFinder2.java:337)
	 at org.eclipse.jdt.groovy.search.MethodReferenceSearchRequestor.acceptASTNode(MethodReferenceSearchRequestor.java:178)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.notifyRequestor(TypeInferencingVisitorWithRequestor.java:2427)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitConstructorOrMethod(TypeInferencingVisitorWithRequestor.java:1185)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodInternal(TypeInferencingVisitorWithRequestor.java:750)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodOverrides(TypeInferencingVisitorWithRequestor.java:769)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1520)
	 at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:66)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitClassInternal(TypeInferencingVisitorWithRequestor.java:689)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitJDT(TypeInferencingVisitorWithRequestor.java:383)
	 at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitCompilationUnit(TypeInferencingVisitorWithRequestor.java:353)
	 at org.codehaus.jdt.groovy.integration.internal.GroovyLanguageSupport.maybePerformDelegatedSearch(GroovyLanguageSupport.java:196)
	 at org.codehaus.jdt.groovy.integration.LanguageSupportFactory.maybePerformDelegatedSearch(LanguageSupportFactory.java:110)
	 at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1236)
	 at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1368)
	 at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1500)
	 at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:122)
	 at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:236)
	 at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:583)
	 at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:609)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder2.findAllDeclarations(RippleMethodFinder2.java:356)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder2.findAllRippleMethods(RippleMethodFinder2.java:187)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder2.getAllRippleMethods(RippleMethodFinder2.java:168)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RippleMethodFinder2.getRelatedMethods(RippleMethodFinder2.java:161)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor.initializeMethodsToRename(RenameMethodProcessor.java:248)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor.doCheckFinalConditions(RenameMethodProcessor.java:386)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor.doCheckFinalConditions(RenameVirtualMethodProcessor.java:146)
	 at org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor.checkFinalConditions(JavaRenameProcessor.java:48)
	 at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:222)
	 at org.eclipse.ltk.core.refactoring.Refactoring.checkAllConditions(Refactoring.java:162)
	 at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:81)
	 at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	 at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724)
	 at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	 at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	 at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5521)
	 at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:105)
	 at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)


BUNDLES

name                org.codehaus.groovy
version             2.4.12.xx-201711162156-e46

name                org.eclipse.core.resources
version             3.11.1.v20161107-2032

name                org.eclipse.jdt.core
version             3.12.3.xx-201711162156-e46

name                org.eclipse.jdt
version             3.12.3.v20170301-0400

name                org.eclipse.jdt.ui
version             3.12.2.v20160929-0804

name                org.eclipse.jface
version             3.12.2.v20170113-2113

name                org.eclipse.ltk.core.refactoring
version             3.7.0.v20160419-0705

Any idea?

@eric-milles
Copy link
Member

eric-milles commented Nov 17, 2017 via email

@eric-milles
Copy link
Member

Be advised, renames originating from anonymous inner classes (and probably traits) are not working, but you should be able to rename if you navigate to the base class. And it may not get fixed for some time due to the complexity of moving Groovy model data into the Java model and then back again in this situation.

@mauromol
Copy link
Author

I see. So, isn't it just a "if the method is an override, then perform the action on the overridden method"?
If I understand it correctly, the problem is to have an answer to the "is the method an override", isn't it?

@eric-milles
Copy link
Member

"=MyGroovyProject/src/main/groovy<b{R.groovy[R[b.R$1~getFoo" is the memento that JDT is using to recover the model data way down in the rename process; it acts as a simple handle that can be passed more easily than IJavaElement references. When this is hydrated, the element comes up as missing and so the rename is halted.

eric-milles added a commit that referenced this issue Nov 17, 2017
Fixes ClassCastException: org.eclipse.jdt.internal.core.SourceType
cannot be cast to org.eclipse.jdt.core.IMethod -- due to passing
enclosing type instead of enclosing method during source visitation
@eric-milles eric-milles changed the title Cannot rename overridden method in enum Error when renaming overridden method in enum constant Aug 28, 2018
@eric-milles eric-milles self-assigned this Sep 6, 2018
@eric-milles eric-milles added this to the v3.1.0 milestone Sep 7, 2018
@eric-milles
Copy link
Member

Type hierarchy is not resolving. When it is available, rename will work.

eric-milles added a commit that referenced this issue Sep 20, 2018
- supports rename refactor, type hierarchy, etc.
@eric-milles
Copy link
Member

Ready to test

@mauromol
Copy link
Author

Seems to work well in 3.1.0.xx-201809202224-e48, thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants