What are the methods for verifying type ranges using Java Development Tools (JDT)? [message #1857118] |
Wed, 18 January 2023 11:31 |
Ashley coder Messages: 11 Registered: October 2022 |
Junior Member |
|
|
Using JDT, I would like to analyze a String to determine if the number it contains is within the valid range of any of the primitive data types.
Is there a fast way to check if "1.7976931348623157e350" is within the valid range of a 'double' primitive type without using the Double.parseDouble("1.7976931348623157e350") method?
If you are familiar with the Eclipse development environment, you are aware that Eclipse can detect when a variable is out of range by underlining it red. However, using this feature is not as simple as it sounds.
I have begun trying out the ASTParser from the org.eclipse.jdt.core.dom library.
I attempted to access the visitor methods using resolveBinding() but unfortunately, I was not successful. The methods I used and from resources, I have tried it always returned 'null'.
I discovered a class called ASTSyntaxErrorPropagator, but I'm unsure of how to use it correctly. It appears to be related to propagating parsing issues, and appears to get its information from another class called CodeSnippetParsingUtil. These are only my guesses, however.
Does anyone have experience using the ASTParser properly?
Could someone please help me debug the following code snippet that I have attempted to fix? I would be very grateful for any advice.
public class DatatypesParser {
public static void main(String[] args) {
ASTParser parser = ASTParser.newParser(AST.JLS4);
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
String statement = new String("int i = " + Long.MAX_VALUE + ";");
parser.setSource(statement.toCharArray());
parser.setKind(ASTParser.K_STATEMENTS);
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
ASTNode ast = parser.createAST(null);
ast.accept(new ASTVisitor() {
@Override
public boolean visit(VariableDeclarationStatement node) {
CodeSnippetParsingUtil util = new CodeSnippetParsingUtil();
return true;
}
});
}
|
|
|
Powered by
FUDForum. Page generated in 0.03843 seconds