} else { pb(varName + ".isStatic = " + c.isStatic() + ";"); pb(varName + ".isAbstract = " + c.isAbstract() + ";"); if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) { createTypeInvokables(c, varName, "Constructor", c.getConstructors()); } else {
} else { pb(varName + ".isStatic = " + c.isStatic() + ";"); pb(varName + ".isAbstract = " + c.isAbstract() + ";"); if (c.isPublic() && !c.isAbstract() && (c.getEnclosingType() == null || c.isStatic())) { createTypeInvokables(c, varName, "Constructor", c.getConstructors()); } else {
/** * Enumerated types can be instantiated even if they are abstract. You will * have an abstract enum in cases where the enum type is sub-classed. * Non-default instantiable classes cannot have instantiate methods. */ private boolean needsTypeHandler() { return serializableClass.isEnum() != null || !serializableClass.isAbstract(); }
/** * Enumerated types can be instantiated even if they are abstract. You will * have an abstract enum in cases where the enum type is sub-classed. * Non-default instantiable classes cannot have instantiate methods. */ private boolean needsTypeHandler() { return serializableClass.isEnum() != null || !serializableClass.isAbstract(); }
private boolean isAConcreteGenericEvent(JClassType param) { return param != null && !param.isAbstract() && param.isAssignableTo(genericEventType); }
@Override public boolean isAbstract() { return getEnclosedMetaObject().isClass() != null && getEnclosedMetaObject().isClass().isAbstract(); }
@Override public boolean isAbstract() { return getEnclosedMetaObject().isClass() != null && getEnclosedMetaObject().isClass().isAbstract(); }
protected List<Subtype> getPossibleTypesForClass(GeneratorContext context, JClassType classType, Id id, boolean isLeaf, TreeLogger logger, Collection<JsonSubTypes.Type> types) throws UnableToCompleteException { List<Subtype> possibleTypes = Lists.newArrayList(); List<JClassType> resolvedSubtypes = Lists.newArrayList(); if (types != null && !types.isEmpty()) { for (JsonSubTypes.Type type : types) { JClassType typeClass = BaseSourceCreator.find(type.value(), logger, context); if (!isLeaf || classType.equals(typeClass)) { resolvedSubtypes.add(typeClass); } } } else { for (JClassType typeClass : context.getTypeOracle().getTypes()) { if (!typeClass.isAbstract() && typeClass.isAssignableTo(classType)) { resolvedSubtypes.add(typeClass); } } } for (JClassType typeClass : resolvedSubtypes) { possibleTypes.add( new Subtype(id == Id.CLASS ? typeClass.getQualifiedSourceName() : "." + typeClass.getSimpleSourceName(), typeClass)); } return possibleTypes; }
protected List<Subtype> getPossibleTypesForClass(GeneratorContext context, JClassType classType, Id id, boolean isLeaf, TreeLogger logger, Collection<JsonSubTypes.Type> types) throws UnableToCompleteException { List<Subtype> possibleTypes = Lists.newArrayList(); List<JClassType> resolvedSubtypes = Lists.newArrayList(); if (types != null && !types.isEmpty()) { for (JsonSubTypes.Type type : types) { JClassType typeClass = BaseSourceCreator.find(type.value(), logger, context); if (!isLeaf || classType.equals(typeClass)) { resolvedSubtypes.add(typeClass); } } } else { for (JClassType typeClass : context.getTypeOracle().getTypes()) { if (!typeClass.isAbstract() && typeClass.isAssignableTo(classType)) { resolvedSubtypes.add(typeClass); } } } for (JClassType typeClass : resolvedSubtypes) { possibleTypes.add( new Subtype(id == Id.CLASS ? typeClass.getQualifiedSourceName() : "." + typeClass.getSimpleSourceName(), typeClass)); } return possibleTypes; }
if (classType.isAbstract()) { continue;
static boolean canBeInstantiated(JClassType type, ProblemReport problems) { if (type.isEnum() == null) { if (type.isAbstract()) { // Abstract types will be picked up if there is an instantiable // subtype. return false; } if (!type.isDefaultInstantiable() && !isManuallySerializable(type)) { // Warn and return false. problems.add(type, type.getParameterizedQualifiedSourceName() + " is not default instantiable (it must have a zero-argument " + "constructor or no constructors at all) and has no custom " + "serializer.", Priority.DEFAULT); return false; } } else { /* * Enums are always instantiable regardless of abstract or default * instantiability. */ } return true; }
static boolean canBeInstantiated(JClassType type, ProblemReport problems) { if (type.isEnum() == null) { if (type.isAbstract()) { // Abstract types will be picked up if there is an instantiable // subtype. return false; } if (!type.isDefaultInstantiable() && !isManuallySerializable(type)) { // Warn and return false. problems.add(type, type.getParameterizedQualifiedSourceName() + " is not default instantiable (it must have a zero-argument " + "constructor or no constructors at all) and has no custom " + "serializer.", Priority.DEFAULT); return false; } } else { /* * Enums are always instantiable regardless of abstract or default * instantiability. */ } return true; }
@Override protected void doGenerate(SourceWriter sourceWriter) throws UnableToCompleteException { JClassType adapterProviderClassType = typeOracle.findType(getAdapterProviderBaseClass().getCanonicalName()); JClassType[] adapterProviders = adapterProviderClassType.getSubtypes(); sourceWriter.println("public void registerAllAdapters() {"); sourceWriter.indent(); for (JClassType adapterProviderImplementationClassType : adapterProviders) { if (!adapterProviderImplementationClassType.isAbstract()) { boolean found = false; for (JConstructor constructor :adapterProviderImplementationClassType.getConstructors()) { if (constructor.getParameters().length == 0) { found = true; } } if (found) { sourceWriter.println(BeanAdapterFactory.class.getSimpleName() + ".addProvider(new " + adapterProviderImplementationClassType.getQualifiedSourceName() + "());"); } } } sourceWriter.indent(); sourceWriter.println("}"); }
private void generateCreate(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("public %s newInstance() {", this.beanType.getSimpleSourceName()); srcWriter.indent(); if (!this.beanType.isAbstract()) { srcWriter.println("return new %s();", this.beanType.getSimpleSourceName()); } else { srcWriter.println("throw new RuntimeException(\"Can not instantiate the abstract class %s\");", this.beanType.getSimpleSourceName()); } srcWriter.outdent(); srcWriter.println("}"); }
if (classOrInterface != null) if (classOrInterface.isAbstract() || classOrInterface.isInterface() != null)
private void generateCreate(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("public %s newInstance() {", this.beanType.getSimpleSourceName()); srcWriter.indent(); if (!this.beanType.isAbstract()) { srcWriter.println("return new %s();", this.beanType.getSimpleSourceName()); } else { srcWriter.println("throw new RuntimeException(\"Can not instantiate the abstract class %s\");", this.beanType.getSimpleSourceName()); } srcWriter.outdent(); srcWriter.println("}"); }
/** * <p>filterSubtypesForDeserialization</p> * * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object. * @param configuration a {@link com.github.nmorel.gwtjackson.rebind.RebindConfiguration} object. * @param type a {@link com.google.gwt.core.ext.typeinfo.JClassType} object. * @return a {@link com.google.gwt.thirdparty.guava.common.collect.ImmutableList} object. */ 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 ) // 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(); }
@Override public void generate() throws UnableToCompleteException { JsonTypeInfo typeInfo = getClassAnnotation(source, JsonTypeInfo.class); boolean isLeaf = isLeaf(source); List<Subtype> possibleTypes = getPossibleTypes(typeInfo, isLeaf); Collections.sort(possibleTypes); JClassType sourceClazz = source.isClass() == null ? source.isInterface() : source.isClass(); if (sourceClazz == null) { getLogger().log(ERROR, "Type is not a class"); throw new UnableToCompleteException(); } if (sourceClazz.isEnum() == null && sourceClazz.isAbstract()) { if (typeInfo == null) { getLogger().log(ERROR, "Abstract classes must be annotated with JsonTypeInfo"); throw new UnableToCompleteException(); } } Json jsonAnnotation = getAnnotation(source, Json.class); Style classStyle = jsonAnnotation != null ? jsonAnnotation.style() : Style.DEFAULT; String railsWrapperName = jsonAnnotation != null && !jsonAnnotation.name().isEmpty() ? jsonAnnotation.name() : sourceClazz.getName().toLowerCase(); locator = EncoderDecoderLocatorFactory.getEncoderDecoderInstanceLocator(context, getLogger()); generateSingleton(shortName); generateEncodeMethod(source, classStyle, typeInfo, railsWrapperName, possibleTypes, isLeaf, locator); generateDecodeMethod(source, classStyle, typeInfo, railsWrapperName, possibleTypes, isLeaf, locator); }
@Override public void generate() throws UnableToCompleteException { JsonTypeInfo typeInfo = getClassAnnotation(source, JsonTypeInfo.class); boolean isLeaf = isLeaf(source); List<Subtype> possibleTypes = getPossibleTypes(typeInfo, isLeaf); Collections.sort(possibleTypes); JClassType sourceClazz = source.isClass() == null ? source.isInterface() : source.isClass(); if (sourceClazz == null) { getLogger().log(ERROR, "Type is not a class"); throw new UnableToCompleteException(); } if (sourceClazz.isEnum() == null && sourceClazz.isAbstract()) { if (typeInfo == null) { getLogger().log(ERROR, "Abstract classes must be annotated with JsonTypeInfo"); throw new UnableToCompleteException(); } } Json jsonAnnotation = getAnnotation(source, Json.class); Style classStyle = jsonAnnotation != null ? jsonAnnotation.style() : Style.DEFAULT; String railsWrapperName = jsonAnnotation != null && !jsonAnnotation.name().isEmpty() ? jsonAnnotation.name() : sourceClazz.getName().toLowerCase(); locator = EncoderDecoderLocatorFactory.getEncoderDecoderInstanceLocator(context, getLogger()); generateSingleton(shortName); generateEncodeMethod(source, classStyle, typeInfo, railsWrapperName, possibleTypes, isLeaf, locator); generateDecodeMethod(source, classStyle, typeInfo, railsWrapperName, possibleTypes, isLeaf, locator); }
for (JClassType type : typeOracle.getTypes()) { if (type.isAnnotationPresent(ComponentExtension.class)) { if (type.isClass() == null || type.isAbstract()) {