use of org.eclipse.text.templates.ContextTypeRegistry in project eclipse.jdt.ls by eclipse.
the class JavaLanguageServerPlugin method getTemplateContextRegistry.
/**
* Returns the template context type registry for the java plug-in.
*
* @return the template context type registry for the java plug-in
*/
public synchronized ContextTypeRegistry getTemplateContextRegistry() {
if (fContextTypeRegistry == null) {
ContextTypeRegistry registry = new ContextTypeRegistry();
JavaContextType statementContextType = new JavaContextType();
statementContextType.setId(JavaContextType.ID_STATEMENTS);
statementContextType.setName(JavaContextType.ID_STATEMENTS);
statementContextType.initializeContextTypeResolvers();
// Todo: Some of the resolvers is defined in the XML of the jdt.ui, now we have to add them manually.
// See: https://github.com/eclipse/eclipse.jdt.ui/blob/cf6c42522ee5a5ea21a34fcfdecf3504d4750a04/org.eclipse.jdt.ui/plugin.xml#L5619-L5625
TemplateVariableResolver resolver = new VarResolver();
resolver.setType("var");
statementContextType.addResolver(resolver);
registry.addContextType(statementContextType);
fContextTypeRegistry = registry;
}
return fContextTypeRegistry;
}
use of org.eclipse.text.templates.ContextTypeRegistry in project eclipse.jdt.ui by eclipse-jdt.
the class ChainCompletionTemplateBuilder method createJavaContext.
private static JavaContext createJavaContext(final JavaContentAssistInvocationContext contentAssistContext) {
final ContextTypeRegistry templateContextRegistry = JavaPlugin.getDefault().getTemplateContextRegistry();
final TemplateContextType templateContextType = templateContextRegistry.getContextType(JavaContextType.ID_ALL);
final CompletionContext ctx = contentAssistContext.getCoreContext();
final JavaContext javaTemplateContext = new JavaContext(templateContextType, contentAssistContext.getDocument(), ctx.getTokenStart(), ctx.getToken().length, contentAssistContext.getCompilationUnit());
javaTemplateContext.setForceEvaluation(true);
return javaTemplateContext;
}
use of org.eclipse.text.templates.ContextTypeRegistry in project eclipse.jdt.ls by eclipse.
the class PreferenceManager method initialize.
/**
* Initialize default preference values of used bundles to match server
* functionality.
*/
public static void initialize() {
// Update JavaCore options
initializeJavaCoreOptions();
// Initialize default preferences
IEclipsePreferences defEclipsePrefs = DefaultScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
defEclipsePrefs.put("org.eclipse.jdt.ui.typefilter.enabled", "");
defEclipsePrefs.put(CodeStyleConfiguration.ORGIMPORTS_IMPORTORDER, String.join(";", Preferences.JAVA_IMPORT_ORDER_DEFAULT));
// $NON-NLS-1$
defEclipsePrefs.put(MembersOrderPreferenceCacheCommon.APPEARANCE_MEMBER_SORT_ORDER, "T,SF,SI,SM,F,I,C,M");
defEclipsePrefs.put(CodeGenerationSettingsConstants.CODEGEN_USE_OVERRIDE_ANNOTATION, Boolean.TRUE.toString());
defEclipsePrefs.put(StubUtility.CODEGEN_KEYWORD_THIS, Boolean.FALSE.toString());
defEclipsePrefs.put(StubUtility.CODEGEN_IS_FOR_GETTERS, Boolean.TRUE.toString());
// $NON-NLS-1$
defEclipsePrefs.put(StubUtility.CODEGEN_EXCEPTION_VAR_NAME, "e");
defEclipsePrefs.put(StubUtility.CODEGEN_ADD_COMMENTS, Boolean.FALSE.toString());
ContextTypeRegistry registry = new ContextTypeRegistry();
// Register standard context types from JDT
CodeTemplateContextType.registerContextTypes(registry);
// Register additional context types
registry.addContextType(new CodeTemplateContextType(CodeTemplatePreferences.CLASSSNIPPET_CONTEXTTYPE));
registry.addContextType(new CodeTemplateContextType(CodeTemplatePreferences.INTERFACESNIPPET_CONTEXTTYPE));
registry.addContextType(new CodeTemplateContextType(CodeTemplatePreferences.RECORDSNIPPET_CONTEXTTYPE));
// These should be upstreamed into CodeTemplateContextType & GlobalVariables
TemplateContextType tmp = registry.getContextType(CodeTemplateContextType.TYPECOMMENT_CONTEXTTYPE);
tmp.addResolver(new CodeTemplatePreferences.Month());
tmp.addResolver(new CodeTemplatePreferences.ShortMonth());
tmp.addResolver(new CodeTemplatePreferences.Day());
tmp.addResolver(new CodeTemplatePreferences.Hour());
tmp.addResolver(new CodeTemplatePreferences.Minute());
JavaManipulation.setCodeTemplateContextRegistry(registry);
// Initialize templates
templates.put(CodeTemplatePreferences.CODETEMPLATE_FIELDCOMMENT, CodeGenerationTemplate.FIELDCOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_METHODCOMMENT, CodeGenerationTemplate.METHODCOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_CONSTRUCTORCOMMENT, CodeGenerationTemplate.CONSTRUCTORCOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_CONSTRUCTORBODY, CodeGenerationTemplate.CONSTRUCTORBODY.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_DELEGATECOMMENT, CodeGenerationTemplate.DELEGATECOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_OVERRIDECOMMENT, CodeGenerationTemplate.OVERRIDECOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_TYPECOMMENT, CodeGenerationTemplate.TYPECOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_GETTERCOMMENT, CodeGenerationTemplate.GETTERCOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_SETTERCOMMENT, CodeGenerationTemplate.SETTERCOMMENT.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_GETTERBODY, CodeGenerationTemplate.GETTERBODY.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_SETTERBODY, CodeGenerationTemplate.SETTERBOY.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_CATCHBODY, CodeGenerationTemplate.CATCHBODY.createTemplate());
templates.put(CodeTemplatePreferences.CODETEMPLATE_METHODBODY, CodeGenerationTemplate.METHODBODY.createTemplate());
reloadTemplateStore();
}
use of org.eclipse.text.templates.ContextTypeRegistry in project eclipse.platform.text by eclipse-platform.
the class TemplateStore method getRegistry.
@Override
protected final org.eclipse.jface.text.templates.ContextTypeRegistry getRegistry() {
ContextTypeRegistry registry = super.getRegistry();
if (registry == null) {
return null;
}
org.eclipse.jface.text.templates.ContextTypeRegistry res = new org.eclipse.jface.text.templates.ContextTypeRegistry();
registry.contextTypes().forEachRemaining(t -> res.addContextType(t));
return res;
}
Aggregations