Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] [ajdt structures]


What you have here is a snippet that uses the DOM to manipulate Java code. As explained in my previous post, AspectJ only extends the core compilation AST at the moment, not the DOM, so we don't support programmatic construction of AspectJ types in this way yet. What features is your plugin implementing? There might be a way we can help you to get what you need from the current code base...

(The ASTParser in your snippet below is the org.eclipse.jdt.core.*dom*.ASTParser type - ie. it really is a DOM type, the two trees use identical (unqualified) type names in many places which can be very confusing at times...)

-- Adrian
Adrian_Colyer@xxxxxxxxxx



Alex Vasc <altvex@xxxxxxxxx>
Sent by: aspectj-dev-bounces@xxxxxxxxxxx

27/05/2005 15:29

Please respond to
Alex Vasc <altvex@xxxxxxxxx>; Please respond to
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>

To
aspectj-dev@xxxxxxxxxxx
cc
Subject
[aspectj-dev] [ajdt structures]





Hello everybody,
 I found in eclipse help (JDT Core > Manipulating Java Code) an
example of how to create an AST from scratch. The example is something
like the one below:

//------------------------------------------------
IDocument doc = new Document("import java.util.List;");
ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setSource(doc.get().toCharArray());
CompilationUnit cU = (CompilationUnit) parser.createAST(null);
cU.recordModifications();
AST ast = cU.getAST();
               
PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
packageDeclaration.setName(ast.newSimpleName("exemplo"));
cU.setPackage(packageDeclaration);

TypeDeclaration type = ast.newTypeDeclaration();
type.setInterface(false);
type.setModifiers(Modifier.PUBLIC);
type.setName(ast.newSimpleName("HelloWorld"));
cU.types().add(type);

TextEdit edits = cU.rewrite(doc, null);
edits.apply(doc);
//------------------------------------------------

I´d like to do the same thing with the ajdt structures. Any thoughts?

Thanks!

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

                }
}
//-----------------------

where cu is a CompilationUnit and the .java where the plugin runs is:

//-----------------------
public class HelloChild {
                public void print(int x) {
                                 System.out.println("Hello! I´m a child! My number is: "+ x);                                  
                }
}

aspect World1 {
}
//-----------------------

I did it because the AspectDeclaration extends the TypeDeclaration
from jdt.core.dom. So, I supposed that I could get this element from a
.java file. Is this correct? Any thoughts?! Please, tell me if I´m
doing something stupid! My only itention is to get aspectj elements
from an open file editor.

Best regards!

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


Back to the top