- def generateRangeRestriction(Type type, Type returnType, Restrictions restrictions, String paramName,
- boolean isNestedType) '''
- «val javaType = Class.forName(returnType.fullyQualifiedName)»
- if («paramName» != null) {
- boolean isValidRange = false;
- «List.importedName»<«Range.importedName»<«javaType.importedName»>> rangeConstraints = new «ArrayList.
- importedName»<>();
- «FOR r : restrictions.rangeConstraints»
- rangeConstraints.add(«Range.importedName».closed(new «javaType.importedName»(«r.min.toQuote»), new «javaType.
- importedName»(«r.max.toQuote»)));
- «ENDFOR»
- for («Range.importedName»<«javaType.importedName»> r : rangeConstraints) {
- «IF isNestedType»
- if (r.contains(«paramName».getValue())) {
- «ELSE»
- if (r.contains(«paramName»)) {
- «ENDIF»
- isValidRange = true;
+ var ret = description.replace("*/", "*/")
+
+ // FIXME: Use Guava's HtmlEscapers once we have it available
+ ret = AMP_MATCHER.replaceFrom(ret, "&");
+ ret = GT_MATCHER.replaceFrom(ret, ">");
+ ret = LT_MATCHER.replaceFrom(ret, "<");
+ return ret;
+ }
+
+ def protected String formatDataForJavaDoc(GeneratedType type, String additionalComment) {
+ val StringBuilder typeDescription = new StringBuilder();
+ if (!type.description.nullOrEmpty) {
+ typeDescription.append(type.description)
+ typeDescription.append(NEW_LINE)
+ typeDescription.append(NEW_LINE)
+ typeDescription.append(NEW_LINE)
+ typeDescription.append(additionalComment)
+ } else {
+ typeDescription.append(additionalComment)
+ }
+
+ return '''
+ «typeDescription.toString»
+ '''.toString
+ }
+
+ def asLink(String text) {
+ val StringBuilder sb = new StringBuilder()
+ var tempText = text
+ var char lastChar = ' '
+ var boolean badEnding = false
+
+ if (text.endsWith('.') || text.endsWith(':') || text.endsWith(',')) {
+ tempText = text.substring(0, text.length - 1)
+ lastChar = text.charAt(text.length - 1)
+ badEnding = true
+ }
+ sb.append("<a href = \"")
+ sb.append(tempText)
+ sb.append("\">")
+ sb.append(tempText)
+ sb.append("</a>")
+
+ if(badEnding)
+ sb.append(lastChar)
+
+ return sb.toString
+ }
+
+ protected def formatToParagraph(String text) {
+ if(text == null || text.isEmpty)
+ return text
+
+ var formattedText = text
+ val StringBuilder sb = new StringBuilder();
+ var StringBuilder lineBuilder = new StringBuilder();
+ var boolean isFirstElementOnNewLineEmptyChar = false;
+
+ formattedText = formattedText.encodeJavadocSymbols
+ formattedText = NL_MATCHER.removeFrom(formattedText)
+ formattedText = TAB_MATCHER.removeFrom(formattedText)
+ formattedText = SPACES_PATTERN.matcher(formattedText).replaceAll(" ")
+
+ val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);
+
+ while(tokenizer.hasMoreElements) {
+ val nextElement = tokenizer.nextElement.toString
+
+ if(lineBuilder.length + nextElement.length > 80) {
+ if (lineBuilder.charAt(lineBuilder.length - 1) == ' ') {
+ lineBuilder.setLength(0)
+ lineBuilder.append(lineBuilder.substring(0, lineBuilder.length - 1))
+ }
+ if (lineBuilder.charAt(0) == ' ') {
+ lineBuilder.setLength(0)
+ lineBuilder.append(lineBuilder.substring(1))
+ }
+
+ sb.append(lineBuilder);
+ lineBuilder.setLength(0)
+ sb.append(NEW_LINE)
+
+ if(nextElement.toString == ' ') {
+ isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;