Reputation: 49
I have a folder with java files. I would like to find out if a class contains an attribute of type X without compiling the project, i.e. I don't want to use reflection. How can I achieve this in a static way?
Upvotes: 1
Views: 62
Reputation: 819
Have you considered using JBoss Forge's roster library?
String javaCode = "public class MyClass{ private String field;} public class AnotherClass {}";
JavaUnit unit = Roaster.parseUnit(javaCode);
JavaClassSource myClass = unit.getGoverningType();
JavaClassSource anotherClass = (JavaClassSource) unit.getTopLevelTypes().get(1);
Upvotes: 1