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

Number of Polymorphic Methods (NOP) #118

Closed
yegor256 opened this issue Oct 22, 2023 · 6 comments
Closed

Number of Polymorphic Methods (NOP) #118

yegor256 opened this issue Oct 22, 2023 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@yegor256
Copy link
Owner

yegor256 commented Oct 22, 2023

Let's add NOP metric to ast.py, should be relatively easy to calculate. A method is "polymorphic" if there exists another method with the same name:

class Foo {
  void bar(int x) {} // polymorphic
  void bar(float x) {} // polymorphic
  void f(int z) {} // not polymorphic
}
@yegor256 yegor256 added enhancement New feature or request help wanted Extra attention is needed labels Oct 22, 2023
@ocelot335
Copy link
Contributor

When there are two subclasses of a class, and both contain a method with the same name, are these methods polymorphic?

@yegor256
Copy link
Owner Author

@ocelot335 I didn't understand the question. Can you give an example?

@ocelot335
Copy link
Contributor

@yegor256 How many polymorphic methods should there be in the following cases in your opinion?

class Foo {
  calss A {
    int getF() {}
  }
  calss B {
    int getF() {}
  }
}
class Foo {
  calss A {
    int getF() {}
  }
  calss B extends A {
    int getF(int f) {}
  }
}

Also, if there "getF()" method in Parent? Should we ignore this?

class Foo extends Parent{
  int getF(int f) {}
}

@yegor256
Copy link
Owner Author

@ocelot335 they are not "subclasses", they are "nested" classes: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html (also known as inner or embedded).

I suggest we only count methods inside one class, ignoring parent classes.

@ocelot335
Copy link
Contributor

@yegor256 Okay, did I understand correctly that NOP values will be 0 in appropriate cases?

class Foo {
  calss A {
    int getF() {}
  }
  calss B {
    int getF() {}
  }
}
class Foo {
  int getF() {}
  calss A {
    int getF() {}
  }
}

@yegor256
Copy link
Owner Author

@ocelot335 correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants