[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
][
Date Index
][
Thread Index
]
[news.eclipse.tools.jdt] Using the ASTParser for parsing an expression...
From
:
judith.wiesinger@xxxxxxxxxxxxxxx
(Judith Wiesinger)
Date
: Thu, 6 Apr 2006 12:48:56 +0000 (UTC)
Newsgroups
:
eclipse.tools.jdt
Organization
: Eclipse
User-agent
: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
Hello there,
I want to use the ASTParser for parsing an expression in order to get the return type.
String expr1 = "5 + 4";
//String expr2 = "myVar.myMethod(myParam)";
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_EXPRESSION);
parser.setResolveBindings(true);
parser.setSource(expr1.toCharArray());
ASTNode astNode = parser.createAST(null); Expression expr = (Expression) astNode;
ITypeBinding typeBinding = expr.resolveTypeBinding();
The problem is that typeBinding is null. How can I get the return type then?
2nd question: If I have got a more complex expression (like expr2) how do I add the declaration of those variables to the expression?
AST ast = astNode.getAST();
SingleVariableDeclaration varDecl = ast.newSingleVariableDeclaration();
varDecl.setType(ast.newSimpleType(ast.newSimpleName("MyType")));
varDecl.setName(ast.newSimpleName("myVar"));
Thanks a lot for your consideration!
Judith
Follow-Ups
:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
From:
Olivier Thomann
Prev by Date:
[news.eclipse.tools.jdt] Plugin and Registry
Next by Date:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
Previous by thread:
[news.eclipse.tools.jdt] Plugin and Registry
Next by thread:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
Index(es):
Date
Thread