List of usage examples for com.google.gwt.core.ext.typeinfo JType isInterface
JClassType isInterface();
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private String createTypeGenerator(JType t) { buffer.setLength(0);/* w ww . ja v a 2 s . com*/ 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//ww w .j a v a2 s . c om * * @return true if the type is {@link Serializable}, false otherwise */ public static boolean isSerializable(JType type) { return null != type.isInterface() && Serializable.class.getName().equals(type.getQualifiedSourceName()); }
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 . j a v a 2 s . co 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.kk_electronic.gwt.rebind.JsonEncoderGenerator.java
License:Open Source License
/** * @throws UnableToCompleteException /*from w w w. j a va 2 s . co m*/ * */ private void retrieveInformation() throws UnableToCompleteException { JClassType desiredInterface; try { desiredInterface = typeOracle.getType(AsyncCallback.class.getCanonicalName()); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "Unable to retrieve the AsyncCallback class"); return; } processJsonValueClasses(); JClassType[] remoteServices = getClasses(RemoteService.class.getCanonicalName(), true); for (JClassType service : remoteServices) { JMethod[] methods = service.getMethods(); for (JMethod m : methods) { JParameter[] paras = m.getParameters(); for (JParameter p : paras) { JType t = p.getType(); if (t == null) { continue; } JClassType jct = t.isInterface(); if (jct != null) { if (jct.isAssignableTo(desiredInterface)) { processGenerics(jct); jct = null; } } else { jct = t.isClass(); } if (jct == null) { continue; } processClass(jct); } } } }
From source file:com.seanchenxi.gwt.storage.rebind.StorageKeyProviderModel.java
License:Apache License
private boolean isValideType(JType type) { if (type == null) return false; if (type.isInterface() != null) return false; if (type.isPrimitive() != null) return true; JClassType aClass = type.isClass();/*from www . j a v a 2 s .c o m*/ if (aClass != null && (aClass.isAssignableTo(serializableIntf) || aClass.isAssignableTo(isSerializableIntf))) { return true; } JArrayType array = type.isArray(); if (array == null) return false; return isValideType(array.getComponentType()); }
From source file:com.totsp.gwt.freezedry.rebind.SerializableTypeOracleBuilder.java
License:Apache License
/** * Builds a {@link SerializableTypeOracle} for a give * {@link com.google.gwt.user.client.rpc.RemoteService} interface. * //from w w w . jav a2 s. c o m * @throws UnableToCompleteException if the the remote service is considered * invalid due to serialization problem or a missing or ill formed * remote service asynchronous interface */ public SerializableTypeOracle build(PropertyOracle propertyOracle, JClassType remoteService) throws UnableToCompleteException { initializeProperties(rootLogger, propertyOracle); //remoteServiceAsyncValidator.validateRemoteServiceAsync(rootLogger, // remoteService); TreeLogger logger = rootLogger.branch(TreeLogger.DEBUG, "Analyzing '" + remoteService.getParameterizedQualifiedSourceName() + "' for serializable types", null); validateRemoteService(logger, remoteService); if (validationFailed) { // the validation code has already logged why throw new UnableToCompleteException(); } List serializableTypesList = new ArrayList(); Iterator iterTypes = typeToMetaTypeInfo.values().iterator(); while (iterTypes.hasNext()) { MetaTypeInfo mti = (MetaTypeInfo) iterTypes.next(); JType type = mti.getType(); if (mti.isSerializable() && type.isInterface() == null) { serializableTypesList.add(type); } } JType[] serializableTypes = new JType[serializableTypesList.size()]; serializableTypesList.toArray(serializableTypes); Arrays.sort(serializableTypes, new Comparator() { public int compare(Object o1, Object o2) { String n1 = ((JType) o1).getQualifiedSourceName(); String n2 = ((JType) o2).getQualifiedSourceName(); return n1.compareTo(n2); } }); logSerializableTypes(logger, serializableTypes); return new SerializableTypeOracleImpl(typeOracle, serializableTypes); }
From source file:org.fusesource.restygwt.rebind.GwtJacksonEncoderDecoderInstanceLocator.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() == null ? type.isInterface() : type.isClass(); GwtJacksonEncoderDecoderClassCreator generator = new GwtJacksonEncoderDecoderClassCreator(logger, context, ct);//from w ww. j a v a2 s . c o m return generator.create() + ".INSTANCE"; } return rc; }
From source file:org.jrydberg.bindings.rebind.DataBindingGenerator.java
License:Apache License
private void findImplClasses(TypeOracle typeOracle, JClassType type, Map<JClassType, JClassType> classes) throws NotFoundException { JClassType[] interfaces = type.getImplementedInterfaces(); if (interfaces.length != 1) { throw new NotFoundException(); }//w w w.j a v a 2 s .c om JParameterizedType isParameterized = interfaces[0].isParameterized(); if (isParameterized == null) { // logger.warn( // "The method 'getAssociatedType()' in '%s' does not return Type<? extends EventHandler>.", // eventType.getName()); // return null; } JClassType[] argTypes = isParameterized.getTypeArgs(); if ((argTypes.length != 1)) { // logger.warn( // "The method 'getAssociatedType()' in '%s' does not return Type<? extends EventHandler>.", // eventType.getName()); // return null; } classes.put(type, argTypes[0]); // JClassType superClass = type.getSuperclass(); // JGenericType genericType = superClass.isGenericType(); // JTypeParameter[] typeParameters = genericType.getTypeParameters(); // classes.put(type, typeParameters[0]); JClassType dataBindingClass = typeOracle.getType(DataBinding.class.getName()); JMethod[] methods = type.getOverridableMethods(); for (JMethod method : methods) { if (!method.isPublic() || method.isStatic()) { continue; } JType propertyType = method.getReturnType().getErasedType(); assert propertyType != null; JClassType possibleImplClass = propertyType.isInterface(); if (possibleImplClass != null) { if (possibleImplClass.isAssignableTo(dataBindingClass)) { if (!classes.containsKey(possibleImplClass)) findImplClasses(typeOracle, possibleImplClass, classes); } } } }
From source file:org.jrydberg.bindings.rebind.DataBindingGenerator.java
License:Apache License
private Set<Binding> findBindings(JClassType type) { Set<Binding> types = new HashSet<Binding>(); JMethod[] methods = type.getOverridableMethods(); for (JMethod method : methods) { if (!method.isPublic() || method.isStatic()) { continue; }/*from w w w .j av a 2 s .c o m*/ JType propertyType = method.getReturnType(); assert propertyType != null; JParameterizedType isParameterized = propertyType.isParameterized(); if (isParameterized != null) { JClassType enclosingType = isParameterized.getBaseType(); if (enclosingType.getQualifiedSourceName().equals(PROPERTY_CLASS_NAME)) { JClassType[] argTypes = isParameterized.getTypeArgs(); if (argTypes.length == 1) { types.add(new Binding(method.getName(), argTypes[0], false)); } } } JClassType isInterface = propertyType.isInterface(); if (isInterface != null) { JClassType[] interfaces = isInterface.getImplementedInterfaces(); if (interfaces.length != 1) { continue; } JClassType dataBindingInterface = interfaces[0]; if (dataBindingInterface.getQualifiedSourceName().equals(DATA_BINDING_CLASS_NAME)) { JParameterizedType bindingParameters = dataBindingInterface.isParameterized(); JClassType[] argTypes = bindingParameters.getTypeArgs(); if (argTypes.length != 1) { continue; } Binding binding = new Binding(method.getName(), isInterface, true); binding.parameterType = argTypes[0]; types.add(binding); } } } return types; }
From source file:org.rapla.rest.gwtjsonrpc.rebind.SerializerCreator.java
License:Apache License
void checkCanSerialize(final TreeLogger logger, final JType type, boolean allowAbstractType) throws UnableToCompleteException { if (type.isPrimitive() == JPrimitiveType.LONG) { logger.log(TreeLogger.ERROR, "Type 'long' not supported in JSON encoding", null); throw new UnableToCompleteException(); }/* w w w .j av a2 s . c o m*/ // if (type.isPrimitive() == JPrimitiveType.VOID) { // logger.log(TreeLogger.ERROR, // "Type 'void' not supported in JSON encoding", null); // throw new UnableToCompleteException(); // } final String qsn = type.getQualifiedSourceName(); if (type.isEnum() != null) { return; } if (isJsonPrimitive(type) || isBoxedPrimitive(type)) { return; } if (type.isArray() != null) { final JType leafType = type.isArray().getLeafType(); if (leafType.isPrimitive() != null || isBoxedPrimitive(leafType)) { if (type.isArray().getRank() != 1) { logger.log(TreeLogger.ERROR, "gwtjsonrpc does not support " + "(de)serializing of multi-dimensional arrays of primitves"); // To work around this, we would need to generate serializers for // them, this can be considered a todo throw new UnableToCompleteException(); } else // Rank 1 arrays work fine. return; } checkCanSerialize(logger, type.isArray().getComponentType()); return; } if (defaultSerializers.containsKey(qsn)) { return; } if (type.isParameterized() != null) { final JClassType[] typeArgs = type.isParameterized().getTypeArgs(); for (final JClassType t : typeArgs) { checkCanSerialize(logger, t); } if (parameterizedSerializers.containsKey(qsn)) { return; } } else if (parameterizedSerializers.containsKey(qsn)) { logger.log(TreeLogger.ERROR, "Type " + qsn + " requires type paramter(s)", null); throw new UnableToCompleteException(); } if (qsn.startsWith("java.") || qsn.startsWith("javax.")) { logger.log(TreeLogger.ERROR, "Standard type " + qsn + " not supported in JSON encoding", null); throw new UnableToCompleteException(); } if (type.isInterface() != null) { logger.log(TreeLogger.ERROR, "Interface " + qsn + " not supported in JSON encoding", null); throw new UnableToCompleteException(); } final JClassType ct = (JClassType) type; if (checkedType.contains(ct)) { return; } checkedType.add(ct); if (ct.isAbstract() && !allowAbstractType) { logger.log(TreeLogger.ERROR, "Abstract type " + qsn + " not supported here", null); throw new UnableToCompleteException(); } for (final JField f : sortFields(ct)) { final TreeLogger branch = logger.branch(TreeLogger.DEBUG, "In type " + qsn + ", field " + f.getName()); checkCanSerialize(branch, f.getType()); } }