public Parameter getMainUpdateParameter(Method method) { Parameter mainParameter = method.getParameters().stream() .filter(x -> x.getType() instanceof StructType) .findFirst() .orElse(null); return mainParameter; }
public boolean isContained(Method method, Method method2) { if (method.getName().equals(method2.getName())) { return false; //same method } if (method.getBase()==null || method2.getBase()==null) { return false; //no parent, containment irrelevant } if (!method.getBase().getName().equals(method2.getBase().getName())) { return false; //different parents, containment irrelevant. } return isParametersContained(method.getMandatoryParameters(), method2.getMandatoryParameters()) && isAttributesContained(method.getMandatoryAttributes(), method2.getMandatoryAttributes()); }
/** * Determines if this is an action method, i.e., any method whose name isn't {@code Add}, {@code Get}, {@code List}, * {@code Update} or {@code Remove}. */ public boolean isAction() { return !(NON_ACTION_METHOD_NAMES.contains(getName()) || (base!=null && NON_ACTION_METHOD_NAMES.contains(base.getName()))); }
javaNames.getJavaMemberStyleName(methodName)); validateActionNotNull(); for (Parameter parameter : method.getParameters()) { generateActionParameterValidation(parameter); javaBuffer.addDocComment(signature.getName().toString()); if (signature.isMandatoryAttributeExists()) { javaBuffer.addLine("if (action!=null"); for (Parameter parameter : signature.getParameters()) { if (parameter.isMandatory()) { assert parameter.getType() instanceof EnumType || parameter.getType() instanceof PrimitiveType; + javaNames.getJavaMemberStyleName(method.getName()) + javaNames.getJavaClassStyleName(signature.getName()) + "\", Action.class);"); javaBuffer.addLine("}"); javaBuffer.addLine();
private void generateValidation(Method method) { if (method.isMandatoryAttributeExists()) { generateValidationMethodName(method); for (Parameter parameter : method.getParameters()) { generateParameterValidation(parameter); } javaBuffer.addLine("}"); //close validation method javaBuffer.addLine(""); } }
javaBuffer.addLine( "@Path(\"%s\")", jaxrsNames.getActionPath(method.getName()) ); String methodName = jaxrsNames.getMethodName(method.getName()); if (baseMethods.containsKey(method)) { javaBuffer.addLine("default Response %s(Action action) {", methodName); Set<Method> signatures = baseMethods.get(method); if (signatures!=null && mandatoryAttributeExists(signatures)) { writeHelperInvocation(helperClassName, "action", method.getName()); } else { if (method.isMandatoryAttributeExists()) { javaBuffer.addLine("default Response %s(Action action) {", "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1)); javaBuffer.addLine(helperClassName.getSimpleName() + ".validate" + getActionValidationMethodName(methodName) + "(action);"); addResponseReturnMethod(jaxrsNames.getMethodName(method.getName()) + "(Action action)");
for (Service service : model.getServices()) { for (Method method : service.getMethods()) { if (jaxrsNames.isActionName(method.getName())) { for (Parameter parameter : method.getParameters()) { Name name = parameter.getName(); Parameter existing = parameters.get(name);
/** * For method 'signatures' (e:g FromStorageDomain, DirectLun) Parameters should * be mostly copied from the base method (e.g: add). This method does this. */ private void copyParameters(Method childMethod, Method method) { for (Parameter parameter : method.getParameters()) { Parameter newParameter = new Parameter(); //copy from base parameter. Member-involvement-trees not copied on purpose. newParameter.setIn(parameter.isIn()); newParameter.setOut(parameter.isOut()); newParameter.setType(parameter.getType()); newParameter.setName(parameter.getName()); newParameter.setDoc(parameter.getDoc()); newParameter.setSource(parameter.getSource()); newParameter.getAnnotations().addAll(parameter.getAnnotations()); //set the child-method as the declaring method newParameter.setDeclaringMethod(childMethod); childMethod.addParameter(newParameter); } }
private void handleSignature(Name parentMethodName, Method signature, Name parameterName, Type parameterType) { Parameter parameter = signature.getParameter(parameterName); Iterator<MemberInvolvementTree> iterator = parameter.getMandatoryAttributes().iterator(); if (iterator.hasNext()) {//if there are any mandatory attributes javaBuffer.addDocComment(signature.getName().toString()); javaBuffer.addLine("if (" +javaNames.getJavaMemberStyleName(parameter.getName()) + "!=null"); while (iterator.hasNext()) { MemberInvolvementTree attribute = iterator.next(); List<MemberInvolvementTree> list = stackAttributeComponents(attribute); String attributeCheck = getFullAttributeCheck(javaNames.getJavaMemberStyleName(parameter.getName()), list, Operator.AND, true); if (attribute.getAlternative()!=null) {//'or' expression list = stackAttributeComponents(attribute.getAlternative()); String alternativeCheck = getFullAttributeCheck(javaNames.getJavaMemberStyleName(parameter.getName()), list, Operator.AND, true); String fullCheck = mergeChecks(attributeCheck, alternativeCheck); javaBuffer.addLine(fullCheck); } else { javaBuffer.addLine(attributeCheck); } } javaBuffer.addLine(") {"); javaBuffer.addLine("return " + resourceName.getSimpleName() + ".class.getMethod(\"" + javaNames.getJavaMemberStyleName(parentMethodName) + javaNames.getJavaClassStyleName(signature.getName()) + "\", " + javaNames.getJavaClassStyleName(parameter.getType().getName()) + ".class);"); javaBuffer.addLine("}"); } }
Service service = path.get(size -1).getService(); service.methods() .filter(method -> method.getBase() == null) .forEach(method -> { Point point = new Point();
private void documentRequest(Point point) { Method method = point.getMethod(); Service service = method.getDeclaringService(); StringBuilder buffer = new StringBuilder(); buffer.append(String.format("* <<%s,%s>> ", getId(service, method), getHttpMethod(method))); point.path().forEach(locator -> { buffer.append("/"); String link = String.format("<<%s,%s>>", getId(locator.getService()), getUrlSegment(locator)); buffer.append(link); }); if (method.isAction()) { buffer.append("/"); String link = String.format("<<%s,%s>>", getId(service), getUrlSegment(method)); buffer.append(link); } docBuffer.addLine(buffer.toString()); }
public Method analyzeMethod(JavaClass javaClass, Service service) { Method method = new Method(); analyzeName(javaClass, method); analyzeAnnotations(javaClass, method); analyzeDocumentation(javaClass, method); // Find the mix-ins: List<JavaClass> javaMixins = javaClass.getInterfaces().stream() .filter(javaInterface -> isAnnotatedWith(javaInterface, ModelAnnotations.MIXIN)) .collect(toList()); // Analyze the members of the method and the mix-ins: analyzeMethodMembers(javaClass, method); javaMixins.forEach(javaMixin -> analyzeMethodMembers(javaMixin, method)); // Add the member to the service: method.setDeclaringService(service); createSignatures(javaClass, service, method); return method; }
Parameter parameter = method.getParameter(name); if (parameter != null) { ParameterExpression replacement = new ParameterExpression();
private String getName(Concept concept) { String name = concept.getName().toString(); String parent = null; if (concept instanceof StructMember) { StructMember member = (StructMember) concept; parent = member.getDeclaringType().getName().toString(); } else if (concept instanceof Method) { Method method = (Method) concept; parent = method.getDeclaringService().getName().toString(); } if (parent != null) { name = parent + "/" + name; } return name; }
private void analyzeConstraint(JavaMethod javaMethod, Method method) { // Create the constraint: Constraint constraint = new Constraint(); analyzeName(javaMethod, constraint); analyzeAnnotations(javaMethod, constraint); analyzeDocumentation(javaMethod, constraint); // Get the direction: if (isAnnotatedWith(javaMethod, ModelAnnotations.IN)) { constraint.setIn(true); } if (isAnnotatedWith(javaMethod, ModelAnnotations.OUT)) { constraint.setOut(true); } // Get the source: String source = javaMethod.getSourceCode(); constraint.setSource(source); // Remember to analyze the constraint source once the types and services have been completely defined: undefinedConstraints.add(constraint); // Add the constraint to the method: constraint.setDeclaringMethod(method); method.addConstraint(constraint); }
private void analyzeParameter(JavaMethod javaMethod, Method method) { // Create the parameter: Parameter parameter = new Parameter(); analyzeName(javaMethod, parameter); analyzeAnnotations(javaMethod, parameter); analyzeDocumentation(javaMethod, parameter); // Get the direction: if (isAnnotatedWith(javaMethod, ModelAnnotations.IN)) { parameter.setIn(true); } if (isAnnotatedWith(javaMethod, ModelAnnotations.OUT)) { parameter.setOut(true); } // Get the type: assignTypeReference(javaMethod.getReturns(), parameter::setType); // Get the default value: String javaValue = javaMethod.getSourceCode(); if (javaValue != null && !javaValue.isEmpty()) { Expression expression = analyzeExpression(javaValue); parameter.setDefaultValue(expression); } // Add the parameter to the method: parameter.setDeclaringMethod(method); method.addParameter(parameter); }
private String getName(Method method) { return names.getLowerJoined(method.getName(), ""); }
private void generateActionValidation(Method method) { if (method.isMandatoryAttributeExists()) { writeActionValidationMethodName(method); validateActionNotNull(); for (Parameter parameter : method.getParameters()) { generateActionParameterValidation(parameter); } javaBuffer.addLine("}"); //close validation method javaBuffer.addLine(""); } }