Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » bindings are null
bindings are null [message #506290] Wed, 06 January 2010 14:33 Go to next message
Eclipse UserFriend
Hi Everyone,

I'm trying to retrieve the type and method bindings in each of the appropriate endVisit() methods in my ASTVisitor class, but I'm not having any luck and the bindings are consistently null. The interesting thing is that the bindings work on the same code with the eclipse ASTView plugin. What am I doing wrong?

Here are some relevant code snippets which will hopefully help someone figure out what is going on!

ASTParser parser = ASTParser.newParser(AST.JLS3); 
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(source);
parser.setResolveBindings(true);
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
		
GenericVisitor visitor = new GenericVisitor(outDir + "//" + file.getName() + ".xml");
visitor.process(unit);


public class GenericVisitor extends ASTVisitor 
{

	 public void endVisit(FieldDeclaration node) 
	 {
	
            String bindingInfo = "";	
            ITypeBinding binding = node.getType().resolveBinding();
			
	     if(binding == null)
	     {                    
	        System.out.println("field declaration binding = null");
	     }
	     else
	     {
	        bindingInfo = binding.getQualifiedName();
	     }
	        
	    endVisitNode(node, bindingInfo); 
	 }
	 
        public void endVisit(MethodInvocation node) 
	 {
	
             String bindingInfo = "";	
             IMethodBinding binding = node.resolveMethodBinding();
			
	     if(binding == null)
	     {                    
	        System.out.println("method binding = null");
	     }
	     else
	     {
	         bindingInfo = binding.toString();
	     }
		 
	     endVisitNode(node, bindingInfo); 
	 }
}




Thanks in advance,

Shirley













Re: bindings are null [message #506331 is a reply to message #506290] Wed, 06 January 2010 17:06 Go to previous messageGo to next message
Eclipse UserFriend
Le 2010-01-06 14:33, Shirley Cohen a écrit :
> Hi Everyone,
>
> I'm trying to retrieve the type and method bindings in each of the
> appropriate endVisit() methods in my ASTVisitor class, but I'm not
> having any luck and the bindings are consistently null. The interesting
> thing is that the bindings work on the same code with the eclipse
> ASTView plugin. What am I doing wrong?
>
> Here are some relevant code snippets which will hopefully help someone
> figure out what is going on!
>
>
> ASTParser parser = ASTParser.newParser(AST.JLS3);
> parser.setKind(ASTParser.K_COMPILATION_UNIT);
> parser.setSource(source);
> parser.setResolveBindings(true);
> CompilationUnit unit = (CompilationUnit) parser.createAST(null);
In order to get the bindings, you need to set a context and the context
is a java project in the current API.
So unless you have a java project around, you won't be able to get the
bindings.

Let me know if you need more help,

Olivier
Re: bindings are null [message #506450 is a reply to message #506331] Thu, 07 January 2010 10:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Olivier,

Thanks! This is exactly what I needed to know. I do have a java project in eclipse, but it is located in a different workspace from the one that I'm using for parsing. Is it possible to reference a java project from another eclipse workspace? If so, how can that be done?

Many thanks,

Shirley
Re: bindings are null [message #506455 is a reply to message #506450] Thu, 07 January 2010 10:13 Go to previous messageGo to next message
Eclipse UserFriend
Le 2010-01-07 10:07, Shirley Cohen a écrit :
> Thanks! This is exactly what I needed to know. I do have a java project
> in eclipse, but it is located in a different workspace from the one that
> I'm using for parsing. Is it possible to reference a java project from
> another eclipse workspace? If so, how can that be done?
No, you need the java project to be defined inside the workbench that
you are using. If you describe what you are trying to do, I might be
able to help you better.
--
Olivier
Re: bindings are null [message #506462 is a reply to message #506455] Thu, 07 January 2010 10:41 Go to previous messageGo to next message
Eclipse UserFriend
So, what you're saying is that an IProject cannot be created for an existing java project that resides in a separate eclipse workspace?

What I am trying to do is parse the contents of various third party software, which already exist somewhere else on the file system in their own workspaces. I don't want to have to import every single one into my own workspace where the parsing is done. Does this help? Do you need more info?

Thanks,

Shirley

Re: bindings are null [message #506649 is a reply to message #506462] Fri, 08 January 2010 04:04 Go to previous message
Eclipse UserFriend
Le 2010-01-07 10:41, Shirley Cohen a écrit :
> So, what you're saying is that an IProject cannot be created for an
> existing java project that resides in a separate eclipse workspace?
> What I am trying to do is parse the contents of various third party
> software, which already exist somewhere else on the file system in their
> own workspaces. I don't want to have to import every single one into my
> own workspace where the parsing is done. Does this help? Do you need
> more info?
Are you running your code from within Eclipse or on a command line?
What you are trying to do is not simple to achieve.
--
Olivier
Previous Topic:What is the best way to find an interface for Java classes
Next Topic:Debugging fails with cannot connect to VM message
Goto Forum:
  


Current Time: Mon Mar 17 05:33:04 EDT 2025

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

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

Back to the top