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

Exception on Java class refactoring #1043

Open
mauromol opened this issue Feb 27, 2020 · 1 comment
Open

Exception on Java class refactoring #1043

mauromol opened this issue Feb 27, 2020 · 1 comment

Comments

@mauromol
Copy link

Consider this Java class:

package test59;

public class Test59Java {

	public void foo(String string, Integer num) {
		
	}
}

and this Groovy class:

package test59

import groovy.transform.CompileStatic

@CompileStatic
class Test59 {

	void bar() {
		def t = new Test59Java()
		t.foo('a', 1)
	}
}

Now go to test59.Test59Java.foo(String, Integer) and hit Alt+Shift+C to invoke Change Method Signature refactoring. Add a new parameter, type String, name another, default value null.
Hit OK.
I get the following exception:

eclipse.buildId=4.14.0.I20191210-0610
java.version=1.8.0_202
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=it_IT
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -data file:/D:/ws/rolling/DCS-SHOP-trunk/

org.eclipse.jdt.ui
Error
Thu Feb 27 12:47:08 CET 2020
Internal Error

java.lang.Exception: Cannot update found node: nodeType=8; {
  java.lang.Object t;
}
[105, 50] in [Working copy] Test59.groovy [in test59 [in src [in TestGroovyNull]]]
  package test59
  import groovy.transform.CompileStatic
  class Test59
    void bar():
{
		def t = new Test59Java()
		t.foo('a', 1)
	}
	at org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor$NullOccurrenceUpdate.updateNode(ChangeSignatureProcessor.java:2779)
	at org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor.createChangeManager(ChangeSignatureProcessor.java:1436)
	at org.eclipse.jdt.internal.corext.refactoring.structure.ChangeSignatureProcessor.checkFinalConditions(ChangeSignatureProcessor.java:863)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:226)
	at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:86)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:122)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:210)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:89)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)

If you hit Continue, the Groovy class is not updated and a compilation error on it arises, of course.

@eric-milles
Copy link
Member

When JDT searches for the method's references, any occurrences in Groovy sources are not represented in the Java AST and so the covering node is used (block statement in this case).

	public static ASTNode perform(ASTNode root, int start, int length) {
		NodeFinder finder = new NodeFinder(root, start, length);
		ASTNode result= finder.getCoveredNode();
		if (result == null || result.getStartPosition() != start || result.getLength() != length) {
			return finder.getCoveringNode();
		}

Groovy would need to provide AST for the method statements for this to work. At the moment only a minimal amount of AST is provided in method bodies to support declaration of local variables.

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

No branches or pull requests

2 participants