Class AbstractCodeLanguage
java.lang.Object
io.github.mmm.code.api.language.AbstractCodeLanguage
- All Implemented Interfaces:
CodeLanguage
- Direct Known Subclasses:
JavaLanguage
The default implementation of
CodeLanguage (for Java).- Since:
- 1.0.0
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CodeModifiersgetMethodModifiers(CodeMethod method) protected abstract Patternprotected StringgetOperationName(CodeOperation operation) protected abstract Patternprotected abstract Patternprotected abstract booleanisRevervedKeyword(String name, CodeItem item) protected StringverifyName(CodeItem item, Pattern pattern, String name) verifyName(CodeItemWithName item, String name) verifySimpleName(CodeItemWithQualifiedName item, String simpleName) voidwriteAnnotations(CodeAnnotations annotations, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeAnnotations.voidwriteBody(CodeOperation operation, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeOperation.voidwriteBody(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the type body (e.g.voidwriteComment(CodeComment comment, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeComment.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.voidWrites the givenCodeDoc.voidwriteElement(CodeElement element, Appendable sink, String newline, String defaultIndent, String currentIndent) 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.protected voidwriteOperation(CodeOperation operation, CodeModifiers modifiers, CodeReturn opReturn, Appendable sink, String newline, String defaultIndent, String currentIndent) voidwriteParameters(CodeParameters parameters, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeParameters.protected voidwriteTypeReferenceBegin(CodeGenericType type, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the type reference at the beginning.protected voidwriteTypeReferenceEnd(CodeGenericType type, Appendable sink, String newline, String defaultIndent, String currentIndent) voidwriteTypeVariables(CodeTypeVariables typeVariables, Appendable sink, String newline, String defaultIndent, String currentIndent) Writes the givenCodeTypeVariables.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CodeLanguage
getAnnotationEndIfEmpty, getAnnotationStart, getFileFilename, getKeywordForCategory, getKeywordForExtends, getKeywordForImplements, getKeywordForVariable, getLanguageName, getMethodKeyword, getPackageFilename, getPackageSeparator, getStatementTerminator, getVariableNameThis, isSupportingNativeProperties
-
Constructor Details
-
AbstractCodeLanguage
public AbstractCodeLanguage()
-
-
Method Details
-
verifyName
- Specified by:
verifyNamein interfaceCodeLanguage- Parameters:
item- theCodeItemWithNameto verify.name- the newnameto verify.- Returns:
- the given
name(or potentially a "normalized" name that is valid).
-
verifySimpleName
- Specified by:
verifySimpleNamein interfaceCodeLanguage- Parameters:
item- theCodeItemWithQualifiedNameto verify.simpleName- the newsimple nameto verify.- Returns:
- the given
simpleName(or potentially a "normalized" name that is valid).
-
verifyName
-
getSimpleNamePatternForPackage
- Returns:
- the
Patternthat defines validCodePackagenames.
-
getSimpleNamePatternForType
-
getNamePattern
-
isRevervedKeyword
- Parameters:
name- the name of theCodeItemto create.item- theCodeItemto verify that defines the givenname. Will most probably be ignored but a language may allow keywords in specific places and forbid in others.- Returns:
trueif the givennameis invalid (for the givenCodeItem) because it is a reserved keyword.
-
writeDoc
public void writeDoc(CodeDoc doc, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeDoc.- Parameters:
doc- theCodeDocto 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.
-
writeComment
public void writeComment(CodeComment comment, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeComment.- Parameters:
comment- theCodeCommentto 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.
-
writeAnnotations
public void writeAnnotations(CodeAnnotations annotations, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeAnnotations.- Parameters:
annotations- theCodeAnnotationsto 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.
-
writeElement
public void writeElement(CodeElement element, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException - Parameters:
element- theCodeElementto 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.
-
writeDeclaration
Description copied from interface:CodeLanguage- Specified by:
writeDeclarationin interfaceCodeLanguage- Parameters:
variable- theCodeVariableto write.sink- theAppendablewhere toappendthe code to.- Throws:
IOException- if thrown byAppendable.
-
writeDeclaration
public void writeDeclaration(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Description copied from interface:CodeLanguageWrites a type declaration (e.g. "public class MyClass").- Specified by:
writeDeclarationin interfaceCodeLanguage- 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
public void writeBody(CodeType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Description copied from interface:CodeLanguageWrites the type body (e.g. "{\n private String field;\n }\n").- Specified by:
writeBodyin interfaceCodeLanguage- 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
public void writeField(CodeField field, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Description copied from interface:CodeLanguageWrites the given field (e.g. "private String field;\n").- Specified by:
writeFieldin interfaceCodeLanguage- 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
public void writeMethod(CodeMethod method, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Description copied from interface:CodeLanguageWrites the given method (e.g. "String getName();\n").- Specified by:
writeMethodin interfaceCodeLanguage- 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.
-
writeOperation
protected void writeOperation(CodeOperation operation, CodeModifiers modifiers, CodeReturn opReturn, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException - Parameters:
operation- theCodeOperationto write.modifiers- theCodeModifiersof the operation, potentially transformed.opReturn- theCodeReturnof the operation ornullforCodeConstructor.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.
-
getOperationName
- Parameters:
operation- theCodeOperation.- Returns:
- the
nameof the givenCodeOperationto be written as source-code. May also be "constructor" forCodeConstructorin languages like TypeScript.
-
writeTypeReferenceBegin
protected void writeTypeReferenceBegin(CodeGenericType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the type reference at the beginning. In languages like Java this is the place where type references are written. However, some other languages write the type referenceat the end. Example: In Java we have the type references at the beginning so this has to be implemented in this method:abstract String method(long parameter);
In TypeScript however, type references are at the end so this method has to be overridden doing nothing andwriteTypeReferenceEnd(CodeGenericType, Appendable, String, String, String)has to be overridden to append a colon followed by the type:abstract method(parameter:number):string;
- Parameters:
type- theCodeGenericTypeto 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.
-
writeTypeReferenceEnd
protected void writeTypeReferenceEnd(CodeGenericType type, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException - Parameters:
type- theCodeGenericTypeto 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.- See Also:
-
getMethodModifiers
- Parameters:
method- theCodeMethod.- Returns:
- the
modifiersof the givenCodeMethodto write as source-code. However, with potential transformation for thisCodeLanguage.
-
writeConstructor
public void writeConstructor(CodeConstructor constructor, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Description copied from interface:CodeLanguageWrites the givenCodeConstructor.- Specified by:
writeConstructorin interfaceCodeLanguage- 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.
-
writeParameters
public void writeParameters(CodeParameters parameters, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeParameters.- Parameters:
parameters- theCodeParametersto 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.
-
writeTypeVariables
public void writeTypeVariables(CodeTypeVariables typeVariables, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeTypeVariables.- Parameters:
typeVariables- theCodeTypeVariablesto 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
public void writeBody(CodeOperation operation, Appendable sink, String newline, String defaultIndent, String currentIndent) throws IOException Writes the givenCodeOperation.- Parameters:
operation- theCodeOperationto 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.
-