Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to generate binding (key) for a CompilationUnit? [100$ reward for solution]
How to generate binding (key) for a CompilationUnit? [100$ reward for solution] [message #1726164] Thu, 10 March 2016 09:14 Go to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Hi, I'm making ASTs for a whole project and I don't know how to generate bindings:
getDefaultParser().createASTs(files.toArray(new String[files.size()]), null, createBindings(files), fileAstRequestor, null);

	private String[] createBindings(List<String> files)
	{
		String[] bindings = new String[files.size()];
		for(int i = 0; i < files.size(); i++)
		{
			bindings[i] = createBinding(files.get(i));
		}
		return bindings;
	}
	
	private String createBinding(String file)
	{
		return file.replace(File.separatorChar, '.');
	}

But how is that right? I see that here's a problem and I'm doing something wrong, because some of bindings are not resolved

UPD:
Anyone who will help me to resolve this problem will receive 100$ on his paypal

[Updated on: Fri, 18 March 2016 06:38]

Report message to a moderator

Re: How to generate binding for a CompilationUnit? [message #1726267 is a reply to message #1726164] Thu, 10 March 2016 20:22 Go to previous messageGo to next message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 107
Registered: April 2014
Location: USA
Senior Member
Ok, so first, the bindingKeys parameter on createASTs() expects binding keys, not bindings. You are supplying file path names, and those are not binding keys. Second, you can't create binding keys, you can only safely use binding keys that you have gotten from an IBinding. (The algorithm is not published and can't be expected to remain constant between releases.) See JavaDoc for IBinding.getKey(). So the parser is not finding any of the "bindings" that you've specified. If any bindings are being resolved, they're being resolved simply by the normal actions of the parser. (Default parser resolves all of the bindings that it can.)

So, um, some bindings are not resolved. What can you share that will help narrow down that statement?
Re: How to generate binding for a CompilationUnit? [message #1726295 is a reply to message #1726267] Fri, 11 March 2016 07:49 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
So if I have a source path, how can I generate binding key for a file inside it? I just want to create CompilationUnits for files related to one project

Also how to handle exceptions from ASTParser.createASTs(...)? If bad code is specified, sometimes it throws IllegalArgumentException/ArrayIndexOutOfBoundsException/NullPointerException etc. If I just wrap this call with try{}catch(){} then other CompilationUnits won't be created

[Updated on: Fri, 11 March 2016 08:38]

Report message to a moderator

Re: How to generate binding for a CompilationUnit? [message #1726517 is a reply to message #1726295] Mon, 14 March 2016 11:45 Go to previous messageGo to next message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 107
Registered: April 2014
Location: USA
Senior Member
The parser won't throw exceptions if you give it bad code, i.e. that doesn't compile. It just creates whatever AST it can. If you're getting exceptions, something very bad is happening. What kind of "bad code" are we talking about?

There's no point in talking about bindings while the parser is blowing up.
Re: How to generate binding for a CompilationUnit? [message #1726534 is a reply to message #1726517] Mon, 14 March 2016 13:39 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Okay, please let's return to bindings, it's the most huge problem.
We assume that I have logically and sintactically correct code. It's a project which contains over 1000 files related with each other (as a usual code). How to retrieve binding keys for them? My task is just to generate CompilationUnits for all of them, and I use http://help.eclipse.org/mars/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/ASTParser.html#createASTs-java.lang.String:A-java.lang.String:A-java.lang.String:A-org.eclipse.jdt.core.dom.FileASTRequestor-org.eclipse.core.runtime.IProgressMonitor- this method (I don't see here other ways). But this method requires me to give it binding keys which I don't have. So because I'm asking how to get them. Thanks!
Re: How to generate binding for a CompilationUnit? [message #1727372 is a reply to message #1726534] Tue, 22 March 2016 13:48 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Absolutely no ideas? Sad
Erick, can you suggest something, please?

I want to remind.
I have:
1) Set of java files
2) These files are placed to a root directory and a path of each file has its package, for example, root is C:\myproj\source and one of files is C:\myproj\source\com\test\path\Test.java (so class Test will have com.test.path package)

I want:
Just to get CompilationUnits for all of these source files with restored bindings

I tried:
1) Use ASTParser.createAST. I decided that it's bad because this method creates tree of dependencies each time for each new source file (but all bindings were restored fine!). Creating AST took a lot of time and RAM resources
2) Use ASTParser.createASTs. Speed of creating CompilationUnits is very fast. But I don't know what should I put into bindingKeys (how to generate them?)
Re: How to generate binding for a CompilationUnit? [message #1727924 is a reply to message #1727372] Tue, 29 March 2016 13:09 Go to previous messageGo to next message
Erick Hagstrom is currently offline Erick HagstromFriend
Messages: 107
Registered: April 2014
Location: USA
Senior Member
Ivan, sorry buddy, but I just don't know. I always just parse files one at a time. I hope you find your answer, but it's not likely to come from me. Sad
Re: How to generate binding for a CompilationUnit? [message #1782766 is a reply to message #1727372] Thu, 01 March 2018 08:02 Go to previous message
Federer Roger  is currently offline Federer Roger Friend
Messages: 30
Registered: December 2017
Member
You can set binding keys empty. You can get Bindings using createASTs.
Previous Topic:What's the use of Database class in internal.search.core.nd.db?
Next Topic:JDT - Find startline of method excluding Javadocs
Goto Forum:
  


Current Time: Thu Apr 25 12:42:27 GMT 2024

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

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

Back to the top