Java Code Examples for com.sun.codemodel.JDocComment#append()
The following examples show how to use
com.sun.codemodel.JDocComment#append() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavadocUtils.java From jaxb2-rich-contract-plugin with MIT License | 6 votes |
/** * Adds a paragraph and optionally a p tag to the head of the passed {@link JDocComment}. * Also hard wraps the text. */ static JDocComment appendJavadocParagraph(final JDocCommentable jDocCommentable, final String paragraphText) { final JDocComment jDocComment = jDocCommentable.javadoc(); if (paragraphText != null && !paragraphText.isEmpty()) { List<Object> jdocItems = new ArrayList<>(jDocComment); jDocComment.clear(); // Add hard line breaks so we get readable javadoc String wrappedText = hardWrapTextForJavadoc(paragraphText); jDocComment.append(wrappedText + "\n\n"); if (!jdocItems.isEmpty()) { Object firstItem = jdocItems.get(0); if (!(firstItem instanceof String) || !((String) firstItem).startsWith("<p>") ) { // We already had text in the comment section so add line break and p tag jDocComment.append("<P>\n"); } } // add the removed items back in so we have our para at the head jDocComment.addAll(jdocItems); } return jDocComment; }
Example 2
Source File: JavadocUtils.java From jaxb2-rich-contract-plugin with MIT License | 6 votes |
/** * Adds each paragraph to the tail of the javadoc comment section of {@link JDocComment}. Also adds a p tag between * each paragraph and hard wraps the text. */ static JDocComment appendJavadocCommentParagraphs(final JDocComment jDocComment, final String... paragraphs) { if (paragraphs != null) { for (int i = 0; i < paragraphs.length; i++) { if (paragraphs[i] != null && !paragraphs[i].isEmpty()) { // Add hard line breaks so we get readable javadoc String wrappedText = hardWrapTextForJavadoc(paragraphs[i]); jDocComment.append(wrappedText); if (i != paragraphs.length - 1) { jDocComment.append("\n<P>\n"); } } } } return jDocComment; }
Example 3
Source File: ImmutableJaxbGenerator.java From rice with Educational Community License v2.0 | 6 votes |
private void renderConstantsClass(JDefinedClass classModel) throws Exception { // define constants class JDefinedClass constantsClass = classModel._class(JMod.STATIC, Util.CONSTANTS_CLASS_NAME); // generate the javadoc on the top of the Constants class JDocComment javadoc = constantsClass.javadoc(); javadoc.append(Util.CONSTANTS_CLASS_JAVADOC); // render root element name JFieldVar rootElementField = constantsClass.field(JMod.FINAL | JMod.STATIC, String.class, Util.ROOT_ELEMENT_NAME_FIELD); rootElementField.init(JExpr.lit(Util.toLowerCaseFirstLetter(classModel.name()))); // render type name JFieldVar typeNameField = constantsClass.field(JMod.FINAL | JMod.STATIC, String.class, Util.TYPE_NAME_FIELD); typeNameField.init(JExpr.lit(classModel.name() + Util.TYPE_NAME_SUFFIX)); }
Example 4
Source File: ImmutableJaxbGenerator.java From rice with Educational Community License v2.0 | 6 votes |
private void renderElementsClass(JDefinedClass classModel, List<FieldModel> fields) throws Exception { // define constants class JDefinedClass elementsClass = classModel._class(JMod.STATIC, Util.ELEMENTS_CLASS_NAME); // generate the javadoc on the top of the Elements class JDocComment javadoc = elementsClass.javadoc(); javadoc.append(Util.ELEMENTS_CLASS_JAVADOC); // go through each field and create a corresponding constant for (FieldModel fieldModel : fields) { if (Util.isCommonElement(fieldModel.fieldName)) { continue; } JFieldVar elementFieldVar = elementsClass.field(JMod.FINAL | JMod.STATIC, String.class, Util.toConstantsVariable(fieldModel.fieldName)); elementFieldVar.init(JExpr.lit(fieldModel.fieldName)); } }
Example 5
Source File: InterfaceBuilder.java From aem-component-generator with Apache License 2.0 | 5 votes |
/** * Adds Javadoc to the method based on the information in the property and the generation config options. * * @param method * @param property */ private void addJavadocToMethod(JMethod method, Property property) { String javadocStr = null; if (StringUtils.isNotBlank(property.getJavadoc())) { javadocStr = property.getJavadoc(); } else if (generationConfig.getOptions() != null && generationConfig.getOptions().isHasGenericJavadoc()) { javadocStr = "Get the " + property.getField() + "."; } if (StringUtils.isNotBlank(javadocStr)) { JDocComment javadoc = method.javadoc(); javadoc.append(javadocStr).append(""); javadoc.append("\n\n@return " + StringEscapeUtils.escapeHtml4(getGetterMethodReturnType(property).name())); } }
Example 6
Source File: ImmutableJaxbGenerator.java From rice with Educational Community License v2.0 | 5 votes |
private void renderBuilderClass(JDefinedClass classModel, List<FieldModel> fields, Class<?> contractInterface) throws Exception { // define constants class JDefinedClass builderClass = classModel._class(JMod.PUBLIC | JMod.STATIC | JMod.FINAL, Util.BUILDER_CLASS_NAME); // create a literal version of the Builder class so that the code generator won't pre-pend Builder class references with outermost class JClass literalBuilderClass = codeModel.ref("Builder"); // generate the javadoc on the top of the Elements class JDocComment javadoc = builderClass.javadoc(); javadoc.append(Util.generateBuilderJavadoc(classModel.name(), contractInterface.getSimpleName())); builderClass._implements(contractInterface); builderClass._implements(ModelBuilder.class); builderClass._implements(Serializable.class); // render the builder fields for (FieldModel fieldModel : fields) { builderClass.field(JMod.PRIVATE, fieldModel.fieldType, fieldModel.fieldName); } // render default empty constructor for builder JMethod constructor = builderClass.constructor(JMod.PRIVATE); constructor.body().directStatement("// TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods"); renderBuilderDefaultCreate(builderClass, literalBuilderClass); renderBuilderCreateContract(builderClass, literalBuilderClass, fields, contractInterface); renderBuild(builderClass); renderGetters(builderClass, fields); renderSetters(builderClass, fields); }