Class Formats

java.lang.Object
eu.bandm.tools.metajava.Formats

public abstract class Formats extends Object
Container for fundamental static Format patterns, used by the metajava source code generators.
  • Field Details

    • semicolonFormat

      public static final Format semicolonFormat
    • packageFormat

      public static final Format packageFormat
    • openParenFormat

      public static final Format openParenFormat
    • closeParenFormat

      public static final Format closeParenFormat
    • openBraceFormat

      public static final Format openBraceFormat
    • closeBraceFormat

      public static final Format closeBraceFormat
    • ltFormat

      public static final Format ltFormat
    • gtFormat

      public static final Format gtFormat
    • commaFormat

      public static final Format commaFormat
    • enumFormat

      public static final Format enumFormat
    • implementsFormat

      public static final Format implementsFormat
    • classFormat

      public static final Format classFormat
    • extendsFormat

      public static final Format extendsFormat
    • equalFormat

      public static final Format equalFormat
    • throwsFormat

      public static final Format throwsFormat
    • importFormat

      public static final Format importFormat
    • dotFormat

      public static final Format dotFormat
    • pattern_newlineAndTabs

      public static final Pattern pattern_newlineAndTabs
      Matches one single "linefeed", "carriage return", or "horizontal tab" character.
    • CREATED_ON

      public static final String CREATED_ON
      See Also:
    • F_CREATED_ON

      public static final Format F_CREATED_ON
  • Constructor Details

    • Formats

      public Formats()
  • Method Details

    • roundList

      public static Format roundList(List<Format> elems)
    • openList

      public static Format openList(List<Format> elems)
    • angledList

      public static Format angledList(List<Format> elems)
    • genericFormat

      public static Format genericFormat(List<Format> types)
    • statementFormat

      public static Format statementFormat(Format format)
      Generates <statement>;
    • modifierFormat

      public static Format modifierFormat(Format annotations, int modifiers)
    • modifierFormat

      public static Format modifierFormat(int modifiers)
    • packageDecl

      public static Format packageDecl(String name)
    • packageDecl

      public static Format packageDecl(Format annotations, String name)
    • declarationFormat

      public static Format declarationFormat(Format modifiers, Format type, String name)
      Generates [<modifiers> ]<type> <name>
    • declarationFormat

      public static Format declarationFormat(Format type, Format item)
    • declarationFormat

      public static Format declarationFormat(Format modifiers, Format type, String name, Format initializer)
      Generates [<modifiers> ]<type> <name> = <expr>
    • declarationFormat

      public static Format declarationFormat(Format modifiers, Format type, Format name, Format initializer)
    • classDefinition

      public static Format classDefinition(Format modifiers, Format name, Format typevars, Format superclass, List<Format> implementing, Format body)
      Generates <modifiers> class <name> <typevars> extends <superclass> [implements <interfaces>] { <body> }
    • enumDefinition

      public static Format enumDefinition(Format modifiers, Format name, Format typevars, List<Format> implementing, List<Format> constants, Format body)
      Generates <modifiers> enum <name> <typevars> [implements <interfaces>] { [<consts>;] <body> }
    • definitionFormat

      public static Format definitionFormat(Format header, Format body)
      Generates <header> { <body> }
    • definitionFormat

      public static Format definitionFormat(Format header, Format body, boolean braces)
    • enumConstant

      public static Format enumConstant(String name, List<Format> params, Format body)
    • blockFormat

      public static Format blockFormat(Format statements)
    • constructorDefinition

      public static Format constructorDefinition(Format modifiers, Format typevars, Format name, List<Format> parameters, List<Format> exceptions, Format body)
      Generates <modifiers> <name>(<parameters>) [throws <exceptions>] { <body> }
    • methodDefinition

      public static Format methodDefinition(Format modifiers, Format typevars, Format returntype, String name, List<Format> parameters, List<Format> exceptions, Format body)
      Generates <modifiers> <typevars> <type> <name>(<parameters>) [throws <exceptions>] { <body> }
    • methodDefinition

      public static Format methodDefinition(Format modifiers, Format typevars, Format returntype, String name, List<Format> parameters, List<Format> exceptions)
      Generates <modifiers> <typevars> <type> <name>(<parameters>) [throws <exceptions>] ; }
    • stringEscape

      public static String stringEscape(String data, Formats.stringEscapeMode mode)
      Escapes blank characters in the given datum according to the methods selected by the mode parameter:
      Parameters:
      data - to transform
      mode - how to react to contained blanks
      Returns:
      the transformed data
    • replaceNewlinesAndTabs

      public static String replaceNewlinesAndTabs(String s)
      Replaces all occurences of "linefeed", "carriage return", or "horizontal tab" character by a space character.
      Parameters:
      s - to transform
      Returns:
      the transformed data
    • generationComment

      public static Format generationComment(String main_class, @Opt @Opt String descriptive_name, @Opt @Opt String clickable, @Opt @Opt String versionText, String dateAndTime, Formats.stringEscapeMode escapemode, boolean htmlMode, String[] args)
      Generates a Format which explains the tool application to generate a Java source file. This format can be used documents the command line call and its parameters and can be included as a doc-comment in the generated soruce.

      The format returned by this method is not a particular (programming language) comment format, but only its contents. It can be converted to a string (containing line breaks) by result.toString(70), etc., as documented with Format. or to a string (probably) not containing line breaks by result.toString(1000).

      The result will look like

         Created on  [calendaric date and time]
         by [descriptive_name] (=[main_class])   (version [name_version])?
         command line:
         java [main_class] [arg1] [arg2]
        
      All strings in the "args" array are considered as potential file paths and thus (heuristically) anonymized by calling FilenameUtils.anonymiseLocalFile(String).
      Parameters:
      main_class - must be given,
      descriptive_name - is optional and may contain blanks and special characters
      clickable - target url which can be reached by clicking the program name. Relevant only with htmlMode set.
      versionText - may be ==null, omitting the "version ..." text
      dateAndTime - must be given,
      escapemode - how arg-strings which contain whitespace shall be encoded, see stringEscape(String,stringEscapeMode)
      htmlMode - whether to insert html line break commands and other markup.
      args - the array of arguments which reached static void main() in the call of the tool application.
      See Also:
    • primeAssignment

      public static Format primeAssignment(String target, Format value)
      Target of assignment is a variable name.
    • annotationGeneratedArguments

      public static Format annotationGeneratedArguments(String tool, String version, String date, String... args)
    • annotationGeneratedArguments

      public static Format annotationGeneratedArguments(String tool, String version, String date)
    • annotationGeneratedArguments

      public static Format annotationGeneratedArguments(String tool, String version, String date, @Opt @Opt List<String> args)
    • extractFirstSentence_basic

      public static String extractFirstSentence_basic(String text)
      Extract the prefix from a Java doc text. The rules applied by JavaDoc are quite complex and pluggable; see the e.g. "-breakiterator" in the java tool reference.

      See also the source of "module jdk.compiler / package com.sun.source.doctree / interface DocCommentTree", method "getFirstSentence()".

      This very primitive version requires:

      • Any HTML markup or javadoc inline tag delimits the first sentence.
      • Otherwise a dot followed by a whitespace ends the first sentence.
      • But HTML "&amp;nbsp;" is allowed to escape a single dot in e.g. "Dr. Suess".
    • extractFirstSentence

      public static String extractFirstSentence(String text)
    • apidoc2attValue

      public static String apidoc2attValue(String text)