Search in sources :

Example 1 with VarResolver

use of org.eclipse.jdt.internal.corext.template.java.VarResolver 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;
}
Also used : JavaContextType(org.eclipse.jdt.ls.core.internal.corext.template.java.JavaContextType) ContextTypeRegistry(org.eclipse.text.templates.ContextTypeRegistry) VarResolver(org.eclipse.jdt.internal.corext.template.java.VarResolver) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 2 with VarResolver

use of org.eclipse.jdt.internal.corext.template.java.VarResolver in project che by eclipse.

the class ContributionContextTypeRegistry method readRegistry.

/**
	 * Registers all context types contributed for the given registry ID.
	 *
	 * @param registryId the registry ID
	 * @since 3.5
	 */
private void readRegistry(String registryId) {
    Assert.isNotNull(registryId);
    //		IConfigurationElement[] extensions= getTemplateExtensions();
    //
    //		for (int i= 0; i < extensions.length; i++) {
    //			if (extensions[i].getName().equals(REGISTRY)) {
    //				String id= extensions[i].getAttribute(ID);
    //				if (registryId.equals(id)) {
    //					for (int j= 0; j < extensions.length; j++) {
    //						if (extensions[j].getName().equals(CONTEXT_TYPE)) {
    //							if (registryId.equals(extensions[j].getAttribute(REGISTRY_ID)))
    //								addContextType(extensions[j].getAttribute(ID));
    //						}
    //					}
    //					return;
    //				}
    //
    //			}
    //		}
    //
    //		Assert.isTrue(false, "invalid registry id"); //$NON-NLS-1$
    JavaContextType javaType = new JavaContextType();
    javaType.setId("java");
    FieldResolver fieldResolver = new FieldResolver();
    fieldResolver.setType("field");
    javaType.addResolver(fieldResolver);
    LocalVarResolver localVarResolver = new LocalVarResolver();
    localVarResolver.setType("localVar");
    javaType.addResolver(localVarResolver);
    VarResolver varResolver = new VarResolver();
    varResolver.setType("var");
    javaType.addResolver(varResolver);
    NameResolver nameResolver = new NameResolver();
    nameResolver.setType("newName");
    javaType.addResolver(nameResolver);
    TypeResolver typeResolver = new TypeResolver();
    typeResolver.setType("newType");
    javaType.addResolver(typeResolver);
    ElementTypeResolver elementTypeResolver = new ElementTypeResolver();
    elementTypeResolver.setType("elemType");
    javaType.addResolver(elementTypeResolver);
    TypeVariableResolver typeVariableResolver = new TypeVariableResolver();
    typeVariableResolver.setType("argType");
    javaType.addResolver(typeVariableResolver);
    LinkResolver linkResolver = new LinkResolver();
    linkResolver.setType("link");
    javaType.addResolver(linkResolver);
    ImportsResolver importsResolver = new ImportsResolver();
    importsResolver.setType("import");
    javaType.addResolver(importsResolver);
    StaticImportResolver staticImportResolver = new StaticImportResolver();
    staticImportResolver.setType("importStatic");
    javaType.addResolver(staticImportResolver);
    ExceptionVariableNameResolver exceptionVariableNameResolver = new ExceptionVariableNameResolver();
    exceptionVariableNameResolver.setType("exception_variable_name");
    javaType.addResolver(exceptionVariableNameResolver);
    addContextType(javaType);
    JavaContextType statements = new JavaContextType();
    statements.setId("java-statements");
    //		statements.addResolver(new FieldResolver());
    //		statements.addResolver(new LocalVarResolver());
    //		statements.addResolver(new VarResolver());
    //		statements.addResolver(new NameResolver());
    //		statements.addResolver(new TypeResolver());
    //		statements.addResolver(new ElementTypeResolver());
    //		statements.addResolver(new TypeVariableResolver());
    //		statements.addResolver(new LinkResolver());
    //		statements.addResolver(new ImportsResolver());
    //		statements.addResolver(new StaticImportResolver());
    //		statements.addResolver(new ExceptionVariableNameResolver());
    addContextType(statements);
    JavaContextType members = new JavaContextType();
    members.setId("java-members");
    //		members.addResolver(new FieldResolver());
    //		members.addResolver(new LocalVarResolver());
    //		members.addResolver(new VarResolver());
    //		members.addResolver(new NameResolver());
    //		members.addResolver(new TypeResolver());
    //		members.addResolver(new ElementTypeResolver());
    //		members.addResolver(new TypeVariableResolver());
    //		members.addResolver(new LinkResolver());
    //		members.addResolver(new ImportsResolver());
    //		members.addResolver(new StaticImportResolver());
    //		members.addResolver(new ExceptionVariableNameResolver());
    addContextType(members);
    JavaContextType javadoc = new JavaContextType();
    javadoc.setId("javadoc");
    addContextType(javadoc);
}
Also used : LocalVarResolver(org.eclipse.jdt.internal.corext.template.java.LocalVarResolver) JavaContextType(org.eclipse.jdt.internal.corext.template.java.JavaContextType) FieldResolver(org.eclipse.jdt.internal.corext.template.java.FieldResolver) StaticImportResolver(org.eclipse.jdt.internal.corext.template.java.StaticImportResolver) TypeVariableResolver(org.eclipse.jdt.internal.corext.template.java.TypeVariableResolver) LinkResolver(org.eclipse.jdt.internal.corext.template.java.LinkResolver) TypeResolver(org.eclipse.jdt.internal.corext.template.java.TypeResolver) ElementTypeResolver(org.eclipse.jdt.internal.corext.template.java.ElementTypeResolver) ElementTypeResolver(org.eclipse.jdt.internal.corext.template.java.ElementTypeResolver) ExceptionVariableNameResolver(org.eclipse.jdt.internal.corext.template.java.ExceptionVariableNameResolver) ImportsResolver(org.eclipse.jdt.internal.corext.template.java.ImportsResolver) VarResolver(org.eclipse.jdt.internal.corext.template.java.VarResolver) LocalVarResolver(org.eclipse.jdt.internal.corext.template.java.LocalVarResolver) ExceptionVariableNameResolver(org.eclipse.jdt.internal.corext.template.java.ExceptionVariableNameResolver) NameResolver(org.eclipse.jdt.internal.corext.template.java.NameResolver)

Aggregations

VarResolver (org.eclipse.jdt.internal.corext.template.java.VarResolver)2 ElementTypeResolver (org.eclipse.jdt.internal.corext.template.java.ElementTypeResolver)1 ExceptionVariableNameResolver (org.eclipse.jdt.internal.corext.template.java.ExceptionVariableNameResolver)1 FieldResolver (org.eclipse.jdt.internal.corext.template.java.FieldResolver)1 ImportsResolver (org.eclipse.jdt.internal.corext.template.java.ImportsResolver)1 JavaContextType (org.eclipse.jdt.internal.corext.template.java.JavaContextType)1 LinkResolver (org.eclipse.jdt.internal.corext.template.java.LinkResolver)1 LocalVarResolver (org.eclipse.jdt.internal.corext.template.java.LocalVarResolver)1 NameResolver (org.eclipse.jdt.internal.corext.template.java.NameResolver)1 StaticImportResolver (org.eclipse.jdt.internal.corext.template.java.StaticImportResolver)1 TypeResolver (org.eclipse.jdt.internal.corext.template.java.TypeResolver)1 TypeVariableResolver (org.eclipse.jdt.internal.corext.template.java.TypeVariableResolver)1 JavaContextType (org.eclipse.jdt.ls.core.internal.corext.template.java.JavaContextType)1 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)1 ContextTypeRegistry (org.eclipse.text.templates.ContextTypeRegistry)1