Klasse TranspilerTypeScriptPlugin

java.lang.Object
de.svws_nrw.transpiler.TranspilerLanguagePlugin
de.svws_nrw.transpiler.typescript.TranspilerTypeScriptPlugin

public final class TranspilerTypeScriptPlugin extends TranspilerLanguagePlugin
This is the transpiler language plugin for Type Script.
  • Felddetails

    • indentC

      public int indentC
      the indentation state used during transpilation
    • renamedInterfaces

      public static final Set<String> renamedInterfaces
      Ein Set mit allen im Transpiler umbenannten interfaces
  • Konstruktordetails

    • TranspilerTypeScriptPlugin

      public TranspilerTypeScriptPlugin(Transpiler transpiler, String outputDir, boolean includeTSJavaCore)
      Create a Type Script transpiler language plugin
      Parameter:
      transpiler - the transpiler that uses this plugin
      outputDir - the output directory where all generated files should be placed
      includeTSJavaCore - gibt an, ob auch der Typescript-Code für die grundlegenden Java-Bibliotheken mit eingebunden werden sollen
  • Methodendetails

    • setIgnoreJavaPackagePrefix

      public void setIgnoreJavaPackagePrefix(String prefix)
      Sets the configuration parameter for the prefix part of the java packages to be ignored while creating the sub directories for the Type Script output.
      Parameter:
      prefix - the prefix part of the java package to be ignored
    • getIndent

      public String getIndent()
      Returns the current indentation string used during transpilation
      Gibt zurück:
      the current indentation string
    • pruefeBezeichner

      public static void pruefeBezeichner(String bezeichner)
      Prüft, ob der übergebene Bezeichner ein Schlüsselwort in Type-Script ist, welches nicht auch in Java ein Schlüsselwortd er Sprache ist.
      Parameter:
      bezeichner - der zu prüfende Bezeichner
    • convertTypeParameter

      public String convertTypeParameter(TypeParameterTree node, boolean withBounds)
      Transpiles the type parameter node.
      Parameter:
      node - the type parameter node to be transpiled
      withBounds - specifies whether the bounds of the type parametes should be transpiled or not
      Gibt zurück:
      the type parameter string
    • convertTypeParameters

      public String convertTypeParameters(List<? extends TypeParameterTree> nodes, boolean withBounds)
      Transpiles the type parameters nodes.
      Parameter:
      nodes - the type parameter nodes to be transpiled
      withBounds - specifies whether the bounds of the type parametes should be transpiled or not
      Gibt zurück:
      the type parameters string
    • convertBlockVariable

      public String convertBlockVariable(VariableTree node)
      Transpiles the variable declared in a statement block.
      Parameter:
      node - the variable declaration
      Gibt zurück:
      the transpiled statement block
    • convertEnhancedForLoop

      public String convertEnhancedForLoop(EnhancedForLoopTree node)
      Transpiles the for each loop.
      Parameter:
      node - the enhanced for loop statement
      Gibt zurück:
      the transpiled for each loop
    • convertForLoop

      public String convertForLoop(ForLoopTree node)
      Transpiles the for loop.
      Parameter:
      node - the for loop statement
      Gibt zurück:
      the transpiled for loop
    • convertWhileLoop

      public String convertWhileLoop(WhileLoopTree node)
      Transpiles the while loop.
      Parameter:
      node - the while loop statement
      Gibt zurück:
      the transpiled while loop
    • convertDoWhileLoop

      public String convertDoWhileLoop(DoWhileLoopTree node)
      Transpiles the do while loop.
      Parameter:
      node - the do while loop statement
      Gibt zurück:
      the transpiled do while loop
    • convertIdentifier

      public String convertIdentifier(IdentifierTree node)
      Transpiles the identifier.
      Parameter:
      node - the identifier
      Gibt zurück:
      the transpiled identifier
    • convertMemberSelect

      public String convertMemberSelect(MemberSelectTree node)
      Transpiles the member select statement.
      Parameter:
      node - the member select statement
      Gibt zurück:
      the transpiled member select statement
    • convertParenthesized

      public String convertParenthesized(ParenthesizedTree node)
      Transpiles the parenthesized node.
      Parameter:
      node - the parenthesized node
      Gibt zurück:
      the transpiled parenthesized statement
    • convertBinaryOperator

      public String convertBinaryOperator(BinaryTree node)
      Transpiles the binary operation.
      Parameter:
      node - the binary operation node
      Gibt zurück:
      the transpiled binary operation
    • convertUnaryOperator

      public String convertUnaryOperator(UnaryTree node)
      Transpiles the unary operation.
      Parameter:
      node - the unary operation node
      Gibt zurück:
      the transpiled unary operation
    • convertCompoundAssignment

      public String convertCompoundAssignment(CompoundAssignmentTree node)
      Transpiles the compound assignment.
      Parameter:
      node - the compound assignment
      Gibt zurück:
      the transpiled compound assignment
    • convertArrayAccess

      public String convertArrayAccess(ArrayAccessTree node)
      Transpiles the array access expression.
      Parameter:
      node - the array access expression
      Gibt zurück:
      the transpiled array access expression
    • convertTypeCast

      public String convertTypeCast(TypeCastTree node)
      Transpiles the type cast expression.
      Parameter:
      node - the type cast expression tree node
      Gibt zurück:
      the transpiled type cast expression
    • convertInstanceOf

      public String convertInstanceOf(InstanceOfTree node)
      Transpiles the instance of expression.
      Parameter:
      node - the instance of expression tree node
      Gibt zurück:
      the transpiled instance of expression
    • convertLambdaExpression

      public String convertLambdaExpression(LambdaExpressionTree node)
      Transpiles the lambda expression.
      Parameter:
      node - the lambda expression tree node
      Gibt zurück:
      the transpiled lambda expression
    • convertSwitchExpression

      public String convertSwitchExpression(SwitchExpressionTree node, String switchVarName)
      Transpiles the switch expression.
      Parameter:
      node - the switch expression tree node
      switchVarName - der Variablenname, welcher im switch verwendet werden soll
      Gibt zurück:
      the transpiled switch expression
    • convertExpression

      public String convertExpression(ExpressionTree node)
      Transpiles the expression.
      Parameter:
      node - the expression
      Gibt zurück:
      the transpiled string if the expression was transpiled successfully and null otherwise
    • convertConditionalExpression

      public String convertConditionalExpression(ConditionalExpressionTree node)
      Transpiles the conditional expression.
      Parameter:
      node - the conditional expression
      Gibt zurück:
      the transpiled conditional expression
    • convertLiteral

      public static String convertLiteral(LiteralTree node)
      Transpiles the literal.
      Parameter:
      node - the literal
      Gibt zurück:
      the transpiled literal
    • getDefaultValueForPrimitiveType

      public static String getDefaultValueForPrimitiveType(PrimitiveTypeTree node)
      Returns the default value for primitive types.
      Parameter:
      node - the primitive type tree node
      Gibt zurück:
      the default value as String
    • getDefaultValueForType

      public static String getDefaultValueForType(Tree node)
      Returns the default value for the specified type node.
      Parameter:
      node - the type tree node
      Gibt zurück:
      the default value as String
    • convertNewArray

      public String convertNewArray(NewArrayTree node)
      Transpiles the new array expression node.
      Parameter:
      node - the new array expression to be transpiled
      Gibt zurück:
      the transpiled new array expression
    • convertAssignment

      public String convertAssignment(AssignmentTree node)
      Transpiles the simple assignment.
      Parameter:
      node - the assignment
      Gibt zurück:
      the transpiled simple assignment
    • convertExpressionStatement

      public String convertExpressionStatement(ExpressionStatementTree node)
      Transpiles the expression statement.
      Parameter:
      node - the expression statement
      Gibt zurück:
      the transpiled expression if the statement was transpiled successfully and null otherwise
    • convertThrow

      public String convertThrow(ThrowTree node)
      Transpiles the throw expression.
      Parameter:
      node - the expression
      Gibt zurück:
      the transpiled expression if the statement was transpiled successfully and null otherwise
    • convertStatement

      public String convertStatement(StatementTree node, boolean noIndent)
      Transpiles the statement.
      Parameter:
      node - the statement
      noIndent - true if no indentation should be used
      Gibt zurück:
      the transpiled statement
    • convertIf

      public String convertIf(IfTree node)
      Transpiles the if statement.
      Parameter:
      node - the if statement
      Gibt zurück:
      the transpiled if statement
    • convertSwitch

      public String convertSwitch(SwitchTree node, boolean noIndent)
      Transpiles the switch statement.
      Parameter:
      node - the switch statement
      noIndent - true if no indentation should be used
      Gibt zurück:
      the transpiled switch statement
    • convertReturn

      public String convertReturn(ReturnTree node)
      Transpiles the return statement.
      Parameter:
      node - the return statement
      Gibt zurück:
      the transpiled return statement
    • convertYield

      public String convertYield(YieldTree node, String yieldVar)
      Transpiles the yield statement.
      Parameter:
      node - the yield statement
      yieldVar - the temporary variable for the switch-yield-expression
      Gibt zurück:
      the transpiled yield statement
    • convertBreak

      public static String convertBreak(BreakTree node)
      Transpiles the break statement.
      Parameter:
      node - the break statement
      Gibt zurück:
      the transpiled break statement
    • convertContinue

      public static String convertContinue(ContinueTree node)
      Transpiles the continue statement.
      Parameter:
      node - the continue statement
      Gibt zurück:
      the transpiled continue statement
    • convertCatch

      public String convertCatch(CatchTree node)
      Transpiles the catch clause.
      Parameter:
      node - the catch clause
      Gibt zurück:
      the transpiled catch clause
    • convertTry

      public String convertTry(TryTree node)
      Transpiles the try statement.
      Parameter:
      node - the try statement
      Gibt zurück:
      the transpiled try statement
    • convertBlock

      public String convertBlock(BlockTree node, boolean ignoreFirst, String yieldVar)
      Transpiles the statement block.
      Parameter:
      node - the statement block
      ignoreFirst - if set, the first statement is ignored (sometimes super constructor calls must be ignored)
      yieldVar - the name of the temporary yield variable if yield is used
      Gibt zurück:
      the transpiled block
    • convertMethodInvocationParameters

      public String convertMethodInvocationParameters(List<? extends ExpressionTree> expressions, String enumValueName, Integer enumOrdinal, boolean noParentheses)
      Transpiles the list of method invocation parameters.
      Parameter:
      expressions - the list of method invocation parameters
      enumValueName - the name of the enum value as first method invocation parameter, if the method is the constructor of an enum value
      enumOrdinal - the ordinal as second method invocation parameter, if the method is the constructor of an enum value
      noParentheses - defines whether the parameters should be surrounded by parentheses
      Gibt zurück:
      the transpiled method invocation parameters
    • convertNewClass

      public String convertNewClass(NewClassTree node)
      Transpiles the new class expression.
      Parameter:
      node - the new class expression
      Gibt zurück:
      the transpiled new class expression
    • convertMethodInvocation

      public String convertMethodInvocation(MethodInvocationTree node)
      Transpiles the method invocation expression.
      Parameter:
      node - the method invocation expression
      Gibt zurück:
      the transpiled method invocation expression and null if the method invocation was skipped to prevent typescript errors
    • convertAttribute

      public String convertAttribute(VariableTree node, String enumName)
      Transpiles the attribute of a class.
      Parameter:
      node - the attribute to be transpiled
      enumName - specifies the name of the enum if the attribute belongs to an enum
      Gibt zurück:
      the transpiled attribute
    • getCastFunctionName

      public String getCastFunctionName(ClassTree node)
      Determines the cast function name for the specified class tree node
      Parameter:
      node - the class tree node
      Gibt zurück:
      the name of the cast function fpr the specified class tree object
    • appendCast

      public void appendCast(StringBuilder sb, ClassTree node)
      Appends a function to cast an object to the class type. The function is appended after the class definition.
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the class to be transpiled
    • appendTranspilerCanonicalName

      public String appendTranspilerCanonicalName(ClassTree node)
      Appends a method that returns the classes canonical name for simulating part of Javas refelction API.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the transpilerCanonicalName method code as a String
    • appendClassAttribute

      public String appendClassAttribute(ClassTree node)
      Appends the attribute class specifying the objects class for simulating part of Javas refelction API.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the class attribute code as a string
    • appendIsTranspiledInstanceOf

      public String appendIsTranspiledInstanceOf(ClassTree node)
      Appends a method to the transpiled class code for simulating the Java instanceof operator. This is required to support instanceof checks on interfaces that are not available in typescript since the underlying javascript does not support interfaces.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the isTranspiledInstanceOf method code as a String
    • appendTranspilerFromJSON

      public String appendTranspilerFromJSON(ClassTree node)
      Appends a method for creating a TS object from JSON to the transpiled class code.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the transpilerFromJSON method code as a String
    • appendTranspilerToJSON

      public String appendTranspilerToJSON(ClassTree node)
      Appends a method for creating JSON from the TS object to the transpiled class
      Parameter:
      node - the class tree node
      Gibt zurück:
      the transpilerToJSON method code as a String
    • appendTranspilerToJSONPatch

      public String appendTranspilerToJSONPatch(ClassTree node)
      Appends a method for creating a JSON Patch from the TS object to the transpiled class
      Parameter:
      node - the class tree node
      Gibt zurück:
      the transpilerToJSON method code as a String
    • transpileClassMethods

      public void transpileClassMethods(StringBuilder sb, ClassTree node, List<MethodTree> methodNodes)
      Transpiles the class methods.
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the class to be transpiled
      methodNodes - the class methods to be transpiled
    • convertDefaultMethodParameters

      public String convertDefaultMethodParameters(ExecutableElement method, Map<String,TypeMirror> resolved)
      Konvertiert die Parameter des übergebenen Methode nach Typescript
      Parameter:
      method - die zu konvertierende Methode
      resolved - eine Map mit den Typen von aufgelösten Typ-Variablen
      Gibt zurück:
      die Methoden-Parameter als String
    • transpileDefaultMethodImplementations

      public void transpileDefaultMethodImplementations(StringBuilder sb, ClassTree node)
      Erzeugt den Code für die Verwendung von Default-Methoden innerhalb der Klasse
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the class or enum to be transpiled
    • transpileClass

      public void transpileClass(StringBuilder sb, ClassTree node)
      Transpiles the class.
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the class to be transpiled
    • transpileEnum

      public void transpileEnum(StringBuilder sb, ClassTree node)
      Transpiles the enumeration.
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the enumeration class to be transpiled
    • transpileInterface

      public void transpileInterface(StringBuilder sb, ClassTree node)
      Transpiles the interface.
      Parameter:
      sb - the StringBuilder where the output is written to
      node - the class to be transpiled
    • getImportName

      public static String getImportName(String className, String packageName)
      Bestimmt anhand der Namen der Klasse und des Packages den Klassennamen für das Schreiben des transpilierten Codes. Hierbei finden Umbenennungen statt, falls in Typescript identische Bezeichner vorkommen.
      Parameter:
      className - der Name der Java-Klasse
      packageName - der Name des Java-Packages
      Gibt zurück:
      der Typescript-Klassenname
    • getImportPackageName

      public static String getImportPackageName(String className, String packageName)
      Bestimmt anhand der Namen der Klasse und des Packages den Packagenamen für das Schreiben des transpilierten Codes. Hierbei finden ggf. Umbenennungen statt.
      Parameter:
      className - der Name der Java-Klasse
      packageName - der Name des Java-Packages
      Gibt zurück:
      der Typescript-Packagename
    • getImports

      public String getImports(TranspilerUnit unit, String strIgnoreJavaPackagePrefix, String body)
      Prints the import information of the transpiler unit
      Parameter:
      unit - the transpiler unit containing the import information
      strIgnoreJavaPackagePrefix - the package prefix to be ignored
      body - the file body of the transpiled class
      Gibt zurück:
      the imports for the transpiled typescript class
    • transpile

      public void transpile()
      Beschreibung aus Klasse kopiert: TranspilerLanguagePlugin
      This method is invoked by the transpiler to start the transpiling process for this language plugin. It must be implemented by the language plugin.
      Angegeben von:
      transpile in Klasse TranspilerLanguagePlugin