Klasse Transpiler

Alle implementierten Schnittstellen:
Processor

This class provides a transpiler for transpiling java source code into another programming language that is supported by implementing the TranspilerLanguagePlugin class. Therefore the Java Compiler API (module java.compiler) and its abstract syntax tress (AST, module jdk.compiler) are used.
  • Konstruktordetails

    • Transpiler

      public Transpiler(String classdir, File... sources)
      Creates a new transpiler object for transpiling the specified java sources
      Parameter:
      classdir - the directory where to place the compiler class output files
      sources - the File-Objects for all Java-Sources
  • Methodendetails

    • printSourceFiles

      public void printSourceFiles()
      Prints the paths of all Java input files on the command line.
    • transpile

      public void transpile()
      Starts the compilation process for all Java sources passed to the transpiler and aggregates information about the Java sources for the transpiling process.
    • addLanguagePlugin

      public void addLanguagePlugin(TranspilerLanguagePlugin plugin)
      Add a language plugin to this transpiler for transpiling into a specific language
      Parameter:
      plugin - the language plugin for the transpiler
    • getTypeUtils

      public Types getTypeUtils()
      Returns the type utility class from the java compiler (see Types).
      Gibt zurück:
      the type utility class
    • getAllClasses

      public List<ClassTree> getAllClasses()
      Returns all classes to be transpiled - nested and non nested classes.
      Gibt zurück:
      a list containing all classes to be transpiled
    • getTranspilerUnit

      public TranspilerUnit getTranspilerUnit(Tree node)
      Returns the transpiler unit for the specified tree node.
      Parameter:
      node - the tree node
      Gibt zurück:
      the transpiler unit
    • getTreePath

      public TreePath getTreePath(Element element)
      Returns the tree path for the specified element or null if the element ist not found
      Parameter:
      element - the element
      Gibt zurück:
      the tree path or null
    • getParent

      public Tree getParent(Tree node)
      Returns the parent tree object for the specified tree object
      Parameter:
      node - the tree object
      Gibt zurück:
      the parent tree object
    • isNested

      public boolean isNested(ClassTree node)
      Checks whether the specified class tree node is a nested class or not.
      Parameter:
      node - the class tree node
      Gibt zurück:
      true if the class is nested and false otherwise
    • hasTranspilerUnit

      public boolean hasTranspilerUnit(String packageName, String className)
      Returns whether a transpiler unit exists for the class represented by the specified package and class name.
      Parameter:
      packageName - the package name
      className - the class name
      Gibt zurück:
      true if the class exists and false otherwise
    • getTranspilerUnit

      public TranspilerUnit getTranspilerUnit(String packageName, String className)
      Returns whether a transpiler unit exists for the class represented by the specified package and class name.
      Parameter:
      packageName - the package name
      className - the class name
      Gibt zurück:
      true if the class exists and false otherwise
    • getClassTree

      public ClassTree getClassTree(String qualifiedName)
      Gibt den zugehörigen ClassTree für den übergebenen Klassennamen zurück, sofern diese Klasse auch von Transpiler transpiliert wird.
      Parameter:
      qualifiedName - der voll qualifizirte Name der Klasse
      Gibt zurück:
      das ClassTree-Objekt oder null
    • getFullClassName

      public String getFullClassName(ClassTree node)
      Returns the full class name of the specified class tree, i.e. with the package and in case of a nested class with its parent class(es).
      Parameter:
      node - the class tree node
      Gibt zurück:
      the full class name
    • getAttributes

      public static List<VariableElement> getAttributes(TypeElement typeElement)
      Returns the list of attributes of the TypeElement, e.g. a class.
      Parameter:
      typeElement - the type element
      Gibt zurück:
      the list of attributes of the type element
    • getAttributesFromClassTree

      public List<VariableElement> getAttributesFromClassTree(ClassTree node)
      Returns the list of attributes of the class tree node as VariableElement
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of attributes of the class tree node as VariableElement
    • getAttributes

      public static List<VariableTree> getAttributes(ClassTree node)
      Returns the list of attributes of the class tree node
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of attributes of the class tree node
    • getAttributesWithSuperclassAttributes

      public List<VariableTree> getAttributesWithSuperclassAttributes(ClassTree node)
      Returns the list of attributes of the class tree node
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of attributes of the class tree node
    • getAttribute

      public static VariableTree getAttribute(ClassTree node, String name)
      Returns the attribute of the class tree node with the specified name
      Parameter:
      node - the class tree node
      name - the attributes name
      Gibt zurück:
      the attribute of the class tree node
    • getConstructors

      public static List<MethodTree> getConstructors(ClassTree node)
      Returns the list of constructors of the class tree node.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of methods of the class tree node
    • getMethods

      public static List<MethodTree> getMethods(ClassTree node)
      Returns the list of methods - excluding constructors - of the class tree node.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of methods of the class tree node
    • getDefaultMethods

      public static List<MethodTree> getDefaultMethods(ClassTree node)
      Returns the list of default methods of the specified class tree node of kind INTERFACE.
      Parameter:
      node - the class tree node of kind INTERFACE
      Gibt zurück:
      the list of default methods of the class tree node
    • getNonDefaultMethods

      public static List<MethodTree> getNonDefaultMethods(ClassTree node)
      Returns the list of non default methods of the specified class tree node of kind INTERFACE.
      Parameter:
      node - the class tree node of kind INTERFACE
      Gibt zurück:
      the list of non-default methods of the class tree node
    • getAllMethods

      public static List<MethodTree> getAllMethods(ClassTree node)
      Returns the list of all methods - including constructors - of the class tree node.
      Parameter:
      node - the class tree node
      Gibt zurück:
      the list of methods of the class tree node
    • getMethods

      public static List<MethodTree> getMethods(ClassTree node, String name)
      Returns the methods of the class tree node with the specified name.
      Parameter:
      node - the class tree node
      name - the method name
      Gibt zurück:
      the list of methods of the class tree node with the specified name
    • isClassMember

      public boolean isClassMember(IdentifierTree node)
      Checks whether the identifier is a class member if not access with "this.".
      Parameter:
      node - the identifier node to be checked
      Gibt zurück:
      true if the identifier is a class member in this scope and false otherwise
    • isStaticClassMember

      public boolean isStaticClassMember(IdentifierTree node)
      Checks whether the identifier is a static class member if not accessed by a member select with its class name.
      Parameter:
      node - the identifier node to be checked
      Gibt zurück:
      true if the identifier is a static class member in this scope and false otherwise
    • getDeclaration

      public VariableTree getDeclaration(IdentifierTree node)
      Returns the variable declaration for the specified identifier or null if a variable declaration is not found.
      Parameter:
      node - the identifier
      Gibt zurück:
      the variable declaration or null
    • getDeclaration

      public VariableTree getDeclaration(ExpressionTree node)
      Returns the variable declaration for the specified identifier or null if a variable declaration is not found.
      Parameter:
      node - the expression to be evaluated
      Gibt zurück:
      the variable declaration or null
    • getClass

      public ClassTree getClass(Tree node)
      Returns the class or enum that is the ancestor of this tree node. This may be an inner class.
      Parameter:
      node - the tree node
      Gibt zurück:
      the parent class tree node
    • hasTsObjectAnnotation

      public static boolean hasTsObjectAnnotation(List<? extends AnnotationTree> annotations, TranspilerUnit tu)
      Checks whether the annotation list contains a TsObject annotation.
      Parameter:
      annotations - the list of annotation nodes
      tu - the transpiler unit
      Gibt zurück:
      true if the list contains a TsObject annotation
    • hasAllowNullAnnotation

      public static boolean hasAllowNullAnnotation(List<? extends AnnotationTree> annotations, TranspilerUnit tu)
      Checks whether the annotation list contains a AllowNull annotation.
      Parameter:
      annotations - the list of annotation nodes
      tu - the transpiler unit
      Gibt zurück:
      true if the list contains a AllowNull annotation
    • hasAllowNullAnnotation

      public static boolean hasAllowNullAnnotation(List<? extends AnnotationMirror> annotations)
      Checks whether the annotation list contains a AllowNull annotation.
      Parameter:
      annotations - the list of annotation nodes
      Gibt zurück:
      true if the list contains a AllowNull annotation
    • hasAllowNullAnnotation

      public static boolean hasAllowNullAnnotation(TypeMirror type)
      Checks whether the type mirror has a AllowNull annotation assigned.
      Parameter:
      type - the type mirror
      Gibt zurück:
      true if is has a AllowNull annotation assigned
    • hasAllowNullAnnotation

      public static boolean hasAllowNullAnnotation(Element elem)
      Checks whether the element has a AllowNull annotation assigned.
      Parameter:
      elem - the element
      Gibt zurück:
      true if is has a AllowNull annotation assigned
    • hasAllowNullAnnotation

      public boolean hasAllowNullAnnotation(Tree node)
      Checks whether the tree node has a AllowNull annotation assigned.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if is has a AllowNull annotation assigned
    • hasNotNullAnnotation

      public static boolean hasNotNullAnnotation(List<? extends AnnotationTree> annotations, TranspilerUnit tu)
      Checks whether the annotation list contains a Not Null annotation from the jakartax.validation package.
      Parameter:
      annotations - the list of annotation nodes
      tu - the transpiler unit
      Gibt zurück:
      true if the list contains a not null annotation
    • hasNotNullAnnotation

      public static boolean hasNotNullAnnotation(List<? extends AnnotationMirror> annotations)
      Checks whether the annotation list contains a Not Null annotation from the jakartax.validation package.
      Parameter:
      annotations - the list of annotation nodes
      Gibt zurück:
      true if the list contains a not null annotation
    • hasNotNullAnnotation

      public static boolean hasNotNullAnnotation(TypeMirror type)
      Checks whether the type mirror has a Not Null annotation from the jakartax.validation package assigned.
      Parameter:
      type - the type mirror
      Gibt zurück:
      true if is has a not null annotation assigned
    • hasNotNullAnnotation

      public static boolean hasNotNullAnnotation(Element elem)
      Checks whether the element has a Not Null annotation from the jakartax.validation package assigned.
      Parameter:
      elem - the element
      Gibt zurück:
      true if is has a not null annotation assigned
    • hasNotNullAnnotation

      public boolean hasNotNullAnnotation(Tree node)
      Checks whether the tree node has a Not Null annotation from the jakartax.validation package assigned.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if is has a not null annotation assigned
    • isDeclaredUsingVar

      public static boolean isDeclaredUsingVar(VariableTree node)
      Prüft, ob die Variable mit dem Schlüsselwort var für den Typ deklariert wurde oder nicht.
      Parameter:
      node - die Variablendeklaration
      Gibt zurück:
      true, falls das Schlüsselwort var verwendet wurde.
    • hasTranspilerDTOAnnotation

      public static boolean hasTranspilerDTOAnnotation(List<? extends AnnotationTree> annotations, TranspilerUnit tu)
      Checks whether the annotation list contains a TranspilerDTO annotation.
      Parameter:
      annotations - the list of annotation nodes
      tu - the transpiler unit
      Gibt zurück:
      true if the list contains a TranspilerDTO annotation
    • hasTranspilerDTOAnnotation

      public boolean hasTranspilerDTOAnnotation(ClassTree node)
      Checks whether the class tree node has a TranspilerDTO annotation.
      Parameter:
      node - the class tree node
      Gibt zurück:
      true if the class has a TranspilerDTO annotation
    • getAnnotation

      public AnnotationTree getAnnotation(String annotationType, Tree tree)
      Returns the annotation of the annotation list which has specified type.
      Parameter:
      annotationType - the name of the annotation type (e.g. )
      tree - the class or method where to check for the annotation
      Gibt zurück:
      the annotation if an annotation of the specified type exists
    • isAnnotationType

      public boolean isAnnotationType(String annotationType, AnnotationTree annotation)
      Returns whether the specified annotation has the specified type
      Parameter:
      annotationType - the annotation types fully qualified name
      annotation - the annotation to be checked
      Gibt zurück:
      true if the annotation has the specified type
    • getAnnotationList

      public List<AnnotationTree> getAnnotationList(String annotationType, Tree tree)
      Returns all annotation of the annotation list which has specified type.
      Parameter:
      annotationType - the name of the annotation type (e.g. )
      tree - the class or method where to check for the annotation
      Gibt zurück:
      the list of all annotations of the specified type
    • getArguments

      public static Map<String,ExpressionTree> getArguments(AnnotationTree annotation)
      Returns for the specified AnnotationTree a mapping of all variable names to their assigned ExpressionTree.
      Parameter:
      annotation - the annotation tree
      Gibt zurück:
      the mapping
    • getFunctionInterfaceMethodName

      public String getFunctionInterfaceMethodName(String name)
      Checks whether the java full qualified name is the name of a functional interface or not and returns the name of the abstract method name for the specified functional interface.
      Parameter:
      name - the full qualified name of the interface
      Gibt zurück:
      the method name or null if name is not the name of a functional interface
    • isAnnotationArgument

      public boolean isAnnotationArgument(IdentifierTree node)
      Checks whether the specified identifier tree node is part of an annotation tree but not the type of an annotation.
      Parameter:
      node - the identifier tree node
      Gibt zurück:
      true, if the specified identifier tree node is part of an annotation tree, and false otherwise
    • isParentAnnotationType

      public boolean isParentAnnotationType(IdentifierTree node)
      Checks whether the specified identifier tree node is part of an annotation.
      Parameter:
      node - the identifier tree node
      Gibt zurück:
      true, if the specified identifier tree node is part of an annotation, and false otherwise
    • getExpressionType

      public ExpressionType getExpressionType(ExpressionTree node)
      Gets the type object associated with specified expression tree node.
      Parameter:
      node - the expression tree node
      Gibt zurück:
      the type object
    • getAccessModifier

      public String getAccessModifier(Tree node)
      Returns the access modifier associated with the tree node as a string. If there is none an empty string is returned.
      Parameter:
      node - the tree node
      Gibt zurück:
      the access modifier string or an empty string.
    • getMethod

      public Tree getMethod(ReturnTree node)
      Retrieves the method that belongs to the specified return tree.
      Parameter:
      node - the return tree node
      Gibt zurück:
      the tree of the method or the lambda.
    • hasAbstractModifier

      public boolean hasAbstractModifier(Tree node)
      Returns whether the tree node has an abstract modifier or not.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if the tree node has an abstract modifier and false otherwise
    • hasFinalModifier

      public boolean hasFinalModifier(Tree node)
      Returns whether a final modifier is associated with the tree node.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if the tree node has a final modifier and false otherwise
    • hasStaticModifier

      public boolean hasStaticModifier(Tree node)
      Returns whether a static modifier is associated with the tree node.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if the tree node has a static modifier and false otherwise
    • hasDefaultModifier

      public boolean hasDefaultModifier(Tree node)
      Returns whether a default modifier is associated with the tree node.
      Parameter:
      node - the tree node
      Gibt zurück:
      true if the tree node has a default modifier and false otherwise
    • getElement

      public Element getElement(Tree node)
      Retrieves the java compiler element for the tree node or null if none exists.
      Parameter:
      node - the tree node
      Gibt zurück:
      the java compiler element
    • getPackageOf

      public PackageElement getPackageOf(Element elem)
      Retrieves the PackageElement of the specified Element
      Parameter:
      elem - the element
      Gibt zurück:
      the package element
    • getTypeMirror

      public TypeMirror getTypeMirror(Tree node)
      Return the type mirror for the specified tree node
      Parameter:
      node - the tree node
      Gibt zurück:
      the type mirror
    • getTypeElement

      public TypeElement getTypeElement(String name)
      Returns the type element for the specified canonical name
      Parameter:
      name - the canonical name
      Gibt zurück:
      the type element
    • checkForSuperclass

      public int checkForSuperclass(ExpressionType classType, ExpressionType superType)
      Checks whether the specified class type has the specified super type, either a class type or an interface type
      Parameter:
      classType - the class type
      superType - the super type
      Gibt zurück:
      -1 on error or a positive value signaling the depth in the super class / interface tree
    • checkForSuperclass

      public int checkForSuperclass(TypeElement te, String superFullQualified)
      Checks whether the type element has the specified super type, either a class type or an interface type
      Parameter:
      te - the type element
      superFullQualified - the full qualified name of the super type
      Gibt zurück:
      -1 on error or a positive value signaling the depth in the super class / interface tree
    • getComment

      public String getComment(Tree node)
      Retrieves the comment for the specified tree node or null if none exists.
      Parameter:
      node - the tree node
      Gibt zurück:
      the comment or null
    • getCompilationUnit

      public CompilationUnitTree getCompilationUnit(Tree node)
      Retrieves the compilation unit for the specified tree node.
      Parameter:
      node - the tree node
      Gibt zurück:
      the compilation units tree node
    • init

      public void init(ProcessingEnvironment processingEnv)
      Angegeben von:
      init in Schnittstelle Processor
      Setzt außer Kraft:
      init in Klasse AbstractProcessor
    • process

      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
      Angegeben von:
      process in Schnittstelle Processor
      Angegeben von:
      process in Klasse AbstractProcessor