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

WIP -- Generators and Lexical Preserving Printer #2704

Open
wants to merge 116 commits into
base: master
Choose a base branch
from

Conversation

MysterAitch
Copy link
Member

@MysterAitch MysterAitch commented May 31, 2020

This is a bit muddled given that I ended up doing a bunch of printer fixes in addition to the generator stuff...

Let's see how much I can recall! 👍 👍 👍

Fixed:

  • Any generated methods which are then not re-generated are marked as "stale" (and are reported within the console at the end of running the core generator).
  • Generators now run with lexical preservation turned on.
  • Difference.MatchClassification now has an additional option -- newline. This is used when trying to rank which differences applies (e.g. since JP now respects the line endings in the file, they're not necessarily always going to be equal, thus \r is treated differently to \n etc and causes problems in the "same before" and "same after" logic).
  • A couple of areas of the ConcreteSyntaxModel have been fixed/tweaked/reformatted.
  • When creating methods/method bodies (e.g. methodBody.addStatement()) newlines aren't automatically present, thus the lexical preserving printer retains this code style and doesn't automatically insert them. For this reason, I've added a prettyPrint method to the AbstractGenerator that is used a few times to rectify this (i.e. where we want the generated nodes to be pretty printed, but the "other" nodes to be preserved).
  • Many methods which previously missed the annotation @Generated now have it
  • Many methods which previously missed the annotation @Override now have it
  • Fixed setting the annotation of @SuppressWarnings (n.b.: side effect of reversing the annotation now that adding that annotation happens prior to adding the @Generated annotation)
  • Fixed cases where the generated/replaced nodes have non-javadoc comments (previously they'd be removed/lost, now they're retained)
  • Added a common ancestor to the printers (not sure why I did this and could probably split out into a separate PR, but it's helpful when we don't really care what kind of printer we have so I'm leaving it)

Outstanding:

  • For some reason, the space between the imports and the class/enum header is removed.
  • Indentation on "entries" (i.e. within an enum and switch) isn't right
    • This can be seen within JavaToken.java and ObservableProperty.java
  • Indentation of the valueOf method within JavaToken.java increases on every run of the generator.
  • When removing all "entries" within an enum, the lines / indentation remain -- they should probably be removed (i.e. when deleting the last entry, the whole line should be removed). The consequence is that when adding the entries back in, these newlines are retained in addition to the newly inserted ones.

There is probably some tidying that is needed to be done also (offhand: probably leftover commented code, and test code that I'm not sure is in the correct test class).

Closes #1301

Replaces: #2554
Replaces: #2557

…that those are the ones which are run directly
… and ensure that relevant imports have been added
…make it explicit WHICH 'parse()' method is being used within tests (many cases of per-test-specific private methods etc)
…dd a "StaleGenerated" annotation and remove that...
… currently pass due to deliberately "bad" expected string)
…s when also handling raw CSM elements (e.g. `original.elements`)
…. indent followed by newline, as opposed to newline followed by indent)
…ctoring_latest

# Conflicts:
#	javaparser-core-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinterTest.java
#	javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java
#	javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/DifferenceElementCalculator.java
@MysterAitch
Copy link
Member Author

Currently has expected / known test failures per the issues described in the comment above -- there are issues with indentation when adding/removing nodes with lexical preservation enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LexicalPreservingPrinter does not play well with core-generators.
2 participants