Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] detecting AspectJ classes

Hi,

If you have the source code, you could use the AST support, extending
the AjASTVisitor class (i put some examples bellow if you want to
follow that direction).
If you want to perform this on bytecodes you will probably use the
AspectJ Reflection API, but then you have to load the classes you
need.

Hope that helps,
Eduardo
-------------------------------------------------------------------------------------------------------------------------------------
Here goes a code sample on Aspectj AST support:

import java.util.*;
import org.aspectj.org.eclipse.jdt.core.dom.*;

public class Program {

 public static void main(String []argv) {
   ASTParser parser = ASTParser.newParser(AST.JLS2);
   parser.setCompilerOptions(new HashMap());
   parser.setSource(argv[0].toCharArray());
   CompilationUnit cu2 = (CompilationUnit);
   parser.createAST(null);
   AjNaiveASTFlattener visitor = new AjNaiveASTFlattener();
   cu2.accept(visitor);
   System.err.println(visitor.getResult());
 }
}

Retrieved from: https://bugs.eclipse.org/bugs/show_bug.cgi?id=88861

You have to extend the AjASTVisitor class in order to define your own
visitors. Consider, for example, that you want to implement a visitor
that take some action whenever a privileged aspect is found:

public class PrivilegedAspectVisitor extends AjASTVisitor {
  public boolean visit(TypeDeclaration node) {
     if (((AjTypeDeclaration) node).isAspect()){
        AspectDeclaration a = (AspectDeclaration) node;
        if (a.isPrivileged()) { // Some action }
     }
     return false;
  }
}

You have a visit method for each class representing AspectJ AST elements.
Retrieved from: https://bugs.eclipse.org/bugs/show_bug.cgi?id=110465


On 10/17/06, Eugene Kuleshov <eu@xxxxxxxx> wrote:

  Thanks Andy. The problem is that I need to do that without loading
classes.

  I see that iajc is adding @Aspect attribute with value that has
expression for deployment model, but then I need to parse that
expression. Is there are some helper class that I can use to parse that
expression? Also, is this information is duplicated in some other
attribute, maybe org.aspectj.weaver.Aspect?

  regards,
  Eugene


Andy Clement wrote:
> See AjTypeSystem in the doc:
>
> http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/org/aspectj/lang/reflect/AjTypeSystem.html#getAjType(java.lang.Class)
>
>
> eg.
>
> AjType fooType = AjTypeSystem.getAjType(Foo.class);
> boolean isAspect = fooType.isAspect()
> PerClause pc = fooType.getPerClause()
> assertEquals(PerClauseKind.PERTHIS,pc.getKind());
>
> the individual attribute format are not documented anywhere other than
> in the code.
>
>
> On 17/10/06, Eugene Kuleshov <eu@xxxxxxxx> wrote:
>> Hi,
>>
>>   I need to detect that some particular class is in fact an aspect and
>> then I would also need to retrieve details on its deployment mode (i.e.
>> singleton, percflow, pertarget, etc). What would be the most reliable
>> way of doing that?
>>
>>   Actually I wonder if AspectJ-specific bytecode attributes are
>> documented anywhere? It would be really handy to have something like VM
>> ClassFormat spec that would document standard attributes used by
>> AspectJ.
>>
>>   Thanks in advance
>>
>>   Eugene
>>
>>
>> _______________________________________________
>> aspectj-dev mailing list
>> aspectj-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-dev
>>
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top