/** * Generate getter method name for property. * * @param propertyName * @param type * @param node * @return */ public String getGetterName(String propertyName, JType type, JsonNode node) { propertyName = getPropertyNameForAccessor(propertyName, node); String prefix = type.equals(type.owner()._ref(boolean.class)) ? "is" : "get"; String getterName; if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) { getterName = prefix + propertyName; } else { getterName = prefix + capitalize(propertyName); } if (getterName.equals("getClass")) { getterName = "getClass_"; } return getterName; }
JFieldRef getOrAddNotFoundVar(JDefinedClass jclass) { jclass.field(PROTECTED | STATIC | FINAL, Object.class, NOT_FOUND_VALUE_FIELD, _new(jclass.owner()._ref(Object.class))); return jclass.staticRef(NOT_FOUND_VALUE_FIELD); }
/** * Start generating code * @return workspace variables */ @Override public JVar[] renderStart(ClassGenerator<?> g, HoldingContainer[] inputVariables, FieldReference fieldReference){ JVar[] workspaceJVars = new JVar[5]; workspaceJVars[0] = g.declareClassField("returnOI", g.getModel()._ref(ObjectInspector.class)); workspaceJVars[1] = g.declareClassField("udfInstance", g.getModel()._ref(GenericUDF.class)); workspaceJVars[2] = g.declareClassField("deferredObjects", g.getModel()._ref(DrillDeferredObject[].class)); workspaceJVars[3] = g.declareClassField("arguments", g.getModel()._ref(DrillDeferredObject[].class)); workspaceJVars[4] = g.declareClassField("returnValueHolder", TypeHelper.getHolderType(g.getModel(), returnType.getMinorType(), TypeProtos.DataMode.OPTIONAL)); return workspaceJVars; }
private JMethod addInternalGetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addGetPropertyCase(jclass, propertySwitch, propertyName, propertyType, node); } } JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); propertySwitch._default().body() ._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam)); } else { propertySwitch._default().body() ._return(notFoundParam); } return method; }
private JInvocation illegalArgumentInvocation(JDefinedClass jclass, JVar propertyName) { return _new(jclass.owner()._ref(IllegalArgumentException.class)) .arg(lit("property \"").plus(propertyName).plus(lit("\" is not defined"))); }
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar valueParam = method.param(Object.class, "value"); JBlock body = method.body(); JSwitch propertySwitch = body._switch(nameParam); if (propertiesNode != null) { for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) { Map.Entry<String, JsonNode> property = properties.next(); String propertyName = property.getKey(); JsonNode node = property.getValue(); String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node); JType propertyType = jclass.fields().get(fieldName).type(); addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node); } } JBlock defaultBlock = propertySwitch._default().body(); JClass extendsType = jclass._extends(); if (extendsType != null && extendsType instanceof JDefinedClass) { JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam)); } else { defaultBlock._return(FALSE); } return method; }
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 addInternalGetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) { JMethod method = jclass.method(PROTECTED, jclass.owner()._ref(Object.class), DEFINED_GETTER_NAME); JVar nameParam = method.param(String.class, "name"); JVar notFoundParam = method.param(jclass.owner()._ref(Object.class), "notFoundValue"); JBlock body = method.body(); JConditional propertyConditional = null; JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_GETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(notFoundParam)); } else {
JDefinedClass parentClass = (JDefinedClass) extendsType; JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME, new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) }); lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam)); } else {
m._ref(ObjectInspector[].class), "argOIs", JExpr.newArray(m._ref(ObjectInspector.class), argTypes.length)); sub.assign(workspaceJVars[2], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length)); sub.assign(workspaceJVars[3], JExpr.newArray(m._ref(DrillDeferredObject.class), argTypes.length));
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; }
JVar retVal = sub.decl(m._ref(Object.class), "ret");
public JFieldVar field( int mods, Class<?> type, String name, JExpression init) { return field(mods, owner()._ref(type), name, init); }
/** * @see #varParam(JType, String) */ public JVar varParam(Class type, String name) { return varParam(outer.owner()._ref(type),name); }
/** * @see #varParam(JType, String) */ public JVar varParam(Class<?> type, String name) { return varParam(outer.owner()._ref(type),name); }
/** * @see #varParam(JType, String) */ public JVar varParam(Class<?> type, String name) { return varParam(outer.owner()._ref(type),name); }
public JExpression getBindingProviderExpr(GenerationContext context) { JType aegis = context.getCodeModel()._ref(AegisBindingProvider.class); JInvocation expr = JExpr._new(aegis); JType xbean = context.getCodeModel()._ref(XmlBeansTypeRegistry.class); expr.arg(JExpr._new(xbean)); return expr;//JExpr._new() }
private String getGetterName(String propertyName, JType type) { String prefix = (type.equals(type.owner()._ref(boolean.class))) ? "is" : "get"; propertyName = ruleFactory.getNameHelper().replaceIllegalCharacters(propertyName); String getterName = prefix + capitalize(ruleFactory.getNameHelper().capitalizeTrailingWords(propertyName)); if (getterName.equals("getClass")) { getterName = "getClass_"; } return getterName; }
public TreeVarGenerator(final JBlock body, final String fieldName) { this.fieldPathVar = body.decl(JMod.FINAL, PartialCopyGenerator.this.pluginContext.codeModel._ref(PropertyTree.class), fieldName + "PropertyTree", JOp.cond(PartialCopyGenerator.this.propertyTreeParam.eq(JExpr._null()), JExpr._null(),PartialCopyGenerator.this.propertyTreeParam.invoke("get").arg(JExpr.lit(fieldName))) ); }
private void generateCastMethod(JCodeModel codeModel, EBeanHolder holder) { JType objectType = codeModel._ref(Object.class); JMethod method = holder.generatedClass.method(JMod.PRIVATE, objectType, "cast_"); JTypeVar genericType = method.generify("T"); method.type(genericType); JVar objectParam = method.param(objectType, "object"); method.annotate(SuppressWarnings.class).param("value", "unchecked"); method.body()._return(JExpr.cast(genericType, objectParam)); holder.cast = method; }