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

👔 Add identification logic of parameters in Spring #233

Merged
merged 9 commits into from
Mar 5, 2024

Conversation

hahwul
Copy link
Member

@hahwul hahwul commented Jan 23, 2024

Hi @ksg97031 👋🏼

I've added some code to the SpringAnalyzer for #232. This code identifies well-known parameter processing logic and adds it as a parameter to the last added Endpoint during file content analysis. I've written it lightly for now, but please review and let me know if this method seems good!

If this direction is correct, I think it would be good to continue expanding the pattern together in the future. However, I'm slightly worried because developers have such a wide variety of ways to handle parameters.

@hahwul hahwul requested a review from ksg97031 January 23, 2024 13:53
@github-actions github-actions bot added the 💊 spec Issue for test codes label Jan 23, 2024
@hahwul hahwul added the 🔬 analyzer Issue for Analyzer label Jan 23, 2024
@hahwul hahwul changed the title 👔 Add identification logic of parameters in Spring (targeting specifi… 👔 Add identification logic of parameters in Spring Jan 23, 2024
@hahwul hahwul removed the request for review from ksg97031 January 23, 2024 14:06
@hahwul hahwul marked this pull request as draft January 23, 2024 14:07
@hahwul hahwul marked this pull request as ready for review January 24, 2024 01:15
- Added `src/miniparsers/java.cr` file
- Added `JavaParser` class with `parse`, `parse_import_statements`, `parse_classes_body`, and `print_tokens` methods
- Implemented tokenization logic in `MiniLexer` class
- Added `line` property to `Token` class and updated `to_s` method to handle newline characters correctly
- Added `src/minilexers/java.cr` file with keyword, literal, separator, and operator definitions for Java
- Implemented `JavaLexer` class for tokenizing Java code, handling different types of tokens, and skipping whitespace and comments
- Refactor `@classes_body_tokens` variable to `@classes_tokens` in `java.cr`
- Add `@class_annotation` variable for storing class annotations in `java.cr`
- Modify `parse_classes` method in `java.cr` to also parse class annotations
- Add `parse_formal_parameters` method for parsing formal parameters in `java.cr`
- Add `parse_annotations` method for parsing annotations in `java.cr`
- Modify `parse_methods` method in `java.cr` to correctly parse method declarations and bodies
- Add imports for `java` lexer and parser in `analyzer_spring.cr`
- Change variable name `has_class_been_imported` to `has_spring_web_bind_class_been_import` in `analyzer_spring.cr`
- Refactor code in `analyzer_spring.cr` to use the `JavaLexer` and `JavaParser` classes
- Modify `tokenize` method in `minilexer.cr` to pass line number obtained from `line()` method to `Token` constructor
- Modify `<<` method in `minilexer.cr` to use the new `line()` method to calculate line number for each token
- Modify `JavaParser` class for improved handling of `{}` characters in `parse_formal_parameters` method
- Update `parse_classes` method to correctly parse class bodies
- Implement `parse_methods` method to handle parsing of methods within the class body
- Refactor `analyzers/analyzer_spring.cr` by removing unnecessary `begin` and `rescue` blocks in `analyze` method
- Rename `has_spring_web_bind_class_been_import` to `has_spring_web_bind_package_been_import`
- Add parsing of base URL, methods, annotations, and parameters in the Spring MVC class
- Improve handling of methods without `@RequestMapping` annotation
- Remove unused code and variables related to the `Reactive Router`
- Add `get_mapping_path` method for handling parsing of path parameters in method annotations
- Modify logic for retrieving endpoint parameters in the Spring MVC class
- Made modifications to the `java.cr` file to improve logic in tokenization and matching of literals, identifiers, and operators
- Added new methods and updated existing methods in the `java.cr` file to support class parsing and model creation
- Updated the `AnalyzerSpring` class to handle parsing of Spring MVC and Reactive Router code, including endpoints, annotations, and parameters
- Added a `.gitignore` file to the `kotlin_spring` fixtures and included `.gradle` in it
- Added a `.gitignore` file to the `java_spring` fixtures and added `.gradle` to the ignore list
- Refactored and implemented various methods and classes in `src/miniparsers/java.cr`
- Added a new file `detect_kotlin_spring_spe_spec.cr` and test case in `spec/unit_test/detector` for detecting Java Spring
- Updated `src/models/minilexer/minilexer.cr` to include a new line and fix a typo in the method signature
- Made modifications and additions to `src/models/noir.cr` including the addition of new methods
- Updated `spec/functional_test/fixtures/java_spring/src/ItemController.java` to include a package statement and class definition
- Created a new file `src/analyzer/analyzers/analyzer_kotlin_spring.cr` with various methods and functions
- Deleted `src/analyzer/analyzers/analyzer_spring.cr`
- Made changes to `spec/functional_test/testers/java_spring_spec.cr` related to endpoint definitions
- Refactored and reordered code in `src/minilexers/java.cr`
- Made changes to `src/models/endpoint.cr` including the addition of comparison methods
- Modified `src/analyzer/analyzer.cr` to use updated analyzer functions and remove duplicate checks
- Renamed `spec/unit_test/analyzer/analyzer_spring_spec.cr` to `analyzer_kotlin_spring_spec.cr` and updated its contents
- Refactored conditions in `src/detector/detectors/java_spring.cr` for better readability
- Modified `src/detector/detectors/kotlin_spring.cr` to add additional detection conditions
- Added a new file `src/analyzer/analyzers/analyzer_java_spring.cr` with various methods and functions.
@github-actions github-actions bot added 🔎 detector Issue for Detector 📦 output-builder Issue for output builder (format) 🥢 mini-lexer Issue for mini-lexer and mini-parser labels Mar 5, 2024
@ksg97031 ksg97031 requested review from ksg97031 and removed request for ksg97031 March 5, 2024 05:05
- Added support for RequestHeader annotation in endpoint parameters
- Added support for HttpServletRequest argument in endpoint parameters
@ksg97031 ksg97031 merged commit b6d90c8 into dev Mar 5, 2024
7 checks passed
@ksg97031
Copy link
Member

ksg97031 commented Mar 5, 2024

@hahwul

Hi~ I've implemented a simple lexer and parser for the Java language.
Now we can gather parameters for Spring MVC annotations and endpoints more accurately.
Since it took longer than expected, I decided to implement it first for Java then Kotlin later.
Let me know if you encounter any suspicious issues while using it!

@hahwul
Copy link
Member Author

hahwul commented Mar 5, 2024

@ksg97031
Cool! Thank you for the great work!
I'll make sure to try to include the changes you've applied in the next release (maybe 0.13.0).

Have a wonderful refresh :D

@hahwul hahwul deleted the improve/add-param-in-spring-analyzer branch March 7, 2024 13:28
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 🥢 mini-lexer Issue for mini-lexer and mini-parser 📦 output-builder Issue for output builder (format) 💊 spec Issue for test codes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants