Search in sources :

Example 6 with JClassType

use of com.google.gwt.core.ext.typeinfo.JClassType in project gwt-test-utils by gwt-test-utils.

the class RewriteSingleJsoImplDispatches method computeAllInterfaces.

private Set<String> computeAllInterfaces(String intfName) {
    Set<String> toReturn = intfNamesToAllInterfaces.get(intfName);
    if (toReturn != null) {
        return toReturn;
    }
    toReturn = Sets.create();
    List<JClassType> q = new LinkedList<JClassType>();
    JClassType intf = typeOracle.findType(intfName.replace('/', '.').replace('$', '.'));
    /*
       * If the interface's compilation unit wasn't retained due to an error, then it won't be
       * available in the typeOracle for us to rewrite
       */
    if (intf != null) {
        q.add(intf);
    }
    while (!q.isEmpty()) {
        intf = q.remove(0);
        String resourceName = getResourceName(intf);
        if (!toReturn.contains(resourceName)) {
            toReturn = Sets.add(toReturn, resourceName);
            Collections.addAll(q, intf.getImplementedInterfaces());
        }
    }
    intfNamesToAllInterfaces = Maps.put(intfNamesToAllInterfaces, intfName, toReturn);
    return toReturn;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType)

Example 7 with JClassType

use of com.google.gwt.core.ext.typeinfo.JClassType in project gerrit by GerritCodeReview.

the class PluginGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();
    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);
    // Ensure that the requested type exists
    if (sourceType == null) {
        logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
        throw new UnableToCompleteException();
    }
    // Make sure the Gadget type is correctly defined
    validateType(logger, sourceType);
    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "PluginImpl";
    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(), generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.setSuperclass(typeName);
    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);
    // If an implementation already exists, we don't need to do any work
    if (out != null) {
        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);
        sw.commit(logger);
    }
    return f.getCreatedClassName();
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) GWT(com.google.gwt.core.client.GWT) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 8 with JClassType

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

the class GenUtils method isSubclassOf.

public boolean isSubclassOf(JType type, String superClass) {
    JClassType classType = type.isInterface();
    if (classType == null) {
        classType = type.isClass();
    }
    if (classType == null) {
        return false;
    }
    Set<? extends JClassType> superTypes = classType.getFlattenedSupertypeHierarchy();
    for (JClassType superType : superTypes) {
        if (superType.getSimpleSourceName().equals(superClass)) {
            return true;
        }
    }
    return false;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType)

Example 9 with JClassType

use of com.google.gwt.core.ext.typeinfo.JClassType 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 10 with JClassType

use of com.google.gwt.core.ext.typeinfo.JClassType in project gwtphonegap by dankurka.

the class PhoneGapLogValueGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    int value = 100;
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
        } else {
            String stringValue = values.get(0);
            try {
                value = Integer.parseInt(stringValue);
            } catch (Exception e) {
                logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
            }
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
    }
    JClassType classType = null;
    try {
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }
    String packageName = classType.getPackage().getName();
    String simpleName = classType.getSimpleSourceName() + "_" + value;
    String fullName = packageName + "." + simpleName;
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.addImplementedInterface(typeName);
    composer.addImport(typeName);
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return fullName;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.println("public int getMaxEntries() {");
    writer.println("return " + value + ";");
    writer.println("}");
    writer.commit(logger);
    return fullName;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Aggregations

JClassType (com.google.gwt.core.ext.typeinfo.JClassType)14 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)7 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)6 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)4 SourceWriter (com.google.gwt.user.rebind.SourceWriter)4 PrintWriter (java.io.PrintWriter)4 GWT (com.google.gwt.core.client.GWT)3 ArrayList (java.util.ArrayList)3 JField (com.google.gwt.core.ext.typeinfo.JField)2 JType (com.google.gwt.core.ext.typeinfo.JType)2 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)2 Extension (org.eclipse.che.ide.api.extension.Extension)2 BadPropertyValueException (com.google.gwt.core.ext.BadPropertyValueException)1 ConfigurationProperty (com.google.gwt.core.ext.ConfigurationProperty)1 PropertyOracle (com.google.gwt.core.ext.PropertyOracle)1 JConstructor (com.google.gwt.core.ext.typeinfo.JConstructor)1 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)1 Resource (com.google.gwt.dev.resource.Resource)1 ClientBundleWithLookup (com.google.gwt.resources.client.ClientBundleWithLookup)1 DataResource (com.google.gwt.resources.client.DataResource)1