org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void completeVariable_Type(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	if ((mode & NORMAL) != 0) {
		super.completeVariable_Name(model, assignment, context, acceptor);
		TemplateData data = new TemplateData(model);
		if (data.doCreateProposals()) {
			ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language); 
			if (helper != null) {
				String contextTypeId = helper.getId(data.rule);
				ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
				TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
				if (contextType != null) {
					Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class);
					while(resolvers.hasNext()) {
						TemplateVariableResolver resolver = resolvers.next();
						String type = resolver.getType();
						StyledString displayString = new StyledString(type).append(" - " + resolver.getDescription(), StyledString.QUALIFIER_STYLER);
						acceptor.accept(createCompletionProposal(type, displayString, null, context));
					}
				}
			}
		}
	}
}
 
Example #2
Source File: TemplateValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkParameters(Variable variable) {
	Codetemplate template = EcoreUtil2.getContainerOfType(variable, Codetemplate.class);
	Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class);
	if (templates != null && template != null) {
		Grammar language = templates.getLanguage();
		AbstractRule rule = template.getContext();
		ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(language);
		if (helper != null && rule != null && !rule.eIsProxy() && rule instanceof ParserRule) {
			String contextTypeId = helper.getId(rule);
			ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(language);
			TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
			if (contextType != null) {
				Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(),
						TemplateVariableResolver.class);
				String type = variable.getType();
				if (type == null)
					type = variable.getName();
				while (resolvers.hasNext()) {
					final TemplateVariableResolver resolver = resolvers.next();
					if (resolver.getType().equals(type)) {
						IInspectableTemplateVariableResolver inspectableResolver = registry
								.toInspectableResolver(resolver);
						if (inspectableResolver != null) {
							inspectableResolver.validateParameters(variable, this);
						}
					}
				}
			}
		}
	}
}
 
Example #3
Source File: CodetemplatesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void completeNestedCrossReference(CrossReference crossReference, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor, TemplateData data) {
	if (data.doCreateProposals()) {
		ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language);
		if (helper != null) {
			String contextTypeId = helper.getId(data.rule);
			ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
			TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
			TemplateVariableResolver crossRefResolver = getResolver(contextType, "CrossReference");
			if (crossRefResolver != null) {
				Assignment assignment = (Assignment) crossReference.eContainer();
				EReference reference = GrammarUtil.getReference(crossReference);
				if (reference != null) {
					String proposalText = "${" + assignment.getFeature() + ":CrossReference("
							+ reference.getEContainingClass().getName() + "." + reference.getName() + ")}";
					StyledString displayText = new StyledString("${", StyledString.DECORATIONS_STYLER)
							.append(assignment.getFeature())
							.append(":CrossReference(", StyledString.DECORATIONS_STYLER)
							.append(reference.getEContainingClass().getName() + "." + reference.getName(),
									StyledString.COUNTER_STYLER)
							.append(")}", StyledString.DECORATIONS_STYLER)
							.append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
					ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
					if (proposal instanceof ConfigurableCompletionProposal) {
						ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
						configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
						configurable.setSelectionLength(assignment.getFeature().length());
						configurable.setAutoInsertable(false);
						configurable.setSimpleLinkedMode(context.getViewer(), '\t');
						configurable.setPriority(configurable.getPriority() * 2);
					}
					acceptor.accept(proposal);
				}
			}
		}
	}
}
 
Example #4
Source File: LanguageAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void accept(Grammar grammar, 
		Provider<TemplateBodyHighlighter> highlighter, 
		ContextTypeRegistry registry, 
		ContextTypeIdHelper helper,
		Provider<IPartialEditingContentAssistContextFactory> contentAssistContextFactory,
		String primaryFileExtension) {
	this.registry.register(grammar, highlighter, registry, helper, contentAssistContextFactory, primaryFileExtension);
}
 
Example #5
Source File: LanguageRegistry.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
void register(Grammar grammar, 
		Provider<TemplateBodyHighlighter> highlighter, 
		ContextTypeRegistry registry, 
		ContextTypeIdHelper helper,
		Provider<IPartialEditingContentAssistContextFactory> partialContentAssistContextFactory,
		String primaryFileExtension) {
	Language language = new Language();
	language.contextTypeRegistry = registry;
	language.templateBodyHighlighter = highlighter;
	language.helper = helper;
	language.partialContentAssistContextFactory = partialContentAssistContextFactory;
	language.primaryFileExtension = primaryFileExtension;
	registeredLanguages.put(grammar.getName(), language);
}
 
Example #6
Source File: XtextTemplateContextTypeRegistryTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testTypesAreSorted() {
	XtextTemplateContextTypeRegistry registry = new XtextTemplateContextTypeRegistry(grammarAccess, this, new ContextTypeIdHelper());
	String prevName = "";
	Iterator<?> iter = registry.contextTypes();
	assertTrue(iter.hasNext());
	while(iter.hasNext()) {
		XtextTemplateContextType next = (XtextTemplateContextType) iter.next();
		assertTrue(prevName.compareTo(next.getName()) < 0);
		prevName = next.getName();
	}
}
 
Example #7
Source File: ContentAssistCustomizingTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public TestableTemplateProposalProvider(TemplateStore templateStore, ContextTypeRegistry registry, ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}
 
Example #8
Source File: LanguageRegistry.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public ContextTypeIdHelper getContextTypeIdHelper(Grammar grammar) {
	Language language = registeredLanguages.get(grammar.getName());
	if (language == null)
		return null;
	return language.helper;
}
 
Example #9
Source File: XbaseTemplateProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public XbaseTemplateProposalProvider(TemplateStore templateStore, ContextTypeRegistry registry,
		ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}
 
Example #10
Source File: DotTemplateProposalProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public DotTemplateProposalProvider(TemplateStore templateStore,
		ContextTypeRegistry registry, ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}
 
Example #11
Source File: TemplateProposalProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public TemplateProposalProvider(TemplateStore templateStore, ContextTypeRegistry registry,
		ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}
 
Example #12
Source File: CheckTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Inject
public CheckTemplateProposalProvider(final TemplateStore templateStore, final ContextTypeRegistry registry, final ContextTypeIdHelper helper) {
  super(templateStore, registry, helper);
}
 
Example #13
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Inject
public CheckCfgTemplateProposalProvider(final TemplateStore templateStore, final ContextTypeRegistry registry, final ContextTypeIdHelper helper) {
  super(templateStore, registry, helper);
  this.templateStore = templateStore;
}
 
Example #14
Source File: SGenTemplateProposalProvider.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Inject
public SGenTemplateProposalProvider(TemplateStore templateStore, ContextTypeRegistry registry,
		ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
	this.helper = helper;
}
 
Example #15
Source File: GamlTemplateProposalProvider.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Inject
public GamlTemplateProposalProvider(final TemplateStore templateStore, final ContextTypeRegistry registry,
		final ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}
 
Example #16
Source File: SARLTemplateProposalProvider.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Construct the provider.
 *
 * @param templateStore the store of templates.
 * @param registry the template context registry.
 * @param helper the context helper.
 */
@Inject
public SARLTemplateProposalProvider(TemplateStore templateStore, ContextTypeRegistry registry,
		ContextTypeIdHelper helper) {
	super(templateStore, registry, helper);
}