Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Which AST parse level should I be using?
Which AST parse level should I be using? [message #268851] Thu, 26 August 2004 11:35 Go to next message
Eclipse UserFriend
I know that I create a parse with the following code:
ASTParser p = ASTParser.newParser(AST.JLS3);
p.setSource(unit);
CompilationUnit u = (CompilationUnit) p.createAST(null);

This, of course, fails because 1.5 parsing is not yet supported. The
question is, how do I choose the correct parse level? Once 1.5 parsing is
supported, shouldn't there be a setting somewhere that allows me to NOT do
1.5 level compilation? Shouldn't I be getting the current parse level from a
more static location? Has that location already been implemented and I just
haven't found it? Is my code up above totally screwed?

Jim Adams
Re: Which AST parse level should I be using? [message #268855 is a reply to message #268851] Thu, 26 August 2004 11:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomannNOSPAM.ca.ibm.com

Jim Adams wrote:
> I know that I create a parse with the following code:
> ASTParser p = ASTParser.newParser(AST.JLS3);
> p.setSource(unit);
> CompilationUnit u = (CompilationUnit) p.createAST(null);
>
> This, of course, fails because 1.5 parsing is not yet supported. The
> question is, how do I choose the correct parse level? Once 1.5 parsing is
> supported, shouldn't there be a setting somewhere that allows me to NOT do
> 1.5 level compilation? Shouldn't I be getting the current parse level from a
> more static location? Has that location already been implemented and I just
> haven't found it? Is my code up above totally screwed?
You should use setCompilerOptions(Map options) on the ASTParser.
You can do something like:
ASTParser astParser = ASTParser.newParser(AST.JLS3);
astParser.setSource(unit);
Map options = unit.getJavaProject().getOptions(true);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
JavaCore.VERSION_1_5);
astParser.setCompilerOptions(options);
astParser.setResolveBindings(false);
CompilationUnit u = (CompilationUnit) astParser.createAST(null);

HTH,
--
Olivier
Re: Which AST parse level should I be using? [message #269030 is a reply to message #268855] Fri, 27 August 2004 11:49 Go to previous messageGo to next message
Eclipse UserFriend
Does that allow for a fallback to level 2? Or do I really not even need to
do the options.put()? Will I get whatever was set on the project? Isn't that
enough?

"Olivier Thomann" <olivier_thomannNOSPAM@ca.ibm.com> wrote in message
news:cgl101$96j$1@eclipse.org...
> Jim Adams wrote:
> > I know that I create a parse with the following code:
> > ASTParser p = ASTParser.newParser(AST.JLS3);
> > p.setSource(unit);
> > CompilationUnit u = (CompilationUnit) p.createAST(null);
> >
> > This, of course, fails because 1.5 parsing is not yet supported. The
> > question is, how do I choose the correct parse level? Once 1.5 parsing
is
> > supported, shouldn't there be a setting somewhere that allows me to NOT
do
> > 1.5 level compilation? Shouldn't I be getting the current parse level
from a
> > more static location? Has that location already been implemented and I
just
> > haven't found it? Is my code up above totally screwed?
> You should use setCompilerOptions(Map options) on the ASTParser.
> You can do something like:
> ASTParser astParser = ASTParser.newParser(AST.JLS3);
> astParser.setSource(unit);
> Map options = unit.getJavaProject().getOptions(true);
> options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
> options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
> JavaCore.VERSION_1_5);
> astParser.setCompilerOptions(options);
> astParser.setResolveBindings(false);
> CompilationUnit u = (CompilationUnit) astParser.createAST(null);
>
> HTH,
> --
> Olivier
Re: Which AST parse level should I be using? [message #269058 is a reply to message #269030] Fri, 27 August 2004 13:47 Go to previous messageGo to next message
Eclipse UserFriend
The code, as given, does not solve the problem. This still fails with an
exception because Java 1.5 is not supported. I am looking for something that
will allow my code to work even when 1.5 is supported. I have always heard
that you shouldn't use exceptions to handle code flow but it seems that that
is what I am being forced into.

"Jim Adams" <Jim.Adams@sas.com> wrote in message
news:cgnl07$9rj$1@eclipse.org...
> Does that allow for a fallback to level 2? Or do I really not even need to
> do the options.put()? Will I get whatever was set on the project? Isn't
that
> enough?
>
> "Olivier Thomann" <olivier_thomannNOSPAM@ca.ibm.com> wrote in message
> news:cgl101$96j$1@eclipse.org...
> > Jim Adams wrote:
> > > I know that I create a parse with the following code:
> > > ASTParser p = ASTParser.newParser(AST.JLS3);
> > > p.setSource(unit);
> > > CompilationUnit u = (CompilationUnit) p.createAST(null);
> > >
> > > This, of course, fails because 1.5 parsing is not yet supported. The
> > > question is, how do I choose the correct parse level? Once 1.5 parsing
> is
> > > supported, shouldn't there be a setting somewhere that allows me to
NOT
> do
> > > 1.5 level compilation? Shouldn't I be getting the current parse level
> from a
> > > more static location? Has that location already been implemented and I
> just
> > > haven't found it? Is my code up above totally screwed?
> > You should use setCompilerOptions(Map options) on the ASTParser.
> > You can do something like:
> > ASTParser astParser = ASTParser.newParser(AST.JLS3);
> > astParser.setSource(unit);
> > Map options = unit.getJavaProject().getOptions(true);
> > options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
> > options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
> > JavaCore.VERSION_1_5);
> > astParser.setCompilerOptions(options);
> > astParser.setResolveBindings(false);
> > CompilationUnit u = (CompilationUnit) astParser.createAST(null);
> >
> > HTH,
> > --
> > Olivier
>
>
Re: Which AST parse level should I be using? [message #269100 is a reply to message #269058] Fri, 27 August 2004 17:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomannNOSPAM.ca.ibm.com

Jim Adams wrote:
> The code, as given, does not solve the problem. This still fails with an
> exception because Java 1.5 is not supported. I am looking for something that
> will allow my code to work even when 1.5 is supported. I have always heard
> that you shouldn't use exceptions to handle code flow but it seems that that
> is what I am being forced into.
Could you please create a bug report against JDT/Core with your test case?
I am assuming that you are using one of the 3.1 integration build,
otherwise it won't work for sure. Most of the 1.5 support is not
included in 3.0.
--
Olivier
Re: Which AST parse level should I be using? [message #269302 is a reply to message #269100] Mon, 30 August 2004 15:10 Go to previous messageGo to next message
Eclipse UserFriend
I am NOT using any of the 1.5 support. I don't need the 1.5 support. What I
am trying to do is plan for the future so that, when there IS 1.5 support,
my code doesn't break.

"Olivier Thomann" <olivier_thomannNOSPAM@ca.ibm.com> wrote in message
news:cgoako$a3k$1@eclipse.org...
> Jim Adams wrote:
> > The code, as given, does not solve the problem. This still fails with an
> > exception because Java 1.5 is not supported. I am looking for something
that
> > will allow my code to work even when 1.5 is supported. I have always
heard
> > that you shouldn't use exceptions to handle code flow but it seems that
that
> > is what I am being forced into.
> Could you please create a bug report against JDT/Core with your test case?
> I am assuming that you are using one of the 3.1 integration build,
> otherwise it won't work for sure. Most of the 1.5 support is not
> included in 3.0.
> --
> Olivier
Re: Which AST parse level should I be using? [message #269304 is a reply to message #269100] Mon, 30 August 2004 15:15 Go to previous message
Eclipse UserFriend
Bug 72899 was added to address this issue.

"Olivier Thomann" <olivier_thomannNOSPAM@ca.ibm.com> wrote in message
news:cgoako$a3k$1@eclipse.org...
> Jim Adams wrote:
> > The code, as given, does not solve the problem. This still fails with an
> > exception because Java 1.5 is not supported. I am looking for something
that
> > will allow my code to work even when 1.5 is supported. I have always
heard
> > that you shouldn't use exceptions to handle code flow but it seems that
that
> > is what I am being forced into.
> Could you please create a bug report against JDT/Core with your test case?
> I am assuming that you are using one of the 3.1 integration build,
> otherwise it won't work for sure. Most of the 1.5 support is not
> included in 3.0.
> --
> Olivier
Previous Topic:JBoss-IDE or Lomboz
Next Topic:moving views between folders
Goto Forum:
  


Current Time: Wed Nov 05 17:06:38 EST 2025

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

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

Back to the top