List of usage examples for com.google.gwt.core.ext.typeinfo JClassType isLocalType
@Deprecated
boolean isLocalType();
From source file:com.totsp.gwt.freezedry.rebind.SerializableTypeOracleBuilder.java
License:Apache License
/** * Case 1: Type is automatically serializable a) All fields must be * serializable b) All subtypes must be serializable unless we allow subtypes * that are not serializable c) If inherited automatic serialization * superclass must be serializable/*from w w w. ja va 2s . c om*/ * * Case 2: Type is manually serializable a) CSF must be valid b) All * automatically and manually serializable fields must be serializable c) Any * field that is not manually or automatically serializable is okay * * Case 3: Type is neither automatically or manually serializable a) If type * has at least one automatically or manually serializable subtype then we are * okay. b) If type has no serializable subtypes then: i) context is * automatically serializable => error ii) context is manually serializable => * warning iii) context is neither manually nor automatically serializable => * warning. */ private void checkClassOrInterface(TreeLogger logger, JClassType type, boolean validateSubtypes) { if (type == stringClass) { // we know that it is serializable return; } if (type == typeOracle.getJavaLangObject()) { // Object is never serializable setUnserializableAndLog(logger, inManualSerializationContext() ? TreeLogger.WARN : TreeLogger.ERROR, "In order to produce smaller client-side code, 'Object' is not allowed; consider using a more specific type", type); return; } JClassType superclass = type.getSuperclass(); if (superclass != null) { MetaTypeInfo smti = getMetaTypeInfo(superclass); if (smti.qualifiesForSerialization()) { checkType(logger.branch(TreeLogger.DEBUG, "Analyzing superclass:", null), superclass, false); } else { logger.branch(TreeLogger.DEBUG, "Not analyzing superclass '" + superclass.getParameterizedQualifiedSourceName() + "' because it is not assignable to '" + IsSerializable.class.getName() + "' or '" + Serializable.class.getName() + "' nor does it have a custom field serializer", null); } } MetaTypeInfo mti = getMetaTypeInfo(type); if (mti.qualifiesForManualSerialization()) { List failures = CustomFieldSerializerValidator.validate(streamReaderClass, streamWriterClass, mti.getManualSerializer(), type); if (!failures.isEmpty()) { setUnserializableAndLog(logger, TreeLogger.ERROR, failures, type); return; } mti.setSerializable(true); checkFields(logger, type); } else if (mti.qualifiesForAutoSerialization()) { if (type.isLocalType()) { setUnserializableAndLog(logger, TreeLogger.WARN, "Is a local type, it will be excluded from the set of serializable types", type); return; } if (type.isMemberType() && !type.isStatic()) { setUnserializableAndLog(logger, TreeLogger.WARN, "Is nested but not static, it will be excluded from the set of serializable types", type); return; } if (type.isClass() != null && !type.isDefaultInstantiable()) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Was not default instantiable (it must have a zero-argument public constructor or no constructors at all)", type); return; } if (type.isAbstract() && type.getSubtypes().length == 0) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Is abstract and it has no serializable subtypes", type); return; } getMetaTypeInfo(type).setSerializable(true); checkMethods(logger, type); checkFields(logger, type); } if (validateSubtypes) { int nSubtypes = 0; int nSerializableSubtypes = 0; JClassType[] subtypes = type.getSubtypes(); if (subtypes.length > 0) { TreeLogger localLogger = logger.branch(TreeLogger.DEBUG, "Analyzing subclasses:", null); for (int i = 0; i < subtypes.length; ++i) { JClassType subtype = subtypes[i]; MetaTypeInfo smti = getMetaTypeInfo(subtype); if (smti.qualifiesForSerialization()) { checkType(localLogger, subtype, false); ++nSubtypes; if (smti.isSerializable()) { ++nSerializableSubtypes; } else { localLogger.branch(TreeLogger.DEBUG, subtype.getParameterizedQualifiedSourceName() + " is not serializable", null); if (subtype.isLocalType() || subtype.isMemberType() && !subtype.isStatic()) { --nSubtypes; } } } else { localLogger.branch(TreeLogger.DEBUG, "Not analyzing subclass '" + subtype.getParameterizedQualifiedSourceName() + "' because it is not assignable to '" + IsSerializable.class.getName() + "' or '" + Serializable.class.getName() + "' nor does it have a custom field serializer", null); } } } if (mti.qualifiesForAutoSerialization()) { if (nSerializableSubtypes < nSubtypes) { if (!allowUnserializableSubtypesOfAutoSerializableTypes || nSerializableSubtypes == 0) { setUnserializableAndLog(logger, TreeLogger.ERROR, "Not all subtypes are serializable", type); } } } else if (!mti.qualifiesForManualSerialization() && nSerializableSubtypes == 0) { /* * The type does not qualify for either serialization and it has no * serializable subtypes; this is only an error if we are not in the * context of a custom field serializer */ String message = MessageFormat.format( "Type ''{0}'' is not assignable to IsSerializable or java.io.Serializable, it does not have a custom field serializer and it does not have any serializable subtypes", new String[] { type.getParameterizedQualifiedSourceName() }); setUnserializableAndLog(logger, inManualSerializationContext() ? TreeLogger.WARN : TreeLogger.ERROR, message, type); } } }
From source file:com.totsp.gwt.freezedry.rebind.SerializableTypeOracleBuilder.java
License:Apache License
private void logReasonsForUnserializability(TreeLogger logger, JType type) { TreeLogger.Type logType;// w ww. j av a 2 s . c om MetaTypeInfo mti = getMetaTypeInfo(type); boolean autoSerializable = mti.qualifiesForAutoSerialization(); if (inManualSerializationContext() && !autoSerializable) { logType = TreeLogger.WARN; } else { logType = TreeLogger.ERROR; if (autoSerializable) { JClassType classOrInterface = type.isClassOrInterface(); if (classOrInterface.isLocalType() || (classOrInterface.isMemberType() && !classOrInterface.isStatic())) { logType = TreeLogger.WARN; } } } if (logType == TreeLogger.ERROR) { validationFailed = true; } Set /* <String> */ reasons = mti.getFailures(); Iterator iter = reasons.iterator(); while (iter.hasNext()) { logger.branch(logType, (String) iter.next(), null); } }