Re: Extract information from a Java source (possible with syntax errors)



Stefan Istrate a écrit :
Hi everybody,

I want to extract information from a Java source file about the
packages, imports, classes, methods and, for every method, about its
local variables. The source file may contain syntax error, so I need
also a skip mechanism. Could you recommend me a good solution provided
by Sun to do this? I don't want to use tools written by any third
party, just Sun libraries. Maybe there is a possibility to invoke the
parser used by javac? A parse tree also would be great.

I've taken a look on sun.tools.java.Parser but it's not so good
documented. Also it seems that it needs to be improved because I'm
getting some NullPointerExceptions when it parses the class body.

Thanks,
Stefan Istrate

If you could trust thrid party tools, like eclipse compiler, you could get all you asked (AST, imports, etc.). Beside i'm sure eclipse compiler provide some "not resolved" feature while i doubt sun compiler do.

.



Relevant Pages

  • Re: programmatic way for detecting imports....
    ... > 1) for each class in a jar see what are the imports for that class. ... "import" statements were in the corresponding source file (if there was ... convenience for programmers but has no representation in bytecode. ...
    (comp.lang.java.programmer)
  • Re: Indirect - Why does it seem to only work sometimes?
    ... The source file is renamed to standard one, ... or imports data from selected source file into workbook. ... in some of Excel NG's some time ago. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Imports question
    ... At the very top of your .vb source file ... Imports Microsoft.VisualBasic ... keyword at the top of your .cs source file: ... Prev by Date: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: vb.net "Name is not declared" question
    ... Imports Lucene.Net.Documents ... details and modify your source file appropriately. ... Parser Error Message: ... >> start learning VB.NET from scratch, ...
    (microsoft.public.dotnet.general)