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 AST Functionality #248

Merged
merged 28 commits into from
Jun 21, 2023
Merged

Add AST Functionality #248

merged 28 commits into from
Jun 21, 2023

Conversation

MarkusPaulsen
Copy link
Contributor

First implementation of the AST-checker, which can search through Java-Files for unwanted:

  • Loop statements
  • Conditional statements
  • Function-based statements
  • Local class statements
  • Exception handling statememts
  • Synchronisation statements

@MarkusPaulsen MarkusPaulsen added enhancement New feature or request dependencies Pull requests that update a dependency file labels Nov 1, 2022
@MarkusPaulsen MarkusPaulsen self-assigned this Nov 1, 2022
@MaisiKoleni MaisiKoleni marked this pull request as draft November 1, 2022 10:08
Copy link
Collaborator

@MaisiKoleni MaisiKoleni left a comment

Choose a reason for hiding this comment

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

I don't know if this was intended for review already, but the comments will probably help anyway.

The overall direction where this is going is good, and most of the API looks as well.

Just some use cases are still unclear to me, mostly this has to do with the different types.

I think some classes can be merged, and the code might get more compact, the types may even fit in a single class with nested static classes. This might also reduce the number of sub-packages to zero.

Please adjust the changes such that all tests and code style checks still work.

Don't be scared by the number of comments, I just noted everything that came to my mind and could be improved. I hope it helps to have all that feedback as early as possible.

pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
@MaisiKoleni MaisiKoleni added this to the Version 1.11.0 milestone Nov 1, 2022
@MaisiKoleni
Copy link
Collaborator

MaisiKoleni commented Nov 1, 2022

I realize now, that apart from assertThatFile(Path) and assertThatDirectory(Path) another solution might be, as discussed some weeks ago:

  • assertThat(Path).asFile().hasNo(...) and assertThat(Path).asDirectory().hasNo(...)
  • assertThat(Path).withConfiguration(AstAssertConfiguration).hasNo(...)

or some similar APIs.
The fluent API and the configuration+builder have the advantage that they are extensible without combinatorial explosion.
Here, it would be easy to add using(Version.JAVA_17) or similar.

The config+builder has the advantage that they can be specified once and then used for every assertion.
But then again, how many of such assertThat statements do we expect a project to have? I would assume that this is 0 or 1 in 99% of the cases, as chaining is always possible.

We can also consider if varargs is a useful addition to hasNo(...).

Please tell me what you think about the suggestions; it would be very interesting to hear of other use cases than students should not be allowed to use any loops. Because this is larger in scope than that, it would be good to know what users might need and expect.

Could you ask the users (exercise creators at TUM for EIST/PSE/PGdP/...) what would be helpful? Maybe @JohannesStoehr has some suggestions as well, he knows both Ares and many instructors fairly well.

MarkusPaulsen and others added 6 commits January 12, 2023 10:52
- Deleted redundant test classes
- Deleted SynchronizationType.java, as it caused more problems with tests than benefit

Open aspect:
- Replacement of Path.properties by reusing the functionality in de.tum.in.test.api.structural.testutils.ClassNameScanner.findObservedClassesInProject()
@MaisiKoleni
Copy link
Collaborator

Sadly had no time to do a full review, but I hope it helps anyway.

Huge Thanks to @Strohgelaender for reviewing! Much appreciated 👍

Copy link
Collaborator

@MaisiKoleni MaisiKoleni left a comment

Choose a reason for hiding this comment

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

So I had a more in-depth look at the code now and changed a few small things myself, have a look if you agree. I also added the @API tags as far as I understand, check if they are correct.

I think the changes for the most part will get more detailed now, as the approach in general is good, I think. Only some questionable aspects remain:

  1. The defaults for the assertion could become a problem, maybe we could make them explicit.
  2. The assertion is created new every time we configure it, this differs from the default AssertJ behavior. Maybe we should match that, although I like immutable objects.
  3. The way the files are located, I think this is still too much additional usage weight if we already have the configuration resolving in the class name scanner.
  4. The requirements, what the user's aims are, are still unclear to me for many node type enum values.

src/main/java/de/tum/in/test/api/ast/tool/PathTool.java Outdated Show resolved Hide resolved
src/main/java/de/tum/in/test/api/ast/tool/PathTool.java Outdated Show resolved Hide resolved
src/main/java/de/tum/in/test/api/ast/type/ClassType.java Outdated Show resolved Hide resolved
src/main/java/de/tum/in/test/api/ast/model/JavaFile.java Outdated Show resolved Hide resolved
@MarkusPaulsen MarkusPaulsen marked this pull request as ready for review May 10, 2023 11:59
Copy link
Collaborator

@MaisiKoleni MaisiKoleni left a comment

Choose a reason for hiding this comment

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

This looks better and better, and I am now happy with almost everything, the only part that stands out is the assertion and how the paths are handled. If we sort out how to do that cleanly, we can merge it. If you like, we can also have a quick talk about it when I have time. I think extracting the source folder search from the ClassNameScanner would yield clean code without too much effort.

MarkusPaulsen and others added 5 commits May 19, 2023 19:18
Copy link
Collaborator

@MaisiKoleni MaisiKoleni left a comment

Choose a reason for hiding this comment

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

Looks good to me now, thank you @MarkusPaulsen for repeatedly improving the code and being patient.

This should enable us to release version 1.12.0 after a few dependency updates (the open PRs).

@MaisiKoleni MaisiKoleni merged commit ffcfa98 into master Jun 21, 2023
@MaisiKoleni MaisiKoleni deleted the AddASTFunctionality branch June 21, 2023 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants