org.eclipse.jface.text.templates.ContextTypeRegistry Java Examples

The following examples show how to use org.eclipse.jface.text.templates.ContextTypeRegistry. 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: GamlEditTemplateDialog.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public GamlEditTemplateDialog(final Shell parent, final TemplatePersistenceData data, final boolean edit,
		final ContextTypeRegistry registry, final TemplatesLanguageConfiguration configuration,
		final IEditedResourceProvider resourceProvider, final String languageName) {
	super(parent);
	this.data = data;
	this.configuration = configuration;
	this.resourceProvider = resourceProvider;
	this.languageName = languageName;

	final String title = edit ? TemplateDialogMessages.EditTemplateDialog_title_edit
			: TemplateDialogMessages.EditTemplateDialog_title_new;
	setTitle(title);

	// this.fTemplate = data.getTemplate();
	// fIsNameModifiable = isNameModifiable;

	final List<String[]> contexts = Lists.newArrayList();
	for (final Iterator<TemplateContextType> it =
			Iterators.filter(registry.contextTypes(), TemplateContextType.class); it.hasNext();) {
		final TemplateContextType type = it.next();
		contexts.add(new String[] { type.getId(), type.getName() });
	}
	// fContextTypes = contexts.toArray(new String[contexts.size()][]);
	// fContextTypeRegistry = registry;

}
 
Example #2
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 #3
Source File: CodeTemplateContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void registerContextTypes(ContextTypeRegistry registry) {
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.CATCHBLOCK_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.METHODBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.CONSTRUCTORBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.GETTERBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.SETTERBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.NEWTYPE_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.CLASSBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.INTERFACEBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.ENUMBODY_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.ANNOTATIONBODY_CONTEXTTYPE));

	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.FILECOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.TYPECOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.FIELDCOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.METHODCOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.CONSTRUCTORCOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.OVERRIDECOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.DELEGATECOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.GETTERCOMMENT_CONTEXTTYPE));
	registry.addContextType(new CodeTemplateContextType(CodeTemplateContextType.SETTERCOMMENT_CONTEXTTYPE));
}
 
Example #4
Source File: EditTemplateDialog.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public EditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable, 
		ContextTypeRegistry registry, TemplatesLanguageConfiguration configuration, 
		IEditedResourceProvider resourceProvider, String languageName) {
	super(parent);
	this.configuration = configuration;
	this.resourceProvider = resourceProvider;
	this.languageName = languageName;

	String title= edit
		? TemplateDialogMessages.EditTemplateDialog_title_edit
		: TemplateDialogMessages.EditTemplateDialog_title_new;
	setTitle(title);

	this.fTemplate= template;
	fIsNameModifiable= isNameModifiable;

	List<String[]> contexts= Lists.newArrayList();
	for (Iterator<TemplateContextType> it= Iterators.filter(registry.contextTypes(), TemplateContextType.class); it.hasNext();) {
		TemplateContextType type= it.next();
		contexts.add(new String[] { type.getId(), type.getName() });
	}
	fContextTypes= contexts.toArray(new String[contexts.size()][]);
	fContextTypeRegistry= registry;
}
 
Example #5
Source File: JavaPlugin.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the template context type registry for the java plug-in.
 *
 * @return the template context type registry for the java plug-in
 * @since 3.0
 */
public synchronized ContextTypeRegistry getTemplateContextRegistry() {
	if (fContextTypeRegistry == null) {
		ContributionContextTypeRegistry registry= new ContributionContextTypeRegistry(JavaUI.ID_CU_EDITOR);

		TemplateContextType all_contextType= registry.getContextType(JavaContextType.ID_ALL);
		((AbstractJavaContextType) all_contextType).initializeContextTypeResolvers();

		registerJavaContext(registry, JavaContextType.ID_MEMBERS, all_contextType);
		registerJavaContext(registry, JavaContextType.ID_STATEMENTS, all_contextType);

		registerJavaContext(registry, SWTContextType.ID_ALL, all_contextType);
		all_contextType= registry.getContextType(SWTContextType.ID_ALL);

		registerJavaContext(registry, SWTContextType.ID_MEMBERS, all_contextType);
		registerJavaContext(registry, SWTContextType.ID_STATEMENTS, all_contextType);

		fContextTypeRegistry= registry;
	}

	return fContextTypeRegistry;
}
 
Example #6
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 #7
Source File: JsonContentAssistProcessor.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    String contextType = getContextTypeId(currentModel, currentPath.toString());
    ContextTypeRegistry registry = getContextTypeRegistry();
    if (registry != null) {
        return registry.getContextType(contextType);
    } else {
        return null;
    }
}
 
Example #8
Source File: KaizenTemplatePreferences.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
public KaizenTemplatePreferences(SourceViewerConfiguration sourceViewerConfiguration,
        IPreferenceStore preferenceStore, TemplateStore templateStore, ContextTypeRegistry contextTypeRegistry) {
    this.sourceViewerConfiguration = sourceViewerConfiguration;
    setPreferenceStore(preferenceStore);
    setTemplateStore(templateStore);
    setContextTypeRegistry(contextTypeRegistry);
}
 
Example #9
Source File: JSDTTypeScriptUIPlugin.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Returns the template context type registry for the java plug-in.
 * 
 * @return the template context type registry for the java plug-in
 * 
 */
public ContextTypeRegistry getTemplateContextRegistry() {
	if (fContextTypeRegistry == null) {
		ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry(CONTEXT_TYPE_REGISTRY_ID);
		fContextTypeRegistry = registry;
	}

	return fContextTypeRegistry;
}
 
Example #10
Source File: SWTTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public SWTTemplateCompletionProposalComputer() {
	ContextTypeRegistry templateContextRegistry= JavaPlugin.getDefault().getTemplateContextRegistry();
	fSWTTemplateEngine= createTemplateEngine(templateContextRegistry, SWTContextType.ID_ALL);
	fSWTMembersTemplateEngine= createTemplateEngine(templateContextRegistry, SWTContextType.ID_MEMBERS);
	fSWTStatementsTemplateEngine= createTemplateEngine(templateContextRegistry, SWTContextType.ID_STATEMENTS);

	JavaCore.addElementChangedListener(new BuildPathChangeListener());
}
 
Example #11
Source File: TemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TemplateCompletionProposalComputer() {
	ContextTypeRegistry templateContextRegistry= JavaPlugin.getDefault().getTemplateContextRegistry();
	fJavaTemplateEngine= createTemplateEngine(templateContextRegistry, JavaContextType.ID_ALL);
	fJavaMembersTemplateEngine= createTemplateEngine(templateContextRegistry, JavaContextType.ID_MEMBERS);
	fJavaStatementsTemplateEngine= createTemplateEngine(templateContextRegistry, JavaContextType.ID_STATEMENTS);
	fJavadocTemplateEngine= createTemplateEngine(templateContextRegistry, JavaDocContextType.ID);
}
 
Example #12
Source File: ConfigurableTemplateStore.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
@Inject
public ConfigurableTemplateStore(final ContextTypeRegistry registry, final IPreferenceStore store, @Named(Constants.LANGUAGE_NAME) final String key, final AbstractUIPlugin plugin) {
  super(registry, store, key + ".templates"); //$NON-NLS-1$
  this.res = getTemplateFileURL(plugin);
  this.preferenceStore = store;
  this.key = key + ".sharedTemplates"; //$NON-NLS-1$
  try {
    load();
  } catch (IOException e) {
    LOG.error(e.getMessage(), e);
  }
}
 
Example #13
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 5 votes vote down vote up
public JFaceCompletionProposalComputer() {
	final ContextTypeRegistry templateContextRegistry = JavaPlugin.getDefault().getTemplateContextRegistry();
	jFaceTemplateEngine = createTemplateEngine(templateContextRegistry, JFaceContextType.ID_ALL);
	jFaceMembersTemplateEngine = createTemplateEngine(templateContextRegistry, JFaceContextType.ID_MEMBERS);
	jFaceStatementsTemplateEngine = createTemplateEngine(templateContextRegistry, JFaceContextType.ID_STATEMENTS);

	JavaCore.addElementChangedListener(new BuildPathChangeListener());
}
 
Example #14
Source File: XtextTemplateStore.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Inject
public XtextTemplateStore(ContextTypeRegistry registry, IPreferenceStore store, @Named(Constants.LANGUAGE_NAME) String key,
		AbstractUIPlugin plugin) {
	super(registry, store, key + ".templates");
	res = getTemplateFileURL(plugin);
	try {
		load();
	} catch (IOException e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #15
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 #16
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 #17
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 #18
Source File: TemplateRegistry.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected ContextTypeRegistry createContributionContextTypeRegistry() {
	final ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
	for(String id : getRegisteredContextTypeIds()) {
		registry.addContextType(id);
	}
	return registry;
}
 
Example #19
Source File: LangUIPlugin.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public ContextTypeRegistry getTemplateContextTypeRegistry() {
	return getTemplateRegistry().getContextTypeRegistry();
}
 
Example #20
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 #21
Source File: TemplateSet.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public TemplateSet(String templateTag, ContextTypeRegistry registry) {
	fTemplateTag= templateTag;
	fRegistry= registry;
}
 
Example #22
Source File: JavaTemplatesPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ContextTypeRegistry getContextTypeRegistry() {
	return TEMPLATE_CONTEXT_REGISTRY;
}
 
Example #23
Source File: CompatibilityTemplateStore.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CompatibilityTemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key, org.eclipse.jdt.internal.corext.template.java.TemplateSet legacySet) {
	super(registry, store, key);
	fLegacySet= legacySet;
}
 
Example #24
Source File: TemplateRegistry.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public ContextTypeRegistry getContextTypeRegistry() {
	if(contextTypeRegistry == null) {
		contextTypeRegistry = createContributionContextTypeRegistry();
	}
	return contextTypeRegistry;
}
 
Example #25
Source File: SWTTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
	TemplateContextType contextType= templateContextRegistry.getContextType(contextTypeId);
	Assert.isNotNull(contextType);
	return new TemplateEngine(contextType);
}
 
Example #26
Source File: LangTemplatePreferencePage.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public LangEditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable,
		ContextTypeRegistry registry) {
	super(parent, template, edit, isNameModifiable, registry);
}
 
Example #27
Source File: JFaceCompletionProposalComputer.java    From saneclipse with Eclipse Public License 1.0 4 votes vote down vote up
private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
	final TemplateContextType contextType = templateContextRegistry.getContextType(contextTypeId);
	Assert.isNotNull(contextType);
	return new TemplateEngine(contextType);
}
 
Example #28
Source File: TemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
	TemplateContextType contextType= templateContextRegistry.getContextType(contextTypeId);
	Assert.isNotNull(contextType);
	return new TemplateEngine(contextType);
}
 
Example #29
Source File: PostfixCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public PostfixCompletionProposalComputer() {
	ContextTypeRegistry templateContextRegistry = JavaPlugin.getDefault().getTemplateContextRegistry();
	postfixCompletionTemplateEngine = createTemplateEngine(templateContextRegistry, JavaStatementPostfixContextType.ID_ALL);
}
 
Example #30
Source File: PostfixCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static PostfixTemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
	TemplateContextType contextType = templateContextRegistry.getContextType(contextTypeId);
	Assert.isNotNull(contextType);
	return new PostfixTemplateEngine(contextType);
}