public class StringEnumAdapter extends PrinterAdapter
@StringType.
For instance: @StringType enum MyEnum { A, B, C } will be erased
and all subsequent accesses to the enum will be mapped to simple strings.
Typically, the method declaration void m(MyEnum e) {...} will be
mapped to void m(e : string) {...}. And of course, the
invocation xxx.m(MyEnum.A) will be mapped to
xxx.m("A").
Warning: this adapter is not activated by default. See JSweet specifications to know how to activate this adapter.
context, logger, typeVariablesToErase| Constructor and Description |
|---|
StringEnumAdapter(PrinterAdapter parent)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
substituteCaseStatementPattern(CaseElement caseStatement,
ExtendedElement pattern)
Special case for the case statement patter.
|
boolean |
substituteMethodInvocation(MethodInvocationElement invocation)
Uses of enum API need to be translated accordingly to strings.
|
boolean |
substituteVariableAccess(VariableAccessElement variableAccess)
Accessing an enum field is replaced by a simple string value (
MyEnum.A => "A"). |
adaptDocComment, addAnnotation, addAnnotation, addAnnotationManager, addAnnotationWithValue, addHeader, addTypeMapping, addTypeMapping, addTypeMappings, afterType, endIndent, eraseSuperClass, eraseSuperInterface, findExecutableDeclarationInType, getAnnotationValue, getAnnotationValue, getContext, getErasedTypes, getFunctionalTypeMappings, getHeader, getMappedType, getModuleImportDescriptor, getParentAdapter, getParentElement, getParentElement, getPrinter, getRootRelativeName, getTranspilerOptions, getTypeMappingTarget, hasAnnotationType, isAmbientDeclaration, isMappedType, isSubstituteSuperTypes, needsImport, print, print, print, print, printArgList, printIdentifierList, printIndent, println, printMacroName, removeLastChar, removeLastChar, removeLastChars, removeLastIndent, report, report, report, report, setParentAdapter, setPrinter, space, startIndent, substitute, substituteArrayAccess, substituteAssignment, substituteAssignmentWithOperator, substituteBinaryOperator, substituteForEachLoop, substituteIdentifier, substituteInstanceof, substituteNewClass, substituteUnaryOperator, types, utilpublic StringEnumAdapter(PrinterAdapter parent)
Performs the following initializations:
@Erased to all
eligible enum declarations
An eligible enum type is an enum type that has a @StringType
annotation.
public boolean substituteMethodInvocation(MethodInvocationElement invocation)
substituteMethodInvocation in class PrinterAdapterinvocation - the invocation being printedpublic boolean substituteVariableAccess(VariableAccessElement variableAccess)
MyEnum.A => "A").substituteVariableAccess in class PrinterAdaptervariableAccess - the variable access being printedpublic boolean substituteCaseStatementPattern(CaseElement caseStatement, ExtendedElement pattern)
substituteCaseStatementPattern in class PrinterAdapter