Class SourceToObjectUtils
java.lang.Object
edu.university.ecs.lab.common.utils.SourceToObjectUtils
Static utility class for parsing a file and returning associated models from code structure.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Stringprivate static com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolverprivate static Configprivate static com.github.javaparser.ast.CompilationUnitprivate static Stringprivate static Stringprivate static Stringprivate static String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MethodconvertValidEndpoints(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, Method method, com.github.javaparser.ast.expr.AnnotationExpr requestMapping) This method converts a valid Method to an Endpointstatic MethodCallconvertValidRestCalls(com.github.javaparser.ast.expr.MethodCallExpr methodCallExpr, MethodCall methodCall) This method converts a valid MethodCall to an RestCallprivate static Set<com.github.javaparser.ast.expr.AnnotationExpr>private static voidgenerateStaticValues(File sourceFile, Config config1) private static StringgetCallingObjectName(com.github.javaparser.ast.expr.MethodCallExpr mce) Get the name of the object a method is being called from (callingObj.methodName())private static StringgetCallingObjectType(com.github.javaparser.ast.expr.MethodCallExpr mce) private static StringgetMicroserviceName(File sourceFile) Get the name of the microservice based on the fileprivate static JClasshandleFeignClient(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.private static JClassprivate static JClasshandleRepositoryRestResource(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.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 modelsstatic JClassparseClass(File sourceFile, Config config, String microserviceName) This method parses a Java class file and return a JClass object.private static ClassRoleparseClassRole(Set<com.github.javaparser.ast.expr.AnnotationExpr> annotations) This method searches a list of Annotation expressions and returns a ClassRole foundstatic ConfigFileparseConfigurationFile(File file, Config config) parseFields(List<com.github.javaparser.ast.body.FieldDeclaration> fieldDeclarations) This method converts a list of FieldDeclarations to a set of Field modelsstatic List<MethodCall>parseMethodCalls(List<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations) This method parses methodDeclarations list and returns a Set of MethodCall modelsparseMethods(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
-
Field Details
-
cu
private static com.github.javaparser.ast.CompilationUnit cu -
microserviceName
-
path
-
className
-
packageName
-
packageAndClassName
-
combinedTypeSolver
private static com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver combinedTypeSolver -
config
-
-
Constructor Details
-
SourceToObjectUtils
public SourceToObjectUtils()
-
-
Method Details
-
generateStaticValues
-
parseClass
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 Methodmethod- the Method to be convertedrequestMapping- 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 MethodmethodCall- 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
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
-
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
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
-
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
-