Handle field declaration in parser [message #531830] |
Thu, 06 May 2010 06:06  |
Eclipse User |
|
|
|
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 06:24] by Moderator
|
|
|
|
|
Re: Handle field declaration in parser [message #533586 is a reply to message #533232] |
Fri, 14 May 2010 12:08  |
Eclipse User |
|
|
|
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 10:39] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.26596 seconds