Home » Language IDEs » Java Development Tools (JDT) » Developing a AST parser plugin, but starting as a standalone first(FIRST QUESTION OF MANY.)
Developing a AST parser plugin, but starting as a standalone first [message #1730044] |
Thu, 21 April 2016 07:08 |
Kauan Klein Messages: 8 Registered: April 2016 Location: Brazil, RJ, Petrópolis |
Junior Member |
|
|
this is the first question of what I indent to be be a series of question consolidated as one thread.
Since the tutorials about plugins are either cryptic with very little information usable by a plugin dev beginer (e.g. Incremental builders and Project Natures) or too simple to be useful in anyway (Hello world)I decided to make my AST parser as a standalone.
the purpose of this program is to parse a java project and take into considerations certain annotations (mainly the @Const annotation, whose javadoc I'll provide bellow) and make sure the code enforces those annotations.
That all being said as an introduction to the context of the project, what I'd really like to know is the actual different between using the visitor pattern or the query methods of an AST. Is there any difference between
CompilationUnit#accept(new TypeDeclarationVisitor()
{
void visit (TypeDeclaration decl)
{
}
});
and
TypeDeclaration typeDecl = CompilationUnit#types()
//continue down the AST tree, doing the same for methods, fields, parameters, statements, etc.
(and then progress this way until the leaf nodes of the AST, without ever implementing the visitor pattern)
My goal is, once I have the standalone working, I'll bother about turning it into a plugin (hopefully with the help of someone knowledgful and interested in teaching).
|
|
| |
Re: Developing a AST parser plugin, but starting as a standalone first [message #1730364 is a reply to message #1730091] |
Mon, 25 April 2016 10:13 |
Kauan Klein Messages: 8 Registered: April 2016 Location: Brazil, RJ, Petrópolis |
Junior Member |
|
|
Thank you. I learned a lot since the first question andt he project is no longer a standalone, but a plugin now. I have another question, though:
I want to check if a variable (local, field, parameter, anything) participates in any side of an assignment, but assignments can be complex expressions. rather than a simple a = b; we can have something like this:
SomeType.SomeStaticMethod(someParams).someInstanceMethod(someMoreParams).fieldGetter() = [Another Expression of arbitrary complexity]
How can I know the final Names that are the left and right side of that assignment?
currently, I have this:
@Override
public boolean visit(SimpleName node)
{
IBinding bind = node.resolveBinding();
if(bind.getKind() == IBinding.VARIABLE)
{
IVariableBinding vBind = (IVariableBinding)bind;
if(node.getParent().getNodeType() == ASTNode.ASSIGNMENT)
{
//I know the name participates in a direct assignment like a = b;
//but I don't think this covers an arbitraryly complex expression
}
}
}
(more similar questions may follow).
|
|
| | | |
Goto Forum:
Current Time: Sun Oct 13 07:34:02 GMT 2024
Powered by FUDForum. Page generated in 0.04403 seconds
|