Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] Parsing a Java file with bindings

Hi all!

I've been using Eclipse JDT to parse a Java source file for the purpose of writing a Java translator. So far the parsing itself has been the most trivial possible:

-code-

    public static ASTNode parseString(char[] code) throws Exception {
	ASTParser parser = ASTParser.newParser(AST.JLS2);
	parser.setSource(code);
	return parser.createAST(null);
    }

-/code-

This method works well for a single file but doesn't provide binding information. According to the docs, I also have to set a IJavaProject and unit name if I want that. The problem is that I wanted the translator to be independent from Eclipse and the only way I've found so far to get an IJavaProject has been through something like:

-code-

  IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
  IProject project= root.getProject(projectName);

-/code-

My ideal would be to give the path to a folder with .project and .classpath files and have something give me the corresponding IProject.

Is this at all possible? What's the best place to look at if I want to implement something like this myself?

Thank you for your time,

Tiago Maduro-Dias.



Back to the top