Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » Implement language specific declarations(How create a Declaration type and use the framework to handle it.)
Implement language specific declarations [message #709792] Thu, 04 August 2011 10:04 Go to next message
Kevin KIN-FOO is currently offline Kevin KIN-FOO
Messages: 49
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

Re: Implement language specific declarations [message #714156 is a reply to message #709792] Tue, 09 August 2011 22:53 Go to previous message
Timothy Wall is currently offline Timothy Wall
Messages: 21
Registered: July 2009
Junior Member
If you look at the ruby (and other) implementations, they create a FakeField model element, which may be what you're looking for.

(Look up FakeField and then references to it)

Previous Topic:Custom breakpoint type
Next Topic:Multiple languages per project
Goto Forum:
  


Current Time: Mon Sep 22 18:23:21 GMT 2014

Powered by FUDForum. Page generated in 0.06921 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software