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

org.joinedworkz.common.helper.CommentHelper 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.eclipse.xtext.xbase.lib.Extension;
import org.joinedworkz.core.model.CmnElement;
import org.joinedworkz.core.model.CmnNamedObject;

@Singleton
@SuppressWarnings("all")
public class CommentHelper {
  @Inject
  @Extension
  private StringHelper _stringHelper;

  public CharSequence singleLineComment(final String text) {
    return this.genComment(text, null, null, "// ");
  }

  public CharSequence multiLineComment(final String text) {
    return this.genComment(text, "/*", " */", " * ");
  }

  public CharSequence javaDocComment(final CmnElement element) {
    CharSequence _xifexpression = null;
    if ((element instanceof CmnNamedObject)) {
      _xifexpression = this.javaDocComment(((CmnNamedObject)element).getDescription());
    }
    return _xifexpression;
  }

  public CharSequence javaDocComment(final String text) {
    return this.genComment(text, "/**", " */", " * ");
  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy