Handle field declaration in parser [message #531830] |
Thu, 06 May 2010 10:06 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Hi,
In the parser I wrote I manage to handle classes and methods declaration, but I am facing some issues handling fields. As instance, for the following code: public ModuleDeclaration getRoot() {
// Defining module
ModuleDeclaration m = new ModuleDeclaration(25);
// Defining class
TypeDeclaration dec = new TypeDeclaration("class", 0, 5, 0, 25);
// Defining method and attribute
Declaration method = new MethodDeclaration("method", 10, 16, 10, 25);
Declaration attibute = new FieldDeclaration("field", 20, 25, 20, 25);
// Place method and attribute in class
Block block = new Block();
block.addStatement(method);
block.addStatement(attibute);
dec.setBody(block);
// Place class in module
m.addStatement(dec);
return m;
}
Checking outline I do have class and method, but no field at all. Am I using the wrong type for fields? Do I need to override FieldDeclartion's getKind() Method? Even reading the code of existing editors I do not see the difference. I'm pretty lost about It.
Regards
[Updated on: Thu, 06 May 2010 10:24] Report message to a moderator
|
|
|
|
Re: Handle field declaration in parser [message #533232 is a reply to message #532660] |
Wed, 12 May 2010 16:02 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Hi,
You we're definitely right, I did extend SourceElementRequestVisitor, without override any method. So I proceeded as you suggested with the following code.public class LuaSourceElementRequestor extends SourceElementRequestVisitor {
public LuaSourceElementRequestor(ISourceElementRequestor requesor) {
super(requesor);
}
public boolean visit(MethodDeclaration method) throws Exception {
return super.visit(method);
}
public boolean visit(FieldDeclaration field) throws Exception {
return true;
}
public boolean endvisit(FieldDeclaration f) throws Exception {
return true;
}
} While running it with the debugger an pertinent AST, the visit method for MethodDeclaration objects is called but not for FieldDeclaration ones. Is there any further interface to implement? What did I missed?
Regards
[Updated on: Wed, 12 May 2010 16:07] Report message to a moderator
|
|
|
Re: Handle field declaration in parser [message #533586 is a reply to message #533232] |
Fri, 14 May 2010 16:08 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
My bad, I thought that the visitor was using the object type for its visit. But you must cast it yourself. So I tried it this way. I hope it's good.
Regards public class LuaSourceElementRequestor extends SourceElementRequestVisitor {
public LuaSourceElementRequestor(ISourceElementRequestor requesor) {
super(requesor);
}
@Override
public boolean visit(Statement s) throws Exception {
if (s instanceof FieldDeclaration) {
return visit((FieldDeclaration) s);
}
return super.visit(s);
}
public boolean visit(FieldDeclaration f) throws Exception {
return true;
}
}
[Updated on: Wed, 19 May 2010 14:39] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02846 seconds