/******************************************************************************* * Copyright (c) 2007, 2008 Edgar Espina. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * *******************************************************************************/ package org.deved.antlride.internal.ui.text.completion; import org.deved.antlride.core.AntlrNature; import org.eclipse.dltk.core.CompletionProposal; import org.eclipse.dltk.core.IScriptProject; import org.eclipse.dltk.core.ISourceModule; import org.eclipse.dltk.ui.text.completion.IScriptCompletionProposal; import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext; import org.eclipse.swt.graphics.Image; public class AntlrCompletionProposalCollector extends ScriptCompletionProposalCollector { protected final static char[] VAR_TRIGGER = new char[] { '\t', ' ', '=', ';', '.' }; protected char[] getVarTrigger() { return VAR_TRIGGER; } public AntlrCompletionProposalCollector(ISourceModule sourceModule) { super(sourceModule); } public ScriptContentAssistInvocationContext getContentAssistInvocationContext() { return getInvocationContext(); } @Override protected IScriptCompletionProposal createScriptCompletionProposal( CompletionProposal proposal) { return super.createScriptCompletionProposal(proposal); } // Invocation context protected ScriptContentAssistInvocationContext createScriptContentAssistInvocationContext( ISourceModule sourceModule) { return new AntlrContentAssistInvocationContext(sourceModule); } // Specific proposals creation. May be use factory? protected ScriptCompletionProposal createScriptCompletionProposal( String completion, int replaceStart, int length, Image image, String displayString, int i) { return new AntlrCompletionProposal(completion, replaceStart, length, image, displayString, i); } protected ScriptCompletionProposal createScriptCompletionProposal( String completion, int replaceStart, int length, Image image, String displayString, int i, boolean isInDoc) { return new AntlrCompletionProposal(completion, replaceStart, length, image, displayString, i, isInDoc); } protected ScriptCompletionProposal createOverrideCompletionProposal( IScriptProject scriptProject, ISourceModule compilationUnit, String name, String[] paramTypes, int start, int length, String displayName, String completionProposal) { return new AntlrOverrideCompletionProposal(scriptProject, compilationUnit, name, paramTypes, start, length, displayName, completionProposal); } protected IScriptCompletionProposal createKeywordProposal( CompletionProposal proposal) { String completion = String.valueOf(proposal.getCompletion()); int start = proposal.getReplaceStart(); int length = getLength(proposal); String label = getLabelProvider().createSimpleLabel(proposal); Image img = getImage(getLabelProvider().createImageDescriptor(proposal)); int relevance = computeRelevance(proposal); return createScriptCompletionProposal(completion, start, length, img, label, relevance); } @Override protected String getNatureId() { return AntlrNature.NATURE_ID; } }