Search in sources :

Example 96 with JMethod

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

the class TextWatcherHolder method createOnTextChanged.

private void createOnTextChanged() {
    JPrimitiveType intClass = holder.getCodeModel().INT;
    JMethod onTextChangedMethod = listenerClass.method(JMod.PUBLIC, holder.getCodeModel().VOID, "onTextChanged");
    onTextChangedMethod.annotate(Override.class);
    onTextChangedBody = onTextChangedMethod.body();
    onTextChangedCharSequenceParam = onTextChangedMethod.param(holder.getClasses().CHAR_SEQUENCE, "s");
    onTextChangedStartParam = onTextChangedMethod.param(intClass, "start");
    onTextChangedBeforeParam = onTextChangedMethod.param(intClass, "before");
    onTextChangedCountParam = onTextChangedMethod.param(intClass, "count");
}
Also used : JPrimitiveType(com.helger.jcodemodel.JPrimitiveType) JMethod(com.helger.jcodemodel.JMethod)

Example 97 with JMethod

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

the class EActivityHandler method process.

@Override
public void process(Element element, EActivityHolder holder) {
    List<JFieldRef> fieldRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.LAYOUT, false);
    JFieldRef contentViewId = null;
    if (fieldRefs.size() == 1) {
        contentViewId = fieldRefs.get(0);
    }
    if (contentViewId != null) {
        JBlock onCreateBody = holder.getOnCreate().body();
        JMethod setContentView = holder.getSetContentViewLayout();
        onCreateBody.invoke(setContentView).arg(contentViewId);
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 98 with JMethod

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

the class EServiceHolder method setOnDestroy.

private void setOnDestroy() {
    JMethod onDestroy = generatedClass.method(PUBLIC, getCodeModel().VOID, "onDestroy");
    onDestroy.annotate(Override.class);
    JBlock onDestroyBody = onDestroy.body();
    onDestroyBeforeSuperBlock = onDestroyBody.blockSimple();
    onDestroyBody.invoke(JExpr._super(), onDestroy);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod)

Example 99 with JMethod

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

the class EViewHolder method createConstructorAndBuilder.

private void createConstructorAndBuilder() {
    List<ExecutableElement> constructors = new ArrayList<>();
    for (Element e : annotatedElement.getEnclosedElements()) {
        if (e.getKind() == CONSTRUCTOR) {
            constructors.add((ExecutableElement) e);
        }
    }
    for (ExecutableElement userConstructor : constructors) {
        JMethod copyConstructor = generatedClass.constructor(PUBLIC);
        JMethod staticHelper = generatedClass.method(PUBLIC | STATIC, generatedClass._extends(), "build");
        codeModelHelper.generify(staticHelper, getAnnotatedElement());
        JBlock body = copyConstructor.body();
        JInvocation superCall = body.invoke("super");
        AbstractJClass narrowedGeneratedClass = narrow(generatedClass);
        JInvocation newInvocation = JExpr._new(narrowedGeneratedClass);
        for (VariableElement param : userConstructor.getParameters()) {
            String paramName = param.getSimpleName().toString();
            AbstractJClass paramType = codeModelHelper.typeMirrorToJClass(param.asType());
            copyConstructor.param(paramType, paramName);
            staticHelper.param(paramType, paramName);
            superCall.arg(JExpr.ref(paramName));
            newInvocation.arg(JExpr.ref(paramName));
        }
        JVar newCall = staticHelper.body().decl(narrowedGeneratedClass, "instance", newInvocation);
        staticHelper.body().invoke(newCall, getOnFinishInflate());
        staticHelper.body()._return(newCall);
        body.invoke(getInit());
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 100 with JMethod

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

the class KeyEventCallbackMethodsDelegate method createOnKeyLongPressMethod.

private void createOnKeyLongPressMethod() {
    JMethod method = getGeneratedClass().method(PUBLIC, codeModel().BOOLEAN, "onKeyLongPress");
    method.annotate(Override.class);
    JVar keyCode = method.param(codeModel().INT, "keyCode");
    onKeyLongPressKeyEventParam = method.param(getClasses().KEY_EVENT, "keyEvent");
    JBlock methodBody = method.body();
    onKeyLongPressSwitchBody = methodBody._switch(keyCode);
    methodBody._return(_super().invoke(method).arg(keyCode).arg(onKeyLongPressKeyEventParam));
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Aggregations

JMethod (com.helger.jcodemodel.JMethod)122 JBlock (com.helger.jcodemodel.JBlock)73 JVar (com.helger.jcodemodel.JVar)56 AbstractJClass (com.helger.jcodemodel.AbstractJClass)36 JInvocation (com.helger.jcodemodel.JInvocation)26 JDefinedClass (com.helger.jcodemodel.JDefinedClass)20 IJExpression (com.helger.jcodemodel.IJExpression)15 ExecutableElement (javax.lang.model.element.ExecutableElement)13 JFieldVar (com.helger.jcodemodel.JFieldVar)10 JConditional (com.helger.jcodemodel.JConditional)8 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JTypeVar (com.helger.jcodemodel.JTypeVar)7 TypeMirror (javax.lang.model.type.TypeMirror)7 VariableElement (javax.lang.model.element.VariableElement)6 JFieldRef (com.helger.jcodemodel.JFieldRef)5 JPrimitiveType (com.helger.jcodemodel.JPrimitiveType)5 ArrayList (java.util.ArrayList)5 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)4 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)4 AbstractJType (com.helger.jcodemodel.AbstractJType)4