Java API for retrieving Java source code metadata

I would like to create some reverse oriented project documents based on Java code (rather than bytecode) instead of writing my own interpreter, what tools and APIs are available for passing Java code using Java code?

Reflection occurs on bytecode and is limited by the method level, I want to "objectify" the method code as well.

Java-doc ignores the code itself and only based on comments, automatic UML-sequnces are too strict

eg. An API like this (forgive my ignorance of the official terms of the Structure of Programming Languages):

JavaCodeDom jcd = new JavaCodeDom(new File(pathToJavaSource), CompilerEnum.Java16)
List <ClassSrc> classes = jcd.getClasses();
ClassSrc cls = classes.get(0);
Map<MethodSignatureSrc,MethodSrc> methods = cls.getMethodsMap();
MethodSrc main = mothds.get(new MethodSignatureSrc(Modifiers.Public, Modifiers.Static, ReturnTypes.Void, "main", new MethodParams(String[].class))
List<StatementSrc> statements = main.getStatements();
for(StatementSrc statement : statements){
   if(statement.getType()==StatementTypes.Assignment()){
        AssignmentStatementSrc assignment = (AssignmentStatementSrc)statement;
        Identifier src = assignment.getAssigneeVariable();
        ExpressinoSrc = assignment.getAssignmentValue();
   }
}
List<AnnotationsSrc> annotations = cls.getAnnotations();
+3
source share
4 answers

API ( JDK), Java Compiler (javac).

  • API- , ( ) Java.
  • API- - (, , ) - API , . .
  • , API Reflection (java.lang.Class java.lang.reflect.* java.lang.annotation).
  • API , API .
  • , Doclet API Javadoc, , API , ( ).

- Doclet API API- Compiler Tree, ( , ).

+3

BCEL Java. ( , , .)

    The Byte Code Engineering Library is intended to give users a convenient
    possibility to analyze, create, and manipulate (binary) Java class files
    (those ending with .class). Classes are represented by objects which 
    contain all the symbolic information of the given class: methods, 
    fields and byte code instructions, in particular. 

, . Java.

+2

ANTLR seems to be one option, but I haven't used it

0
source

This seems to answer my question: How to generate an AST from Java source code? ( Spoon )

0
source

All Articles