private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType }); JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure())); isInstance._then() .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar)); isInstance._else() ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar)); }
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; }
JVar exVar = udfInitCatch.param("ex"); udfInitCatch.body() ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName())) .arg(JExpr.lit(String.format("Failed to initialize GenericUDF"))).arg(exVar));
private void addFactoryMethod(JDefinedClass _enum, JType backingType) { JFieldVar quickLookupMap = addQuickLookupMap(_enum, backingType); JMethod fromValue = _enum.method(JMod.PUBLIC | JMod.STATIC, _enum, "fromValue"); JVar valueParam = fromValue.param(backingType, "value"); JBlock body = fromValue.body(); JVar constant = body.decl(_enum, "constant"); constant.init(quickLookupMap.invoke("get").arg(valueParam)); JConditional _if = body._if(constant.eq(JExpr._null())); JInvocation illegalArgumentException = JExpr._new(_enum.owner().ref(IllegalArgumentException.class)); JExpression expr = valueParam; // if string no need to add "" if(!isString(backingType)){ expr = expr.plus(JExpr.lit("")); } illegalArgumentException.arg(expr); _if._then()._throw(illegalArgumentException); _if._else()._return(constant); ruleFactory.getAnnotator().enumCreatorMethod(_enum, fromValue); }
JVar exVar = udfEvalCatch.param("ex"); udfEvalCatch.body() ._throw(JExpr._new(m.directClass(RuntimeException.class.getCanonicalName())) .arg(JExpr.lit(String.format("GenericUDF.evaluate method failed"))).arg(exVar));
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; }
/** * Invoked when we need to throw a generic failure exception because * we don't have an element mapped. */ protected void generateThrowWebApplicationExceptionFromResponse(JBlock caseBody, JVar $response) { // In RS 2.0 we can pass in the response object as they // are consistent across the API caseBody._throw( JExpr._new(webApplicationExceptionType()) .arg($response)); }
@Override protected void annotate(GenerationContext context, OperationInfo op, JMethod method) { JType ex = context.getCodeModel()._ref(UnsupportedOperationException.class); method.body()._throw(JExpr._new(ex)); }
private void addRuntimeExceptionThrowingCatchTo(final JTryBlock block, final JClass exceptionClass) { final JCatchBlock catchBlock = block._catch(exceptionClass); final JVar catchedException = catchBlock.param("exception"); final JBlock catchBody = catchBlock.body(); catchBody._throw(JExpr._new(_classByNames(RuntimeException.class.getName())).arg(catchedException)); }
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) { JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation"); JConditional ifBlock = m.body()._if(exField.ne(JExpr._null())); ifBlock._then()._throw(exField); m.body()._return(urlField); }
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) { JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation"); JConditional ifBlock = m.body()._if(exField.ne(JExpr._null())); ifBlock._then()._throw(exField); m.body()._return(urlField); }
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) { JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation"); JConditional ifBlock = m.body()._if(exField.ne(JExpr._null())); ifBlock._then()._throw(exField); m.body()._return(urlField); }
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) { JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation"); JConditional ifBlock = m.body()._if(exField.ne(JExpr._null())); ifBlock._then()._throw(exField); m.body()._return(urlField); }
/** * Invoked when we need to throw a generic failure exception because * we don't have an element mapped. */ protected void generateThrowWebApplicationExceptionFromResponse(JBlock caseBody, JVar $response) { // Just for a WebApplicationException in this case // with the right status code, in RS 2.0 we can provide // the entire reponse caseBody._throw( JExpr._new(webApplicationExceptionType()) .arg( codeModel.ref(Response.class).staticInvoke("status") .arg($response.invoke("getClientResponseStatus")).invoke("build"))); }
private void addNotNullParamCheck(final JBlock methodBody, final JVar param) { methodBody._if(param.eq(JExpr._null()))._then() ._throw(JExpr._new(getModel().ref(IllegalArgumentException.class)) .arg(JExpr.lit(param.name() + " cannot be null"))); }
private void addNotNullParamCheck(final JBlock methodBody, final JVar param) { methodBody._if(param.eq(JExpr._null()))._then() ._throw(JExpr._new(getModel().ref(IllegalArgumentException.class)) .arg(JExpr.lit(param.name() + " cannot be null"))); }
private void addSetProperty(JDefinedClass jclass, JBlock callSite, String propertyName, JType propertyType, JVar valueVar, JsonNode node) { JMethod propertySetter = jclass.getMethod(getSetterName(propertyName, node), new JType[] { propertyType }); JConditional isInstance = callSite._if(valueVar._instanceof(propertyType.boxify().erasure())); isInstance._then() .invoke(propertySetter).arg(cast(propertyType.boxify(), valueVar)); isInstance._else() ._throw(illegalArgumentInvocation(jclass, propertyName, propertyType, valueVar)); }
public JFieldVar getDatatypeFactory() { if (datatypeFactory == null) { datatypeFactory = jaxbObjectClass.field(JMod.PRIVATE | JMod.FINAL, builderContext.toJClass(DatatypeFactory.class), fieldManager.createId("datatypeFactory")); // add code to constructor which initializes the static dtFactory field JTryBlock tryBlock = constructor.body()._try(); tryBlock.body().assign(datatypeFactory, builderContext.toJClass(DatatypeFactory.class).staticInvoke("newInstance")); JCatchBlock catchBlock = tryBlock._catch((builderContext.toJClass(DatatypeConfigurationException.class))); catchBlock.body()._throw(JExpr._new(builderContext.toJClass(RuntimeException.class)).arg("Unable to initialize DatatypeFactory").arg(catchBlock.param("e"))); } return datatypeFactory; }
public JFieldVar getDatatypeFactory() { if (datatypeFactory == null) { datatypeFactory = jaxbObjectClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, builderContext.toJClass(DatatypeFactory.class), fieldManager.createId("datatypeFactory")); // add code to constructor which initializes the static dtFactory field JTryBlock tryBlock = jaxbObjectClass.init()._try(); tryBlock.body().assign(datatypeFactory, builderContext.toJClass(DatatypeFactory.class).staticInvoke("newInstance")); JCatchBlock catchBlock = tryBlock._catch((builderContext.toJClass(DatatypeConfigurationException.class))); catchBlock.body()._throw(JExpr._new(builderContext.toJClass(RuntimeException.class)).arg("Unable to initialize DatatypeFactory").arg(catchBlock.param("e"))); } return datatypeFactory; }