Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others. 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.eclipse.xtext.ui.editor.templates;
import  org.eclipse.jface.text.templates.ContextTypeRegistry;

Author(s):
Sven Efftinge - Initial contribution and API
Michael Clay
public class XtextTemplateContextTypeRegistry extends ContextTypeRegistry {
	private final ContextTypeIdHelper helper;
		this. = helper;
		registerContextTypes(grammarAccessctxTypeProvider);
	}
	protected void registerContextTypes(IGrammarAccess grammarAccessProvider<XtextTemplateContextTypectxTypeProvider) {
		List<ParserRuleparserRules = GrammarUtil.allParserRules(grammarAccess.getGrammar());
		List<XtextTemplateContextTypeallContextTypes = Lists.newArrayList();
		for (ParserRule parserRule : parserRules) {
			XtextTemplateContextType type = ctxTypeProvider.get();
			type.setName(parserRule.getName());
			type.setId(getId(parserRule));
			allContextTypes.add(type);
			List<Keywordkeywords = EcoreUtil2.getAllContentsOfType(parserRuleKeyword.class);
			for (Keyword keyword : keywords) {
				String value = getId(keyword);
				if (value!=null) {
					type = ctxTypeProvider.get();
					type.setName("Keyword '"+keyword.getValue()+"'");
					type.setId(value);
					allContextTypes.add(type);
				}
			}
		}
		Collections.sort(allContextTypes);
		for (XtextTemplateContextType templateContextTypeallContextTypes) {
			addContextType(templateContextType);
		}
	}
	public String getId(Keyword k) {
		return .getId(k);
	}
	public String getId(ParserRule parserRule) {
		return .getId(parserRule);
	}
		return ;
	}
New to GrepCode? Check out our FAQ X