Search in sources :

Example 86 with AbstractJClass

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

the class ViewBindingObjectClassGen method defineMapBindingAttributesMethod.

/**
	 * 
    	@Override
    	public void mapBindingAttributes(BindingAttributeMappings<ImageView> mappings) {
    		mappings.mapOneWayProperty(ImageAlphaAttribute.class, "imageAlpha");
    		mappings.mapOneWayProperty(MaxWidthAttribute.class, "maxWidth");
    		mappings.mapOneWayProperty(MaxHeightAttribute.class, "maxHeight");
    		
    		customViewBinding.mapBindingAttributes(mappings);
    	}
	 * 
	 */
public void defineMapBindingAttributesMethod() {
    JMethod method = definedClass.method(JMod.PUBLIC, codeModel.VOID, "mapBindingAttributes");
    method.annotate(Override.class);
    AbstractJClass bindingAttributeMappingsType = codeModel.ref(BindingAttributeMappings.class).narrow(viewClass);
    JVar mappingsParam = method.param(bindingAttributeMappingsType, "mappings");
    JBlock body = method.body();
    for (SimpleOneWayPropertyInfo info : simpleOneWayPropertyInfoList) {
        body.invoke(mappingsParam, "mapOneWayProperty").arg(info.getBindingClass().dotclass()).arg(info.propertyName());
    }
    body.invoke(customViewBindingFieldWithoutThis, "mapBindingAttributes").arg(mappingsParam);
}
Also used : BindingAttributeMappings(org.robobinding.viewbinding.BindingAttributeMappings) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 87 with AbstractJClass

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

the class AbstractListenerHandler method castArgumentIfNecessary.

protected final IJExpression castArgumentIfNecessary(T holder, String baseType, JVar param, Element element) {
    IJExpression argument = param;
    TypeMirror typeMirror = element.asType();
    if (!baseType.equals(typeMirror.toString())) {
        AbstractJClass typeMirrorToJClass = codeModelHelper.typeMirrorToJClass(typeMirror);
        argument = JExpr.cast(typeMirrorToJClass, param);
    }
    return argument;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 88 with AbstractJClass

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

the class AppHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentHolder holder, Element element, Element param) {
    String applicationQualifiedName = param.asType().toString();
    AbstractJClass applicationClass = getJClass(applicationQualifiedName + classSuffix());
    targetBlock.add(fieldRef.assign(applicationClass.staticInvoke(EApplicationHolder.GET_APPLICATION_INSTANCE)));
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 89 with AbstractJClass

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

the class BackgroundHandler method process.

@Override
public void process(Element element, EComponentHolder holder) throws Exception {
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    JBlock previousMethodBody = codeModelHelper.removeBody(delegatingMethod);
    JDefinedClass anonymousTaskClass = getCodeModel().anonymousClass(BackgroundExecutor.Task.class);
    JMethod executeMethod = anonymousTaskClass.method(JMod.PUBLIC, getCodeModel().VOID, "execute");
    executeMethod.annotate(Override.class);
    // Catch exception in user code
    JTryBlock tryBlock = executeMethod.body()._try();
    tryBlock.body().add(previousMethodBody);
    JCatchBlock catchBlock = tryBlock._catch(getClasses().THROWABLE);
    JVar caughtException = catchBlock.param("e");
    IJStatement uncaughtExceptionCall = //
    getClasses().THREAD.staticInvoke(//
    "getDefaultUncaughtExceptionHandler").invoke(//
    "uncaughtException").arg(//
    getClasses().THREAD.staticInvoke("currentThread")).arg(caughtException);
    catchBlock.body().add(uncaughtExceptionCall);
    Background annotation = element.getAnnotation(Background.class);
    String id = annotation.id();
    long delay = annotation.delay();
    String serial = annotation.serial();
    AbstractJClass backgroundExecutorClass = getJClass(BackgroundExecutor.class);
    JInvocation newTask = _new(anonymousTaskClass).arg(lit(id)).arg(lit(delay)).arg(lit(serial));
    JInvocation executeCall = backgroundExecutorClass.staticInvoke("execute").arg(newTask);
    delegatingMethod.body().add(executeCall);
}
Also used : BackgroundExecutor(org.androidannotations.api.BackgroundExecutor) Background(org.androidannotations.annotations.Background) JDefinedClass(com.helger.jcodemodel.JDefinedClass) ExecutableElement(javax.lang.model.element.ExecutableElement) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) IJStatement(com.helger.jcodemodel.IJStatement) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JTryBlock(com.helger.jcodemodel.JTryBlock) JCatchBlock(com.helger.jcodemodel.JCatchBlock) JVar(com.helger.jcodemodel.JVar)

Example 90 with AbstractJClass

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

the class SharedPrefHolder method createEditorFieldMethods.

public void createEditorFieldMethods(ExecutableElement method, IJExpression keyExpression) {
    String returnType = method.getReturnType().toString();
    EditorFieldHolder editorFieldHolder = EDITOR_FIELD_BY_TYPE.get(returnType);
    AbstractJClass editorFieldClass = getJClass(editorFieldHolder.fieldClass);
    String fieldName = method.getSimpleName().toString();
    JMethod editorFieldMethod = editorClass.method(PUBLIC, editorFieldClass.narrow(editorClass), fieldName);
    String docComment = getProcessingEnvironment().getElementUtils().getDocComment(method);
    codeModelHelper.addTrimmedDocComment(editorFieldMethod, docComment);
    editorFieldMethod.body()._return(JExpr.invoke(editorFieldHolder.fieldMethodName).arg(keyExpression));
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)125 JVar (com.helger.jcodemodel.JVar)48 JMethod (com.helger.jcodemodel.JMethod)36 JBlock (com.helger.jcodemodel.JBlock)35 JInvocation (com.helger.jcodemodel.JInvocation)31 TypeMirror (javax.lang.model.type.TypeMirror)24 IJExpression (com.helger.jcodemodel.IJExpression)23 JDefinedClass (com.helger.jcodemodel.JDefinedClass)19 VariableElement (javax.lang.model.element.VariableElement)14 JFieldVar (com.helger.jcodemodel.JFieldVar)13 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)9 ExecutableElement (javax.lang.model.element.ExecutableElement)9 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)8 JConditional (com.helger.jcodemodel.JConditional)8 JTypeVar (com.helger.jcodemodel.JTypeVar)8 DeclaredType (javax.lang.model.type.DeclaredType)8 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)6 JFieldRef (com.helger.jcodemodel.JFieldRef)6 ArrayList (java.util.ArrayList)6 BundleHelper (org.androidannotations.helper.BundleHelper)6