Example usage for com.google.gwt.core.ext.typeinfo JClassType isAbstract

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType isAbstract

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType isAbstract.

Prototype

boolean isAbstract();

Source Link

Usage

From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java

License:Apache License

/**
 * Since overridden parent annotations are potentially useful, we don't use
 * standard overriding behaviour//  w  w  w .  j  av  a 2 s  .  c o  m
 *
 * @throws ClassNotFoundException
 */
private Map<JClassType, Set<RegistryLocation>> getRegistryAnnotations(TypeOracle typeOracle)
        throws ClassNotFoundException {
    HashMap<JClassType, Set<RegistryLocation>> results = new HashMap<JClassType, Set<RegistryLocation>>();
    JClassType[] types = typeOracle.getTypes();
    for (JClassType jct : types) {
        if (jct.getName().matches("(?i).*AlcinaBeanSerializerC.*")) {
            int debug = 3;
        }
        if ((jct.isAnnotationPresent(RegistryLocation.class)
                || jct.isAnnotationPresent(RegistryLocations.class)) && !jct.isAbstract()) {
            Set<RegistryLocation> rls = getClassAnnotations(jct, RegistryLocation.class, true);
            Set<RegistryLocations> rlsSet = getClassAnnotations(jct, RegistryLocations.class, true);
            for (RegistryLocations rlcs : rlsSet) {
                for (RegistryLocation rl : rlcs.value()) {
                    rls.add(rl);
                }
            }
            rls = new LinkedHashSet<RegistryLocation>(rls);
            CollectionFilters.filterInPlace(rls, CLIENT_VISIBLE_ANNOTATION_FILTER);
            rls = Registry.filterForRegistryPointUniqueness(rls);
            if (!rls.isEmpty() && !ignore(jct)) {
                results.put(jct, rls);
            }
        }
    }
    return results;
}

From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java

License:Apache License

private boolean ignore(JClassType jClassType, ReflectionAction reflectionAction) {
    return (jClassType.isAbstract() && jClassType.isEnum() == null) || (jClassType.isInterface() != null)
            || !jClassType.isPublic() || filter.omitForModule(jClassType, reflectionAction);
}

From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private String createTypeGenerator(JType t) {
    buffer.setLength(0);/*  w  w  w .  j  a va  2  s  .c o  m*/
    String varName = "t";
    if (t instanceof JPrimitiveType)
        varName = "p";
    int id = nextId();
    typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id);
    pb("Type " + varName + " = new Type();");
    pb(varName + ".name = \"" + t.getErasedType().getQualifiedSourceName() + "\";");
    pb(varName + ".id = " + id + ";");
    pb(varName + ".clazz = " + t.getErasedType().getQualifiedSourceName() + ".class;");
    if (t instanceof JClassType) {
        JClassType c = (JClassType) t;
        if (isVisible(c.getSuperclass()))
            pb(varName + ".superClass = " + c.getSuperclass().getErasedType().getQualifiedSourceName()
                    + ".class;");
        if (c.getFlattenedSupertypeHierarchy() != null) {
            pb("Set<Class> " + varName + "Assignables = new HashSet<Class>();");
            for (JType i : c.getFlattenedSupertypeHierarchy()) {
                if (!isVisible(i))
                    continue;
                pb(varName + "Assignables.add(" + i.getErasedType().getQualifiedSourceName() + ".class);");
            }
            pb(varName + ".assignables = " + varName + "Assignables;");
        }
        if (c.isInterface() != null)
            pb(varName + ".isInterface = true;");
        if (c.isEnum() != null)
            pb(varName + ".isEnum = true;");
        if (c.isArray() != null)
            pb(varName + ".isArray = true;");
        if (c.isMemberType())
            pb(varName + ".isMemberClass = true;");
        pb(varName + ".isStatic = " + c.isStatic() + ";");
        pb(varName + ".isAbstract = " + c.isAbstract() + ";");

        if (c.getFields() != null) {
            pb(varName + ".fields = new Field[] {");
            for (JField f : c.getFields()) {
                String enclosingType = getType(c);
                String fieldType = getType(f.getType());
                int setter = nextId();
                int getter = nextId();
                String elementType = getElementTypes(f);
                String annotations = getAnnotations(f.getDeclaredAnnotations());

                pb("new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", " + f.isFinal()
                        + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", " + f.isProtected() + ", "
                        + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient() + ", " + f.isVolatile()
                        + ", " + getter + ", " + setter + ", " + elementType + ", " + annotations + "), ");

                SetterGetterStub stub = new SetterGetterStub();
                stub.name = f.getName();
                stub.enclosingType = enclosingType;
                stub.type = fieldType;
                stub.isStatic = f.isStatic();
                stub.isFinal = f.isFinal();
                if (enclosingType != null && fieldType != null) {
                    stub.getter = getter;
                    stub.setter = setter;
                }
                setterGetterStubs.add(stub);
            }
            pb("};");
        }

        printMethods(c, varName, "Method", c.getMethods());
        if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) {
            printMethods(c, varName, "Constructor", c.getConstructors());
        } else {
            logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated");
        }

        if (c.isArray() != null) {
            pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";");
        }
        if (c.isEnum() != null) {
            JEnumConstant[] enumConstants = c.isEnum().getEnumConstants();
            if (enumConstants != null) {
                pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];");
                for (int i = 0; i < enumConstants.length; i++) {
                    pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName()
                            + "." + enumConstants[i].getName() + ";");
                }
            }
        }

        Annotation[] annotations = c.getDeclaredAnnotations();
        if (annotations != null && annotations.length > 0) {
            pb(varName + ".annotations = " + getAnnotations(annotations) + ";");
        }
    } else if (t.isAnnotation() != null) {
        pb(varName + ".isAnnotation = true;");
    } else {
        pb(varName + ".isPrimitive = true;");
    }

    pb("types.put(\"" + t.getErasedType().getQualifiedSourceName() + "\", " + varName + ");");
    return buffer.toString();
}

From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java

License:Apache License

private String createTypeGenerator(JType t) {
    buffer.setLength(0);//  www.j  av  a2 s  . c o m
    int id = nextTypeId++;
    typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id);
    JClassType c = t.isClass();

    String name = t.getErasedType().getQualifiedSourceName();
    String superClass = null;
    if (c != null && (isVisible(c.getSuperclass())))
        superClass = c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class";
    String assignables = null;
    String interfaces = null;

    if (c != null && c.getFlattenedSupertypeHierarchy() != null) {
        assignables = "new HashSet<Class>(Arrays.asList(";
        boolean used = false;
        for (JType i : c.getFlattenedSupertypeHierarchy()) {
            if (!isVisible(i) || i.equals(t)
                    || "java.lang.Object".equals(i.getErasedType().getQualifiedSourceName()))
                continue;
            if (used)
                assignables += ", ";
            assignables += i.getErasedType().getQualifiedSourceName() + ".class";
            used = true;
        }
        if (used)
            assignables += "))";
        else
            assignables = null;
    }

    if (c == null) {
        // if it's not a class, it may be an interface instead
        c = t.isInterface();
    }

    if (c != null && c.getImplementedInterfaces() != null) {
        interfaces = "new HashSet<Class>(Arrays.asList(";
        boolean used = false;
        for (JType i : c.getImplementedInterfaces()) {
            if (!isVisible(i) || i.equals(t))
                continue;
            if (used)
                interfaces += ", ";
            interfaces += i.getErasedType().getQualifiedSourceName() + ".class";
            used = true;
        }
        if (used)
            interfaces += "))";
        else
            interfaces = null;
    }

    String varName = "c" + id;
    pb("private static Type " + varName + ";");
    pb("private static Type " + varName + "() {");
    pb("if(" + varName + "!=null) return " + varName + ";");
    pb(varName + " = new Type(\"" + name + "\", " + id + ", " + name + ".class, " + superClass + ", "
            + assignables + ", " + interfaces + ");");

    if (c != null) {
        if (c.isEnum() != null)
            pb(varName + ".isEnum = true;");
        if (c.isArray() != null)
            pb(varName + ".isArray = true;");
        if (c.isMemberType())
            pb(varName + ".isMemberClass = true;");
        if (c.isInterface() != null) {
            pb(varName + ".isInterface = true;");
        } else {
            pb(varName + ".isStatic = " + c.isStatic() + ";");
            pb(varName + ".isAbstract = " + c.isAbstract() + ";");
        }

        if (c.getFields() != null && c.getFields().length > 0) {
            pb(varName + ".fields = new Field[] {");
            for (JField f : c.getFields()) {
                String enclosingType = getType(c);
                String fieldType = getType(f.getType());
                int setterGetter = nextSetterGetterId++;
                String elementType = getElementTypes(f);
                String annotations = getAnnotations(f.getDeclaredAnnotations());

                pb("    new Field(\"" + f.getName() + "\", " + enclosingType + ", " + fieldType + ", "
                        + f.isFinal() + ", " + f.isDefaultAccess() + ", " + f.isPrivate() + ", "
                        + f.isProtected() + ", " + f.isPublic() + ", " + f.isStatic() + ", " + f.isTransient()
                        + ", " + f.isVolatile() + ", " + setterGetter + ", " + setterGetter + ", " + elementType
                        + ", " + annotations + "), ");

                SetterGetterStub stub = new SetterGetterStub();
                stub.name = f.getName();
                stub.enclosingType = enclosingType;
                stub.type = fieldType;
                stub.isStatic = f.isStatic();
                stub.isFinal = f.isFinal();
                if (enclosingType != null && fieldType != null) {
                    stub.getter = setterGetter;
                    stub.setter = setterGetter;
                }
                setterGetterStubs.add(stub);
            }
            pb("};");
        }

        createTypeInvokables(c, varName, "Method", c.getMethods());
        if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) {
            createTypeInvokables(c, varName, "Constructor", c.getConstructors());
        } else {
            logger.log(Type.INFO, c.getName() + " can't be instantiated. Constructors not generated");
        }

        if (c.isArray() != null) {
            pb(varName + ".componentType = " + getType(c.isArray().getComponentType()) + ";");
        }
        if (c.isEnum() != null) {
            JEnumConstant[] enumConstants = c.isEnum().getEnumConstants();
            if (enumConstants != null) {
                pb(varName + ".enumConstants = new Object[" + enumConstants.length + "];");
                for (int i = 0; i < enumConstants.length; i++) {
                    pb(varName + ".enumConstants[" + i + "] = " + c.getErasedType().getQualifiedSourceName()
                            + "." + enumConstants[i].getName() + ";");
                }
            }
        }

        Annotation[] annotations = c.getDeclaredAnnotations();
        if (annotations != null && annotations.length > 0) {
            pb(varName + ".annotations = " + getAnnotations(annotations) + ";");
        }
    } else if (t.isAnnotation() != null) {
        pb(varName + ".isAnnotation = true;");
    } else {
        pb(varName + ".isPrimitive = true;");
    }

    pb("return " + varName + ";");
    pb("}");
    return buffer.toString();
}

From source file:com.github.nmorel.gwtjackson.rebind.bean.BeanProcessor.java

License:Apache License

/**
 * Look for the method to create a new instance of the bean. If none are found or the bean is abstract or an interface, we considered it
 * as non instantiable.//www.  j a v  a 2s. c om
 *
 * @param typeOracle the oracle
 * @param logger logger
 * @param beanType type to look for constructor
 * @param builder current bean builder
 */
private static void determineInstanceCreator(RebindConfiguration configuration, JacksonTypeOracle typeOracle,
        TreeLogger logger, JClassType beanType, BeanInfoBuilder builder) {
    if (isObjectOrSerializable(beanType)) {
        return;
    }

    Optional<JClassType> mixinClass = configuration.getMixInAnnotations(beanType);

    List<JClassType> accessors = new ArrayList<JClassType>();
    if (mixinClass.isPresent()) {
        accessors.add(mixinClass.get());
    }
    accessors.add(beanType);

    // Look for a builder class
    Optional<Annotation> jsonDeserialize = CreatorUtils
            .getAnnotation("com.fasterxml.jackson.databind.annotation.JsonDeserialize", accessors);
    if (jsonDeserialize.isPresent()) {
        Optional<JClassType> builderClass = typeOracle.getClassFromJsonDeserializeAnnotation(logger,
                jsonDeserialize.get(), "builder");
        if (builderClass.isPresent()) {
            builder.setBuilder(builderClass.get());
            return;
        }
    }

    // we search for @JsonCreator annotation
    JConstructor creatorDefaultConstructor = null;
    JConstructor creatorConstructor = null;

    // we keep the list containing the mixin creator and the real creator
    List<? extends JAbstractMethod> creators = Collections.emptyList();

    if (null == beanType.isInterface() && !beanType.isAbstract()) {
        for (JConstructor constructor : beanType.getConstructors()) {
            if (constructor.getParameters().length == 0) {
                creatorDefaultConstructor = constructor;
                continue;
            }

            // A constructor is considered as a creator if
            // - he is annotated with JsonCreator and
            //   * all its parameters are annotated with JsonProperty
            //   * or it has only one parameter
            // - or all its parameters are annotated with JsonProperty

            List<JConstructor> constructors = new ArrayList<JConstructor>();
            if (mixinClass.isPresent() && null == mixinClass.get().isInterface()) {
                JConstructor mixinConstructor = mixinClass.get()
                        .findConstructor(constructor.getParameterTypes());
                if (null != mixinConstructor) {
                    constructors.add(mixinConstructor);
                }
            }
            constructors.add(constructor);

            Optional<JsonIgnore> jsonIgnore = getAnnotation(JsonIgnore.class, constructors);
            if (jsonIgnore.isPresent() && jsonIgnore.get().value()) {
                continue;
            }

            boolean isAllParametersAnnotatedWithJsonProperty = isAllParametersAnnotatedWith(constructors.get(0),
                    JsonProperty.class);
            if ((isAnnotationPresent(JsonCreator.class, constructors)
                    && ((isAllParametersAnnotatedWithJsonProperty)
                            || (constructor.getParameters().length == 1)))
                    || isAllParametersAnnotatedWithJsonProperty) {
                creatorConstructor = constructor;
                creators = constructors;
                break;
            }
        }
    }

    JMethod creatorFactory = null;
    if (null == creatorConstructor) {
        // searching for factory method
        for (JMethod method : beanType.getMethods()) {
            if (method.isStatic()) {

                List<JMethod> methods = new ArrayList<JMethod>();
                if (mixinClass.isPresent() && null == mixinClass.get().isInterface()) {
                    JMethod mixinMethod = mixinClass.get().findMethod(method.getName(),
                            method.getParameterTypes());
                    if (null != mixinMethod && mixinMethod.isStatic()) {
                        methods.add(mixinMethod);
                    }
                }
                methods.add(method);

                Optional<JsonIgnore> jsonIgnore = getAnnotation(JsonIgnore.class, methods);
                if (jsonIgnore.isPresent() && jsonIgnore.get().value()) {
                    continue;
                }

                if (isAnnotationPresent(JsonCreator.class, methods) && (method.getParameters().length == 1
                        || isAllParametersAnnotatedWith(methods.get(0), JsonProperty.class))) {
                    creatorFactory = method;
                    creators = methods;
                    break;
                }
            }
        }
    }

    final Optional<JAbstractMethod> creatorMethod;
    boolean defaultConstructor = false;

    if (null != creatorConstructor) {
        creatorMethod = Optional.<JAbstractMethod>of(creatorConstructor);
    } else if (null != creatorFactory) {
        creatorMethod = Optional.<JAbstractMethod>of(creatorFactory);
    } else if (null != creatorDefaultConstructor) {
        defaultConstructor = true;
        creatorMethod = Optional.<JAbstractMethod>of(creatorDefaultConstructor);
    } else {
        creatorMethod = Optional.absent();
    }

    builder.setCreatorMethod(creatorMethod);
    builder.setCreatorDefaultConstructor(defaultConstructor);

    if (creatorMethod.isPresent() && !defaultConstructor) {
        if (creatorMethod.get().getParameters().length == 1
                && !isAllParametersAnnotatedWith(creators.get(0), JsonProperty.class)) {
            // delegation constructor
            builder.setCreatorDelegation(true);
            builder.setCreatorParameters(ImmutableMap.of(BeanJsonDeserializerCreator.DELEGATION_PARAM_NAME,
                    creatorMethod.get().getParameters()[0]));
        } else {
            // we want the property name define in the mixin and the parameter defined in the real creator method
            ImmutableMap.Builder<String, JParameter> creatorParameters = ImmutableMap.builder();
            for (int i = 0; i < creatorMethod.get().getParameters().length; i++) {
                creatorParameters.put(
                        creators.get(0).getParameters()[i].getAnnotation(JsonProperty.class).value(),
                        creators.get(creators.size() - 1).getParameters()[i]);
            }
            builder.setCreatorParameters(creatorParameters.build());
        }
    }
}

From source file:com.github.nmorel.gwtjackson.rebind.CreatorUtils.java

License:Apache License

public static ImmutableList<JClassType> filterSubtypesForDeserialization(TreeLogger logger,
        RebindConfiguration configuration, JClassType type) {
    boolean filterOnlySupportedType = isObjectOrSerializable(type);

    ImmutableList.Builder<JClassType> builder = ImmutableList.builder();
    if (type.getSubtypes().length > 0) {
        for (JClassType subtype : type.getSubtypes()) {
            if ((null == subtype.isInterface() && !subtype.isAbstract()
                    && (!subtype.isMemberType() || subtype.isStatic())) && null == subtype.isAnnotation()
                    && subtype.isPublic()
                    && (!filterOnlySupportedType || (configuration.isTypeSupportedForDeserialization(logger,
                            subtype)/*  w  ww.  ja  va2s. co m*/
                            // EnumSet and EnumMap are not supported in subtype deserialization because we can't know the enum to use.
                            && !EnumSet.class.getCanonicalName().equals(subtype.getQualifiedSourceName())
                            && !EnumMap.class.getCanonicalName().equals(subtype.getQualifiedSourceName())))
                    && !findFirstEncounteredAnnotationsOnAllHierarchy(configuration,
                            subtype.isClassOrInterface(), JsonIgnoreType.class, Optional.of(type))
                                    .isPresent()) {
                builder.add(subtype);
            }
        }
    }
    return builder.build();
}

From source file:com.google.web.bindery.event.gwt.rebind.binder.EventBinderWriter.java

License:Apache License

private boolean isAConcreteGenericEvent(JClassType param) {
    return param != null && !param.isAbstract() && param.isAssignableTo(genericEventType);
}

From source file:com.kk_electronic.gwt.rebind.FlexInjectorGenerator.java

License:Open Source License

private Map<String, Vector<JClassType>> getClasses() throws UnableToCompleteException {
    if (this.groups != null) {
        return this.groups;
    }/*from w  w  w .j  a  v  a2 s . c om*/

    this.groups = new HashMap<String, Vector<JClassType>>();

    try {
        typeOracle.getType(ConstructFromLiteral.class.getCanonicalName());
    } catch (NotFoundException error) {
        logger.log(TreeLogger.ERROR, "Can't find marker interface", error);
        throw new UnableToCompleteException();
    }

    for (JClassType j : typeOracle.getTypes()) {
        ConstructFromLiteral a = j.getAnnotation(ConstructFromLiteral.class);
        if (a != null) {
            if (a.includeConcreteClasses() && (j.isClass() != null && !j.isAbstract())) {
                addClass(j);
            }
            if (a.includeInterfaces() && (j.isInterface() != null)) {
                addClass(j);
            }
            if (a.recursive()) {
                for (JClassType e : j.getSubtypes()) {
                    if (a.includeConcreteClasses() && (e.isClass() != null && !e.isAbstract())) {
                        addClass(e);
                    }
                    if (a.includeInterfaces() && (e.isInterface() != null)) {
                        addClass(e);
                    }
                }
            }
        }
    }
    return groups;
}

From source file:com.kk_electronic.gwt.rebind.JsonEncoderGenerator.java

License:Open Source License

private JClassType[] getClasses(String classCanonicalName, boolean allowAbstract) {
    Vector<JClassType> vector = new Vector<JClassType>();
    JClassType desiredInterface;/*from  www  .j  av a 2 s.c  o m*/
    try {
        desiredInterface = typeOracle.getType(classCanonicalName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "Can't find marker interface: " + classCanonicalName, e);
        return new JClassType[] {};
    }
    for (JClassType j : typeOracle.getTypes()) {
        if (j.isAssignableTo(desiredInterface) && (!j.isAbstract() || allowAbstract)) {
            vector.add(j);
        }
    }
    JClassType[] classArray = new JClassType[vector.size()];
    vector.copyInto(classArray);
    return classArray;
}

From source file:com.kk_electronic.gwt.rebind.ModuleTypeInfoHelperGenerator.java

License:Open Source License

private JClassType[] getClasses() {
    Vector<JClassType> vector = new Vector<JClassType>();
    JClassType desiredInterface;//from  w ww.java 2 s.c o  m
    try {
        desiredInterface = typeOracle.getType(Module.class.getCanonicalName());
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "Can't find marker interface", e);
        return new JClassType[] {};
    }
    for (JClassType j : typeOracle.getTypes()) {
        if (j.isAssignableTo(desiredInterface) && !j.isAbstract()) {
            vector.add(j);
        }
    }
    JClassType[] classArray = new JClassType[vector.size()];
    vector.copyInto(classArray);
    return classArray;
}