List of usage examples for com.google.gwt.core.ext.typeinfo JType isClass
JClassType isClass();
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private String createTypeGenerator(JType t) { buffer.setLength(0);// w w w.jav a 2 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.CreatorUtils.java
License:Apache License
/** * @param type the type to test// w w w.ja v a 2 s. c o m * * @return true if the type is {@link Object}, false otherwise */ public static boolean isObject(JType type) { return null != type.isClass() && Object.class.getName().equals(type.getQualifiedSourceName()); }
From source file:com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle.java
License:Apache License
public boolean isKeySerializer(JType type) { return null != type.isClass() && type.isClass().isAssignableTo(keySerializerType); }
From source file:com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle.java
License:Apache License
public boolean isKeyDeserializer(JType type) { return null != type.isClass() && type.isClass().isAssignableTo(keyDeserializerType); }
From source file:com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle.java
License:Apache License
public boolean isJsonSerializer(JType type) { return null != type.isClass() && type.isClass().isAssignableTo(jsonSerializerType); }
From source file:com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle.java
License:Apache License
public boolean isJsonDeserializer(JType type) { return null != type.isClass() && type.isClass().isAssignableTo(jsonDeserializerType); }
From source file:com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle.java
License:Apache License
public boolean isJavaScriptObject(JType type) { return null != type.isClass() && type.isClass().isAssignableTo(jsoType); }
From source file:com.github.nmorel.gwtjackson.rebind.RebindConfiguration.java
License:Apache License
/** * Parse the configured serializer/deserializer configuration and put them into the corresponding map * * @param configuration configuration/*from w w w. j a v a 2s . c o m*/ * @param mapperType type of the mapper * @param allSupportedSerializationClassBuilder builder aggregating all the types that have a serializer * @param allSupportedDeserializationClassBuilder builder aggregating all the types that have a deserializer */ private void addMappers(final AbstractConfiguration configuration, final MapperType mapperType, Builder<JClassType> allSupportedSerializationClassBuilder, Builder<JClassType> allSupportedDeserializationClassBuilder) { Map<Class, Class> configuredMapper = mapperType.getMapperTypeConfiguration(configuration); for (Entry<Class, Class> entry : configuredMapper.entrySet()) { JType mappedType = findType(entry.getKey()); if (null == mappedType) { continue; } JClassType mapperClassType = findClassType(entry.getValue()); if (null == mapperClassType) { continue; } if (mapperType.isKey()) { MapperInstance keyMapperInstance = getKeyInstance(mappedType, mapperClassType, mapperType.isSerializer()); if (mapperType.isSerializer()) { keySerializers.put(mappedType.getQualifiedSourceName(), keyMapperInstance); } else { keyDeserializers.put(mappedType.getQualifiedSourceName(), keyMapperInstance); } } else { MapperInstance mapperInstance = getInstance(mappedType, mapperClassType, mapperType.isSerializer()); if (null != mapperInstance) { if (mapperType.isSerializer()) { serializers.put(mappedType.getQualifiedSourceName(), mapperInstance); if (null != mappedType.isClass()) { allSupportedSerializationClassBuilder.add(mappedType.isClass()); } } else { deserializers.put(mappedType.getQualifiedSourceName(), mapperInstance); if (null != mappedType.isClass()) { allSupportedDeserializationClassBuilder.add(mappedType.isClass()); } } } } } }
From source file:com.gwtmobile.persistence.rebind.GenUtils.java
License:Apache License
public boolean isSubclassOf(JType type, String superClass) { JClassType classType = type.isInterface(); if (classType == null) { classType = type.isClass(); }/*from w w w . ja va2s .c o m*/ if (classType == null) { return false; } Set<? extends JClassType> superTypes = classType.getFlattenedSupertypeHierarchy(); for (JClassType superType : superTypes) { if (superType.getSimpleSourceName().equals(superClass)) { return true; } } return false; }
From source file:com.hiramchirino.restygwt.rebind.JsonEncoderDecoderInstanceLocator.java
License:Apache License
private String getEncoderDecoder(JType type, TreeLogger logger) throws UnableToCompleteException { String rc = builtInEncoderDecoders.get(type); if (rc == null) { JClassType ct = type.isClass(); if (ct != null && !isCollectionType(ct)) { JsonEncoderDecoderClassCreator generator = new JsonEncoderDecoderClassCreator(logger, context, ct); return generator.create() + ".INSTANCE"; }/*from w w w . j ava 2 s. com*/ } return rc; }