Search in sources :

Example 1 with MethodFoundListener

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);
        }
    });
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) GeneratedTypeElement(com.abubusoft.kripton.processor.element.GeneratedTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotationFoundListener(com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.AnnotationFoundListener) BindSqlInsert(com.abubusoft.kripton.android.annotation.BindSqlInsert) BindSqlUpdate(com.abubusoft.kripton.android.annotation.BindSqlUpdate) SQLiteDaoDefinition(com.abubusoft.kripton.processor.sqlite.model.SQLiteDaoDefinition) ModelAnnotation(com.abubusoft.kripton.processor.core.ModelAnnotation) SQLiteModelMethod(com.abubusoft.kripton.processor.sqlite.model.SQLiteModelMethod) MethodFoundListener(com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.MethodFoundListener) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) BindSqlSelect(com.abubusoft.kripton.android.annotation.BindSqlSelect)

Example 2 with MethodFoundListener

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;
}
Also used : One(com.abubusoft.kripton.common.One) ExecutableElement(javax.lang.model.element.ExecutableElement) MethodFoundListener(com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.MethodFoundListener)

Aggregations

MethodFoundListener (com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.MethodFoundListener)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 BindSqlInsert (com.abubusoft.kripton.android.annotation.BindSqlInsert)1 BindSqlSelect (com.abubusoft.kripton.android.annotation.BindSqlSelect)1 BindSqlUpdate (com.abubusoft.kripton.android.annotation.BindSqlUpdate)1 One (com.abubusoft.kripton.common.One)1 ModelAnnotation (com.abubusoft.kripton.processor.core.ModelAnnotation)1 AnnotationFoundListener (com.abubusoft.kripton.processor.core.reflect.AnnotationUtility.AnnotationFoundListener)1 GeneratedTypeElement (com.abubusoft.kripton.processor.element.GeneratedTypeElement)1 SQLiteDaoDefinition (com.abubusoft.kripton.processor.sqlite.model.SQLiteDaoDefinition)1 SQLiteModelMethod (com.abubusoft.kripton.processor.sqlite.model.SQLiteModelMethod)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1