Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » When AsmManager.getDefault().getRelationshipMap().get(p) is null
When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72497] Wed, 05 November 2008 21:44 Go to next message
Laleh is currently offline Laleh
Messages: 10
Registered: July 2009
Junior Member
Hello Everyone,

I am working an a small project in which we are interested in collecting
information about the method being advised. I looked in sample codes where
ASM packages is used. But I have a problem, in code below:

// .. some code
String[] args = new String[files.length + 1];
args[0] = "-emacssym";
for (int i = 0; i < files.length; i++) {
args[i + 1] = files[i].getAbsolutePath();
}
runMain(args, false);
}

public void runMain(String[] args, boolean useSystemExit) {
super.runMain(args, useSystemExit);
IProgramElement hierarchyRoot =
AsmManager.getDefault().getHierarchy().getRoot();
hierarchyRoot.walk(new MyHierarchyWalker());
}
and then in class MyHierarchyWalker I have the follwing:

public class MyHierarchyWalker extends HierarchyWalker{

public void preProcess(IProgramElement p) {

if (p.getKind().equals(IProgramElement.Kind.METHOD)) {

List relationships = AsmManager.getDefault().getRelationshipMap().get(p);
if (relationships != null){
for (Iterator it = relationships.iterator(); it.hasNext(); ) {
IRelationship relation = (IRelationship)it.next();

// .. some code}
}}

The problem is that "relationships" is null so I cannot do anything with
it. I checked it with different case studies all in AspectJ examples
package. For space war example the "relationships" is null but for
"Tracing Example" and "Telecomm Example" it is working and it gives all
the methods being advised.
Can any one tell me why it is working for one example and not for the
other?

THANKS A LOT
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72515 is a reply to message #72497] Thu, 06 November 2008 00:57 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
We did a major refactoring of how the project model is stored and created
for AJDT 1.6.1. A by product of this refactoring is making AsmManager no
longer a singleton. This means AsmManager.getDefault() is no longer the
proper method to call if you are in a multi-project setting (eg- eclipse).

Instead, you access the Asm through the compiler object. Take a look at
the AJDT core class org.eclipse.ajdt.core.model.AJProjectModelFacade,
particularly the init() method:

AjCompiler compiler =
AspectJPlugin.getDefault().getCompilerFactory().getCompilerF orProject(project.getProject());
AsmManager existingState = compiler.getModel();
if (existingState != null) {
relationshipMap = existingState.getRelationshipMap();
structureModel = existingState.getHierarchy();
if (relationshipMap != null && structureModel != null) {
isInitialized = true;
}
}


Hope this helps,
--andrew
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72532 is a reply to message #72515] Thu, 06 November 2008 13:26 Go to previous messageGo to next message
Laleh is currently offline Laleh
Messages: 10
Registered: July 2009
Junior Member
Hi Andrew,

Thanks for your quick answer. I don't know how can I give the project as
project.getProject(). I did as follows:

IPath pa=new Path("D://eclipse//Workspace//SpacewarExample");
Workspace w=new Workspace();
IProject p=new Project(pa, w);
AspectJPlugin.getDefault().getCompilerFactory().getCompilerF orProject(p);

but it is not working. How can I give the project for which I need to get
information to method getCompilerForProject(Project).

Thanks a lot,

Laleh
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72550 is a reply to message #72532] Fri, 07 November 2008 00:27 Go to previous messageGo to next message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
Try

ResourcesPlugin.getWorkspace().getRoot().getProject("foo");

Note that the path that you pass in is workspace relative.
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72700 is a reply to message #72550] Wed, 12 November 2008 13:36 Go to previous messageGo to next message
Laleh is currently offline Laleh
Messages: 10
Registered: July 2009
Junior Member
Hello Andrew,

I tried what you proposed, the fact is that I am not building a plugin, I
have simple AspectJ project. when I used:

ResourcesPlugin.getWorkspace().getRoot().getProject("SpacewarExample ");

I got this exception:

Exception in thread "main" java.lang.IllegalStateException: Workspace is
closed.
at
org.eclipse.core.resources.ResourcesPlugin.getWorkspace(Reso urcesPlugin.java:320)
at ASMProcessor.runMain(ASMProcessor.java:30)
at ASMProcessor.processFiles(ASMProcessor.java:25)
at MainClass.main(MainClass.java:26)

Would you please help to handle the problem.

THANKS A LOT,

Laleh
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72713 is a reply to message #72700] Wed, 12 November 2008 23:19 Go to previous message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
I had assumed that since you were posting on the ajdt list that you were
using a plugin.

So, the way to grab hold of the AsmManager depends on how you are calling
the compiler. For example, if you can get access to the AjBuildManager,
call getState().getStructureModel().
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #599223 is a reply to message #72497] Thu, 06 November 2008 00:57 Go to previous message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
We did a major refactoring of how the project model is stored and created
for AJDT 1.6.1. A by product of this refactoring is making AsmManager no
longer a singleton. This means AsmManager.getDefault() is no longer the
proper method to call if you are in a multi-project setting (eg- eclipse).

Instead, you access the Asm through the compiler object. Take a look at
the AJDT core class org.eclipse.ajdt.core.model.AJProjectModelFacade,
particularly the init() method:

AjCompiler compiler =
AspectJPlugin.getDefault().getCompilerFactory().getCompilerF orProject(project.getProject());
AsmManager existingState = compiler.getModel();
if (existingState != null) {
relationshipMap = existingState.getRelationshipMap();
structureModel = existingState.getHierarchy();
if (relationshipMap != null && structureModel != null) {
isInitialized = true;
}
}


Hope this helps,
--andrew
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #599230 is a reply to message #72515] Thu, 06 November 2008 13:26 Go to previous message
Laleh is currently offline Laleh
Messages: 10
Registered: July 2009
Junior Member
Hi Andrew,

Thanks for your quick answer. I don't know how can I give the project as
project.getProject(). I did as follows:

IPath pa=new Path("D://eclipse//Workspace//SpacewarExample");
Workspace w=new Workspace();
IProject p=new Project(pa, w);
AspectJPlugin.getDefault().getCompilerFactory().getCompilerF orProject(p);

but it is not working. How can I give the project for which I need to get
information to method getCompilerForProject(Project).

Thanks a lot,

Laleh
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #599238 is a reply to message #72532] Fri, 07 November 2008 00:27 Go to previous message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
Try

ResourcesPlugin.getWorkspace().getRoot().getProject("foo");

Note that the path that you pass in is workspace relative.
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #599315 is a reply to message #72550] Wed, 12 November 2008 13:36 Go to previous message
Laleh is currently offline Laleh
Messages: 10
Registered: July 2009
Junior Member
Hello Andrew,

I tried what you proposed, the fact is that I am not building a plugin, I
have simple AspectJ project. when I used:

ResourcesPlugin.getWorkspace().getRoot().getProject("SpacewarExample ");

I got this exception:

Exception in thread "main" java.lang.IllegalStateException: Workspace is
closed.
at
org.eclipse.core.resources.ResourcesPlugin.getWorkspace(Reso urcesPlugin.java:320)
at ASMProcessor.runMain(ASMProcessor.java:30)
at ASMProcessor.processFiles(ASMProcessor.java:25)
at MainClass.main(MainClass.java:26)

Would you please help to handle the problem.

THANKS A LOT,

Laleh
Re: When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #599323 is a reply to message #72700] Wed, 12 November 2008 23:19 Go to previous message
Andrew Eisenberg is currently offline Andrew Eisenberg
Messages: 368
Registered: July 2009
Senior Member
I had assumed that since you were posting on the ajdt list that you were
using a plugin.

So, the way to grab hold of the AsmManager depends on how you are calling
the compiler. For example, if you can get access to the AjBuildManager,
call getState().getStructureModel().
Previous Topic:Error when using AspectJ with Rational Application Developer headless Ant build
Next Topic:cast thisJoinPoint to ProceedingJoinPoint
Goto Forum:
  


Current Time: Fri Aug 22 05:56:50 EDT 2014

Powered by FUDForum. Page generated in 0.02819 seconds