Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Finding if a selected piece of code is being affected by an advice

Hi everyone, I'm trying to get some information about whether a piece of method code selected from the user is being affected by an advice and if the advice uses withincode.

Since apparently most of this information is available in the cross-references view, I thought AJDT's visualizer content provider would be the right place to look, and just as a test I tried the following code:

        AJXReferenceProvider provider = new AJXReferenceProvider();

        LinkedList<AJRelationshipType> relations = new LinkedList<AJRelationshipType>();
       
        //adding all relationship types, just to see if anything is returned
        AJRelationshipType[] types = AJRelationshipManager.getAllRelationshipTypes();
        for (AJRelationshipType type : types) {
            relations.add(type);    
        }
        
        //refactoringInfo.getOrigin() returns the IFile for the .java class open in the eclipse editor
        Collection references = provider.getXReferences(JavaCore
                .createCompilationUnitFrom(refactoringInfo.getOrigin()),
                relations);

        //print the references
        for (Object object : references) {
            IXReference reference = (IXReference) object;

            System.out.println(reference.getName());
        }

The IFile passed as parameter to create the ICompilationUnit is being affected by advices and inter-type declarations, which are correctly displayed in the cross-references view, but getXReferences is returning an empty Collection, can anyone tell me what I'm doing wrong?

Thanks in advance,
Fernando Calheiros

Back to the top