Search in sources :

Example 1 with JType

use of com.google.gwt.core.ext.typeinfo.JType in project GwtMobile by dennisjzh.

the class GenUtils method inspectType.

public void inspectType(String typeName, List<JMethod> getters, List<JMethod> hasManyRels, List<JMethod> hasOneRels) throws UnableToCompleteException {
    JClassType classType = getClassType(typeName);
    for (JMethod method : classType.getOverridableMethods()) {
        if (!method.isAbstract()) {
            continue;
        }
        String methodName = method.getName();
        if (methodName.startsWith("get")) {
            // getId() is reserved. 
            String propertyName = methodName.substring(3);
            if (propertyName.equals("Id")) {
                continue;
            }
            JType returnType = method.getReturnType();
            String returnTypeName = returnType.getSimpleSourceName();
            if (returnType.isPrimitive() != null && !returnTypeName.equals("long") || returnTypeName.equals("String") || returnTypeName.equals("Date") || isSubclassOf(returnType, "JSONValue")) {
                getters.add(method);
                continue;
            }
            if (returnTypeName.equals("long")) {
                logger.log(TreeLogger.ERROR, "GWT JSNI does not support 'long' as return type on getter '" + methodName + "'. Use 'double' instead.");
                throw new UnableToCompleteException();
            }
            if (returnTypeName.startsWith("Collection")) {
                hasManyRels.add(method);
                continue;
            }
            if (isSubclassOf(returnType, "Persistable")) {
                hasOneRels.add(method);
                continue;
            }
            logger.log(TreeLogger.ERROR, "Unsupported return type '" + returnTypeName + "' on getter '" + methodName + "'.");
            throw new UnableToCompleteException();
        } else {
        // TODO: check if method is a setter. ignore if so, error if not.
        }
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) JMethod(com.google.gwt.core.ext.typeinfo.JMethod) JType(com.google.gwt.core.ext.typeinfo.JType)

Example 2 with JType

use of com.google.gwt.core.ext.typeinfo.JType 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)2 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)2 JType (com.google.gwt.core.ext.typeinfo.JType)2 JConstructor (com.google.gwt.core.ext.typeinfo.JConstructor)1 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)1 Extension (org.eclipse.che.ide.api.extension.Extension)1 SDK (org.eclipse.che.ide.api.extension.SDK)1