private void addOverrideBuilders(JDefinedClass jclass, JDefinedClass parentJclass) { if (parentJclass == null) { return; } for (JMethod parentJMethod : parentJclass.methods()) { if (parentJMethod.name().startsWith("with") && parentJMethod.params().size() == 1) { addOverrideBuilder(jclass, parentJMethod, parentJMethod.params().get(0)); } } }
private static void processMethodCollectionForSerializableSupport(Iterator<JMethod> methods, DataOutputStream dataOutputStream) throws IOException { TreeMap<String, JMethod> sortedMethods = new TreeMap<>(); while (methods.hasNext()) { JMethod method = methods.next(); //Collect non-private methods if ((method.mods().getValue() & JMod.PRIVATE) != JMod.PRIVATE) { sortedMethods.put(method.name(), method); } } for (JMethod method : sortedMethods.values()) { dataOutputStream.writeUTF(method.name()); dataOutputStream.writeInt(method.mods().getValue()); if (method.type() != null) { dataOutputStream.writeUTF(method.type().fullName()); } for (JVar param : method.params()) { dataOutputStream.writeUTF(param.type().fullName()); } } }
public JVar findParameterByName(JMethod method, String name) { for (JVar parameter : method.params()) { if (parameter.name().equals(name)) { return parameter; } } return null; }
private void addOverrideBuilders(JDefinedClass jclass, JDefinedClass parentJclass) { if (parentJclass == null) { return; } for (JMethod parentJMethod : parentJclass.methods()) { if (parentJMethod.name().startsWith("with") && parentJMethod.params().size() == 1) { addOverrideBuilder(jclass, parentJMethod, parentJMethod.params().get(0)); } } }
private JMethod findAlreadyGeneratedMethod(JDefinedClass definedClass, String methodName, List<Parameter> parameters) { method: for (JMethod method : definedClass.methods()) { if (method.name().equals(methodName) && method.params().size() == parameters.size()) { int i = 0; for (JVar param : method.params()) { String searchedParamType = parameters.get(i).jClass.name(); if (!param.type().name().equals(searchedParamType)) { continue method; } i++; } return method; } } return null; }
private JMethod findMethodWithSignature(final JVar param, final JDefinedClass entity, final String name) { for (final JMethod m : entity.methods()) { if (!m.name().equals(name)) { continue; } if (m.params().size() == 1) { final JVar jVar = m.params().get(0); if (jVar.type().equals(param.type()) || jVar.type().fullName().equals(param.type().fullName())) { return m; } } } return null; }
private JMethod findMethodWithSignature(final JVar param, final JDefinedClass entity, final String name) { for (final JMethod m : entity.methods()) { if (!m.name().equals(name)) { continue; } if (m.params().size() == 1) { final JVar jVar = m.params().get(0); if (jVar.type().equals(param.type()) || jVar.type().fullName().equals(param.type().fullName())) { return m; } } } return null; }
protected void addNewInstanceMethodBody(final JMethod method, final JDefinedClass entity) { final JBlock methodBody = method.body(); for (final JVar param : method.params()) { addNotNullParamCheck(methodBody, param); } final JVar instanceRef = methodBody.decl(entity, "instance", JExpr._new(entity)); for (final JVar param : method.params()) { callSetter(methodBody, param, instanceRef, entity); } methodBody._return(instanceRef); }
protected void addNewInstanceMethodBody(final JMethod method, final JDefinedClass entity) { final JBlock methodBody = method.body(); for (final JVar param : method.params()) { addNotNullParamCheck(methodBody, param); } final JVar instanceRef = methodBody.decl(entity, "instance", JExpr._new(entity)); for (final JVar param : method.params()) { callSetter(methodBody, param, instanceRef, entity); } methodBody._return(instanceRef); }
private void collectScopedElementInfos(JClass xmlElementDeclModelClass) { String dotClazz = candidateClass.fullName() + ".class"; // Only value Object Factory methods are inspected: for (JMethod method : objectFactoryClasses.values().iterator().next().methods()) { JAnnotationUse xmlElementDeclAnnotation = getAnnotation(method, xmlElementDeclModelClass); JExpression scope = getAnnotationMemberExpression(xmlElementDeclAnnotation, "scope"); if (scope == null || !dotClazz.equals(generableToString(scope))) { continue; } scopedElementInfos.put(method.name(), new ScopedElementInfo(getAnnotationMemberExpression(xmlElementDeclAnnotation, "name"), getAnnotationMemberExpression(xmlElementDeclAnnotation, "namespace"), method.params().get(0).type())); } }
private void collectScopedElementInfos(JClass xmlElementDeclModelClass) { String dotClazz = candidateClass.fullName() + ".class"; // Only value Object Factory methods are inspected: for (JMethod method : objectFactoryClasses.values().iterator().next().methods()) { JAnnotationUse xmlElementDeclAnnotation = getAnnotation(method, xmlElementDeclModelClass); JExpression scope = getAnnotationMemberExpression(xmlElementDeclAnnotation, "scope"); if (scope == null || !dotClazz.equals(generableToString(scope))) { continue; } scopedElementInfos.put(method.name(), new ScopedElementInfo(getAnnotationMemberExpression(xmlElementDeclAnnotation, "name"), getAnnotationMemberExpression(xmlElementDeclAnnotation, "namespace"), method.params().get(0).type())); } }
public boolean hasGetter() { for (final JMethod method : this.fieldOutline.parent().implClass.methods()) { if ((method.name().equals("get" + this.fieldOutline.getPropertyInfo().getName(true)) || method.name().equals("is" + this.fieldOutline.getPropertyInfo().getName(true))) && method.params().isEmpty()) { return true; } } return false; }
@Override public JMethod apply(ApiActionMetadata endpointMetadata, JExtMethod generatableType) { JMethod jMethod = generatableType.get(); JInvocation jInvocation = JExpr._this().ref(delegateFieldName).invoke(jMethod); jMethod.params().forEach(p -> jInvocation.arg(p)); jMethod.body()._return(jInvocation); return jMethod; } }
public void callSuperMethod(JMethod superMethod, EBeanHolder holder, JBlock callBlock) { JExpression activitySuper = holder.generatedClass.staticRef("super"); JInvocation superCall = JExpr.invoke(activitySuper, superMethod); for (JVar param : superMethod.params()) { superCall.arg(param); } JType returnType = superMethod.type(); if (returnType.fullName().equals("void")) { callBlock.add(superCall); } else { callBlock._return(superCall); } }
protected void addQueryParameters(final JMethod method, final JBlock body, final JClass mapClass, final JClass hashMapClass, final JVar commandParametersRef) { if (!method.params().isEmpty()) { final JVar queryParametersRef = body.decl(mapClass, "queryParameters", JExpr._new(hashMapClass)); for (final JVar param : method.params()) { if (!FORBIDDEN_PARAMETER_NAMES.contains(param.name())) { body.invoke(queryParametersRef, "put").arg(JExpr.lit(param.name())).arg(param); } } body.invoke(commandParametersRef, "put").arg(JExpr.lit("queryParameters")).arg(JExpr.cast(getModel().ref(Serializable.class), queryParametersRef)); } }
protected void addQueryParameters(final JMethod method, final JBlock body, final JClass mapClass, final JClass hashMapClass, final JVar commandParametersRef) { if (!method.params().isEmpty()) { final JVar queryParametersRef = body.decl(mapClass, "queryParameters", JExpr._new(hashMapClass)); for (final JVar param : method.params()) { if (!FORBIDDEN_PARAMETER_NAMES.contains(param.name())) { body.invoke(queryParametersRef, "put").arg(JExpr.lit(param.name())).arg(param); } } body.invoke(commandParametersRef, "put").arg(JExpr.lit("queryParameters")).arg(JExpr.cast(getModel().ref(Serializable.class), queryParametersRef)); } }
private JMethod createPrismContextContainerableConstructor(JDefinedClass definedClass, JMethod setupContainerMethod) { JMethod constructor = definedClass.constructor(JMod.PUBLIC); constructor.param(PrismContext.class, "prismContext"); JBlock body = constructor.body(); body.invoke(setupContainerMethod) // setupContainerValue( .arg(JExpr._new(CLASS_MAP.get(PrismContainerValueImpl.class).narrow(new JClass[0])) // new PrismContainerValueImpl<>( .arg(JExpr._this()) // this, .arg(constructor.params().get(0))); // prismContext); return constructor; }
private JMethod createPrismContextObjectableConstructor(JDefinedClass definedClass) { JMethod constructor = definedClass.constructor(JMod.PUBLIC); constructor.param(PrismContext.class, "prismContext"); JBlock body = constructor.body(); body.invoke("setupContainer") .arg(JExpr._new(CLASS_MAP.get(PrismObjectImpl.class)) .arg(JExpr.invoke("_getContainerName")) .arg(JExpr.invoke("getClass")) .arg(constructor.params().get(0))); return constructor; }
static private void createReportingConstructor(JDefinedClass clazz, ExecutableElement executableElement, String operation, String initialOperation, JPrimitiveType type){ JCodeModel codeModel = clazz.owner(); JMethod constructor = clazz.constructor(JMod.PUBLIC); List<? extends VariableElement> parameterElements = executableElement.getParameters(); for(VariableElement parameterElement : parameterElements){ constructor.param(toType(codeModel, parameterElement.asType()), String.valueOf(parameterElement.getSimpleName())); } JBlock body = constructor.body(); body.add(createSuperInvocation(clazz, constructor)); if((clazz.name()).endsWith("Value")){ JClass reportClazz = codeModel.ref("org.jpmml.evaluator.Report"); JVar reportParameter = constructor.param(reportClazz, "report"); body.add(JExpr.invoke("setReport").arg(reportParameter)); } // End if if(initialOperation != null){ throw new RuntimeException(); } body.add(JExpr.invoke("report").arg(createReportInvocation(clazz, operation, constructor.params(), type))); }
static private JInvocation createSuperInvocation(JDefinedClass clazz, JMethod method){ JInvocation invocation; if(method.type() != null){ invocation = JExpr._super().invoke(method.name()); } else { invocation = JExpr.invoke("super"); } List<JVar> parameters = method.params(); for(JVar parameter : parameters){ invocation.arg(parameter); } return invocation; }