Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] Problems in resolving super aspect

I think you're right about not being able to resolve bindings using
the AspectJ compiler.  I'll talk to Andy to see if and when this
enhancement will be added.

For now, as I mentioned earlier, I think your best bet is to find the
bindngs yourself.

It shouldn't be too hard.

1. You need to parse the AJ compilation unit,
2. look at the extends clause in the aspect declaration (you probably
want to look for inner aspects as well).
3. look for a match in the import statements.
4. if there is no match, then you can assume that the super aspect is
in the same package (or the default package).
5. If you want to be doubly sure that the aspect exists, then you can
go to the IJavaProject (which you can obtain from the
ICompilationUnit) and search for the Aspect there.

A little more complicated, but should work.

On Fri, May 30, 2008 at 5:37 AM, Antonio Cuomo <myskin83@xxxxxxxxx> wrote:
> Thank you for the answer, sorry for the bad code, it was just a feasibility
> sketch. As of now, I can't manage to give you a project, but I can show you
> a better commented  code.
> The code to be parsed is:
> package second;
> import first.SuperAspect;
> public aspect AspectTwo extends SuperAspect{
>
> }
>
>
> The information we want to gather is that second.AspectTwo extends
> first.SuperAspect (which is an abstract aspect).
> The code works fine in this other case:
> package second;
>
> import first.AClass;
>
> public aspect AspectOne extends AClass{
>
> }
>
>
> in which the aspect AspectOne extends a class and not an aspect. It gives us
> back first.AClass.
>
> In the former case the only information obtainable was the unqualified name
> SuperAspect.
>
> Maybe this has something to do with what is said here:
>
> http://wiki.eclipse.org/index.php/Developer%27s_guide_to_building_tools_on_top_of_AJDT_and_AspectJ#Known_limitations.2C_bugs.2C_and_outstanding_issues
>
> Here is the code.
> IType currentAspect=aspectsIterator.next(); //This already contains all the
> aspects of the project
> String superClassName= currentAspect.getSuperclassName(); //this captures
> both class extension and aspect extension
> if(superClassName!=null){       //A superclass or superaspect exists
>   String fqName=null; //That's where we'll place the superaspect fq name;
>   System.out.println("Superclassname for aspect "+
> currentAspect.getFullyQualifiedName() +" is  "+superClassName); //Just a
> debug print   String[][]
> resolvedName=currentAspect.resolveType(superClassName,AJCompilationUnitManager.defaultAJWorkingCopyOwner());
> //Try to resolve the superaspect by name in //the context defined by the
> extending aspect
>   if(resolvedName==null){ //The superaspect was not resolved
>
>       //Go on the AST
>       ASTParser parser = ASTParser.newParser(AST.JLS3);        //This is the
> parser in org.aspectj.org.eclipse.jdt
>       parser.setCompilerOptions(new HashMap());
>       parser.setKind(ASTParser.K_COMPILATION_UNIT);
>
> parser.setSource(currentAspect.getCompilationUnit().getSource().toCharArray());
>       parser.setResolveBindings(true);
>       ASTNode node=parser.createAST(null);
>       AnotherASTVisitor visitor= new AnotherASTVisitor(currentAspect);
>       node.accept(visitor);
>       fqName=visitor.getResolvedName();
>
>   }
>
>       else
>
>           fqName=resolvedName[0][0]+"."+resolvedName[0][1];
>       System.out.println("Resolved name is : "+ fqName);
>
>
> }
>
>
> private final class AnotherASTVisitor extends ASTVisitor {
>
>   private String resolvedName;
>
>   public String getResolvedName(){
>
>       return resolvedName;
>
>   }
>
>   public boolean visit(TypeDeclaration td){
>
>       Type superType= td.getSuperclassType();
>       ITypeBinding superTypeBinding=superType.resolveBinding();
>       resolvedName=superTypeBinding.getQualifiedName(); //Here we get a
> NullPointerException because superTypeBinding is null.
>
>       return true;
>
>   }
> }
>
>
>
> Regarding your last point, it's probably what we'll do if all else fails.
> However, the thing is a little tedious because you have to consider the
> imports, the aspects in the same package and other aspects in the same comp
> unit, as for example in :
>
> package second;
> public aspect AspectThree extends SameunitAspect{
>
>
>
>
> }
>
> abstract  aspect SameUnitAspect{
>
> }
>
>
>
> Andrew Eisenberg wrote:
>>
>> It's hard to tell what your code is doing.  If you send me a zip of a
>> sample project, I can run it and see if I can figure out what's going
>> on.
>>
>> Just eyeballing the code, here are some comments:
>> 1. Perhaps resolve bindings isn't working during the parse and that is
>> why you are not able to find it in the AnotherASTVisitor class.
>> 2. It looks like your visitTypeDeclaration method is looking at the
>> name of the aspect (not its super aspect).  Even so, if bindings
>> haven't been resolved, then you will not be able to find the qualified
>> type for the super aspect.
>> 3. If all else fails, then you can search for the super aspect
>> yourself.  You'd need to search all the import statements.  If you
>> don't find any reference to the aspect there, then it may be in the
>> same package (or it may be an error).
>>
>> hope this helps,
>> --andrew
>>
>> On Thu, May 29, 2008 at 4:06 PM, myskin83@xxxxxxxxx <myskin83@xxxxxxxxx>
>> wrote:
>>
>>>
>>> Hi everybody,
>>> I'm using ajdt 1.5.0 on eclipse 3.3.2 to get structural
>>> information on aspectj projects. I managed to get the fully qualified
>>> name of
>>> the(eventually present) superclass of an aspect with this code snippet
>>>
>>>
>>>                        IType currentAspect=aspectsIterator.next();
>>>                       String
>>> superClassName= currentAspect.getSuperclassName();
>>>                       if(superClassName!=null){
>>>
>>>                               System.out.println("Superclassname for
>>> aspect "+ currentAspect.
>>> getFullyQualifiedName() +" is  "+superClassName);
>>>                               String[][]
>>>
>>> resolvedName=currentAspect.resolveType(superClassName,AJCompilationUnitManager.
>>> defaultAJWorkingCopyOwner());
>>>                               if(resolvedName==null){
>>>
>>>                                        //Didn't manage to auto-resolve-
>>> let's
>>> visit the AST
>>>                                       ASTParser parser =
>>> ASTParser.newParser(AST.JLS3);
>>>
>>>       parser.setCompilerOptions(new HashMap());
>>>                                       parser.setKind(ASTParser.
>>> K_COMPILATION_UNIT);
>>>
>>> parser.setSource(currentAspect.getCompilationUnit().
>>> getSource().toCharArray());
>>>                                       parser.setResolveBindings(true);
>>>                                       ASTNode
>>> node=parser.createAST(null);
>>>                                       node.accept(new AnotherASTVisitor
>>> (currentAspect));
>>>                               }
>>>                               String
>>> fqName=resolvedName[0][0]+"."+resolvedName[0]
>>> [1];
>>>
>>>
>>> rivate final class AnotherASTVisitor extends ASTVisitor {
>>>               IType
>>> aspect;
>>>               public AnotherASTVisitor(IType elem){
>>>                       this.aspect=elem;
>>>               }
>>>
>>>
>>>
>>>       public boolean visit(TypeDeclaration td){
>>>                       //here the code manages to get
>>> only simple name...
>>>               }
>>>       }
>>>
>>> However, this code is not capable to extract
>>> the fully qualified name of the  (eventually present) abstract "super
>>> aspect"-
>>> the aspect that is extended by this aspect. It is able to get only the
>>> simple
>>> name. Some help would be much appreciated:) Hear you soon.
>>> _______________________________________________
>>> ajdt-dev mailing list
>>> ajdt-dev@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/ajdt-dev
>>>
>>>
>>
>>
>
>


Back to the top