Home » Language IDEs » AspectJ » Aspect Rewrite
Aspect Rewrite [message #71366] |
Tue, 18 March 2008 19:15  |
Eclipse User |
|
|
|
Originally posted by: cartona.tcd.ie
Hi,
While using AJDT - is it possible to change the AST of an AspectJ file
and then rewrite it back to a file. The JDT has a "recordModification"
section that shows you how to do this - but the AJCompilationUnit
doesn't support this? I see in there is a AjASTRewrite that does
something like this in the source file. I wonder if anyone has any
success or knows how to do this.
Also, you can't use a visitor on the AJCompilationUnit unlike the
CompilationUnit - which is a bit distressing.
Thanks,
Andrew.
|
|
| | |
Re: Aspect Rewrite [message #71424 is a reply to message #71405] |
Wed, 19 March 2008 08:43   |
Eclipse User |
|
|
|
Ok I'm reading this
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. jdt.doc.isv/guide/jdt_api_manip.htm
and I think I'm incorrect in using the AjRewriter
However, just going on the CompilerUnit recordModifications / rewrite alone
When I attempt record the modifications and then change the AST and
attempt a rewrite - I get an error message in the console saying
"Warning: AspectJ type declaration factory class not found on classpath"
I had a peek in the source and this is the code:
public final class AjASTRewriteAnalyzer extends AjASTVisitor {
private static final String AJ_ASTREWRITEANALYZER_FACTORY
" org.eclipse.ajdt.core.dom.rewrite.AjASTRewriteAnalyzerFactor y ";
private static IASTRewriteAnalyzerFactory astRewriteAnalyzerFactory;
static {
try{
astRewriteAnalyzerFactory = (IASTRewriteAnalyzerFactory)
Class.forName(AJ_ASTREWRITEANALYZER_FACTORY).newInstance();
} catch (InstantiationException ex) {
throw new ExceptionInInitializerError(ex.getMessage());
} catch (IllegalAccessException ex) {
throw new ExceptionInInitializerError(ex.getMessage());
} catch (ClassNotFoundException ex) {
System.err.println("Warning: AspectJ type declaration factory
class not found on classpath"); //$NON-NLS-1$
//throw new ExceptionInInitializerError(ex.getMessage());
}
I've added all the necessary jars in the extension file of my plugin and
I'm not sure why it isn't picking up this - because it is picking up
other classes in this jar file.
Thanks,
Andrew.
Ar 19/03/2008 12:14, Scríobh Andrew Carton:
> Hi Martin + any other people reading this,
>
> Yes - I wish to rewrite a small modification of an aspect from it's AST
> back to it's original file.
>
> I have had partial success with visitors etc but the "writing back"
> still doesn't work.
>
> Here is my example code below:
>
> Just a note on the code - The ChangeSomethingVisitor extends the
> AjASTVisitor and modifies something in the AST (specific to the AspectJ
> class from the AJCompilationUnit).
>
> To make sure the modification is changed I use the AjNaiveASTFlattener
> visitor which just makes a kind of debug information about the aspect.
> The change is successfully implemented.
>
> However, when I attempt to use the AjASTRewrite to modify the tree and
> get the TextEdits - it appears to be 0. I don't understand why!
>
> So I'm stumped really - I read a lot and did a lot to get to this stage
> - it really is a black art (The documentation/API is really poor and
> there are not many posts about how to do this kind of thing!) - is it
> something I did wrong or is it just the libraries aren't fully
> implemented? I'd really appreciate some help on this!
>
> Thanks,
> Andrew.
>
> currentCompUnit is an AJCompilationUnit
>
> if (currentCompUnit == null)
> return;
>
>
> currentCompUnit.requestOriginalContentMode();
>
> String contents = "";
>
> try {
> contents = currentCompUnit.getBuffer().getContents();
>
> } catch (org.eclipse.jdt.core.JavaModelException e)
> {
> e.printStackTrace();
>
> }
> currentCompUnit.discardOriginalContentMode();
>
> ASTParser parser = ASTParser.newParser(AST.JLS3);
> parser.setCompilerOptions(new HashMap());
> parser.setSource(contents.toCharArray());
> Document doc = new Document(contents);
> CompilationUnit c = (CompilationUnit) parser.createAST(null);
> c.recordModifications();
> AjASTRewrite ajrewrite = AjASTRewrite.create(c.getAST());
> ChangeSomethingVisitor visit = new ChangeSomethingVisitor();
>
> AjNaiveASTFlattener visit2 = new AjNaiveASTFlattener();
> c.accept(visit);
> c.accept(visit2);
> System.err.println(visit2.getResult());
> TextEdit edits =
> ajrewrite.rewriteAST(doc,currentCompUnit.getJavaProject().ge tOptions(true));
>
> System.err.println(edits.getChildrenSize());
> edits.apply(doc);
> System.out.println(doc.get());
>
> Ar 19/03/2008 02:51, Scríobh Martin Görg:
>> On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
>>> While using AJDT - is it possible to change the AST of an AspectJ
>>> file and then rewrite it back to a file. The JDT has a
>>> "recordModification" section that shows you how to do this - but the
>>> AJCompilationUnit doesn't support this? I see in there is a
>>> AjASTRewrite that does something like this in the source file. I
>>> wonder if anyone has any success or knows how to do this.
>>
>> I just asked a related question on the aspectj-dev mailinglist. You can
>> view the thread here:
>> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
>>
>> There is also some information included in the docs module of the AspectJ
>> project (docs/developer/compiler-weaver/index.html). Let me know, if you
>> find something useful.
>>
|
|
|
Re: Aspect Rewrite [message #71443 is a reply to message #71424] |
Thu, 20 March 2008 12:28   |
Eclipse User |
|
|
|
Ok I have had limited success with rewriting. However, I can only ever
get it working with SimpleTypes.
For example when I try duplicating a PointcutDeclaration and rewriting
it with the AjASTRewriter it just comes out as empty. I have tested the
copy of the PointcutDeclaration and the settings are not empty...
AjASTRewrite ajrewrite =....
AspectDeclaration ad = ...
PointcutDeclaration[] pointcuts = ad.getPointcuts();
PointcutDeclaration old = pointcuts[0];
PointcutDeclaration newd = (PointcutDeclartion)
PointcutDeclaration.copySubtree(ast, old);
ajrewrite.replace(old, newd, null);
There is 1 rewrite but the subtree is not copied in the TextEdit when I
save the file.
It is just ";" - an empty semicolon.
Does anyone have any ideas - is the implementation unfinished?
Thanks,
andrew.
Ar 19/03/2008 12:43, Scríobh Andrew Carton:
> Ok I'm reading this
> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. jdt.doc.isv/guide/jdt_api_manip.htm
>
>
> and I think I'm incorrect in using the AjRewriter
>
> However, just going on the CompilerUnit recordModifications / rewrite alone
>
> When I attempt record the modifications and then change the AST and
> attempt a rewrite - I get an error message in the console saying
>
> "Warning: AspectJ type declaration factory class not found on classpath"
>
> I had a peek in the source and this is the code:
>
> public final class AjASTRewriteAnalyzer extends AjASTVisitor {
>
> private static final String AJ_ASTREWRITEANALYZER_FACTORY
> " org.eclipse.ajdt.core.dom.rewrite.AjASTRewriteAnalyzerFactor y ";
>
> private static IASTRewriteAnalyzerFactory astRewriteAnalyzerFactory;
>
> static {
> try{
> astRewriteAnalyzerFactory = (IASTRewriteAnalyzerFactory)
> Class.forName(AJ_ASTREWRITEANALYZER_FACTORY).newInstance();
> } catch (InstantiationException ex) {
> throw new ExceptionInInitializerError(ex.getMessage());
> } catch (IllegalAccessException ex) {
> throw new ExceptionInInitializerError(ex.getMessage());
> } catch (ClassNotFoundException ex) {
> System.err.println("Warning: AspectJ type declaration factory
> class not found on classpath"); //$NON-NLS-1$
> //throw new ExceptionInInitializerError(ex.getMessage());
> }
>
> I've added all the necessary jars in the extension file of my plugin and
> I'm not sure why it isn't picking up this - because it is picking up
> other classes in this jar file.
>
> Thanks,
> Andrew.
>
>
> Ar 19/03/2008 12:14, Scríobh Andrew Carton:
>> Hi Martin + any other people reading this,
>>
>> Yes - I wish to rewrite a small modification of an aspect from it's
>> AST back to it's original file.
>>
>> I have had partial success with visitors etc but the "writing back"
>> still doesn't work.
>>
>> Here is my example code below:
>>
>> Just a note on the code - The ChangeSomethingVisitor extends the
>> AjASTVisitor and modifies something in the AST (specific to the
>> AspectJ class from the AJCompilationUnit).
>>
>> To make sure the modification is changed I use the AjNaiveASTFlattener
>> visitor which just makes a kind of debug information about the aspect.
>> The change is successfully implemented.
>>
>> However, when I attempt to use the AjASTRewrite to modify the tree and
>> get the TextEdits - it appears to be 0. I don't understand why!
>>
>> So I'm stumped really - I read a lot and did a lot to get to this
>> stage - it really is a black art (The documentation/API is really poor
>> and there are not many posts about how to do this kind of thing!) - is
>> it something I did wrong or is it just the libraries aren't fully
>> implemented? I'd really appreciate some help on this!
>>
>> Thanks,
>> Andrew.
>>
>> currentCompUnit is an AJCompilationUnit
>>
>> if (currentCompUnit == null)
>> return;
>>
>> currentCompUnit.requestOriginalContentMode();
>>
>> String contents = "";
>>
>> try {
>> contents = currentCompUnit.getBuffer().getContents();
>>
>> } catch (org.eclipse.jdt.core.JavaModelException e)
>> {
>> e.printStackTrace();
>>
>> }
>> currentCompUnit.discardOriginalContentMode();
>>
>> ASTParser parser = ASTParser.newParser(AST.JLS3);
>> parser.setCompilerOptions(new HashMap());
>> parser.setSource(contents.toCharArray());
>> Document doc = new Document(contents);
>> CompilationUnit c = (CompilationUnit) parser.createAST(null);
>> c.recordModifications();
>> AjASTRewrite ajrewrite = AjASTRewrite.create(c.getAST());
>> ChangeSomethingVisitor visit = new ChangeSomethingVisitor();
>>
>> AjNaiveASTFlattener visit2 = new AjNaiveASTFlattener();
>> c.accept(visit);
>> c.accept(visit2);
>> System.err.println(visit2.getResult());
>> TextEdit edits =
>> ajrewrite.rewriteAST(doc,currentCompUnit.getJavaProject().ge tOptions(true));
>>
>> System.err.println(edits.getChildrenSize());
>> edits.apply(doc);
>> System.out.println(doc.get());
>>
>> Ar 19/03/2008 02:51, Scríobh Martin Görg:
>>> On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
>>>> While using AJDT - is it possible to change the AST of an AspectJ
>>>> file and then rewrite it back to a file. The JDT has a
>>>> "recordModification" section that shows you how to do this - but the
>>>> AJCompilationUnit doesn't support this? I see in there is a
>>>> AjASTRewrite that does something like this in the source file. I
>>>> wonder if anyone has any success or knows how to do this.
>>>
>>> I just asked a related question on the aspectj-dev mailinglist. You can
>>> view the thread here:
>>> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
>>>
>>> There is also some information included in the docs module of the
>>> AspectJ
>>> project (docs/developer/compiler-weaver/index.html). Let me know, if you
>>> find something useful.
>>>
|
|
| |
Re: Aspect Rewrite [message #596773 is a reply to message #71366] |
Tue, 18 March 2008 22:51  |
Eclipse User |
|
|
|
On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
> While using AJDT - is it possible to change the AST of an AspectJ file
> and then rewrite it back to a file. The JDT has a "recordModification"
> section that shows you how to do this - but the AJCompilationUnit
> doesn't support this? I see in there is a AjASTRewrite that does
> something like this in the source file. I wonder if anyone has any
> success or knows how to do this.
I just asked a related question on the aspectj-dev mailinglist. You can
view the thread here:
http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
There is also some information included in the docs module of the AspectJ
project (docs/developer/compiler-weaver/index.html). Let me know, if you
find something useful.
--
Cheers
Martin
|
|
|
Re: Aspect Rewrite [message #596780 is a reply to message #71386] |
Wed, 19 March 2008 08:14  |
Eclipse User |
|
|
|
Hi Martin + any other people reading this,
Yes - I wish to rewrite a small modification of an aspect from it's AST
back to it's original file.
I have had partial success with visitors etc but the "writing back"
still doesn't work.
Here is my example code below:
Just a note on the code - The ChangeSomethingVisitor extends the
AjASTVisitor and modifies something in the AST (specific to the AspectJ
class from the AJCompilationUnit).
To make sure the modification is changed I use the AjNaiveASTFlattener
visitor which just makes a kind of debug information about the aspect.
The change is successfully implemented.
However, when I attempt to use the AjASTRewrite to modify the tree and
get the TextEdits - it appears to be 0. I don't understand why!
So I'm stumped really - I read a lot and did a lot to get to this stage
- it really is a black art (The documentation/API is really poor and
there are not many posts about how to do this kind of thing!) - is it
something I did wrong or is it just the libraries aren't fully
implemented? I'd really appreciate some help on this!
Thanks,
Andrew.
currentCompUnit is an AJCompilationUnit
if (currentCompUnit == null)
return;
currentCompUnit.requestOriginalContentMode();
String contents = "";
try {
contents = currentCompUnit.getBuffer().getContents();
} catch (org.eclipse.jdt.core.JavaModelException e)
{
e.printStackTrace();
}
currentCompUnit.discardOriginalContentMode();
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setCompilerOptions(new HashMap());
parser.setSource(contents.toCharArray());
Document doc = new Document(contents);
CompilationUnit c = (CompilationUnit) parser.createAST(null);
c.recordModifications();
AjASTRewrite ajrewrite = AjASTRewrite.create(c.getAST());
ChangeSomethingVisitor visit = new ChangeSomethingVisitor();
AjNaiveASTFlattener visit2 = new AjNaiveASTFlattener();
c.accept(visit);
c.accept(visit2);
System.err.println(visit2.getResult());
TextEdit edits =
ajrewrite.rewriteAST(doc,currentCompUnit.getJavaProject().ge tOptions(true));
System.err.println(edits.getChildrenSize());
edits.apply(doc);
System.out.println(doc.get());
Ar 19/03/2008 02:51, Scríobh Martin Görg:
> On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
>> While using AJDT - is it possible to change the AST of an AspectJ file
>> and then rewrite it back to a file. The JDT has a "recordModification"
>> section that shows you how to do this - but the AJCompilationUnit
>> doesn't support this? I see in there is a AjASTRewrite that does
>> something like this in the source file. I wonder if anyone has any
>> success or knows how to do this.
>
> I just asked a related question on the aspectj-dev mailinglist. You can
> view the thread here:
> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
>
> There is also some information included in the docs module of the AspectJ
> project (docs/developer/compiler-weaver/index.html). Let me know, if you
> find something useful.
>
|
|
|
Re: Aspect Rewrite [message #596786 is a reply to message #71405] |
Wed, 19 March 2008 08:43  |
Eclipse User |
|
|
|
Ok I'm reading this
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. jdt.doc.isv/guide/jdt_api_manip.htm
and I think I'm incorrect in using the AjRewriter
However, just going on the CompilerUnit recordModifications / rewrite alone
When I attempt record the modifications and then change the AST and
attempt a rewrite - I get an error message in the console saying
"Warning: AspectJ type declaration factory class not found on classpath"
I had a peek in the source and this is the code:
public final class AjASTRewriteAnalyzer extends AjASTVisitor {
private static final String AJ_ASTREWRITEANALYZER_FACTORY
" org.eclipse.ajdt.core.dom.rewrite.AjASTRewriteAnalyzerFactor y ";
private static IASTRewriteAnalyzerFactory astRewriteAnalyzerFactory;
static {
try{
astRewriteAnalyzerFactory = (IASTRewriteAnalyzerFactory)
Class.forName(AJ_ASTREWRITEANALYZER_FACTORY).newInstance();
} catch (InstantiationException ex) {
throw new ExceptionInInitializerError(ex.getMessage());
} catch (IllegalAccessException ex) {
throw new ExceptionInInitializerError(ex.getMessage());
} catch (ClassNotFoundException ex) {
System.err.println("Warning: AspectJ type declaration factory
class not found on classpath"); //$NON-NLS-1$
//throw new ExceptionInInitializerError(ex.getMessage());
}
I've added all the necessary jars in the extension file of my plugin and
I'm not sure why it isn't picking up this - because it is picking up
other classes in this jar file.
Thanks,
Andrew.
Ar 19/03/2008 12:14, Scríobh Andrew Carton:
> Hi Martin + any other people reading this,
>
> Yes - I wish to rewrite a small modification of an aspect from it's AST
> back to it's original file.
>
> I have had partial success with visitors etc but the "writing back"
> still doesn't work.
>
> Here is my example code below:
>
> Just a note on the code - The ChangeSomethingVisitor extends the
> AjASTVisitor and modifies something in the AST (specific to the AspectJ
> class from the AJCompilationUnit).
>
> To make sure the modification is changed I use the AjNaiveASTFlattener
> visitor which just makes a kind of debug information about the aspect.
> The change is successfully implemented.
>
> However, when I attempt to use the AjASTRewrite to modify the tree and
> get the TextEdits - it appears to be 0. I don't understand why!
>
> So I'm stumped really - I read a lot and did a lot to get to this stage
> - it really is a black art (The documentation/API is really poor and
> there are not many posts about how to do this kind of thing!) - is it
> something I did wrong or is it just the libraries aren't fully
> implemented? I'd really appreciate some help on this!
>
> Thanks,
> Andrew.
>
> currentCompUnit is an AJCompilationUnit
>
> if (currentCompUnit == null)
> return;
>
>
> currentCompUnit.requestOriginalContentMode();
>
> String contents = "";
>
> try {
> contents = currentCompUnit.getBuffer().getContents();
>
> } catch (org.eclipse.jdt.core.JavaModelException e)
> {
> e.printStackTrace();
>
> }
> currentCompUnit.discardOriginalContentMode();
>
> ASTParser parser = ASTParser.newParser(AST.JLS3);
> parser.setCompilerOptions(new HashMap());
> parser.setSource(contents.toCharArray());
> Document doc = new Document(contents);
> CompilationUnit c = (CompilationUnit) parser.createAST(null);
> c.recordModifications();
> AjASTRewrite ajrewrite = AjASTRewrite.create(c.getAST());
> ChangeSomethingVisitor visit = new ChangeSomethingVisitor();
>
> AjNaiveASTFlattener visit2 = new AjNaiveASTFlattener();
> c.accept(visit);
> c.accept(visit2);
> System.err.println(visit2.getResult());
> TextEdit edits =
> ajrewrite.rewriteAST(doc,currentCompUnit.getJavaProject().ge tOptions(true));
>
> System.err.println(edits.getChildrenSize());
> edits.apply(doc);
> System.out.println(doc.get());
>
> Ar 19/03/2008 02:51, Scríobh Martin Görg:
>> On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
>>> While using AJDT - is it possible to change the AST of an AspectJ
>>> file and then rewrite it back to a file. The JDT has a
>>> "recordModification" section that shows you how to do this - but the
>>> AJCompilationUnit doesn't support this? I see in there is a
>>> AjASTRewrite that does something like this in the source file. I
>>> wonder if anyone has any success or knows how to do this.
>>
>> I just asked a related question on the aspectj-dev mailinglist. You can
>> view the thread here:
>> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
>>
>> There is also some information included in the docs module of the AspectJ
>> project (docs/developer/compiler-weaver/index.html). Let me know, if you
>> find something useful.
>>
|
|
|
Re: Aspect Rewrite [message #596794 is a reply to message #71424] |
Thu, 20 March 2008 12:28  |
Eclipse User |
|
|
|
Ok I have had limited success with rewriting. However, I can only ever
get it working with SimpleTypes.
For example when I try duplicating a PointcutDeclaration and rewriting
it with the AjASTRewriter it just comes out as empty. I have tested the
copy of the PointcutDeclaration and the settings are not empty...
AjASTRewrite ajrewrite =....
AspectDeclaration ad = ...
PointcutDeclaration[] pointcuts = ad.getPointcuts();
PointcutDeclaration old = pointcuts[0];
PointcutDeclaration newd = (PointcutDeclartion)
PointcutDeclaration.copySubtree(ast, old);
ajrewrite.replace(old, newd, null);
There is 1 rewrite but the subtree is not copied in the TextEdit when I
save the file.
It is just ";" - an empty semicolon.
Does anyone have any ideas - is the implementation unfinished?
Thanks,
andrew.
Ar 19/03/2008 12:43, Scríobh Andrew Carton:
> Ok I'm reading this
> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. jdt.doc.isv/guide/jdt_api_manip.htm
>
>
> and I think I'm incorrect in using the AjRewriter
>
> However, just going on the CompilerUnit recordModifications / rewrite alone
>
> When I attempt record the modifications and then change the AST and
> attempt a rewrite - I get an error message in the console saying
>
> "Warning: AspectJ type declaration factory class not found on classpath"
>
> I had a peek in the source and this is the code:
>
> public final class AjASTRewriteAnalyzer extends AjASTVisitor {
>
> private static final String AJ_ASTREWRITEANALYZER_FACTORY
> " org.eclipse.ajdt.core.dom.rewrite.AjASTRewriteAnalyzerFactor y ";
>
> private static IASTRewriteAnalyzerFactory astRewriteAnalyzerFactory;
>
> static {
> try{
> astRewriteAnalyzerFactory = (IASTRewriteAnalyzerFactory)
> Class.forName(AJ_ASTREWRITEANALYZER_FACTORY).newInstance();
> } catch (InstantiationException ex) {
> throw new ExceptionInInitializerError(ex.getMessage());
> } catch (IllegalAccessException ex) {
> throw new ExceptionInInitializerError(ex.getMessage());
> } catch (ClassNotFoundException ex) {
> System.err.println("Warning: AspectJ type declaration factory
> class not found on classpath"); //$NON-NLS-1$
> //throw new ExceptionInInitializerError(ex.getMessage());
> }
>
> I've added all the necessary jars in the extension file of my plugin and
> I'm not sure why it isn't picking up this - because it is picking up
> other classes in this jar file.
>
> Thanks,
> Andrew.
>
>
> Ar 19/03/2008 12:14, Scríobh Andrew Carton:
>> Hi Martin + any other people reading this,
>>
>> Yes - I wish to rewrite a small modification of an aspect from it's
>> AST back to it's original file.
>>
>> I have had partial success with visitors etc but the "writing back"
>> still doesn't work.
>>
>> Here is my example code below:
>>
>> Just a note on the code - The ChangeSomethingVisitor extends the
>> AjASTVisitor and modifies something in the AST (specific to the
>> AspectJ class from the AJCompilationUnit).
>>
>> To make sure the modification is changed I use the AjNaiveASTFlattener
>> visitor which just makes a kind of debug information about the aspect.
>> The change is successfully implemented.
>>
>> However, when I attempt to use the AjASTRewrite to modify the tree and
>> get the TextEdits - it appears to be 0. I don't understand why!
>>
>> So I'm stumped really - I read a lot and did a lot to get to this
>> stage - it really is a black art (The documentation/API is really poor
>> and there are not many posts about how to do this kind of thing!) - is
>> it something I did wrong or is it just the libraries aren't fully
>> implemented? I'd really appreciate some help on this!
>>
>> Thanks,
>> Andrew.
>>
>> currentCompUnit is an AJCompilationUnit
>>
>> if (currentCompUnit == null)
>> return;
>>
>> currentCompUnit.requestOriginalContentMode();
>>
>> String contents = "";
>>
>> try {
>> contents = currentCompUnit.getBuffer().getContents();
>>
>> } catch (org.eclipse.jdt.core.JavaModelException e)
>> {
>> e.printStackTrace();
>>
>> }
>> currentCompUnit.discardOriginalContentMode();
>>
>> ASTParser parser = ASTParser.newParser(AST.JLS3);
>> parser.setCompilerOptions(new HashMap());
>> parser.setSource(contents.toCharArray());
>> Document doc = new Document(contents);
>> CompilationUnit c = (CompilationUnit) parser.createAST(null);
>> c.recordModifications();
>> AjASTRewrite ajrewrite = AjASTRewrite.create(c.getAST());
>> ChangeSomethingVisitor visit = new ChangeSomethingVisitor();
>>
>> AjNaiveASTFlattener visit2 = new AjNaiveASTFlattener();
>> c.accept(visit);
>> c.accept(visit2);
>> System.err.println(visit2.getResult());
>> TextEdit edits =
>> ajrewrite.rewriteAST(doc,currentCompUnit.getJavaProject().ge tOptions(true));
>>
>> System.err.println(edits.getChildrenSize());
>> edits.apply(doc);
>> System.out.println(doc.get());
>>
>> Ar 19/03/2008 02:51, Scríobh Martin Görg:
>>> On Tue, 18 Mar 2008 23:15:06 +0000, Andrew Carton wrote:
>>>> While using AJDT - is it possible to change the AST of an AspectJ
>>>> file and then rewrite it back to a file. The JDT has a
>>>> "recordModification" section that shows you how to do this - but the
>>>> AJCompilationUnit doesn't support this? I see in there is a
>>>> AjASTRewrite that does something like this in the source file. I
>>>> wonder if anyone has any success or knows how to do this.
>>>
>>> I just asked a related question on the aspectj-dev mailinglist. You can
>>> view the thread here:
>>> http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg02330.ht ml
>>>
>>> There is also some information included in the docs module of the
>>> AspectJ
>>> project (docs/developer/compiler-weaver/index.html). Let me know, if you
>>> find something useful.
>>>
|
|
| |
Goto Forum:
Current Time: Tue May 13 19:15:47 EDT 2025
Powered by FUDForum. Page generated in 0.03349 seconds
|