Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Using ASTParser for Android libraries
Using ASTParser for Android libraries [message #1694579] Wed, 06 May 2015 08:49 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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

Previous Topic:Minecraft forge modding 1.7.10 (JDK) corrupted
Next Topic:[Swing] Custom tab problem
Goto Forum:
  


Current Time: Mon Apr 21 05:25:21 EDT 2025

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

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

Back to the top