Search in sources :

Example 1 with JClassAlreadyExistsException

use of com.helger.jcodemodel.JClassAlreadyExistsException in project RoboBinding by RoboBinding.

the class ViewBindingObjectClassGen method defineSimpleOneWayPropertyClasses.

/**
	 * 
    	private static class ImageAlphaAttribute implements OneWayPropertyViewAttribute<ImageView, Integer> {
    		@Override
    		public void updateView(ImageView view, Integer newValue) {
    			view.setImageAlpha(newValue);
    		}
    	}
     *
	 */
public void defineSimpleOneWayPropertyClasses() {
    for (SimpleOneWayPropertyInfo propInfo : simpleOneWayPropertyInfoList) {
        JDefinedClass definedBindingAttributeClass = propInfo.defineBindingClass(new ClassDefinitionCallback() {

            @Override
            public JDefinedClass define(String typeName) {
                try {
                    return definedClass._class(JMod.PUBLIC | JMod.STATIC, typeName);
                } catch (JClassAlreadyExistsException e) {
                    throw new RuntimeException("Class '" + typeName + "' already exists", e);
                }
            }
        });
        AbstractJClass propertyClass = codeModel.ref(propInfo.propertyType());
        AbstractJClass oneWayPropertyInterface = codeModel.ref(OneWayPropertyViewAttribute.class).narrow(viewClass, propertyClass);
        definedBindingAttributeClass._implements(oneWayPropertyInterface);
        JMethod method = definedBindingAttributeClass.method(JMod.PUBLIC, codeModel.VOID, "updateView");
        method.annotate(Override.class);
        JVar viewParam = method.param(viewClass, "view");
        JVar newValueParam = method.param(propertyClass, "newValue");
        JBlock body = method.body();
        body.invoke(viewParam, propInfo.propertySetter()).arg(newValueParam);
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) OneWayPropertyViewAttribute(org.robobinding.viewattribute.property.OneWayPropertyViewAttribute) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 2 with JClassAlreadyExistsException

use of com.helger.jcodemodel.JClassAlreadyExistsException in project RoboBinding by RoboBinding.

the class ViewBindingProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    RoundContext roundContext = new RoundContext(roundEnv, processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getMessager());
    Set<WrappedTypeElement> typeElements = roundContext.typeElementsAnnotatedWith(ViewBinding.class, new ViewBindingFilter());
    for (WrappedTypeElement typeElement : typeElements) {
        String viewBindingObjectTypeName = ViewBindingLoader.getViewBindingClassName(typeElement.binaryName());
        ViewBindingInfoBuilder builder = new ViewBindingInfoBuilder(typeElement, viewBindingObjectTypeName);
        ViewBindingInfo info = builder.build();
        Logger log = typeElement.logger();
        try {
            generateViewBindingObjectSourceFile(info, log);
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (JClassAlreadyExistsException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) IOException(java.io.IOException) Logger(org.robobinding.codegen.apt.Logger) RoundContext(org.robobinding.codegen.apt.RoundContext)

Example 3 with JClassAlreadyExistsException

use of com.helger.jcodemodel.JClassAlreadyExistsException in project androidannotations by androidannotations.

the class RInnerClass method extractIdStaticRef.

public static JFieldRef extractIdStaticRef(AndroidAnnotationsEnvironment environment, String layoutFieldQualifiedName) {
    if (layoutFieldQualifiedName != null) {
        int fieldSuffix = layoutFieldQualifiedName.lastIndexOf('.');
        String fieldName = layoutFieldQualifiedName.substring(fieldSuffix + 1);
        String rInnerClassName = layoutFieldQualifiedName.substring(0, fieldSuffix);
        int innerClassSuffix = rInnerClassName.lastIndexOf('.');
        String rClassQualifiedName = rInnerClassName.substring(0, innerClassSuffix);
        String innerClassSimpleName = rInnerClassName.substring(innerClassSuffix + 1);
        JDirectClass rClass = (JDirectClass) environment.getJClass(rClassQualifiedName);
        AbstractJClass innerClass = null;
        for (JDirectClass clazz : rClass.classes()) {
            if (clazz.name().equals(innerClassSimpleName)) {
                innerClass = clazz;
                break;
            }
        }
        if (innerClass == null) {
            try {
                innerClass = rClass._class(innerClassSimpleName);
            } catch (JClassAlreadyExistsException e) {
            // never happens, since we already checked the inner class does not exist
            }
        }
        return innerClass.staticRef(fieldName);
    } else {
        return null;
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JDirectClass(com.helger.jcodemodel.JDirectClass) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 4 with JClassAlreadyExistsException

use of com.helger.jcodemodel.JClassAlreadyExistsException in project RoboBinding by RoboBinding.

the class PresentationModelProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    RoundContext roundContext = new RoundContext(roundEnv, processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getMessager());
    Set<WrappedTypeElement> typeElements = roundContext.typeElementsAnnotatedWith(PresentationModel.class, new PresentationModelFilter());
    for (WrappedTypeElement typeElement : typeElements) {
        String presentationModelObjectTypeName = PresentationModelObjectLoader.getObjectClassName(typeElement.binaryName());
        PresentationModelInfoBuilder builder = new PresentationModelInfoBuilder(typeElement, presentationModelObjectTypeName, true);
        PresentationModelInfo presentationModelInfo = builder.build();
        Logger log = typeElement.logger();
        ProcessingContext context = new ProcessingContext(processingEnv.getTypeUtils(), processingEnv.getElementUtils(), processingEnv.getMessager());
        try {
            if (isItemPresentationModelAlso(typeElement)) {
                createItemPresentationModelObjectSourceFiles(presentationModelInfo, context);
            } else {
                generateAllClasses(presentationModelInfo, context, log);
            }
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (JClassAlreadyExistsException e) {
            log.error(e);
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : ProcessingContext(org.robobinding.codegen.apt.ProcessingContext) WrappedTypeElement(org.robobinding.codegen.apt.element.WrappedTypeElement) IOException(java.io.IOException) Logger(org.robobinding.codegen.apt.Logger) RoundContext(org.robobinding.codegen.apt.RoundContext) JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) PresentationModelInfo(org.robobinding.codegen.presentationmodel.PresentationModelInfo)

Example 5 with JClassAlreadyExistsException

use of com.helger.jcodemodel.JClassAlreadyExistsException in project adt4j by sviperll.

the class FinalValueClassModel method createMethodBuilder.

MethodBuilder createMethodBuilder(Serialization serialization) {
    if (isError)
        return new MethodBuilder(null, null);
    else {
        JFieldVar acceptorField = buildAcceptorField();
        Map<String, JDefinedClass> caseClasses;
        try {
            caseClasses = buildCaseClasses(serialization);
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException("Unexpected exception :)", ex);
        }
        Caching hashCode = environment.hashCodeCaching();
        if (!hashCode.enabled())
            return new MethodBuilder(caseClasses, acceptorField);
        else {
            JFieldVar hashCodeField = buildHashCodeCachedValueField(serialization);
            return new MethodBuilder(caseClasses, acceptorField, hashCodeField);
        }
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) Caching(com.github.sviperll.adt4j.Caching) JFieldVar(com.helger.jcodemodel.JFieldVar) JDefinedClass(com.helger.jcodemodel.JDefinedClass)

Aggregations

JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)7 JDefinedClass (com.helger.jcodemodel.JDefinedClass)4 AbstractJClass (com.helger.jcodemodel.AbstractJClass)3 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)2 JMethod (com.helger.jcodemodel.JMethod)2 IOException (java.io.IOException)2 Logger (org.robobinding.codegen.apt.Logger)2 RoundContext (org.robobinding.codegen.apt.RoundContext)2 WrappedTypeElement (org.robobinding.codegen.apt.element.WrappedTypeElement)2 Caching (com.github.sviperll.adt4j.Caching)1 GenerateValueClassForVisitor (com.github.sviperll.adt4j.GenerateValueClassForVisitor)1 GenerateValueClassForVisitorProcessor (com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)1 FieldConfiguration (com.github.sviperll.adt4j.model.config.FieldConfiguration)1 PredicateConfigutation (com.github.sviperll.adt4j.model.config.PredicateConfigutation)1 ValueClassConfiguration (com.github.sviperll.adt4j.model.config.ValueClassConfiguration)1 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)1 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)1 JBlock (com.helger.jcodemodel.JBlock)1 JDirectClass (com.helger.jcodemodel.JDirectClass)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1