Search in sources :

Example 1 with JInvocation

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

the class AbstractPresentationModelObjectClassGen method defineTryToCreateFunction.

/*
	@Override
	public Function tryToCreateFunction(MethodDescriptor methodDescriptor) {
		if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK))) {
			return new Function() {
				
				@Override
				public Object call(Object... args) {
					presentationModel.onClick();
					return null;
				}
			};
		}
		
		if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class))){
			return new Function() {
				
				@Override
				public Object call(Object... args) {
					boolean result = presentationModel.onLongClickWithEvent((AbstractViewEvent)args[0]);
					return (Boolean)result;
				}
			};
		}
		
		return null;
	}
	 */
public void defineTryToCreateFunction() {
    JMethod method = declarePublicMethodOverride("tryToCreateFunction", Function.class);
    JVar methodDescriptorParam = method.param(MethodDescriptor.class, "methodDescriptor");
    JBlock body = method.body();
    for (EventMethodInfo eventMethodInfo : presentationModelInfo.eventMethods()) {
        JInvocation getMethod = JExpr.invoke("createMethodDescriptor").arg(eventMethodInfo.name());
        if (eventMethodInfo.hasEventArg()) {
            getMethod.arg(codeModel.ref(eventMethodInfo.eventArgType()).dotclass());
        }
        JConditional conditional = body._if(methodDescriptorParam.invoke("equals").arg(getMethod));
        JBlock conditionalBody = conditional._then();
        //create Function.
        JDefinedClass anonymousFunction = codeModel.anonymousClass(Function.class);
        JMethod call = declarePublicMethodOverride(anonymousFunction, "call", Object.class);
        JVar argsVar = call.varParam(Object.class, "args");
        JBlock callBody = call.body();
        //call event method.
        JInvocation onEvent = presentationModelFieldWithoutThis.invoke(eventMethodInfo.name());
        if (eventMethodInfo.hasEventArg()) {
            AbstractJClass eventArgClass = codeModel.ref(eventMethodInfo.eventArgType());
            onEvent.arg(JExpr.cast(eventArgClass, argsVar.component(JExpr.lit(0))));
        }
        //call return.
        if (eventMethodInfo.hasReturn()) {
            JVar returnVar = callBody.decl(codeModel.ref(eventMethodInfo.nonPrimitiveReturnType()), "result", onEvent);
            callBody._return(returnVar);
        } else {
            callBody.add(onEvent);
            callBody._return(JExpr._null());
        }
        //return Function.
        conditionalBody._return(JExpr._new(anonymousFunction));
    }
    body._return(JExpr._null());
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JConditional(com.helger.jcodemodel.JConditional) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 2 with JInvocation

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

the class APTCodeModelHelper method getSuperCall.

public JInvocation getSuperCall(GeneratedClassHolder holder, JMethod superMethod) {
    IJExpression activitySuper = holder.getGeneratedClass().staticRef("super");
    JInvocation superCall = JExpr.invoke(activitySuper, superMethod);
    for (JVar param : superMethod.params()) {
        superCall.arg(param);
    }
    if (superMethod.hasVarArgs()) {
        superCall.arg(superMethod.varParam());
    }
    return superCall;
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) JVar(com.helger.jcodemodel.JVar)

Example 3 with JInvocation

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

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

the class RestHolder method implementGetCookie.

private void implementGetCookie(List<ExecutableElement> methods) {
    JMethod getCookieMethod = codeModelHelper.implementMethod(this, methods, "getCookie", STRING, STRING);
    if (getCookieMethod != null) {
        JInvocation cookieValue = JExpr.invoke(getAvailableCookiesField(), "get").arg(getCookieMethod.params().get(0));
        getCookieMethod.body()._return(cookieValue);
    }
}
Also used : JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 5 with JInvocation

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

the class RestHandler method setConverters.

private void setConverters(Element element, RestHolder holder) {
    List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "converters");
    JFieldVar restTemplateField = holder.getRestTemplateField();
    JBlock init = holder.getInit().body();
    init.add(invoke(restTemplateField, "getMessageConverters").invoke("clear"));
    for (DeclaredType converterType : converters) {
        JInvocation newConverter = codeModelHelper.newBeanOrEBean(converterType, holder.getInitContextParam());
        init.add(invoke(restTemplateField, "getMessageConverters").invoke("add").arg(newConverter));
    }
}
Also used : JFieldVar(com.helger.jcodemodel.JFieldVar) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

JInvocation (com.helger.jcodemodel.JInvocation)71 JVar (com.helger.jcodemodel.JVar)38 JBlock (com.helger.jcodemodel.JBlock)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)31 IJExpression (com.helger.jcodemodel.IJExpression)27 JMethod (com.helger.jcodemodel.JMethod)26 ExecutableElement (javax.lang.model.element.ExecutableElement)20 VariableElement (javax.lang.model.element.VariableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)14 TypeMirror (javax.lang.model.type.TypeMirror)14 JConditional (com.helger.jcodemodel.JConditional)11 JDefinedClass (com.helger.jcodemodel.JDefinedClass)9 AbstractJType (com.helger.jcodemodel.AbstractJType)5 JFieldVar (com.helger.jcodemodel.JFieldVar)5 JTryBlock (com.helger.jcodemodel.JTryBlock)5 ArrayList (java.util.ArrayList)4 DeclaredType (javax.lang.model.type.DeclaredType)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3