Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.eclipse.xtext.ui.editor.templates;
 
 import java.util.List;
 
 import  org.eclipse.jface.text.templates.TemplateContext;
import  org.eclipse.jface.text.templates.TemplateVariable;
import  org.eclipse.jface.text.templates.TemplateVariableResolver;
Provides a common base class for xtext TemplateVariableResolver.

Author(s):
Michael Clay - Initial contribution and API
public abstract class AbstractTemplateVariableResolver extends
		TemplateVariableResolver {
	@Inject(optional = true)
		super();
	}
	public AbstractTemplateVariableResolver(String typeString description) {
		super(typedescription);
	}
	public void resolve(TemplateVariable variable, TemplateContext templateContext) {
		XtextTemplateContext castedContext = (XtextTemplateContexttemplateContext;
		List<Stringnames = resolveValues(variablecastedContext);
		String[] bindings = names.toArray(new String[names.size()]);
		if (bindings.length != 0)
			variable.setValues(bindings);
		if (bindings.length > 1)
			variable.setUnambiguous(false);
		else
			variable.setUnambiguous(isUnambiguous(castedContext));
		variable.setResolved(true);
	}
	protected EClassifier getEClassifierForGrammar(String fqnClassName,
			Grammar grammar) {
		int dotIndex = fqnClassName.indexOf('.');
		String packageName = null;
		String className = fqnClassName;
		if (dotIndex > 0) {
			packageName = fqnClassName.substring(0, dotIndex);
			className = fqnClassName.substring(dotIndex + 1);
		}
		List<AbstractMetamodelDeclarationallMetamodelDeclarations = GrammarUtil
		for (AbstractMetamodelDeclaration decl : allMetamodelDeclarations) {
			EPackage pack = decl.getEPackage();
			if (packageName == null || pack.getName().equals(packageName)) {
				EClassifier eClassifier = pack.getEClassifier(className);
				if (eClassifier != null) {
					return eClassifier;
				}
			}
		}
		return null;
	}
	protected Grammar getGrammar(XtextTemplateContext xtextTemplateContext) {
		EObject grammarElement = xtextTemplateContext.getContentAssistContext()
		if (grammarElement == null &&  != null)
		return (Grammar) EcoreUtil.getRootContainer(grammarElement);
	}
	public abstract List<StringresolveValues(TemplateVariable variable,
			XtextTemplateContext xtextTemplateContext);
New to GrepCode? Check out our FAQ X