Interface CodeLanguage

All Known Implementing Classes:
AbstractCodeLanguage, JavaLanguage

public interface CodeLanguage
Interface to abstract from a concrete language.
Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
  • Method Details

    • getLanguageName

      String getLanguageName()
      Returns:
      the name of the programming language. E.g. "Java".
    • getVariableNameThis

      String getVariableNameThis()
      Returns:
      the name for CodeVariableThis. E.g. "this" or "self".
    • getKeywordForVariable

      String getKeywordForVariable(CodeLocalVariable variable)
      Parameters:
      variable - the CodeLocalVariable.
      Returns:
      the keyword for the declaration (e.g. "let ", "final ", "var ", or "val ").
    • writeDeclaration

      void writeDeclaration(CodeVariable variable, Appendable sink) throws IOException
      Writes a variable declaration. E.g. «type» «name» or «name»: «type»
      Parameters:
      variable - the CodeVariable to write.
      sink - the Appendable where to append the code to.
      Throws:
      IOException - if thrown by Appendable.
    • writeDeclaration

      void writeDeclaration(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes a type declaration (e.g. "public class MyClass").
      Parameters:
      type - the CodeType to write.
      sink - the Appendable where to append the code to.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • writeBody

      void writeBody(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes the type body (e.g. "{\n private String field;\n }\n").
      Parameters:
      type - the CodeType to write.
      sink - the Appendable where to append the code to.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • writeField

      void writeField(CodeField field, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes the given field (e.g. "private String field;\n").
      Parameters:
      field - the CodeField to write.
      sink - the Appendable where to append the code to.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • writeMethod

      void writeMethod(CodeMethod method, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes the given method (e.g. "String getName();\n").
      Parameters:
      method - the CodeField to write.
      sink - the Appendable where to append the code to.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • writeConstructor

      void writeConstructor(CodeConstructor constructor, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException
      Writes the given CodeConstructor.
      Parameters:
      constructor - the CodeConstructor to write.
      sink - the Appendable where to append the code to.
      newline - the newline String.
      defaultIndent - the String used for indentation (e.g. a number of spaces to insert per indent level).
      currentIndent - the current indent (number of spaces). Initially the empty string (""). Before a recursion the defaultIndent will be appended.
      Throws:
      IOException - if thrown by Appendable.
    • getKeywordForExtends

      default String getKeywordForExtends()
      Returns:
      the " extends " keyword (May also be " : " for Kotlin).
    • getKeywordForImplements

      default String getKeywordForImplements()
      Returns:
      the " implements " keyword (May also be " : " for Kotlin).
    • getKeywordForCategory

      String getKeywordForCategory(CodeTypeCategory category)
      Parameters:
      category - the CodeTypeCategory.
      Returns:
      the keyword for the given category to use in the source-code.
    • getMethodKeyword

      default String getMethodKeyword()
      Returns:
      the keyword/prefix to initiate a method (e.g. "fun " for Kotlin).
    • getStatementTerminator

      String getStatementTerminator()
      Returns:
      the String used as suffix to terminate a CodeAtomicStatement. E.g. ";".
    • getAnnotationStart

      default String getAnnotationStart()
      Returns:
      the String to signal the start of an CodeAnnotation.
    • getAnnotationEndIfEmpty

      default String getAnnotationEndIfEmpty()
      Returns:
      the String to signal the end of an empty CodeAnnotation. Here empty means that the parameters are empty. E.g. for TypeScript even an empty annotation has to be terminated with "()".
    • getPackageSeparator

      default char getPackageSeparator()
      Returns:
      the package separator character.
    • verifyName

      String verifyName(CodeItemWithName item, String name)
      Parameters:
      item - the CodeItemWithName to verify.
      name - the new name to verify.
      Returns:
      the given name (or potentially a "normalized" name that is valid).
      Throws:
      RuntimeException - if the name is invalid.
    • verifySimpleName

      String verifySimpleName(CodeItemWithQualifiedName item, String simpleName)
      Parameters:
      item - the CodeItemWithQualifiedName to verify.
      simpleName - the new simple name to verify.
      Returns:
      the given simpleName (or potentially a "normalized" name that is valid).
      Throws:
      RuntimeException - if the name is invalid.
    • getPackageFilename

      String getPackageFilename(CodePackage pkg)
      Parameters:
      pkg - the CodePackage to be read or write.
      Returns:
      the filename for the given CodePackage.
    • getFileFilename

      String getFileFilename(CodeFile file)
      Parameters:
      file - the CodeType to be read or write.
      Returns:
      the filename for the given CodeType.
    • isSupportingNativeProperties

      default boolean isSupportingNativeProperties()
      Returns:
      true if this language natively supports properties (in such case CodeFactory.createField(io.github.mmm.code.api.member.CodeFields, String, java.lang.reflect.Field) needs to provide an implementation that also implements CodeProperty), false otherwise.