All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinedworkz.common.helper.CommentHelper.xtend Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
package org.joinedworkz.common.helper

import javax.inject.Inject
import javax.inject.Singleton
import org.joinedworkz.core.model.CmnElement
import org.joinedworkz.core.model.CmnNamedObject

@Singleton
class CommentHelper {

    @Inject
    extension StringHelper

    def CharSequence singleLineComment(String text) {
        genComment(text, null, null, "// ")
    }

    def CharSequence multiLineComment(String text) {
        genComment(text, "/*", " */", " * ")
    }
    
    def CharSequence javaDocComment(CmnElement element) {
        if (element instanceof CmnNamedObject) {
            javaDocComment(element.description)
        }
    }

    def CharSequence javaDocComment(String text) {
        genComment(text, "/**", " */", " * ")
    }

    protected def CharSequence genComment(String text, String before, String after, String prefix) {
        if (text !== null) {
            val buffer = new StringBuilder()
            if (before !== null) {
                buffer.append(before)
                addLineBreak(buffer)
            }
            insertLinesOfString(buffer, text, " * ", false)
            if (after !== null) {
                addLineBreak(buffer)
                buffer.append(after)
            }
            return buffer
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy