JDeodorant icon indicating copy to clipboard operation
JDeodorant copied to clipboard

The use of the Java Stream leads to failures in 'Move Method' refactoring.

Open assdfsdafasfa opened this issue 2 months ago • 2 comments

When using a tool to detect Feature Envy and perform automated refactoring, if the refactored code contains syntax errors, should I attempt to fix them manually?

Before Refactoring:

public class SourceClass {
	TargetClass t;
	    private static class Config { }
	    
	    private final Config config = new Config();
	    
	    public void processData() {
	        new ArrayList<Integer>().stream().filter(this::isPositive).collect(toList());
	    }
	    
	    private boolean isPositive(Integer number) {
	        return number != null && number > 0;
	    }
}
public class TargetClass{}

After Refactoring:

public class TargetClass {

	public void processData(SourceClass sourceClass) {
	    new ArrayList<Integer>().stream().filter(sourceClass::isPositive).collect(toList());
	}
}

Error: The type SourceClass does not define isPositive(Integer) that is applicable here

assdfsdafasfa avatar Oct 28 '25 01:10 assdfsdafasfa