Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to create a standalone command line tool that successfully uses ASTParser.setResolveBindings(tru
How to create a standalone command line tool that successfully uses ASTParser.setResolveBindings(tru [message #185255] Thu, 11 November 2004 13:28 Go to next message
Eclipse UserFriend
Originally posted by: rodrigo.db4o.com

Hi!

I'm creating a standalone java source code analyzer tool. The tool needs to
have access to the ast node bindings but I can't find a way to make them
available.

What steps are necessary to properly parse a single java source file and get
the resolved bindings?

void analyze(File inputFile) {
ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setUnitName(inputFile.getName());
parser.setResolveBindings(true);
parser.setSource(readChars(inputFile));

CompilationUnit cu = (CompilationUnit)parser.createAST(null);
// no bindings available!!
// ...
}

Thanks in advance,
Rodrigo

PS: ResourcesPlugin.getWorkspace() returns null as expected since there's no
workspace in scope. I couldn't find a straightforward example of how to
properly initialize a workspace.
Re: How to create a standalone command line tool that successfully uses ASTParser.setResolveBindings [message #185493 is a reply to message #185255] Sun, 14 November 2004 18:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: acr.ai.sri.com

I have been asking for the same for some time now, without sucess. I
always get redirected to the JDT tests, but have not been able to parse
the information contained there.

Maybe the people who maintain AST will realize how valuable it could be
if it was made independent of the workbench. It has worked tremendously
well for SWT, and modularity it's always a good goal.

Anyway, please let this list know if you succeed, and how.

Andres


> Hi!
>
> I'm creating a standalone java source code analyzer tool. The tool needs to
> have access to the ast node bindings but I can't find a way to make them
> available.
>
> What steps are necessary to properly parse a single java source file and get
> the resolved bindings?
>
> void analyze(File inputFile) {
> ASTParser parser = ASTParser.newParser(AST.JLS2);
> parser.setUnitName(inputFile.getName());
> parser.setResolveBindings(true);
> parser.setSource(readChars(inputFile));
>
> CompilationUnit cu = (CompilationUnit)parser.createAST(null);
> // no bindings available!!
> // ...
> }
>
> Thanks in advance,
> Rodrigo
>
> PS: ResourcesPlugin.getWorkspace() returns null as expected since there's no
> workspace in scope. I couldn't find a straightforward example of how to
> properly initialize a workspace.
>
>
Re: How to create a standalone command line tool that successfully uses ASTParser.setResolveBindings [message #185501 is a reply to message #185255] Sun, 14 November 2004 18:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: acr.ai.sri.com

I have been asking for the same for some time now, without sucess. I
always get redirected to the JDT tests, but have not been able to parse
the information contained there.

Maybe the people who maintain AST will realize how valuable it could be
if it was made independent of the workbench. It has worked tremendously
well for SWT, and modularity it's always a good goal.

Anyway, please let this list know if you succeed, and how.

Andres


> Hi!
>
> I'm creating a standalone java source code analyzer tool. The tool needs to
> have access to the ast node bindings but I can't find a way to make them
> available.
>
> What steps are necessary to properly parse a single java source file and get
> the resolved bindings?
>
> void analyze(File inputFile) {
> ASTParser parser = ASTParser.newParser(AST.JLS2);
> parser.setUnitName(inputFile.getName());
> parser.setResolveBindings(true);
> parser.setSource(readChars(inputFile));
>
> CompilationUnit cu = (CompilationUnit)parser.createAST(null);
> // no bindings available!!
> // ...
> }
>
> Thanks in advance,
> Rodrigo
>
> PS: ResourcesPlugin.getWorkspace() returns null as expected since there's no
> workspace in scope. I couldn't find a straightforward example of how to
> properly initialize a workspace.
>
>
Re: How to create a standalone command line tool that successfully uses ASTParser.setResolveBindings [message #185551 is a reply to message #185501] Mon, 15 November 2004 07:47 Go to previous message
Eclipse UserFriend
Originally posted by: rodrigo.db4o.com

Hi Andres,

I solved my problem by creating an plugin that contributes to the
org.eclipse.core.runtime.applications extension point. All I have to provide
to eclipse is a class that implements IPlatformRunnable and then I can take
complete control over the process.

package bamboo.hello;

public class HelloApplication implements IPlatformRunnable {

public Object run(Object arg0) throws Exception {

System.out.println("it worked!");

String[] args = (String[])arg0;
for (int i=0; i<args.length; ++i) {
System.out.println("arg[" + i + "] = " + args[i]);
}
// ResourcesPlugin.getWorkspace() works ok here!
}
}

And then in plugin.xml:

<extension
point="org.eclipse.core.runtime.applications"
id="app"
name="Hello App">

<application>
<run class="bamboo.hello.HelloApplication" />
</application>
</extension>

After the plugin is properly deployed I can start the contributed
application with the following command line (the id of the plugin is
bamboo.hello):

java -cp startup.jar org.eclipse.core.launcher.Main -application
bamboo.hello.app -data "/tmp/workspace" arg1 arg2


This solution works very well for me for all I need is a command line
application. YMMV.

cheers!
Rodrigo

"Andres C. Rodriguez" <acr@ai.sri.com> wrote in message
news:4197E6B7.8070603@ai.sri.com...
>
> I have been asking for the same for some time now, without sucess. I
> always get redirected to the JDT tests, but have not been able to parse
> the information contained there.
>
> Maybe the people who maintain AST will realize how valuable it could be if
> it was made independent of the workbench. It has worked tremendously well
> for SWT, and modularity it's always a good goal.
>
> Anyway, please let this list know if you succeed, and how.
>
> Andres
>
Previous Topic:File Search regex-- crossing line boundaries
Next Topic:Getting IType of a class in jar file.
Goto Forum:
  


Current Time: Fri May 09 23:51:02 EDT 2025

Powered by FUDForum. Page generated in 0.04037 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top