Skip to content

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

@assdfsdafasfa

Description

@assdfsdafasfa

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:

import java.util.ArrayList;
import javax.print.attribute.standard.Destination;
import static java.util.stream.Collectors.toList;
public class SourceClass {
    TargetClass t;
    private static class Config { }
    private final Config config = new Config();
    public void processData(TargetClass tarClass) {
        new ArrayList<Integer>().stream().filter(this::isPositive).collect(toList());
        tarClass.m();
    }
    private boolean isPositive(Integer number) {
        return number != null && number > 0;
    }
}
public class TargetClass {
    public void m() {}
}

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions