Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrate and Enhance Spring Analyzer for Kotlin (#251) #307

Merged
merged 22 commits into from
May 26, 2024

Conversation

ksg97031
Copy link
Member

Overview

I've made some significant updates to migrate our existing Java Spring analyzer to a Kotlin Spring analyzer. This includes adding new classes like KotlinLexer and KotlinParser, as well as various refactorings and improvements to enhance functionality.

Key Changes

  1. Addition of KotlinLexer Class

    • Introduced a new KotlinLexer class that inherits from MiniLexer to tokenize Kotlin code.
    • Improved the handling of string and character literals in the lexer.
  2. Addition and Enhancement of KotlinParser Class

    • Added a new KotlinParser class specifically for analyzing Spring-Kotlin applications.
    • Refactored and enhanced the functions for parsing class fields and annotations.
    • Enhanced parsing capabilities to better handle Kotlin code.
  3. Porting Java Spring Analyzer to Kotlin Spring

    • Ported the existing Java Spring analyzer to a Kotlin Spring analyzer to support Kotlin environments.
    • Refactored Spring detectors to work with both Kotlin and Java files.

Review Requests

Please let me know if you find any bugs or if there are any areas that need improvement.

Thanks a lot!

ksg97031 added 19 commits May 5, 2024 03:05
- Implemented various methods in `KotlinLexer` to tokenize Kotlin code based on logic
- Fixed bug in `trace` method in `minilexer.cr`

Signed-off-by: ksg <ksg97031@gmail.com>
- Defined the `AnnotationModel`, `ClassModel`, `MethodModel`, and `FieldModel` classes within the `KotlinParser` class
- Implemented various methods for parsing import statements, formal parameters, annotations, classes, class fields, and methods in the `KotlinParser` class

Signed-off-by: ksg <ksg97031@gmail.com>
- Updated `print_tokens` method to display token types
- Added `trace` method to display parsed data for classes, fields, and methods

Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
- Fix typos and add missing commas in Kotlin lexer files

Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
- Modified `KotlinLexer` in `src/minilexers/kotlin.cr`
- Added new punctuation types in `src/minilexers/kotlin.cr`
- Modified `AnalyzerKotlinSpring` in `src/analyzer/analyzers/analyzer_kotlin_spring.cr`
- Modified and added methods for parsing Kotlin files in `src/miniparsers/kotlin.cr`

Signed-off-by: ksg <ksg97031@gmail.com>
- Fixed a typo and refactored methods in the Kotlin miniparser
- Updated punctuation tokens and removed unnecessary tokens in the Kotlin minilexer

Signed-off-by: ksg <ksg97031@gmail.com>
- Removed test case for detecting Spring in `pom.xml` and `build.gradle`, added new test case for detecting it in `test.java`
- Various methods for parsing Kotlin files including import statements, class declarations, fields, and methods

Signed-off-by: ksg <ksg97031@gmail.com>
- Modified the expected endpoints in `kotlin_spring_spec.cr`.

Signed-off-by: ksg <ksg97031@gmail.com>
- Add `==` method to the `Param` struct in `src/models/endpoint.cr`

Signed-off-by: ksg <ksg97031@gmail.com>
- Modified method to include method parameters when parsing fields from class body
- Added support for multiple request mappings in processing method annotations
- Implemented support for optional parameters, headers, values, and paths in handling request methods and formats
- Added support for Pageable parameters in endpoint parameter extraction
- Implemented support for default values in extracting parameter details
- Added support for user-defined class fields in adding parameters to user-defined classes

Signed-off-by: ksg <ksg97031@gmail.com>
…_spring.cr`

- Added parameter `lorem` with value `ipsum` and type `cookie` to `/api/user/{login}` endpoint in `kotlin_spring_spec.cr`
- Deleted `pom.xml` file for `kotlin_spring` fixture in `pom.xml`

Signed-off-by: ksg <ksg97031@gmail.com>
- Added new support for Spring framework in Kotlin.
- Fixed the support status for Spring framework in Java (missed in the previous update).

Signed-off-by: ksg <ksg97031@gmail.com>
@ksg97031 ksg97031 requested a review from hahwul May 25, 2024 07:21
@github-actions github-actions bot added 📑 documentation Improvements or additions to documentation 🔎 detector Issue for Detector 🔬 analyzer Issue for Analyzer 💊 spec Issue for test codes 🥢 mini-lexer Issue for mini-lexer and mini-parser labels May 25, 2024
- :STRING_LITERAL tokens are always two characters or more, so the size condition check is redundant and has been removed.

Signed-off-by: ksg <ksg97031@gmail.com>
Signed-off-by: ksg <ksg97031@gmail.com>
@hahwul hahwul added this to the v0.16.0 milestone May 25, 2024
Copy link
Member

@hahwul hahwul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiya @ksg97031
Your code looks fantastic as always! I really appreciate your attention to detail :D

I noticed that you included the gradle-wrapper.jar file. Do you think it's essential for our testing flow? Just curious about your thoughts on this.

Other than that, everything seems perfect. If there are no further issues, I'll go ahead and approve and merge this PR.

Thanks!

- Deleted unnecessary `gradle-wrapper.jar` and `gradle-wrapper.properties` files.

Signed-off-by: ksg <ksg97031@gmail.com>
@ksg97031 ksg97031 closed this May 26, 2024
@ksg97031 ksg97031 reopened this May 26, 2024
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gradle-wrapper.jar is used to ensure that the same version of Gradle is used across all environments, but it is not strictly necessary for the project to function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the gradle-wrapper.jar file as suggested.

@ksg97031 ksg97031 requested a review from hahwul May 26, 2024 03:28
@hahwul hahwul merged commit 2c33e9d into main May 26, 2024
16 checks passed
@hahwul hahwul deleted the improve/spring-kotlin-analyzer branch May 26, 2024 13:15
@hahwul hahwul restored the improve/spring-kotlin-analyzer branch May 26, 2024 13:15
@hahwul hahwul linked an issue May 31, 2024 that may be closed by this pull request
@hahwul hahwul mentioned this pull request Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔬 analyzer Issue for Analyzer 🔎 detector Issue for Detector 📑 documentation Improvements or additions to documentation 🥢 mini-lexer Issue for mini-lexer and mini-parser 💊 spec Issue for test codes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Parameter Analysis Feature for Kotlin Spring
2 participants