Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » parseCompilationUnit problem with passing in true
parseCompilationUnit problem with passing in true [message #121875] Tue, 25 November 2003 15:19 Go to next message
Eclipse UserFriend
When I call AST.parseCompilationUnit( cu, true ), I get back AST that does
not have anyting inside of the method bodies.

When I call AST.parseCompilationUnit( cu, false ), I get back full AST,
but, obviously, can't resolve any bindings.

I get the same behaivior in 3.0 M4 and M5.

Am I missing something here or is this a bug?

Thank you,

Alex
Re: parseCompilationUnit problem with passing in true [message #122040 is a reply to message #121875] Tue, 25 November 2003 21:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.cuthis.mit.edu.andthis

i think you're missing something because otherwise none of the refactorings
would work
they all do AST.parseCompilationUnit(cu, true)
a.
Re: parseCompilationUnit problem with passing in true [message #122079 is a reply to message #122040] Tue, 25 November 2003 22:45 Go to previous messageGo to next message
Eclipse UserFriend
adam kiezun wrote:

> i think you're missing something because otherwise none of the refactorings
> would work
> they all do AST.parseCompilationUnit(cu, true)
> a.

Thanks for the reply, Adam, could you point me to an example of this?

Alex
Re: parseCompilationUnit problem with passing in true [message #122090 is a reply to message #122079] Tue, 25 November 2003 23:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.cuthis.mit.edu.andthis

well, simply search for references to AST.parseCompilationUnit
in the org.eclipse.jdt.ui plugin
a.
Re: parseCompilationUnit problem with passing in true [message #122128 is a reply to message #122090] Wed, 26 November 2003 01:24 Go to previous messageGo to next message
Eclipse UserFriend
adam kiezun wrote:

> well, simply search for references to AST.parseCompilationUnit
> in the org.eclipse.jdt.ui plugin
> a.

Right, I did that. Here is one random example:

IPackageFragmentRoot fragmentRoot =
getDefaultProject().getPackageFragmentRoot(
getDefaultProject().getProject() );
IPackageFragment pkg = fragmentRoot.getPackageFragment( DEFAULT );

StringBuffer buf = new StringBuffer();
buf.append("public class E {\n");
buf.append(" public String foo( int x ) {\n");
buf.append(" return String.valueOf( x );\n");
buf.append(" }\n");
buf.append("}\n");

ICompilationUnit cu= pkg.createCompilationUnit("E.java",
buf.toString(), false, null);
CompilationUnit astRoot= AST.parseCompilationUnit(cu, true);
astRoot.accept( new ASTVisitor() {
public void preVisit( ASTNode node ) {
System.out.println( node.toString() );
}
} );
Re: parseCompilationUnit problem with passing in true [message #122142 is a reply to message #122090] Wed, 26 November 2003 01:26 Go to previous messageGo to next message
Eclipse UserFriend
adam kiezun wrote:

> well, simply search for references to AST.parseCompilationUnit
> in the org.eclipse.jdt.ui plugin
> a.

Right, I did that. Here is one random example:

===================================================
IPackageFragmentRoot fragmentRoot =
getDefaultProject().getPackageFragmentRoot(
getDefaultProject().getProject() );
IPackageFragment pkg = fragmentRoot.getPackageFragment( "default");

StringBuffer buf = new StringBuffer();
buf.append("public class E {\n");
buf.append(" public String foo( int x ) {\n");
buf.append(" return String.valueOf( x );\n");
buf.append(" }\n");
buf.append("}\n");

ICompilationUnit cu= pkg.createCompilationUnit("E.java", buf.toString(),
false, null);
CompilationUnit astRoot= AST.parseCompilationUnit(cu, true);
astRoot.accept( new ASTVisitor() {
public void preVisit( ASTNode node ) System.out.println(
node.toString() );
}
} );

===================================================

Here is the output:

CompilationUnit[E]
TypeDeclaration[class E MethodDeclaration[method foo(int) returns String]]
E
MethodDeclaration[method foo(int) returns String]
String
String
foo
int x
int
x
{}

As you can see no method body...
Re: parseCompilationUnit problem with passing in true [message #122178 is a reply to message #122142] Wed, 26 November 2003 04:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: markus_keller.ch.ibm.spam.protect.com

Alex Iskold wrote:
[..]
> ICompilationUnit cu= pkg.createCompilationUnit("E.java", buf.toString(),
> false, null);
> CompilationUnit astRoot= AST.parseCompilationUnit(cu, true);
> astRoot.accept( new ASTVisitor() {
> public void preVisit( ASTNode node ){System.out.println(
> node.toString() );
> }
> } );
[..]
> As you can see no method body...

The AST is there. ASTNode#toString() just doesn't flatten the whole AST.
Use e.g. ASTFlattener to flatten the AST.

Markus
Re: parseCompilationUnit problem with passing in true [message #122345 is a reply to message #122178] Wed, 26 November 2003 08:59 Go to previous messageGo to next message
Eclipse UserFriend
Markus,

Where can I find ASTFlattener?

I am not sure if it will help, because this code:

astRoot.accept( new ASTVisitor() {
public void preVisit( ASTNode node ) {
if ( node instanceof MethodDeclaration ) {
MethodDeclaration md = (MethodDeclaration)node;
Block b = md.getBody();
List l = b.statements();
System.out.println( l.size() );
}
}
public boolean visit( Block b ) {
System.out.println( b.statements().size() );
return true;
}
} );

Prints:

0
0

Alex

Markus Keller wrote:

> Alex Iskold wrote:
> [..]
> > ICompilationUnit cu= pkg.createCompilationUnit("E.java", buf.toString(),
> > false, null);
> > CompilationUnit astRoot= AST.parseCompilationUnit(cu, true);
> > astRoot.accept( new ASTVisitor() {
> > public void preVisit( ASTNode node ){System.out.println(
> > node.toString() );
> > }
> > } );
> [..]
> > As you can see no method body...

> The AST is there. ASTNode#toString() just doesn't flatten the whole AST.
> Use e.g. ASTFlattener to flatten the AST.

> Markus
Re: parseCompilationUnit problem with passing in true [message #122367 is a reply to message #122345] Wed, 26 November 2003 09:21 Go to previous message
Eclipse UserFriend
I think that I found the problem.

I get error message java.lang.Object can not be resolved,
this is happening because RT.jar is not added to the Classpath by
default.


Alex


Alex Iskold wrote:

> Markus,

> Where can I find ASTFlattener?

> I am not sure if it will help, because this code:

> astRoot.accept( new ASTVisitor() {
> public void preVisit( ASTNode node ) {
> if ( node instanceof MethodDeclaration ) {
> MethodDeclaration md = (MethodDeclaration)node;
> Block b = md.getBody();
> List l = b.statements();
> System.out.println( l.size() );
> }
> }
> public boolean visit( Block b ) {
> System.out.println( b.statements().size() );
> return true;
> }
> } );

> Prints:

> 0
> 0

> Alex

> Markus Keller wrote:

> > Alex Iskold wrote:
> > [..]
> > > ICompilationUnit cu= pkg.createCompilationUnit("E.java", buf.toString(),
> > > false, null);
> > > CompilationUnit astRoot= AST.parseCompilationUnit(cu, true);
> > > astRoot.accept( new ASTVisitor() {
> > > public void preVisit( ASTNode node ){System.out.println(
> > > node.toString() );
> > > }
> > > } );
> > [..]
> > > As you can see no method body...

> > The AST is there. ASTNode#toString() just doesn't flatten the whole AST.
> > Use e.g. ASTFlattener to flatten the AST.

> > Markus
Previous Topic:relative paths in classpath
Next Topic:Running Ant and Can't find JDTCompilerAdapter
Goto Forum:
  


Current Time: Thu Jul 24 20:33:15 EDT 2025

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

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

Back to the top