mkshiblu / jsdiffer

JavaScript refactoring detection tool between commits
MIT License
3 stars 0 forks source link

Revisit className of methods inside a Anonymous class #62

Open mkshiblu opened 3 years ago

mkshiblu commented 3 years ago

Case 1: When assigned to a variable (b) class name of m1() is .A.main.b


class A{
  interface B{}
  void main() {
      B b = new B(){ 
                       void m1(){
                           int d = 5;
                       }
               }
       }
}

Here the class name of the m1() method in RefactoringMiner is .A.main.b. Although JSR miner currently does not have classes, we need to check if the parent names of the container are being generated correctly.

Case 2: When passed as an argument to a function anoArg className of m1() is ..A.main.anoArg

class A {

    interface B {
    }

    void anoArg(B b) {
    }

    void main() {
        anoArg(new B() {
            void m1() {
                int d = 5;
            }
        });
    }
}

Here the immediate container of m10 is set to as the function name of annoArg

mkshiblu commented 3 years ago

@tsantalis what's the motivation behind className for case 2? Shouldn't it be ".A.main"? As in my opinion, it is technically declared inside method main and then passed to anoArg method as an argument.

If we stick to this same convention, is it safe to assume that for "passing as an argument" scenarios, we will use the callee functions name in the className similar as current concept?

tsantalis commented 3 years ago

The class names for anonymous classes was an attempt to make more a more human-readable path to locate the anonymous class from the refactoring descriptions. In Java anonymous classes are named with numbers, such as OuterClass$1 OuterClass$1$2 which will be impossible for humans to understand where the anonymous class is located in the file. The idead for generating the human-readable path is to concatenate all simpleName identifiers that exist in the path to the root class. SimpleNames exist in method call names and variables.

mkshiblu commented 3 years ago

Thanks for the clear explanation. We will stick to it