use of com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.MethodFoundListener in project kripton by xcesco.
the class BindDataSourceSubProcessor method fillMethods.
/**
* @param currentDaoDefinition
* @param daoElement
*/
private void fillMethods(final SQLiteDaoDefinition currentDaoDefinition, Element daoElement) {
// create method for dao
SqlBuilderHelper.forEachMethods((TypeElement) daoElement, new MethodFoundListener() {
@Override
public void onMethod(ExecutableElement element) {
if (excludedMethods.contains(element.getSimpleName().toString()))
return;
final List<ModelAnnotation> annotationList = new ArrayList<>();
// optional annotations
final List<ModelAnnotation> supportAnnotationList = new ArrayList<>();
AnnotationUtility.forEachAnnotations(element, new AnnotationFoundListener() {
@Override
public void onAcceptAnnotation(Element element, String annotationClassName, Map<String, String> attributes) {
if (// @formatter:off
annotationClassName.equals(BindSqlInsert.class.getCanonicalName()) || annotationClassName.equals(BindSqlUpdate.class.getCanonicalName()) || annotationClassName.equals(BindSqlDelete.class.getCanonicalName()) || annotationClassName.equals(BindSqlSelect.class.getCanonicalName()) || annotationClassName.equals(BindContentProviderEntry.class.getCanonicalName())) // @formatter:on
{
ModelAnnotation annotation = new ModelAnnotation(annotationClassName, attributes);
annotationList.add(annotation);
}
// we don't insert annotation
}
});
// AssertKripton. assertTrue(annotationList.size()==1, "Dao
// definition '%s' has method '%s' that is not correctly
// annotated", currentDaoDefinition.getName(),
// element.getSimpleName());
annotationList.addAll(supportAnnotationList);
final SQLiteModelMethod currentMethod = new SQLiteModelMethod(currentDaoDefinition, element, annotationList);
addWithCheckMethod(currentDaoDefinition, currentMethod);
}
private void addWithCheckMethod(SQLiteDaoDefinition currentDaoDefinition, SQLiteModelMethod newMethod) {
SQLiteModelMethod oldMethod = currentDaoDefinition.findPropertyByName(newMethod.getName());
// ASSERT: same name and same number
if (oldMethod != null && oldMethod.getParameters().size() == newMethod.getParameters().size()) {
boolean sameParameters = true;
for (int i = 0; i < oldMethod.getParameters().size(); i++) {
if (!oldMethod.getParameters().get(i).value1.equals(newMethod.getParameters().get(i).value1)) {
sameParameters = false;
break;
}
}
AssertKripton.failWithInvalidMethodSignException(sameParameters, newMethod, "conflict between generated method and declared method.");
}
// add method
currentDaoDefinition.add(newMethod);
}
});
}
use of com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.MethodFoundListener in project kripton by xcesco.
the class BindM2MBuilder method isMethodAlreadyDefined.
/**
* analyze DAO definition to check if method is already defined
*
* @param entity
* @param methodName
* @return
*/
private boolean isMethodAlreadyDefined(M2MEntity entity, final String methodName) {
final One<Boolean> found = new One<Boolean>(false);
SqlBuilderHelper.forEachMethods(entity.daoElement, new MethodFoundListener() {
@Override
public void onMethod(ExecutableElement executableMethod) {
if (executableMethod.getSimpleName().toString().equals(methodName)) {
found.value0 = true;
}
}
});
return found.value0;
}
Aggregations