| When AsmManager.getDefault().getRelationshipMap().get(p) is null [message #72497] | 
Wed, 05 November 2008 21:44   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #599223 is a reply to message #72497] | 
Thu, 06 November 2008 00:57   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #599315 is a reply to message #72550] | 
Wed, 12 November 2008 13:36   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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
 |  
 |  
  | 
 | 
Powered by 
FUDForum. Page generated in 0.30021 seconds