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);
}
}
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);
}
}
}
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;
}
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);
}
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;
}
Aggregations