ftomassetti / effectivejava

Run queries on your Java code to check if it meets the criteria suggested by the book Effective Java. And some others.
Apache License 2.0
506 stars 45 forks source link

SolveSuperclass #66

Closed ftomassetti closed 9 years ago

ftomassetti commented 9 years ago

Given this example:

class B extends A {
}

class C extends B {
}

We need to find the superclasses of C (A and B).

We have most of the logic in place for that, but I could write the last bit for this particular case.

I would write a function named "solveSuperclass" in funcs.clj which would get a ClassDeclaration instance and basically call

(solveClass  classDeclaration nil (.getSuperclass classDeclaration)

solveClass is a method from a protocol.

Once we have this function we can create getAllSuperclasses calling recursively solveSuperclass.

ftomassetti commented 9 years ago

It should be fixed now.

@davidor you can now use solveSuperclass (to get the direct parent class) and getAllSuperclasses (to get all the parents, recurisively)

Do not expect it to work all the times :)

To solve types not in the same file you should set the dynamic variable typeSolver. Probably you want to do something like:

(def typeSolver (typeSolverOnList my-list-of-type-declarations))

where my-list-of-type-declarations is a list of type declarations (classes, enums, interfaces). To get a list of type declarations you can get a list of compilation units and call (flatten (map allTypes cus))

If you have any questions feel absolutely free to write me/ping me!

ftomassetti commented 9 years ago

(closing this issue because it should be solved)