Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to validate a NumberLiteral semantically?
How to validate a NumberLiteral semantically? [message #62651] Fri, 20 June 2003 04:01 Go to next message
Eclipse UserFriend
Originally posted by: taciano.tres.first.fraunhofer.de

Hi All!

I'm parsing a piece of code using AST.parseCompilationUnit(...), and
getting the result, everything OK.
My problem is that when I parse a code like:

String aNumber = "1" + Double.MAX_VALUE; // generates the String
//11.7976931348623157E308, that is not a valid double value (JLS 3.10.2)
String classString =
"public class SampleClass {"
+ " public double atributte = " + aNumber + ";"
+ }";
CompilationUnit cu = AST.parseCompilationUnit(classString.toCharArray());

As AST means (Abstract SYNTAX Tree), that code works without problems,
and I get a CompilationUnit without messages or problems.
But I need to "validate" the value of aNumber "semanticaly", i. e., I
have to know if the NumberLiteral in the AST contains a valid number in
the Java language.

There's a simple way to do this?

Thaks for any help!

--
Taciano Tres
taciano.tres@first.fraunhofer.de
Re: How to validate a NumberLiteral semantically? WORKAROUD! [message #66776 is a reply to message #62651] Wed, 25 June 2003 03:57 Go to previous message
Eclipse UserFriend
Originally posted by: taciano.tres.first.fraunhofer.de

If someone has the same problem, here goes my workaround:
Use the source code inside the methods "computeConstant()" in the
classes IntLiteral, LongLiteral, FloatLiteral and DoubleLiteral, all on
package "org.eclipse.jdt.internal.compiler.ast". Its a internal package,
so copy the method body inside the class you are writing. Cause this
solves a problem unrelated with Eclipse, the code don't need to be
replaced each time a new release is available.
Inside this package is also possible to find anothers "checks" for the
AST nodes.

If someone has a better idea, I'm glad to listen.

--
Taciano Tres
taciano.tres@first.fraunhofer.de
Previous Topic:Modifying format of Template Variables
Next Topic:About start up plugin! Thx
Goto Forum:
  


Current Time: Sun May 11 16:55:16 EDT 2025

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

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

Back to the top