List of usage examples for com.google.gwt.core.ext.typeinfo JMethod getParameterTypes
JType[] getParameterTypes();
From source file:cc.alcina.framework.entity.gwtsynth.ClientReflectionGenerator.java
License:Apache License
public Set<Annotation> getSuperclassAnnotationsForMethod(JMethod m) { if (superMethodAnnotationMap.containsKey(m)) { return superMethodAnnotationMap.get(m); }// w ww.ja v a 2 s.com Map<Class, Annotation> uniqueMap = new HashMap<Class, Annotation>(); JClassType c = m.getEnclosingType(); Set<? extends JClassType> flattenedSupertypeHierarchy = c.getFlattenedSupertypeHierarchy(); for (JClassType jct : flattenedSupertypeHierarchy) { try { JMethod m2 = jct.getMethod(m.getName(), m.getParameterTypes()); for (Annotation a : getVisibleAnnotations(m2, visibleAnnotationClasses)) { if (!uniqueMap.containsKey(a.annotationType())) { uniqueMap.put(a.annotationType(), a); } } } catch (Exception e) { } } HashSet values = new HashSet(uniqueMap.values()); superMethodAnnotationMap.put(m, values); return values; }
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void gatherTypes(JType type, List<JType> types) { nesting++;//w ww . jav a2s . co m // came here from a type that has no super class if (type == null) { nesting--; return; } // package info if (type.getQualifiedSourceName().contains("-")) { nesting--; return; } // not visible if (!isVisible(type)) { nesting--; return; } // filter reflection scope based on configuration in gwt xml module boolean keep = false; String name = type.getQualifiedSourceName(); try { ConfigurationProperty prop; keep |= !name.contains("."); prop = context.getPropertyOracle().getConfigurationProperty("artemis.reflect.include"); for (String s : prop.getValues()) keep |= name.contains(s); prop = context.getPropertyOracle().getConfigurationProperty("artemis.reflect.exclude"); for (String s : prop.getValues()) keep &= !name.equals(s); } catch (BadPropertyValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!keep) { nesting--; return; } // already visited this type if (types.contains(type.getErasedType())) { nesting--; return; } types.add(type.getErasedType()); out(type.getErasedType().getQualifiedSourceName(), nesting); if (type instanceof JPrimitiveType) { // nothing to do for a primitive type nesting--; return; } else { // gather fields JClassType c = (JClassType) type; JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) { gatherTypes(field.getType().getErasedType(), types); } } // gather super types & interfaces gatherTypes(c.getSuperclass(), types); JClassType[] interfaces = c.getImplementedInterfaces(); if (interfaces != null) { for (JClassType i : interfaces) { gatherTypes(i.getErasedType(), types); } } // gather method parameter & return types JMethod[] methods = c.getMethods(); if (methods != null) { for (JMethod m : methods) { gatherTypes(m.getReturnType().getErasedType(), types); if (m.getParameterTypes() != null) { for (JType p : m.getParameterTypes()) { gatherTypes(p.getErasedType(), types); } } } } // gather inner classes JClassType[] inner = c.getNestedTypes(); if (inner != null) { for (JClassType i : inner) { gatherTypes(i.getErasedType(), types); } } } nesting--; }
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void gatherTypes(JType type, List<JType> types) { nesting++;/* w ww . ja v a 2 s .c om*/ // came here from a type that has no super class if (type == null) { nesting--; return; } // package info if (type.getQualifiedSourceName().contains("-")) { nesting--; return; } // not visible if (!isVisible(type)) { nesting--; return; } // filter reflection scope based on configuration in gwt xml module boolean keep = false; String name = type.getQualifiedSourceName(); try { ConfigurationProperty prop; keep |= !name.contains("."); prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.include"); for (String s : prop.getValues()) keep |= name.contains(s); prop = context.getPropertyOracle().getConfigurationProperty("gdx.reflect.exclude"); for (String s : prop.getValues()) keep &= !name.equals(s); } catch (BadPropertyValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!keep) { nesting--; return; } // already visited this type if (types.contains(type.getErasedType())) { nesting--; return; } types.add(type.getErasedType()); out(type.getErasedType().getQualifiedSourceName(), nesting); if (type instanceof JPrimitiveType) { // nothing to do for a primitive type nesting--; return; } else { // gather fields JClassType c = (JClassType) type; JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) { gatherTypes(field.getType().getErasedType(), types); } } // gather super types & interfaces gatherTypes(c.getSuperclass(), types); JClassType[] interfaces = c.getImplementedInterfaces(); if (interfaces != null) { for (JClassType i : interfaces) { gatherTypes(i.getErasedType(), types); } } // gather method parameter & return types JMethod[] methods = c.getMethods(); if (methods != null) { for (JMethod m : methods) { gatherTypes(m.getReturnType().getErasedType(), types); if (m.getParameterTypes() != null) { for (JType p : m.getParameterTypes()) { gatherTypes(p.getErasedType(), types); } } } } // gather inner classes JClassType[] inner = c.getNestedTypes(); if (inner != null) { for (JClassType i : inner) { gatherTypes(i.getErasedType(), types); } } } nesting--; }
From source file:com.cgxlib.xq.rebind.JsonBuilderGenerator.java
License:Apache License
public String generate(TreeLogger treeLogger, GeneratorContext generatorContext, String requestedClass) throws UnableToCompleteException { oracle = generatorContext.getTypeOracle(); JClassType clazz = oracle.findType(requestedClass); jsonBuilderType = oracle.findType(JsonBuilder.class.getName()); settingsType = oracle.findType(IsProperties.class.getName()); stringType = oracle.findType(String.class.getName()); jsType = oracle.findType(JavaScriptObject.class.getName()); listType = oracle.findType(List.class.getName()); functionType = oracle.findType(Function.class.getName()); jsonFactoryType = oracle.findType(JsonFactory.class.getName()); String t[] = generateClassName(clazz); boolean isFactory = clazz.isAssignableTo(jsonFactoryType); SourceWriter sw = getSourceWriter(treeLogger, generatorContext, t[0], t[1], isFactory, requestedClass); if (sw != null) { if (isFactory) { generateCreateMethod(sw, treeLogger); } else {//from w w w . java2 s . com Set<String> attrs = new HashSet<String>(); for (JMethod method : clazz.getInheritableMethods()) { String methName = method.getName(); // skip method from JsonBuilder if (jsonBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null || settingsType.findMethod(method.getName(), method.getParameterTypes()) != null) { continue; } Name nameAnnotation = method.getAnnotation(Name.class); String name = nameAnnotation != null ? nameAnnotation.value() : methName.replaceFirst("^(get|set)", ""); if (nameAnnotation == null) { name = name.substring(0, 1).toLowerCase() + name.substring(1); } attrs.add(name); generateMethod(sw, method, name, treeLogger); } generateFieldNamesMethod(sw, attrs, treeLogger); generateToJsonMethod(sw, t[3], treeLogger); } sw.commit(treeLogger); } return t[2]; }
From source file:com.cgxlib.xq.rebind.XmlBuilderGenerator.java
License:Apache License
public String generate(TreeLogger treeLogger, GeneratorContext generatorContext, String requestedClass) throws UnableToCompleteException { oracle = generatorContext.getTypeOracle(); JClassType clazz = oracle.findType(requestedClass); xmlBuilderType = oracle.findType(XmlBuilder.class.getName()); stringType = oracle.findType(String.class.getName()); String t[] = generateClassName(clazz); SourceWriter sw = getSourceWriter(treeLogger, generatorContext, t[0], t[1], requestedClass); if (sw != null) { for (JMethod method : clazz.getInheritableMethods()) { // skip method from JsonBuilder if (xmlBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null) { continue; }//from w w w .j a v a2s . c o m generateMethod(sw, method, treeLogger); } sw.commit(treeLogger); } return t[2]; }
From source file:com.ekuefler.supereventbus.rebind.EventRegistrationWriter.java
License:Apache License
private void checkValidity(JClassType target, JMethod method) throws UnableToCompleteException { // General checks for all methods annotated with @Subscribe if (method.getParameterTypes().length != 1) { logger.log(Type.ERROR,//from w ww. jav a 2 s . c om String.format("Method %s.%s annotated with @Subscribe must take exactly one argument.", target.getName(), method.getName())); throw new UnableToCompleteException(); } else if (method.isPrivate()) { logger.log(Type.ERROR, String.format("Method %s.%s annotated with @Subscribe must not be private.", target.getName(), method.getName())); throw new UnableToCompleteException(); } if (method.getParameterTypes()[0].getQualifiedSourceName().equals(MultiEvent.class.getCanonicalName())) { // Checks specific to MultiEvents if (method.getParameters()[0].getAnnotation(EventTypes.class) == null) { logger.log(Type.ERROR, String.format("MultiEvent in method %s.%s must be annotated with @EventTypes.", target.getName(), method.getName())); throw new UnableToCompleteException(); } // Ensure that no type is assignable to another type Class<?>[] classes = method.getParameters()[0].getAnnotation(EventTypes.class).value(); for (Class<?> c1 : classes) { for (Class<?> c2 : classes) { if (c1 != c2 && c1.isAssignableFrom(c2)) { logger.log(Type.ERROR, String.format("The type %s is redundant with the type %s in method %s.%s.", c2.getSimpleName(), c1.getSimpleName(), target.getName(), method.getName())); throw new UnableToCompleteException(); } } } } else { // Checks for non-MultiEvents if (method.getParameters()[0].getAnnotation(EventTypes.class) != null) { logger.log(Type.ERROR, String.format( "@EventTypes must not be applied to a non-MultiEvent parameter in method %s.%s.", target.getName(), method.getName())); throw new UnableToCompleteException(); } } }
From source file:com.ekuefler.supereventbus.rebind.EventRegistrationWriter.java
License:Apache License
private String getFirstParameterType(JMethod method) { // If the parameter type is primitive, box it JType type = method.getParameterTypes()[0]; if (type.isPrimitive() != null) { if (type.isPrimitive() == JPrimitiveType.BOOLEAN) { return Boolean.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.BYTE) { return Byte.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.CHAR) { return Character.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.DOUBLE) { return Double.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.FLOAT) { return Float.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.INT) { return Integer.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.LONG) { return Long.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.SHORT) { return Short.class.getName(); }/*from ww w.j av a2s. com*/ } // Otherwise return the fully-qualified type name return type.getQualifiedSourceName(); }
From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java
License:Apache License
private BeanMetadata create(GeneratorContext context, TreeLogger logger, String packageName, JClassType type, Class<?> classAdapter, IsEntity anno) throws TypeOracleException { String beanName = anno == null || anno.aliasName().isEmpty() ? type.getName() : anno.aliasName(); Source implementation = null; JClassType implType = type;//from ww w. jav a 2s .c om TypeOracle typeOracle = context.getTypeOracle(); if (type.isInterface() != null) { implType = null; JClassType[] types = type.getSubtypes(); log(logger, Type.DEBUG, "Get all sub types of %s : %s", type, Arrays.toString(types)); if (types != null && types.length > 0) { for (JClassType jClassType : types) { if (isInstantiable(jClassType, logger)) { implType = jClassType; implementation = new Source(implType.getPackage().getName(), implType.getName()); break; } } } if (implType == null) { log(logger, Type.ERROR, "The type %s has not valid subtypes " + "%s !", type, Arrays.toString(types)); return null; } } if (!implType.isDefaultInstantiable()) return null; String prefix = classAdapter.getSimpleName().replace("Adapter", ""); boolean isEntity = anno != null; String className = prefix + beanName; if (parseOnlyInterface && implType != type) className += "Light"; PrintWriter writer = context.tryCreate(logger, packageName, className); if (writer == null) { return new BeanMetadata(type, className, implementation, isEntity); } ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, className); logger.log(Type.DEBUG, "Create Entity " + factory.getCreatedClassName()); factory.setSuperclass(classAdapter.getSimpleName() + "<" + type.getName() + ">"); factory.addImport(RuntimeException.class.getName()); factory.addImport(classAdapter.getName()); factory.addImport(type.getQualifiedSourceName()); if (isEntity) { factory.addImport(ArrayList.class.getName()); factory.addImport(Collection.class.getName()); } factory.addImport(HashMap.class.getName()); factory.addImport(Property.class.getName()); factory.addImport(Property.class.getName() + ".Kind"); factory.addImport(Index.class.getName()); factory.addImport(implType.getQualifiedSourceName()); factory.addImport("javax.annotation.Generated"); factory.addAnnotationDeclaration("@Generated(" + "value=\"" + AdapterEntity.class.getName() + "\", " + "date=\"" + new Date() + "\", " + "comments=\"Generated by DAO-GWT project.\")"); SourceWriter sourceWriter = factory.createSourceWriter(context, writer); sourceWriter.println("//AUTO GENERATED FILE BY DAO-GWT " + getClass().getName() + ". DO NOT EDIT!\n"); sourceWriter.println("private static HashMap<String,Property<%s,?>> PROPERTIES = " + "new HashMap<String,Property<%s,?>>();", type.getName(), type.getName()); if (isEntity) { factory.addImport(ArrayList.class.getName()); factory.addImport(Index.class.getName()); sourceWriter.println("private static Collection<Index> INDEXES = " + "new ArrayList<Index>();"); } sourceWriter.println("static {"); sourceWriter.indent(); JClassType interfaz = type != implType ? type : null; JMethod[] methods = parseOnlyInterface ? type.getInheritableMethods() : implType.getInheritableMethods(); for (JMethod method : methods) { String name = method.getName(); //Check if the method has a IsIgnored annotation before to continue IsIgnored ignored = method.getAnnotation(IsIgnored.class); if (ignored != null) { log(logger, Type.DEBUG, EXPLICITELY_IGNORED, name, implType); continue; } boolean startsWithGet = name.startsWith("get"); boolean startsWithIs = name.startsWith("is"); if (!startsWithGet && !startsWithIs) { log(logger, Type.DEBUG, IGNORE_METHOD, name, implType); continue; } //check no parameters if (method.getParameterTypes().length != 0) { log(logger, Type.WARN, NO_PARAMETER_GETTER, name, implType); continue; } //check return type JType returnType = method.getReturnType(); if (returnType == null || returnType.getQualifiedSourceName().equals(Void.class.getName()) || returnType.getQualifiedSourceName().equals(void.class.getName())) { log(logger, Type.DEBUG, VOID_GETTER, name + "" + returnType, implType); continue; } //change the format of the name getXyy ==> xyy String getterSetter = name; if (startsWithGet) getterSetter = name.substring(3); else if (startsWithIs) getterSetter = name.substring(2); name = getterSetter.substring(0, 1).toLowerCase() + getterSetter.substring(1); // check if the getter has an annotation IsIndexable indexable = method.getAnnotation(IsIndexable.class); boolean isIndexable = indexable != null; if (isIndexable && !isEntity) log(logger, Type.WARN, ONLY_ENTITY_FOR_INDEX, name, implType, IsEntity.class); isIndexable = isIndexable && isEntity;//only entity can defined indexable element String indexName = isIndexable ? indexable.aliasName() : ""; String[] compositeIndexes = isIndexable ? indexable.compoundWith() : new String[0]; Kind kind = null; JType typeOfCollection = null; String typeOfCollectionString = "null"; if (!isPrimitive(returnType)) { //load complex properties except Key if (returnType.isEnum() != null) { kind = Kind.ENUM; } else { boolean isPrimitive = false; boolean isEnum = false; JParameterizedType pType = returnType.isParameterized(); JType collection = typeOracle.parse(Collection.class.getName()); if (pType != null && pType.getRawType().isAssignableTo(collection.isClassOrInterface())) { JClassType[] types = pType.getTypeArgs(); kind = Kind.COLLECTION_OF_PRIMITIVES; if (types.length > 1) { log(logger, Type.DEBUG, CANNOT_PROCESS_PARAMETERIZED_TYPE, returnType, implType); continue; } typeOfCollection = types[0]; typeOfCollectionString = typeOfCollection.getQualifiedSourceName() + ".class"; log(logger, Type.DEBUG, "The type of the collection is %s", typeOfCollectionString); isPrimitive = isPrimitive(typeOfCollection); isEnum = typeOfCollection.isEnum() != null; } if (!isPrimitive) { if (isEnum && kind != null) { kind = Kind.COLLECTION_OF_ENUMS; } else { JClassType classType = typeOfCollection != null ? typeOfCollection.isClassOrInterface() : returnType.isClassOrInterface(); boolean isBean = isBean(classType); if (isBean) { log(logger, Type.DEBUG, "The property %s is well a type %s", name, classType); if (kind == null) kind = Kind.BEAN; else kind = Kind.COLLECTION_OF_BEANS; } else { log(logger, Type.DEBUG, "The property %s has not a bean type %s", name, classType); continue; } } } } } assert kind != null; boolean isMemo = method.getAnnotation(IsMemo.class) != null; String oldName = "null"; OldName oldNameAnno = method.getAnnotation(OldName.class); if (oldNameAnno != null) oldName = "\"" + oldNameAnno.value() + "\""; //create a property if (kind == Kind.BEAN || kind == Kind.COLLECTION_OF_BEANS) factory.addImport(returnType.getQualifiedSourceName()); String valueType = ""; JClassType classType = returnType.isClassOrInterface(); JPrimitiveType primitiveType = returnType.isPrimitive(); if (classType != null) valueType = classType.getQualifiedSourceName(); else if (primitiveType != null) { valueType = primitiveType.getQualifiedBoxedSourceName(); } sourceWriter.println("{ //Property %s", name); sourceWriter.indent(); sourceWriter.print("Index index ="); if (isIndexable) { if (indexName.isEmpty()) indexName = name; sourceWriter.println("new Index(\"%s\",\"%s\",new String[]{%s});", indexName, name, String.join(",", compositeIndexes)); } else sourceWriter.println("null;"); boolean useKeyAsString = anno != null ? (name.equals(anno.keyName()) ? anno.useKeyAsString() : false) : false; KeyOf keyOf = method.getAnnotation(KeyOf.class); if (keyOf != null) { IsEntity isEntity2 = keyOf.entity().getAnnotation(IsEntity.class); if (isEntity2 == null) { log(logger, Type.ERROR, AdapterEntityManager.KEY_OF_NO_ENTITY, method, keyOf, keyOf.entity(), IsEntity.class); continue; } useKeyAsString = isEntity2.useKeyAsString(); } boolean isHidden = isHidden(method, interfaz); sourceWriter.println( "Property<%s,%s> property = new Property<%s,%s>(\"%s\",%s,%s.class,%s,%s,%s,%s,index,%s){", type.getName(), valueType, type.getName(), valueType, name, oldName, returnType.getQualifiedSourceName(), typeOfCollectionString, kind != null ? "Kind." + kind.name() : "null", useKeyAsString + "", isMemo + "", isHidden + ""); sourceWriter.indent(); sourceWriter.println("@Override"); sourceWriter.println("public %s get(%s instance){", valueType, type.getName()); sourceWriter.indent(); sourceWriter.println("return ((%s)instance).%s();", implType.getName(), startsWithGet ? "get" + getterSetter : "is" + getterSetter); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("@Override"); sourceWriter.println("public void set(%s instance, %s value){", type.getName(), valueType); sourceWriter.indent(); if (getSetter(implType, getterSetter, returnType) != null) sourceWriter.println("((%s)instance).%s(value);", implType.getName(), "set" + getterSetter); else { logger.log(Type.WARN, " Not found setter for " + getterSetter); sourceWriter.println("throw new RuntimeException(\"No such setter " + getterSetter + " \");"); } sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println("};"); sourceWriter.println("PROPERTIES.put(\"%s\",property);", name); if (!oldName.equals("null")) { sourceWriter.println("PROPERTIES.put(%s,property);", oldName); } if (isIndexable) sourceWriter.println("INDEXES.add(index);"); sourceWriter.outdent(); sourceWriter.println("}"); log(logger, Type.DEBUG, SUCCESSFUL_ADD_PROPERTY, name + ":" + valueType, implType); } sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println(); sourceWriter.println("public %s(){", className); sourceWriter.indent(); /* * boolean asyncReady, boolean autoGeneratedFlag, String keyName, boolean useKeyAsString, Class<T> type,Class<? extends T> implType, Map<String, Property<T,?>> mapAllProperties, Collection<Index> indexes) { super(type,implType,mapAllProperties); */ if (isEntity) sourceWriter .println(String.format("super(\"%s\",%s,%s,\"%s\",%s,%s.class,%s.class,PROPERTIES,INDEXES);", anno.aliasName().isEmpty() ? type.getName() : anno.aliasName(), anno.asyncReady(), anno.autoGeneratedKey(), anno.keyName(), anno.useKeyAsString(), type.getName(), implType.getName())); else { sourceWriter.println( String.format("super(%s.class,%s.class,PROPERTIES);", type.getName(), implType.getName())); } sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println(); sourceWriter.println("@Override"); sourceWriter.println("public %s newInstance(){", type.getName()); sourceWriter.indent(); sourceWriter.println("return new %s();", implType.getName()); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.outdent(); sourceWriter.println("}"); context.commit(logger, writer); return new BeanMetadata(type, className, implementation, isEntity); }
From source file:com.github.ludorival.dao.gwt.rebind.EntityManagerGenerator.java
License:Apache License
private boolean isHidden(JMethod method, JClassType interfaz) { if (interfaz == null) return false; return interfaz.findMethod(method.getName(), method.getParameterTypes()) != null; }
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./* ww w .ja v a 2 s . co m*/ * * @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()); } } }