Bug 110465 - Continue AST work
Summary: Continue AST work
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 1.5.3   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-23 12:10 EDT by Andrew Clement CLA
Modified: 2012-04-03 16:05 EDT (History)
4 users (show)

See Also:


Attachments
testcase patch (1.59 KB, patch)
2005-12-08 08:21 EST, Helen Beeken CLA
aclement: iplog+
Details | Diff
Modified AjASTConverter.java (196.17 KB, application/octet-stream)
2005-12-08 08:23 EST, Helen Beeken CLA
aclement: iplog+
Details
patch containing fix and testcase for problem raised in comment #14 (7.53 KB, patch)
2005-12-19 06:08 EST, Helen Beeken CLA
no flags Details | Diff
patch containing fix and testcase for problem raised in comment #14 (8.25 KB, patch)
2005-12-21 04:05 EST, Helen Beeken CLA
aclement: iplog+
Details | Diff
Patch containing enhancement raised in comment #3 (8.03 KB, patch)
2006-01-04 16:27 EST, Eduardo Piveta CLA
aclement: iplog+
Details | Diff
patch containing enhancement raised in comment #19 (55.01 KB, application/zip)
2006-01-25 05:46 EST, Helen Beeken CLA
aclement: iplog+
Details
patch containing enhancement raised in comment #20 (9.56 KB, application/zip)
2006-01-27 05:51 EST, Helen Beeken CLA
no flags Details
Patch to add parameters in pointcut declarations (9.30 KB, patch)
2006-02-03 15:29 EST, Eduardo Piveta CLA
aclement: iplog+
Details | Diff
patch proposed in comment #28 plus more tests (19.89 KB, patch)
2006-02-06 06:23 EST, Helen Beeken CLA
aclement: iplog+
Details | Diff
AjNaiveASTFlattener support for declare statements (4.96 KB, patch)
2006-12-15 09:52 EST, Davi Pires CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2005-09-23 12:10:13 EDT
See bug 88861.  That bug describes how the infrastructure is now in place for
the AspectJ AST (there is also an example in that bug).  This bug is to capture
future work that needs doing, effectively a brain dump from me:

1. LOADS more testcases.  See ASTVisitorTest in the org.aspectj.ajdt.core, there
are loads more examples that could be written that include more sophisticated
constructs, it also seems incorrect that the pointcut expressions (the bit after
the 'pointcut p():') is ignored in the existing testcases.

2. All 'basic' designators (e.g. call/execution/etc - all the ones that don't
next other designators) are captured at the moment as DefaultPointcut.  This
isn't right, there should be a subtype of PointcutDesignator for *all* the
aspectj designators. (and possibly, going further than that with different nodes
for each piece of each pointcut too ... typepattern/etc)

3. We need much more support in the AjASTRewriteAnalyzer if refactorings are
going to be possible.  Unfortunately the analyzer requires more *stuff* to be
around and so testcases for it have to be written in the AJDT core.tests plugin :(

If anyone has a particular use case that they need to get working, please
mention it in this bug and we'll raise the priority of 'that piece' of the AST.
Comment 1 Andrew Clement CLA 2005-09-24 09:09:21 EDT
Another thought.  I'm not sure the new AST support has been tested with Java5
language features in programs (annotations/enums/generics).
Comment 2 Adrian Colyer CLA 2005-10-28 09:33:24 EDT
moved this to "enhancement" rather than bug
Comment 3 Eduardo Piveta CLA 2005-11-03 18:51:36 EST
(In reply to comment #0)
> If anyone has a particular use case that they need to get working, please
> mention it in this bug and we'll raise the priority of 'that piece' of the  AST.

Hi,

I could not find a way to check if an aspect is a privileged one using the
ASTVisitor. What I need is something like the code bellow:

import org.aspectj.org.eclipse.jdt.core.dom.AjASTVisitor;
import org.aspectj.org.eclipse.jdt.core.dom.AjTypeDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration;
import org.aspectj.org.eclipse.jdt.core.dom.TypeDeclaration;

public class PrivilegedAspectVisitor extends AjASTVisitor {
   public boolean visit(TypeDeclaration node) {
      if (((AjTypeDeclaration) node).isAspect()){
         AspectDeclaration a = (AspectDeclaration) node;
         // the method isPrivileged does not exist
         if (a.isPrivileged()) 
            System.out.println("Privileged aspect");
         }	
         return false;
      }
}


If this information is not available, the AjASTConverter could be modified to
accomplish that.
I attempted to find a suitable place to change this. Perhaps the following makes
sense...

Instead of:
-------------------------------------------------------------------------------------------------------------------------
public ASTNode
convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
typeDeclaration) {
  ...
      if (perClause == null){
         typeDecl = new
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,null);
      } else {
         typeDecl = new
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,convert(perClause));
      }
  ...
}

Something like this (note that a constructor could be created to receive this
information):
-------------------------------------------------------------------------------------------------------------------------
public ASTNode
convert(org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
typeDeclaration) {
  ...
   boolean isPrivileged = ((AspectDeclaration)typeDeclaration).isPrivileged;
   if (perClause == null){
      typeDecl = new
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,null, isPrivileged);
   } else {
      typeDecl = new
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration(this.ast,convert(perClause),
isPrivileged);
  ...
}			}

I don't know if this is the appropriate forum for this kind of question. Let me
know if the aspectj-users or aspectj-dev is the right choice.

Regards,
Eduardo Piveta
Comment 4 Andrew Clement CLA 2005-11-04 03:10:34 EST
this is the definetly the right place to post that kind of response - I'll try
and get to look at your proposal soon, but it sounds reasonable and just the
kind of feedback I was after.
Comment 5 Eduardo Piveta CLA 2005-11-04 20:22:09 EST
(In reply to comment #0)
> 1. LOADS more testcases.  See ASTVisitorTest in the org.aspectj.ajdt.core, there
> are loads more examples that could be written that include more sophisticated
> constructs, it also seems incorrect that the pointcut expressions (the bit after
> the 'pointcut p():') is ignored in the existing testcases.
> 

Hi,

I was trying to parse some aspects and classes in an AspectJ GoF design patterns
implementation. In the
ca.ubc.cs.spl.aspectPatterns.patternLibrary.VisitorProtocol aspect a
ClassCastException was thrown. 
It seems that an exception occurs whenever there is a comment before an ITD Method. 

I tried to reproduce the exception using a small example: 
----------------------------------------------------------------------
import java.util.HashMap;

import org.aspectj.org.eclipse.jdt.core.dom.AST;
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;

public class Test {
   public static void check(String source){
      ASTParser parser = ASTParser.newParser(AST.JLS2); 
      parser.setCompilerOptions(new HashMap());
      parser.setSource(source.toCharArray());
      CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
   }
   public static void main(String arf[]){
      Test.check("aspect A{ public void B.x(){} }"); // This one works
      Test.check("aspect A{ /** */ public void B.x(){} }"); // This one raises
an exception
	}
}
----------------------------------------------------------------------

The execution of the example leads to the following ClassCastException:

Exception in thread "main" java.lang.ClassCastException:
org.aspectj.org.eclipse.jdt.core.dom.DefaultCommentMapper$CommentMapperVisitor
	at
org.aspectj.org.eclipse.jdt.core.dom.InterTypeMethodDeclaration.accept0(InterTypeMethodDeclaration.java:71)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration.accept0(AspectDeclaration.java:94)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:299)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at
org.aspectj.org.eclipse.jdt.core.dom.DefaultCommentMapper.initialize(DefaultCommentMapper.java:242)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit.initCommentMapper(CompilationUnit.java:483)
	at
org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:1025)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:252)
	at
org.aspectj.org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:803)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:591)
	at Test.check(Test.java:15)
	at Test.main(Test.java:20)

Looking in the org.aspectj.org.eclipse.jdt.core.dom.InterTypeDeclarationMethod
class, the following code raises the exception:
----------------------------------------------------------------------
void accept0(ASTVisitor visitor) {
   AjASTVisitor ajvis = (AjASTVisitor)visitor;
   ...
   ajvis.endVisit(this);
}
----------------------------------------------------------------------
According to the debugger, the visitor parameter is of type:
org.aspectj.org.eclipse.jdt.core.dom.DefaultCommentMapper$CommentMapperVisitor@1a85d38

Which inheritance tree is: 

ASTVisitor 
 |
 |- DefaultASTVisitor
     |
     |- CommentMapperVisitor  


Perhaps the accept0 method could be modified to:
----------------------------------------------------------------------
void accept0(ASTVisitor visitor) {
   ASTVisitor ajvis = visitor;
   ...
   ajvis.endVisit(this);
}
(Or the 'ajvis' variable renamed to 'visitor')
----------------------------------------------------------------------

And an endVisit method added to org.aspectj.org.eclipse.jdt.core.dom.ASTVisitor
class:
----------------------------------------------------------------------
public abstract class ASTVisitor {
   ...
   public void endVisit(InterTypeMethodDeclaration node) { // default
implementation: do nothing }
   ...
}
----------------------------------------------------------------------

Let me know if you could reproduce this. I'm using ajde 1.5.0.20051014142856.

Eduardo Piveta
Comment 6 Andrew Clement CLA 2005-11-07 09:21:45 EST
I can recreate it with your test program, thanks.

The fix is not perhaps so straightforward.  The problem is that ASTVisitor is a
compiler class and knows only about Java entities - you won't see mention of an
AspectJ type in there.  AjASTVisitor is the subclass that introduces the AspectJ
types.  If (after spending a little while on it...) we can't work out a way to
get visiting to work properly with this hierarchy and ideally without casts then
maybe we could look at merging the two...

Comment 7 Eduardo Piveta CLA 2005-11-10 20:33:21 EST
Hi,

Could you please add the following test method to the ASTVisitorTest? (It also
raises a ClassCastException).

btw: This bug was initially an enhancement about the work in the AST features.
Don't you think that it's better to split this bug (one for the
ClassCastException and another to the enhancements of AST) and give them
different priority and severity?

Best Regards,
Eduardo Piveta
----------------------------------------------------------------
public class ASTVisitorTest extends TestCase {
	
// from bug 110465 - will currently break because of casts
...
public void testAspectWithCommentThenPointcut() {
   a.check("aspect A{ /** */ pointcut x(); }");
}
}

Exception in thread "main" java.lang.ClassCastException:
org.aspectj.org.eclipse.jdt.core.dom.DefaultCommentMapper$CommentMapperVisitor
	at
org.aspectj.org.eclipse.jdt.core.dom.PointcutDeclaration.accept0(PointcutDeclaration.java:291)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at
org.aspectj.org.eclipse.jdt.core.dom.AspectDeclaration.accept0(AspectDeclaration.java:94)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:299)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at
org.aspectj.org.eclipse.jdt.core.dom.DefaultCommentMapper.initialize(DefaultCommentMapper.java:242)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit.initCommentMapper(CompilationUnit.java:483)
	at
org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:1025)
	at
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:252)
	at
org.aspectj.org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:803)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:591)
	at br.ufrgs.inf.badSmells.BBB.check(BBB.java:15)
	at br.ufrgs.inf.badSmells.BBB.main(BBB.java:23)
Comment 8 Andrew Clement CLA 2005-11-11 03:22:37 EST
I've integrated the testcase - thanks.  This bug was raised to cover post 1.5.0
activity.  I didn't plan on doing any more on the AST for 1.5.0 until you began
testing it for me.  The stuff you are adding addresses point (1) in this request
just fine - loads more testcases.  We won't hold up 1.5.0 because the AST isn't
fully tested.

The only piece of work I definetly want to do for 1.5.0 is move the AST rewrite
analyzer into AJDT from AJ, and that is covered by a separate enhancement
request, bug 111317.
Comment 9 Andrew Clement CLA 2005-11-11 03:33:50 EST
Before you raise 20 similar bugs to do with classcastexceptions, I've fixed them
all (at least all the ones I could find) ;)
Comment 10 Eduardo Piveta CLA 2005-12-02 21:33:13 EST
(In reply to comment #9)

Thanks,

The ClassCastException problems are not occurring anymore. It's working perfectly now. I applied successfully some AST visitors in the AO GoF design pattern implementations (http://www.cs.ubc.ca/~jan/AODPs/). 
Now, I'm applying some AST stuff in the GlassBox Inspector (https://glassbox-inspector.dev.java.net/).
If everything works fine, the next step is using AspectJ examples, eclipse AspectJ book samples and AspectJ source code as test cases. Currently I'm having a problem with after returning advice. An NPE is raised whenever this construction appears in an aspect.

Here is the exception stack trace:
--------------------------------------------------------------------------------------------------------------
Exception in thread "main" java.lang.NullPointerException
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.setModifiers(AjASTConverter.java:3647)
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:505)
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:79)
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:220)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:2039)
	at org.aspectj.org.eclipse.jdt.core.dom.AjASTConverter.convert(AjASTConverter.java:998)
	at org.aspectj.org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:252)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:803)
	at org.aspectj.org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:591)
	at a.Test.check(Test.java:14)
	at a.Test.main(Test.java:18)


Here is a test class:
--------------------------------------------------------------------------------------------------------------
package a;

import java.util.HashMap;

import org.aspectj.org.eclipse.jdt.core.dom.AST;
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;

public class Test {
   public static void check(String source){
      ASTParser parser = ASTParser.newParser(AST.JLS2); 
      parser.setCompilerOptions(new HashMap());
      parser.setSource(source.toCharArray());
      CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
   }
   public static void main(String arf[]){
      Test.check("aspect A{ after() : call(* *.*(..)){}}"); // this one works 
      Test.check("aspect A{ after() returning : call(* *.*(..)){}}"); // this raises a NPE
   }
}
--------------------------------------------------------------------------------------------------------------
I'm using AJDT 1.3.0.20051130095036

Regards,
Eduardo
Comment 11 Helen Beeken CLA 2005-12-08 07:32:00 EST
The reason the NPE is occuring is that currently because it's after returning advice we assume that there is an "extra argument". So, for example, changing

"aspect A{ after() returning : call(* *.*(..)){}}"

to be

"aspect A{ after() returning(String s) : call(* *.*(..)){}}"

doesn't produce the NPE. Similarly with "after() throwing" and "after() throwing(Exception e)" - the first throws an NPE and the second doesn't. The fix is to check whether the extra argument is there or not.
Comment 12 Helen Beeken CLA 2005-12-08 08:21:44 EST
Created attachment 31372 [details]
testcase patch

Patch containing testcase which shows the NPE reported in comment #10.

Apply to the org.aspectj.ajdt.core project.
Comment 13 Helen Beeken CLA 2005-12-08 08:23:50 EST
Created attachment 31373 [details]
Modified AjASTConverter.java

The attached file contains the changes to AjASTConverter.java which fix the NPE reported in comment #10.
Comment 14 Eduardo Piveta CLA 2005-12-12 17:56:01 EST
(In reply to comment #0)
> ... 
> If anyone has a particular use case that they need to get working, please
> mention it in this bug and we'll raise the priority of 'that piece' of the AST.

Hello, 

I was trying to get the name of an itmd and perform some actions when the itmd is an abstract one. In the first attempt (see code bellow), I got two issues:
 - The method 'getName()' of class 'InterTypeMethodDeclaration' is returning the mangled name (ex.: ajc$interType$interMethod$callRate66d). 
 - I could not test if an itmd is an abstract one using the Modifier class (available in the java reflection api).

As a workaround, I changed my code to get the 'not mangled' name and to check if the itmd is abstract using the 'getBody' method (see 'Second Attempt'). Perhaps these things could be provided as enhancements by the AST support (if they aren't already there).

First attempt
------------------------------------------------------------------
public class AVisitor extends AjASTVisitor {
   public boolean visit(InterTypeMethodDeclaration node){ 
      String name = node.getName().toString(); 
      if (Modifier.isAbstract(node.getModifiers())){
         ...
      }
   }
}

Second attempt 
------------------------------------------------------------------
public class AVisitor extends AjASTVisitor {
   public boolean visit(InterTypeMethodDeclaration node){
      String name = node.getName().toString();
      name = name.substring(26, name.length()-3); 
      if (node.getBody() == null){
         ...
      }
   }
}

Test code
-----------------------------------------------------------------
public aspect Billing {
    ...
    public abstract long Connection.callRate();
    ...
}

I'm using the 20051208103628 build + AjASTConverter.java modified by Helen.
(btw 1: Thanks to Helen. The NPE reported in comment #10 is not occuring anymore.)
(btw 2: Could you please add the modified AjASTConverter to the CVS?)

Regards,
Eduardo
Comment 15 Andrew Clement CLA 2005-12-13 03:49:57 EST
I've just put in the first patches for the NPE with after returning.  For your latest situation, I don't think we should be hacking strings to get the name.  When the DOM AST node is built from the compiler AST node it should use the declared name and modifiers rather than those 'forced on it' during ITD processing.  These are available as declaredModifiers and declaredSelector in the ITD - want to look at this Helen?
Comment 16 Helen Beeken CLA 2005-12-19 06:08:48 EST
Created attachment 31943 [details]
patch containing fix and testcase for problem raised in comment #14

Apply this patch to the org.aspectj.ajdt.core project.

This patch contains a proposed fix and testcase for the problem raised in comment #14, namely when the method is an ITD method, the name is the mangled name and the modifiers aren't correct. The fix is, as Andy says, to use declaredModifiers and declaredSelector in these cases within AjASTConverter.java.
Comment 17 Helen Beeken CLA 2005-12-21 04:05:59 EST
Created attachment 32069 [details]
patch containing fix and testcase for problem raised in comment #14

ooops....my previous patch didn't add my new testcase ASTidtTest to AjcTests. This one does and this is the only difference between the two.
Comment 18 Andrew Clement CLA 2005-12-21 05:57:00 EST
patch from comment #17 now integrated into HEAD.
Comment 19 Helen Beeken CLA 2006-01-04 03:24:58 EST
A comment/request which has been brought up on the Newsgroup (http://www.eclipse.org/newsportal/article.php?id=1408&group=eclipse.technology.ajdt#1408)
is to be able to do something like

ast.newPointcutDeclaration()

in much the same way as you can today do ast.newMethodDeclaration(). 
Comment 20 Eduardo Piveta CLA 2006-01-04 16:27:12 EST
Created attachment 32485 [details]
Patch containing enhancement raised in comment #3

I added a method to see if an aspect is a privileged one (see comment #3). So I could do things like:

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;
   }
}

I also added a test case in ASTVisitorTest. The code seems to work, but I'm not quite sure about the needed behavior regarding property descriptors. 

Please take a carefull look at the AspectDeclaration class, more specifically on 'PRIVILEGED_PROPERTY' constant, the 'static initialization', and the methods: 'clone0', 'accept0', 'isPrivileged', 'setPrivileged' and 'internalGetSetBooleanProperty'.
Comment 21 Helen Beeken CLA 2006-01-25 05:46:01 EST
Created attachment 33584 [details]
patch containing enhancement raised in comment #19

This zip contains:

* pr110465-ajdt-core-patch-comment19.txt - a patch to be applied to the org.aspectj.ajdt.core project. This contains 
    - new ASTNodes for the different declare statements plus new ASTNodes for 
      the weaver PatternNodes which are required in the declare statements, 
    - an AjAST which contains the methods to create a newXXXDeclaration
    - an AjASTFactory which enables us to create an AjAST rather than an AST if 
      necessary,
    - changes to AjASTConverter to do the right thing when converting a 
      DeclareDeclaration
    - the required modifications to AjASTVisitor and AjASTMatcher due to the 
      introduction of the new ASTNodes
    - a null check in the AndPointcut ASTNode
    - tests for the new AjAST
    - ammendments to the ASTVisitorTest due to the introduction of the new 
      ASTNodes (now getting extra output)

* AST.java - the changes are (all marked AspectJ Extension):
   - removes the final modifer from the class declaration
   - changes "private" to "protected" in AST(int level) contstructor

* ASTParser - the changes are (all marked AspectJ Extension):
   - contains the logic to use the factory to create the AST
   - uses this factory in the method internalCreateASTForKind()

* CompilationUnitResolver - the changes are (all marked AspectJ Extension):
  - uses the factory to create the ast in convert(...)
  - uses the factory to create the ast in resolve(..)

Note - for all the tests to pass, the fix for bug 125027 needs to be applied.
Comment 22 Helen Beeken CLA 2006-01-25 05:50:33 EST
As a follow on from comment #21 and the supplied patch - more tests can be written for the other ASTNodes, for example, checking whether the clone0() methods do the right thing - in much the same way as the supplied tests for the Declare ASTNodes.
Comment 23 Andrew Clement CLA 2006-01-26 06:05:30 EST
Helens *substantial* changes are in that make the AST 100% better - it knows much more than it used to and you can construct nodes in it (i.e. programmatically construct an AJ ast, rather than just asking the parser to process some text string that is your program).

Helen is now going to look at Eduardos change in comment #20 - now she knows much more about the AST - and I hope we can commit it soon.
Comment 24 Helen Beeken CLA 2006-01-27 05:51:08 EST
Created attachment 33695 [details]
patch containing enhancement raised in comment #20

This zip contains patchs that encorporates the patch supplied in comment #20 by Eduardo to be able to set whether an aspect is privileged or not plus fixes the getting/setting of the perClause in an AspectDeclaration.

More specifically, this zip contains:

* pr110465-org-aspectj-ajdt-core-patch-comment20.txt - apply this patch to the org.aspectj.ajdt.core project. This contains:
      * changes to AspectDeclaration:
                - to add the isPrivileged property - as supplied by Eduardo
                - the setting of the perclause property 
                - a new constructor which only takes the AjAST as an argument 
                  which can be used by the AjAST to create a new 
                  AspectDeclaration
               - an implementation of internalGetSetChildProperty(..) for the 
                 perClause property
     * updated AjAST to create a new AspectDeclaration using the newly created 
       constructor
     * updated AjASTConverter to set the isPrivileged property if necessary (as 
       supplied in patch by Eduado)
     * removed the "final" modifier from the 
       AjTypeDeclaration.internalGetSetBooleanProperty(..) to enable the 
       AspectDeclaration to override it and handle the isPrivileged property (as 
       supplied in patch by Eduado)
     * updates to the AjASTTest  to test for the new properties and the use of 
       the clone0 and internalGetXX methods
     * updates to the ASTVisitorTest to handle the introduction of a new test 
       for a privilged aspect (as supplied by Eduado) plus visiting the 
       perClause.

* TypeDeclaration.java - this needs to be updated in the jdt core. The only  
  change is to remove the "final" modifier from the 
  internalGetSetChildProperty(..) method so we can override it in the 
  AspectDeclaration to handle the perClause property.


Eduardo - thanks for supplying a nice patch with testcase :-)
Comment 25 Andrew Clement CLA 2006-01-27 07:05:15 EST
/sigh - gotta love jdt core changes, i'll do this soon as I can.
Comment 26 Andrew Clement CLA 2006-01-27 10:50:58 EST
yuckity yuck.

Its all in now - I hit a slight hitch in that the dynamic class loading in the ASTParser class had an incorrect message in it when it failed (so I kept suspecting the TypeDeclaration factory dynamic class loading) and the name used for the class started with org.eclipse when we have to avoid that string since the build.xml in shadows transforms it.  The other factories live in an org.aspectj.ajdt package.  Anyway, I changed this one to follow the same pattern - rebuilt shadows and there is a new org.eclipse.jdt.core that includes the changes.

The ajdt.core patch is also applied.
Comment 27 Helen Beeken CLA 2006-02-01 04:42:58 EST
As a note, whilst working on the last two enhancement requests, I noticed that there isn't currently an ASTNode to represent an inter-type constructor, plus there isn't one for all the perclauses.
Comment 28 Eduardo Piveta CLA 2006-02-03 15:29:53 EST
Created attachment 34121 [details]
Patch to add parameters in pointcut declarations


Hi,

As reported in the aspectj-users mailing list, there is no way to get the arguments of a pointcut declaration:

http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05069.html

I tried to provide this capability in the AST support. 
I'm sending you a patch (pr110465-org-aspectj-ajdt-core-patch-msg05069.txt) to be applied to the org.aspectj.ajdt.core project, containing changes to:
 - AjASTConverter, so the arguments are added to the dom pointcut declaration.
 - AjNaiveASTFlattener, to serialize the arguments
 - PointcutDeclaration
    - to add the PARAMETERS_PROPERTY property
    - to modify the static initialization
    - to add a field named 'parameters'
    - to update the 'internalGetChildListProperty', 'clone0', 'memSize' and 'treeSize' methods
    - to add a 'parameters()' method // I could have used 'getParameters' instead, but 'MethodDeclaration' class uses 'parameters' as the name ...
 - AjASTTest
    - to add a 'testGetAndSetPointcutArguments' test method (I could not create a SingleVariableDeclaration instance, so the test is not complete)
 - ASTVisitorTest
    - to add the methods: 'testPointcutWithoutArguments', 'testPointcutWithOnePrimitiveArgument', 'testPointcutWithTwoPrimitiveArguments', 'testPointcutWithOneTypedArgument', 'testPointcutWithTwoTypedArgument'


I coded a class to see the use of AjNaiveASTFlattener and if the parameters of a pointcut are ok, but I don't know for sure where in the CVS this kind of code belongs (if desirable):

import java.util.HashMap;

import org.aspectj.org.eclipse.jdt.core.dom.AST;
import org.aspectj.org.eclipse.jdt.core.dom.ASTParser;
import org.aspectj.org.eclipse.jdt.core.dom.AjNaiveASTFlattener;
import org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit;

public class AjPointcutArgumentsTests {
   private void check(String source){
      ASTParser parser = ASTParser.newParser(AST.JLS2);
      parser.setCompilerOptions(new HashMap());
      parser.setSource(source.toCharArray());
      CompilationUnit cu2 = (CompilationUnit) parser.createAST(null);
      AjNaiveASTFlattener visitor = new AjNaiveASTFlattener();
      cu2.accept(visitor);
      System.err.println(visitor.getResult());
   }
   public static void main(String arf[]){
      AjPointcutArgumentsTests a = new AjPointcutArgumentsTests();
      a.check("public aspect A { pointcut y(): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(int a): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(int a, double b): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(X a): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(X a, X b): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(X a, int b): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(int a, X b): call(* *.*(..));}");
      a.check("public aspect A { pointcut y(int a, double b, Y c): call(* *.*(..));}");
   }

}


Regards,
Eduardo
Comment 29 Helen Beeken CLA 2006-02-06 06:23:02 EST
Created attachment 34184 [details]
patch proposed in comment #28 plus more tests

Thanks Eduardo :-)

I've looked at your patch and have updated the tests side of it:

* AjASTTest: testGetAndSetPointcutArguments - I finished this off by creating a SingleVariableDeclaration instance using ast.newSingleVariableDeclaration().
* I added some other tests for the PointcutDeclaration in AjASTTest checking the clone0 and internal property methods (these include testing for the new parameters property, but should have been there anyway testing for the other properties.....)
* I added your AjPointcutArgumentsTests class into the testsuite (same location as the AjASTTest class) calling it AjNaiveASTFlattenerTest and have split out the different checks into separate testcases.

Apply this patch to the org.aspectj.ajdt.core project.
Comment 30 Andrew Clement CLA 2006-02-06 08:29:40 EST
patch committed.
Comment 31 Andrew Clement CLA 2006-04-04 14:17:33 EDT
ongoing, everything done that we plan to do for 1.5.1.  Changes in 3.2 compiler wrt to AST will make the next compiler merge interesting.
Comment 32 Andrew Clement CLA 2006-06-27 10:36:59 EDT
no more work scheduled in the 1.5.2 timeframe.  Next major updates should be contributions from a couple of students (ben/charles) - giving us the extensions they've made in the area of the pointcut AST hierarchy.
Comment 33 Andrew Clement CLA 2006-09-12 11:36:41 EDT
I'm going to close this one - we should open a new one for further enhancements, this contains quite enough!
Comment 34 Davi Pires CLA 2006-12-15 09:52:54 EST
Created attachment 55758 [details]
AjNaiveASTFlattener support for declare statements

Hi all,

This patch adds support in the AjNaiveASTFlattener to the declare-like statements. It contains changes to:

- AjNaiveASTFlattener
    - made the buffer attribute protected, so that others may extend it.
    - created visit methods for: 
        - DeclareParentsDeclaration
        - DeclareWarningDeclaration
        - DeclareSoftDeclaration
        - DeclareErrorDeclaration
        - DeclarePrecedenceDeclaration.
        - DefaultPointcut
        - DefaultTypePattern

- AjNaiveASTFlattenerTest.java
    - added test methods for the new visit methods.

Please check if everything is fine. I look forward to finishing the necessary work on this class.

cheers,
Davi Pires
Comment 35 Andrew Clement CLA 2006-12-16 11:15:33 EST
Thank you for your contribution Davi, I have committed it into the codebase.  However, if you want to supply more patches - please can you raise a new bug where we can track it, since this bug is closed and was intended to track work completed in the shipped 1.5.3.