简体   繁体   中英

Missing class from Refactor -> Move in Eclipse Luna

I am trying to practice some refactoring design patterns and for this particular pattern I need to move one of my methods to a new class to handle complex conditionals. Here is the class with the method I am trying to move

public class Grade
{
    public static double A_GRADE = 0.9;
    public static double B_GRADE = 0.8;
    public static double C_GRADE = 0.7;
    public static double D_GRADE = 0.6;

    private double grade;

    public Grade(double grade)
    {
        this.grade = grade;
    }

    double getGrade() { return grade; }
    void setGrade (double newGrade) { this.grade = newGrade; }

    public String determineGradeLetter()
    {
        if (grade <= 1.0 && grade >= 0)
        {
            if (grade >= A_GRADE) { return "A"; }
            else if (grade >= B_GRADE) { return "B"; }
            else if (grade >= C_GRADE) { return "C"; }
            else if (grade >= D_GRADE) { return "D"; }
            else { return "F"; }
        }
        else { System.out.println("Invalid Grade") }
    }
}

I highlight the determineGradeLetter() method and do Right Click -> Refactor -> Move . When the pop-up menu opens the class (called GradeStrategy ) isn't listed.

What do you think might be going wrong? I am running Eclipse Luna.

Also, I understand I can probably just copy and paste the method into the GradeStrategy class and add a Grade object in the determineGradeLetter() parameters, but I want to take full advantage of Eclipse's refactoring capabilities.

The result of your refactoring should still be compiling. So eclipse needs to be able to determine possible targets to move the method to.

In your case there is no GradeStrategy available to which it can be moved. Eclipse doesn't know what to do with the existing callers then.

If you had, for instance, a GradeStrategy as a parameter for your method, or as a field on Grade , then it could be moved since there were possible candidates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM