[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
][
Date Index
][
Thread Index
]
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
From
:
judith.wiesinger@xxxxxxxxxxxxxxx
(Judith Wiesinger)
Date
: Fri, 7 Apr 2006 09:30:13 +0000 (UTC)
Newsgroups
:
eclipse.tools.jdt
Organization
: Eclipse
User-agent
: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
Hi,
I have tried to parse the expression wrapped in a compilation unit. See the following code but the type binding is still null. Does anybody know why? How can I get to the type binding?
Thanks for your help.
Judith
public void testASTParsing() throws JavaModelException {
ASTParser parser = ASTParser.newParser(AST.JLS3);
String projectName = "at.allianz.test.test1";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IJavaProject javaProject = JavaCore.create(project);
boolean exists = javaProject.exists(); // project does exist
parser.setProject(javaProject);
String source = "class MyClass {\n" + "public static void myMethod() { \n"
+ " int i; \n"
+ " i = 5 + 4; \n"
+ "}"
+ "}"
; parser.setSource(source.toCharArray());
parser.setResolveBindings(true);
ASTNode node = parser.createAST(null);
CompilationUnit cu = (CompilationUnit) node;
TypeDeclaration type = (TypeDeclaration) cu.types().get(0);
MethodDeclaration method = type.getMethods()[0];
Block block = method.getBody();
VariableDeclarationStatement stmt1 = (VariableDeclarationStatement) block.statements().get(0); // stmt1 = "int i;"
ExpressionStatement stmt2 = (ExpressionStatement) block.statements().get(1); // stmt2 = "i=5 + 4;"
ITypeBinding typeBind = stmt2.getExpression().resolveTypeBinding();
// typeBind == null ????
}
References
:
[news.eclipse.tools.jdt] Using the ASTParser for parsing an expression...
From:
Judith Wiesinger
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
From:
Olivier Thomann
Prev by Date:
[news.eclipse.tools.jdt] Newbie needs help: How does javadoc capture highlighting??? NEED HELP REAL BAD!
Next by Date:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
Previous by thread:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
Next by thread:
[news.eclipse.tools.jdt] Re: Using the ASTParser for parsing an expression...
Index(es):
Date
Thread