Search in sources :

Example 6 with JBlock

use of com.helger.jcodemodel.JBlock 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 7 with JBlock

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

the class InjectHelper method processMethod.

private void processMethod(Element element, T holder) {
    ExecutableElement executableElement = (ExecutableElement) element;
    VariableElement param = executableElement.getParameters().get(0);
    String methodName = executableElement.getSimpleName().toString();
    JBlock block = createBlock(holder, true);
    AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
    JVar fieldRef = block.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
    handler.assignValue(block, fieldRef, holder, element, param);
    block.add(JExpr.invoke(methodName).arg(fieldRef));
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 8 with JBlock

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

the class EActivityHolder method setContentViewMethod.

private JMethod setContentViewMethod(AbstractJType[] paramTypes, String[] paramNames) {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "setContentView");
    method.annotate(Override.class);
    List<JVar> params = new ArrayList<>();
    for (int i = 0; i < paramTypes.length; i++) {
        JVar param = method.param(paramTypes[i], paramNames[i]);
        params.add(param);
    }
    JBlock body = method.body();
    JInvocation superCall = body.invoke(JExpr._super(), method);
    for (JVar arg : params) {
        superCall.arg(arg);
    }
    viewNotifierHelper.invokeViewChanged(body);
    return method;
}
Also used : ArrayList(java.util.ArrayList) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 9 with JBlock

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

the class EActivityHolder method setOnStart.

// CHECKSTYLE:OFF
private void setOnStart() {
    JMethod method = generatedClass.method(JMod.PUBLIC, getCodeModel().VOID, "onStart");
    method.annotate(Override.class);
    JBlock body = method.body();
    onStartBeforeSuperBlock = body.blockSimple();
    body.invoke(_super(), method);
    onStartAfterSuperBlock = body.blockSimple();
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 10 with JBlock

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

the class EActivityHolder method setOnRetainNonConfigurationInstance.

private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
    AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
    TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper);
    TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
    String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
    if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
        onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
    }
    NonConfigurationHolder ncHolder = getNonConfigurationHolder();
    JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
    JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
    onRetainNonConfigurationInstanceMethod.annotate(Override.class);
    JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
    onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
    IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
    methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
    onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple();
    methodBody._return(onRetainNonConfigurationInstance);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) AnnotationHelper(org.androidannotations.helper.AnnotationHelper) TypeElement(javax.lang.model.element.TypeElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

JBlock (com.helger.jcodemodel.JBlock)155 JVar (com.helger.jcodemodel.JVar)86 JMethod (com.helger.jcodemodel.JMethod)75 AbstractJClass (com.helger.jcodemodel.AbstractJClass)40 JInvocation (com.helger.jcodemodel.JInvocation)38 IJExpression (com.helger.jcodemodel.IJExpression)31 ExecutableElement (javax.lang.model.element.ExecutableElement)26 JFieldRef (com.helger.jcodemodel.JFieldRef)19 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 VariableElement (javax.lang.model.element.VariableElement)15 JFieldVar (com.helger.jcodemodel.JFieldVar)13 TypeMirror (javax.lang.model.type.TypeMirror)13 JConditional (com.helger.jcodemodel.JConditional)10 JTryBlock (com.helger.jcodemodel.JTryBlock)9 JCatchBlock (com.helger.jcodemodel.JCatchBlock)4 TypeElement (javax.lang.model.element.TypeElement)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 AbstractJType (com.helger.jcodemodel.AbstractJType)2 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 IJStatement (com.helger.jcodemodel.IJStatement)2