Using ASTParser for Android libraries [message #1694579] |
Wed, 06 May 2015 08:49  |
Eclipse User |
|
|
|
I'm trying to get typed AST from ASTParser (org.eclipse.jdt.core.dom.ASTParser)
parser = ASTParser.newParser(AST.JLS8);
parser.setEnvironment(new String[] { env.getRoot().getAbsolutePath() }, jarsArr, extsArr, true);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(IOUtils.toCharArray(new FileInputStream(f)));
parser.setUnitName(f.getAbsolutePath());
jarsArr contains correct jar paths, extsArr contains correct charset names.
So, when I parse code that doesn't use android libraries, it works fine. But when I parse android code, I get errors
cu = (CompilationUnit) parser.createAST(null);
IProblem[] problems = cu.getProblems();
for(IProblem problem : problems)
System.out.println(problem.getMessage());
Errors like
Quote:
The import android.content cannot be resolved
The import android.os cannot be resolved
The import android.app cannot be resolved
The import android.support.v4.app.NavUtils cannot be resolved
The import android.view cannot be resolved
What's wrong and how to fix this?
[Updated on: Thu, 07 May 2015 07:05] by Moderator
|
|
|
Re: Using ASTParser for Android libraries [message #1694719 is a reply to message #1694579] |
Thu, 07 May 2015 07:16  |
Eclipse User |
|
|
|
Look at my problem, please
Check out this guy stackoverflow .com/questions/22879124/eclipse-plugin-get-extended-class-name-using-astparser he's outputing the data and his code works! But why? I have the same code and I added android-support-v4.jar into jars
I have an idea why it doesn't work (but I don't know how to solve it):
1) I tried to parse the code with no any jars and I had an error that "android" cannot be resolved
2) When I added this jar, I have seen new error that "android.widgets" (and other) cannot be resolved. Why? Because this jar contains packages like android.support.v4.etc, but it needs android.widgets. It resolved "android" package, but not android.widgets. So, I sure that I should to set some options to parser, but what exactly?
[Updated on: Thu, 07 May 2015 07:17] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04099 seconds