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 Summary
Modifier and TypeMethodDescriptiondefault Stringdefault StringgetFileFilename(CodeFile file) getKeywordForCategory(CodeTypeCategory category) default Stringdefault StringgetKeywordForVariable(CodeLocalVariable variable) default Stringdefault chardefault booleanverifyName(CodeItemWithName item, String name) verifySimpleName(CodeItemWithQualifiedName item, String simpleName) voidwriteBody(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the type body (e.g.voidwriteConstructor(CodeConstructor constructor, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeConstructor.voidwriteDeclaration(CodeVariable variable, Appendable sink) Writes a variable declaration.voidwriteDeclaration(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes a type declaration (e.g.voidwriteField(CodeField field, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the given field (e.g.voidwriteMethod(CodeMethod method, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the given method (e.g.
-
Method Details
-
getLanguageName
String getLanguageName()- Returns:
- the name of the programming language. E.g. "Java".
-
getVariableNameThis
String getVariableNameThis()- Returns:
- the
nameforCodeVariableThis. E.g. "this" or "self".
-
getKeywordForVariable
- Parameters:
variable- theCodeLocalVariable.- Returns:
- the keyword for the declaration (e.g. "let ", "final ", "var ", or "val ").
-
writeDeclaration
- Parameters:
variable- theCodeVariableto write.sink- theAppendablewhere toappendthe code to.- Throws:
IOException- if thrown byAppendable.
-
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- theCodeTypeto write.sink- theAppendablewhere toappendthe code to.newline- the newlineString.defaultIndent- theStringused 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 thedefaultIndentwill be appended.- Throws:
IOException- if thrown byAppendable.
-
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- theCodeTypeto write.sink- theAppendablewhere toappendthe code to.newline- the newlineString.defaultIndent- theStringused 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 thedefaultIndentwill be appended.- Throws:
IOException- if thrown byAppendable.
-
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- theCodeFieldto write.sink- theAppendablewhere toappendthe code to.newline- the newlineString.defaultIndent- theStringused 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 thedefaultIndentwill be appended.- Throws:
IOException- if thrown byAppendable.
-
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- theCodeFieldto write.sink- theAppendablewhere toappendthe code to.newline- the newlineString.defaultIndent- theStringused 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 thedefaultIndentwill be appended.- Throws:
IOException- if thrown byAppendable.
-
writeConstructor
void writeConstructor(CodeConstructor constructor, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeConstructor.- Parameters:
constructor- theCodeConstructorto write.sink- theAppendablewhere toappendthe code to.newline- the newlineString.defaultIndent- theStringused 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 thedefaultIndentwill be appended.- Throws:
IOException- if thrown byAppendable.
-
getKeywordForExtends
- Returns:
- the " extends " keyword (May also be " : " for Kotlin).
-
getKeywordForImplements
- Returns:
- the " implements " keyword (May also be " : " for Kotlin).
-
getKeywordForCategory
- Parameters:
category- theCodeTypeCategory.- Returns:
- the keyword for the given
categoryto use in the source-code.
-
getMethodKeyword
- Returns:
- the keyword/prefix to initiate a method (e.g. "fun " for Kotlin).
-
getStatementTerminator
String getStatementTerminator()- Returns:
- the
Stringused as suffix to terminate aCodeAtomicStatement. E.g. ";".
-
getAnnotationStart
- Returns:
- the
Stringto signal the start of anCodeAnnotation.
-
getAnnotationEndIfEmpty
- Returns:
- the
Stringto signal the end of an emptyCodeAnnotation. Here empty means that theparametersareempty. E.g. for TypeScript even an empty annotation has to be terminated with "()".
-
getPackageSeparator
default char getPackageSeparator()- Returns:
- the package separator character.
-
verifyName
- Parameters:
item- theCodeItemWithNameto verify.name- the newnameto verify.- Returns:
- the given
name(or potentially a "normalized" name that is valid). - Throws:
RuntimeException- if the name is invalid.
-
verifySimpleName
- Parameters:
item- theCodeItemWithQualifiedNameto verify.simpleName- the newsimple nameto verify.- Returns:
- the given
simpleName(or potentially a "normalized" name that is valid). - Throws:
RuntimeException- if the name is invalid.
-
getPackageFilename
- Parameters:
pkg- theCodePackageto be read or write.- Returns:
- the filename for the given
CodePackage.
-
getFileFilename
-
isSupportingNativeProperties
default boolean isSupportingNativeProperties()- Returns:
trueif this language natively supportsproperties(in such caseCodeFactory.createField(io.github.mmm.code.api.member.CodeFields, String, java.lang.reflect.Field)needs to provide an implementation that also implementsCodeProperty),falseotherwise.
-