private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ") .plus(valueVar.invoke("getClass").invoke("toString"))); }
private JMethod addPublicSetMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass.owner().VOID, SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
private JMethod addPublicWithMethod(JDefinedClass jclass, JMethod internalSetMethod) { JMethod method = jclass.method(PUBLIC, jclass, BUILDER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JBlock notFound = body._if(JOp.not(invoke(internalSetMethod).arg(nameParam).arg(valueParam)))._then(); // if we have additional properties, then put value. JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { JType additionalPropertiesType = ((JClass) (getAdditionalProperties.type())).getTypeParameters().get(1); notFound.add(invoke(getAdditionalProperties).invoke("put").arg(nameParam) .arg(cast(additionalPropertiesType, valueParam))); } // else throw exception. else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } body._return(_this()); return method; }
.getIncoming() .invoke("getContext") .invoke("getManagedBuffer") .invoke("reallocIfNeeded") .arg(JExpr.lit(1024)) ); .getIncoming() .invoke("getContext") .invoke("getManagedBuffer") .invoke("reallocIfNeeded") .arg(JExpr.lit(1024)) ); .getIncoming() .invoke("getContext") .invoke("getManagedBuffer") .invoke("reallocIfNeeded") .arg(JExpr.lit(1024)) ); .getIncoming() .invoke("getContext") .invoke("getManagedBuffer") .invoke("reallocIfNeeded") .arg(JExpr.lit(1024)) );
private JMethod addPublicGetMethod(JDefinedClass jclass, JMethod internalGetMethod, JFieldRef notFoundValue) { JMethod method = jclass.method(PUBLIC, jclass.owner()._ref(Object.class), GETTER_NAME); JTypeVar returnType = method.generify("T"); method.type(returnType); Models.suppressWarnings(method, "unchecked"); JVar nameParam = method.param(String.class, "name"); JBlock body = method.body(); JVar valueVar = body.decl(jclass.owner()._ref(Object.class), "value", invoke(internalGetMethod).arg(nameParam).arg(notFoundValue)); JConditional found = method.body()._if(notFoundValue.ne(valueVar)); found._then()._return(cast(returnType, valueVar)); JBlock notFound = found._else(); JMethod getAdditionalProperties = jclass.getMethod("getAdditionalProperties", new JType[] {}); if (getAdditionalProperties != null) { notFound._return(cast(returnType, invoke(getAdditionalProperties).invoke("get").arg(nameParam))); } else { notFound._throw(illegalArgumentInvocation(jclass, nameParam)); } return method; }
.invoke("append").arg(JExpr.lit('@')) .invoke("append").arg( jclass.owner().ref(Integer.class).staticInvoke("toHexString").arg( jclass.owner().ref(System.class).staticInvoke("identityHashCode").arg(JExpr._this()))) .invoke("append").arg(JExpr.lit('['))); jclass.owner().ref(Arrays.class).staticInvoke("toString") .arg(JExpr.refthis(fieldVar.name())) .invoke("replace").arg(JExpr.lit('[')).arg(JExpr.lit('{')) .invoke("replace").arg(JExpr.lit(']')).arg(JExpr.lit('}')) .invoke("replace").arg(JExpr.lit(", ")).arg(JExpr.lit(","))))); } else { body.add(sb.invoke("append")
.invoke("getValue") .invoke("getBytes")); .invoke("getStrippedValue") .invoke("getBytes")); .invoke("getBytes")); JExpr._new(m.directClass(org.joda.time.LocalDateTime.class.getCanonicalName())).arg(tsVar)); jc._else().assign(returnValueHolder.ref("value"), localDateTimeVar.invoke("toDateTime") .arg(m.directClass(org.joda.time.DateTimeZone.class.getCanonicalName()).staticRef("UTC")).invoke("getMillis")); return block;
private void createAndInitLocationsField() { // private String[] locations; locationsField = jClass.field(JMod.PRIVATE, ref.string().array(), "locations"); // locations = getResources().getStringArray(R.array.locations); JFieldRef rArrayLocations = ref.r().staticRef("array").ref("locations"); JInvocation getResources = JExpr.invoke("getResources"); JInvocation getStringArray = getResources.invoke("getStringArray").arg(rArrayLocations); afterViewsBody.assign(locationsField, getStringArray); }
private void createOnCreateOptionsMenu() { JMethod onCreateOptionsMenu = null; JClass menu = !appDetails.isActionBarSherlock() ? ref.menu() : ref.sMenu(); onCreateOptionsMenu = jClass.method(JMod.PUBLIC, jCodeModel.BOOLEAN, "onCreateOptionsMenu"); JVar menuVar = onCreateOptionsMenu.param(menu, "menu"); onCreateOptionsMenu.annotate(ref.override()); JBlock onCreateOptionsMenuBody = onCreateOptionsMenu.body(); String getMenuInflater = appDetails.isActionBarSherlock() ? "getSupportMenuInflater" : "getMenuInflater"; JFieldRef rMenuMain = ref.r().staticRef("menu").ref("activity_main"); onCreateOptionsMenuBody.invoke(getMenuInflater).// invoke("inflate"). // arg(rMenuMain). // arg(menuVar); onCreateOptionsMenuBody._return(TRUE); }
private JMethod createDefaultConstructor(JDefinedClass definedClass) { JMethod constructor = definedClass.constructor(JMod.PUBLIC); constructor.body().invoke("super").invoke("aaa"); return constructor; }
private void createAsPrismContainerValueInObject(JDefinedClass definedClass) { JMethod getContainer = definedClass.method(JMod.PUBLIC, CLASS_MAP.get(PrismContainerValue.class), METHOD_AS_PRISM_CONTAINER_VALUE); getContainer.annotate(CLASS_MAP.get(Override.class)); //create method body JBlock body = getContainer.body(); body._return(JExpr.invoke(METHOD_AS_PRISM_CONTAINER).invoke(METHOD_CONTAINER_GET_VALUE)); }
private void createToStringMethod(JDefinedClass definedClass, String baseMethod) { JMethod toString = definedClass.getMethod("toString", new JType[]{}); if (toString == null) { toString = definedClass.method(JMod.PUBLIC, CLASS_MAP.get(String.class), METHOD_TO_STRING); } else { toString = recreateMethod(toString, definedClass); } toString.annotate(CLASS_MAP.get(Override.class)); JBlock body = toString.body(); JInvocation invocation = JExpr.invoke(baseMethod).invoke(METHOD_TO_STRING); body._return(invocation); }
JVar tab = forEachLocationBody.decl(ref.sTab(), "tab", getSupportActionBar.invoke("newTab")); forEachLocationBody.invoke(tab, "setText").arg(location); forEachLocationBody.invoke(tab, "setTabListener").arg(JExpr._this());
JInvocation getContext = getSupportActionbar.invoke("getThemedContext"); JVar contextVar = configureActionBarBody.decl(ref.context(), "context", getContext);
@Override protected JExpression fromRawEntity(EntityDescriptionGenerator.CreateFromRawEntityHolder holder, PropertyMirror propertyMirror) { JExpression getEntityId = holder.rawEntity.invoke("getLong").arg(JExpr.lit(propertyMirror.getSafeName())); JExpression loadEntity = holder.torchFactory .invoke("begin") .invoke("load") .invoke("type").arg(CodeModelTypes.ref(propertyMirror).dotclass()) .invoke("id").arg(getEntityId); return JOp.cond(JOp.ne(getEntityId, JExpr._null()), loadEntity, JExpr._null()); }
private void createHashCodeMethod(JDefinedClass definedClass, String baseMethodName) { JMethod hashCode = definedClass.getMethod(METHOD_HASH_CODE, new JType[]{}); if (hashCode == null) { hashCode = definedClass.method(JMod.PUBLIC, int.class, METHOD_HASH_CODE); } else { hashCode = recreateMethod(hashCode, definedClass); } hashCode.annotate(CLASS_MAP.get(Override.class)); JBlock body = hashCode.body(); body._return(JExpr.invoke(baseMethodName).invoke(METHOD_HASH_CODE)); }
JInvocation getTabAtMethod = JExpr.invoke("getSupportActionBar").invoke("getTabAt").arg(positionVar); JVar tabVar = onPageSelectedBody.decl(ref.sTab(), "tab", getTabAtMethod); JInvocation getSupportActionBarInvoke = JExpr.invoke("getSupportActionBar");
@Override public JStatement writeType(JCodeModel model, JVar generator, JVar value) { JClass timeFormat = model.ref(ISODateTimeFormat.class); return generator.invoke("writeString") .arg(timeFormat.staticInvoke("date").invoke("print").arg(value.invoke("getTimeInMillis"))); }
private JInvocation illegalArgumentInvocation(JDefinedClass jclass, String propertyName, JType propertyType, JVar valueVar) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"" + propertyName + "\" is of type \"" + propertyType.fullName() + "\", but got ") .plus(valueVar.invoke("getClass").invoke("toString"))); }
private void handleIdProperty(JCodeModel model, JBlock body, Shape shape, JVar sourceVar, JVar jsonVar) { if (shape.getNodeKind() == NodeKind.IRI) { URI targetClass = shape.getTargetClass(); JBlock then = body._if(sourceVar.invoke("getId").ne(JExpr._null()))._then(); String methodName = owlReasoner.isEnumerationClass(targetClass) ? "getLocalName" : "stringValue"; then.add( jsonVar.invoke("writeStringField").arg(JExpr.lit("id")).arg( sourceVar.invoke("getId").invoke(methodName)) ); } }