if (constr != null) {
addPropertyModelsForFactoryMethodParameters(input.getFactoryMethod(), builderModel);
} else {
addPropertyModelsForConstructor(pojoTypeElement, builderModel);
<<<<<<< HEAD
}
addPropertyModelsForSetterMethods(pojoTypeElement, builderModel);
addPropertyModelsForAccessibleFields(pojoTypeElement, builderModel);
addPropertyModelsForGetterMethods(pojoTypeElement, builderModel);
}
private void addPropertyModelsForConstructor(TypeElement pojoTypeElement, BuilderM builderModel) {
List constructors = ElementFilter.constructorsIn(env.getElementUtils().getAllMembers(
pojoTypeElement));
ExecutableElement constr = findFirstAnnotatedConstructor(constructors, ConstructorProperties.class);
if (constr != null) {
ConstructorProperties constrProps = constr.getAnnotation(ConstructorProperties.class);
String[] propertyNames = constrProps.value();
List extends VariableElement> parameters = constr.getParameters();
if (propertyNames.length != parameters.size()) {
throw new BuildException(Diagnostic.Kind.ERROR,
String.format("Incorrect number of values in annotation %s on constructor %s! "
+ "Expected %d, but was %d.", ConstructorProperties.class.getCanonicalName(), constr,
parameters.size(), propertyNames.length), constr);
}
// loop over all constructor parameters
for (int i = 0; i < propertyNames.length; ++i) {
String propertyName = propertyNames[i];
TypeMirror propertyType = parameters.get(i).asType();
TypeM propertyTypeM = typeMUtils.getTypeM(propertyType);
PropertyM propM = builderModel.getOrCreateProperty(propertyName, propertyTypeM);
propM.setParameterPos(i);
}
} else {
constr = findDefaultConstructor(constructors);
}
if (constr != null) {
// find all exceptions that can be thrown by this constructor
List extends TypeMirror> throwTypes = constr.getThrownTypes();
List exceptionTypes = new ArrayList();
for (TypeMirror throwType : throwTypes) {
TypeM exeptionType = typeMUtils.getTypeM(throwType);
exceptionTypes.add(exeptionType);
}
builderModel.getBuildExceptions().addAll(exceptionTypes);
} else {
throw new BuildException(Diagnostic.Kind.ERROR, String.format(
"Missing default constructor OR constructor annotated with %s in class %s!",
ConstructorProperties.class.getCanonicalName(), pojoTypeElement.getQualifiedName()),
pojoTypeElement);
}
}
=======
}
addPropertyModelsForSetterMethods(pojoTypeElement, builderModel);
addPropertyModelsForAccessibleFields(pojoTypeElement, builderModel);
}
private void addPropertyModelsForConstructor(TypeElement pojoTypeElement, BuilderM builderModel) {
List constructors = ElementFilter.constructorsIn(env.getElementUtils().getAllMembers(
pojoTypeElement));
ExecutableElement constr = findFirstAnnotatedConstructor(constructors, ConstructorProperties.class);
ConstructorProperties constrProps = constr.getAnnotation(ConstructorProperties.class);
String[] propertyNames = constrProps.value();
List extends VariableElement> parameters = constr.getParameters();
if (propertyNames.length != parameters.size()) {
throw new BuildException(Diagnostic.Kind.ERROR,
String.format("Incorrect number of values in annotation %s on constructor %s! "
+ "Expected %d, but was %d.", ConstructorProperties.class.getCanonicalName(), constr,
parameters.size(), propertyNames.length), constr);
}
// loop over all constructor parameters
for (int i = 0; i < propertyNames.length; ++i) {
String propertyName = propertyNames[i];
TypeMirror propertyType = parameters.get(i).asType();
TypeM propertyTypeM = typeMUtils.getTypeM(propertyType);
PropertyM propM = builderModel.getOrCreateProperty(propertyName, propertyTypeM);
propM.setParameterPos(i);
}
} else {
constr = findDefaultConstructor(constructors);
}
if (constr != null) {
// find all exceptions that can be thrown by this constructor
List extends TypeMirror> throwTypes = constr.getThrownTypes();
List exceptionTypes = new ArrayList();
for (TypeMirror throwType : throwTypes) {
TypeM exeptionType = typeMUtils.getTypeM(throwType);
exceptionTypes.add(exeptionType);
}
builderModel.getBuildExceptions().addAll(exceptionTypes);
} else {
throw new BuildException(Diagnostic.Kind.ERROR, String.format(
"Missing default constructor OR constructor annotated with %s in class %s!",
ConstructorProperties.class.getCanonicalName(), pojoTypeElement.getQualifiedName()),
pojoTypeElement);
}
}
>>>>>>> 82da060a119397a67512fb125eacabde113c1367
private void addPropertyModelsForFactoryMethodParameters(ExecutableElement factoryMethod, BuilderM builderModel) {
if (factoryMethod.getParameters().isEmpty()) {
return; |