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);
}
}
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;
}
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;
}
}
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;
}
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);
}
}
}
Aggregations