Search in sources :

Example 1 with Extension

use of org.eclipse.che.ide.api.extension.Extension in project che by eclipse.

the class ExtensionRegistryGenerator method generateDependenciesForExtension.

/**
     * Writes dependency gathering code, like:
     * <p/>
     * Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
     * deps.add(new DependencyDescription("ide.api.ui.menu", ""));
     * deps.add(new DependencyDescription("extension.demo", "1.0.0-alpha"));
     *
     * @param sw
     * @param extension
     * @throws UnableToCompleteException
     */
private void generateDependenciesForExtension(SourceWriter sw, JClassType extension) throws UnableToCompleteException {
    /*      
            Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
            deps.add(new DependencyDescription("ide.api.ui.menu", ""));
      */
    if (extension.getConstructors().length == 0) {
        throw new UnableToCompleteException();
    }
    sw.println("List<DependencyDescription> deps = new ArrayList<>();");
    JConstructor jConstructor = extension.getConstructors()[0];
    JType[] parameterTypes = jConstructor.getParameterTypes();
    for (JType jType : parameterTypes) {
        JClassType argType = jType.isClassOrInterface();
        if (argType != null && (argType.isAnnotationPresent(SDK.class) || argType.isAnnotationPresent(Extension.class))) {
            String id = "";
            String version = "";
            if (argType.isAnnotationPresent(SDK.class)) {
                id = argType.getAnnotation(SDK.class).title();
            } else if (argType.isAnnotationPresent(Extension.class)) {
                id = argType.getQualifiedSourceName();
                version = argType.getAnnotation(Extension.class).version();
            }
            sw.println("deps.add(new DependencyDescription(\"%s\", \"%s\"));", escape(id), escape(version));
        }
    }
}
Also used : Extension(org.eclipse.che.ide.api.extension.Extension) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) JConstructor(com.google.gwt.core.ext.typeinfo.JConstructor) SDK(org.eclipse.che.ide.api.extension.SDK) JType(com.google.gwt.core.ext.typeinfo.JType)

Aggregations

UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 JConstructor (com.google.gwt.core.ext.typeinfo.JConstructor)1 JType (com.google.gwt.core.ext.typeinfo.JType)1 Extension (org.eclipse.che.ide.api.extension.Extension)1 SDK (org.eclipse.che.ide.api.extension.SDK)1