Search in sources :

Example 1 with IJExpression

use of com.helger.jcodemodel.IJExpression in project adt4j by sviperll.

the class EqualsMethod method appendNonnullPrimitive.

private void appendNonnullPrimitive(AbstractJType type, IJExpression value1, IJExpression value2, boolean isLast) {
    IJExpression equalsCondition;
    IJExpression notEqualsCondition;
    if (!type.name().equals("float") && !type.name().equals("doable")) {
        equalsCondition = value1.eq(value2);
        notEqualsCondition = value1.ne(value2);
    } else {
        IJExpression epsilon = type.name().equals("float") ? JExpr.lit(floatCustomization.floatEpsilon()) : JExpr.lit(floatCustomization.doubleEpsilon());
        JInvocation invocation = types._Math.staticInvoke("abs");
        invocation.arg(value1.minus(value2));
        equalsCondition = invocation.lte(epsilon);
        notEqualsCondition = invocation.gt(epsilon);
    }
    if (isLast) {
        body._return(equalsCondition);
    } else {
        JConditional _if = body._if(notEqualsCondition);
        _if._then()._return(JExpr.FALSE);
    }
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) JConditional(com.helger.jcodemodel.JConditional)

Example 2 with IJExpression

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

the class APTCodeModelHelper method copy.

public void copy(JBlock body, JBlock newBody) {
    for (Object statement : body.getContents()) {
        if (statement instanceof JVar) {
            JVar var = (JVar) statement;
            try {
                Field varInitField = JVar.class.getDeclaredField("m_aInitExpr");
                varInitField.setAccessible(true);
                IJExpression varInit = (IJExpression) varInitField.get(var);
                newBody.decl(var.type(), var.name(), varInit);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            newBody.add((IJStatement) statement);
        }
    }
}
Also used : Field(java.lang.reflect.Field) IJExpression(com.helger.jcodemodel.IJExpression) JVar(com.helger.jcodemodel.JVar)

Example 3 with IJExpression

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

the class BundleHelper method getExpressionToRestoreFromBundle.

public IJExpression getExpressionToRestoreFromBundle(AbstractJClass variableClass, IJExpression bundle, IJExpression extraKey, JMethod method) {
    IJExpression expressionToRestore;
    if ("getParcelableArray".equals(methodNameToRestore)) {
        AbstractJClass erasure;
        if (upperBound != null) {
            erasure = codeModelHelper.typeMirrorToJClass(upperBound).erasure().array();
        } else {
            erasure = variableClass.elementType().erasure().array();
        }
        expressionToRestore = environment.getJClass(org.androidannotations.api.bundle.BundleHelper.class).staticInvoke("getParcelableArray").arg(bundle).arg(extraKey).arg(erasure.dotclass());
    } else {
        expressionToRestore = JExpr.invoke(bundle, methodNameToRestore).arg(extraKey);
    }
    if (parcelerBean) {
        expressionToRestore = environment.getJClass(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("unwrap").arg(expressionToRestore);
    }
    if (restoreCallNeedCastStatement) {
        expressionToRestore = JExpr.cast(variableClass, expressionToRestore);
        if (restoreCallNeedsSuppressWarning) {
            codeModelHelper.addSuppressWarnings(method, "unchecked");
        }
    }
    return expressionToRestore;
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 4 with IJExpression

use of com.helger.jcodemodel.IJExpression 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)

Example 5 with IJExpression

use of com.helger.jcodemodel.IJExpression 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)

Aggregations

IJExpression (com.helger.jcodemodel.IJExpression)56 JVar (com.helger.jcodemodel.JVar)33 JBlock (com.helger.jcodemodel.JBlock)31 JInvocation (com.helger.jcodemodel.JInvocation)28 AbstractJClass (com.helger.jcodemodel.AbstractJClass)24 TypeMirror (javax.lang.model.type.TypeMirror)21 JMethod (com.helger.jcodemodel.JMethod)16 ExecutableElement (javax.lang.model.element.ExecutableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)15 VariableElement (javax.lang.model.element.VariableElement)12 JConditional (com.helger.jcodemodel.JConditional)7 JFieldVar (com.helger.jcodemodel.JFieldVar)7 JDefinedClass (com.helger.jcodemodel.JDefinedClass)5 BundleHelper (org.androidannotations.helper.BundleHelper)5 JTryBlock (com.helger.jcodemodel.JTryBlock)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 OnSeekBarChangeListenerHolder (org.androidannotations.holder.OnSeekBarChangeListenerHolder)2