Class SourceToObjectUtils

java.lang.Object
edu.university.ecs.lab.common.utils.SourceToObjectUtils

public class SourceToObjectUtils extends Object
Static utility class for parsing a file and returning associated models from code structure.
  • Field Details

    • cu

      private static com.github.javaparser.ast.CompilationUnit cu
    • microserviceName

      private static String microserviceName
    • path

      private static String path
    • className

      private static String className
    • packageName

      private static String packageName
    • packageAndClassName

      private static String packageAndClassName
    • combinedTypeSolver

      private static com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver combinedTypeSolver
    • config

      private static Config config
  • Constructor Details

    • SourceToObjectUtils

      public SourceToObjectUtils()
  • Method Details

    • generateStaticValues

      private static void generateStaticValues(File sourceFile, Config config1)
    • parseClass

      public static JClass parseClass(File sourceFile, Config config, String microserviceName)
      This method parses a Java class file and return a JClass object.
      Parameters:
      sourceFile - the file to parse
      Returns:
      the JClass object representing the file
    • parseMethods

      public static Set<Method> parseMethods(List<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations, com.github.javaparser.ast.expr.AnnotationExpr requestMapping)
      This method parses methodDeclarations list and returns a Set of Method models
      Parameters:
      methodDeclarations - the list of methodDeclarations to be parsed
      Returns:
      a set of Method models representing the MethodDeclarations
    • convertValidEndpoints

      public static Method convertValidEndpoints(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, Method method, com.github.javaparser.ast.expr.AnnotationExpr requestMapping)
      This method converts a valid Method to an Endpoint
      Parameters:
      methodDeclaration - the MethodDeclaration associated with Method
      method - the Method to be converted
      requestMapping - the class level requestMapping
      Returns:
      returns method if it is invalid, otherwise a new Endpoint
    • parseMethodCalls

      public static List<MethodCall> parseMethodCalls(List<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations)
      This method parses methodDeclarations list and returns a Set of MethodCall models
      Parameters:
      methodDeclarations - the list of methodDeclarations to be parsed
      Returns:
      a set of MethodCall models representing MethodCallExpressions found in the MethodDeclarations
    • convertValidRestCalls

      public static MethodCall convertValidRestCalls(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr, MethodCall methodCall)
      This method converts a valid MethodCall to an RestCall
      Parameters:
      methodCallExpr - the MethodDeclaration associated with Method
      methodCall - the MethodCall to be converted
      Returns:
      returns methodCall if it is invalid, otherwise a new RestCall
    • parseFields

      private static Set<Field> parseFields(List<com.github.javaparser.ast.body.FieldDeclaration> fieldDeclarations)
      This method converts a list of FieldDeclarations to a set of Field models
      Parameters:
      fieldDeclarations - the field declarations to parse
      Returns:
      the set of Field models
    • getCallingObjectName

      private static String getCallingObjectName(com.github.javaparser.ast.expr.MethodCallExpr mce)
      Get the name of the object a method is being called from (callingObj.methodName())
      Returns:
      the name of the object the method is being called from
    • getCallingObjectType

      private static String getCallingObjectType(com.github.javaparser.ast.expr.MethodCallExpr mce)
    • parseAnnotations

      private static Set<Annotation> parseAnnotations(Iterable<com.github.javaparser.ast.expr.AnnotationExpr> annotationExprs)
      This method parses a list of annotation expressions and returns a set of Annotation models
      Parameters:
      annotationExprs - the annotation expressions to parse
      Returns:
      the Set of Annotation models
    • parseClassRole

      private static ClassRole parseClassRole(Set<com.github.javaparser.ast.expr.AnnotationExpr> annotations)
      This method searches a list of Annotation expressions and returns a ClassRole found
      Parameters:
      annotations - the list of annotations to search
      Returns:
      the ClassRole determined
    • getMicroserviceName

      private static String getMicroserviceName(File sourceFile)
      Get the name of the microservice based on the file
      Parameters:
      sourceFile - the file we are getting microservice name for
      Returns:
    • handleFeignClient

      private static JClass handleFeignClient(com.github.javaparser.ast.expr.AnnotationExpr requestMapping, Set<com.github.javaparser.ast.expr.AnnotationExpr> classAnnotations)
      FeignClient represents an interface for making rest calls to a service other than the current one. As such this method converts feignClient interfaces into a service class whose methods simply contain the exact rest call outlined by the interface annotations.
      Parameters:
      classAnnotations -
      Returns:
    • parseConfigurationFile

      public static ConfigFile parseConfigurationFile(File file, Config config)
    • filterClassAnnotations

      private static Set<com.github.javaparser.ast.expr.AnnotationExpr> filterClassAnnotations()
    • handleRepositoryRestResource

      private static JClass handleRepositoryRestResource(com.github.javaparser.ast.expr.AnnotationExpr requestMapping, Set<com.github.javaparser.ast.expr.AnnotationExpr> classAnnotations)
      FeignClient represents an interface for making rest calls to a service other than the current one. As such this method converts feignClient interfaces into a service class whose methods simply contain the exact rest call outlined by the interface annotations.
      Parameters:
      classAnnotations -
      Returns:
    • handleJS

      private static JClass handleJS(String filePath)