Implement language specific declarations [message #709792] |
Thu, 04 August 2011 10:04 |
Kevin KIN-FOO Messages: 58 Registered: January 2010 |
Member |
|
|
Hi,
I would like to create a new Declaration type directly from Declaration, without extending TypeDeclaration or FieldDeclaration.
In order to do so, I implemented my own Declaration
public class VariableDeclaration extends Declaration {
public VariableDeclaration(String name, int nameStart, int nameEnd, int declStart, int declEnd) {
this(name, declStart, declEnd);
setNameStart(nameStart);
setNameEnd(nameEnd);
}
public VariableDeclaration(String name, int nameStart, int nameEnd) {
super(nameStart, nameEnd);
setName(name);
setNameStart(nameStart);
setNameEnd(nameEnd);
occurrences = new ArrayList<ASTNode>();
}
public VariableDeclaration(SimpleReference name, int declStart, int declEnd) {
this(name.getName(), name.sourceStart(), name.sourceEnd(), declStart, declEnd);
}
@Override
public int getKind() {
return Declaration.D_VAR_DECL;
}
}
Then, to complete framework understanding of my Declaration, I modified my SourceElementRequestVisitor
public class LuaSourceElementRequestVisitor extends SourceElementRequestVisitor {
public LuaSourceElementRequestVisitor(ISourceElementRequestor requesor) {
super(requesor);
}
@Override
public boolean endvisit(Statement statement) throws Exception {
if (statement instanceof FieldDeclaration) {
getRequestor().exitField(statement.sourceEnd());
}
return super.endvisit(statement);
}
public IElementRequestor getRequestor() {
return this.fRequestor;
}
public boolean visit(FieldDeclaration f) throws Exception {
FieldInfo field = new FieldInfo();
field.declarationStart = f.sourceStart();
field.modifiers = f.getModifiers();
field.name = f.getName();
field.nameSourceStart = f.getNameStart();
field.nameSourceEnd = f.getNameEnd();
getRequestor().enterField(field);
return true;
}
public boolean visit(VariableDeclaration variable) throws Exception {
FieldInfo field = new FieldInfo();
field.declarationStart = variable.sourceStart();
field.modifiers = variable.getModifiers();
field.name = variable.getName();
field.nameSourceStart = variable.getNameStart();
field.nameSourceEnd = variable.getNameEnd();
getRequestor().enterField(field);
getRequestor().exitField(variable.sourceEnd());
return true;
}
@Override
public boolean visit(Statement s) throws Exception {
if (s instanceof FieldDeclaration) {
return visit((FieldDeclaration) s);
} else if (s instanceof VariableDeclaration) {
return visit((VariableDeclaration) s);
}
return super.visit(s);
}
}
I think I'm doing something wrong. Because using this i get a partial outline. Furthermore I would like to be able to distinct this kind of variable while processing code completion. In ScriptCompletionEngine:
switch (element.getElementType()) {
case IModelElement.METHOD:
proposal = this.createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition);
IMethod method = (IMethod) element;
proposal.setParameterNames(method.getParameterNames());
proposal.setFlags(method.getFlags());
break;
case IModelElement.FIELD:
proposal = this.createProposal(CompletionProposal.FIELD_REF, this.actualCompletionPosition);
proposal.setFlags(((IField) element).getFlags());
break;
case IModelElement.TYPE:
proposal = this.createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
proposal.setFlags(((IType) element).getFlags());
break;
case IModelElement.LOCAL_VARIABLE: // <-- How can I get there?
proposal = this.createProposal(CompletionProposal.LOCAL_VARIABLE_REF, this.actualCompletionPosition);
proposal.setFlags(Flags.AccPrivate);
break;
default:
// Lower relevance for key words
relevance = 1;
proposal = this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition);
proposal.setFlags(Flags.AccDefault);
break;
}
Any advice on processor or visitor would be nice.
Regards
[Updated on: Thu, 04 August 2011 10:06] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.05418 seconds