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

How to make EEA easier to review, diff & merge #16

Open
vorburger opened this issue Sep 15, 2017 · 14 comments
Open

How to make EEA easier to review, diff & merge #16

vorburger opened this issue Sep 15, 2017 · 14 comments

Comments

@vorburger
Copy link
Member

vorburger commented Sep 15, 2017

While working on #10 and merging some EEA java.* from an existing project (tracecompass) with some EEA I had already created in this project before, I realized that diff & merge of *.eea is quite a PITA... e.g. Git is often wrong and would have lost things, because it's algorithm for finding dupes assume you want to change things when really you want to add.

As (or perhaps even more...) important than diff & merge is simple "review-ability" - unless you are really used to the EEA syntax (which e.g. I currently am not yet..), it's kind of really hard actually to immediately understand exactly what gets changed in e.g. something like the Map get() and remove() of PR #21.

The goal of this issue to collect community feedback is there's anything that can be done to help with this:

  • Git settings for *.eea ?!
  • Minor changes to the EEA file format (probably too late already)
  • Alternative friendlier syntax with generator/converter to EEA?

@svenefftinge once suggested the idea of an Xtext grammar for this... that could be cool, some day! ;-) Imagine representing EEA as a very Java-like Xbase validating DSL language, with the respective @nullable etc. annotations as if it was Java (but without any Method bodies), and then a little EEA generator off that - that could be neat. BUT one problem that deserves more thought before jumping into such a DSL (which isn't really THAT hard to put together...) is the workflow... The Eclipse IDE integration using which developers maintain EEA files directly (which is how EEA get created today) would become much MORE cumbersome - after you Quick Fix an EEA, how do you get the EEA changed? In ideal world, that would have to be some fancy bi-directional thingie - but that's a little less immediate easy like pie out of the box, e.g. with Xtext.

vorburger added a commit to vorburger/eclipse-null-eea-augments that referenced this issue Sep 15, 2017
These are the ones I had to indivdually review and in many cases had to
manually resolve merges; that's a PITA (and lead me to open
lastnpe#16), thus I
skipped merged java.lang.String, java.util.Collections and java.util.Map
and kept my original ones, and did not merge with tracecompass'

from
https://github.com/tracecompass/tracecompass/tree/master/common/org.eclipse.tracecompass.common.core/annotations/java

for lastnpe#10
vorburger added a commit to vorburger/eclipse-null-eea-augments that referenced this issue Sep 15, 2017
These are the ones I had to indivdually review and in many cases had to
manually resolve merges; that's a PITA (and lead me to open
lastnpe#16), thus I
skipped merged java.lang.String, java.util.Collections and java.util.Map
and kept my original ones, and did not merge with tracecompass'

from
https://github.com/tracecompass/tracecompass/tree/master/common/org.eclipse.tracecompass.common.core/annotations/java

for lastnpe#10
kaikreuzer pushed a commit that referenced this issue Sep 15, 2017
These are the ones I had to indivdually review and in many cases had to
manually resolve merges; that's a PITA (and lead me to open
#16), thus I
skipped merged java.lang.String, java.util.Collections and java.util.Map
and kept my original ones, and did not merge with tracecompass'

from
https://github.com/tracecompass/tracecompass/tree/master/common/org.eclipse.tracecompass.common.core/annotations/java

for #10
@vorburger vorburger changed the title How to make EEA easier to diff & merge How to make EEA easier to review, diff & merge Sep 16, 2017
@ctron
Copy link
Member

ctron commented Sep 27, 2017

EEA Compiler

I played a bit around with writing some "compiler" for EEAs. My idea was to write an interface/class like:

class java.time.Instant {

public static Instant now();
public static @NonNull _now();

}

So that you have the original methods and the annotated methods prefixed with _. The code to parse the Java stuff is easy, as you can use JDT for that. However I wasn't able to quickly find out how the generate the method signatures from an AST.

I think having such an approach would make it simpler to write EEAs.

EEA validation

I guess having some sort of unit tests would be necessary as well. However the unit test would be some piece of Java code which simply doesn't compile, due to null analysis. So going with plain maven surefire probably won't work. I am not sure if there is a concept in maven for testing the compilability of java source code.

@vorburger
Copy link
Member Author

My idea was to write an interface/class like:

Hm... I was imagining something like that as well, and on further reflection wonder why it couldn't simply be:

package java.time;

import org.eclipse.jdt.annotation.NonNull;

interface Instant {
    @NonNull Instant now();
}

so just forget my earlier Xtext rambling - why not just good old plain valid Java syntax real .java files? And then a lil' "thingie" which transpiles this new "human readable EEA" .java to & fro the current "unreadable almost like binary" .eea... imagine that.

IMHO for this to real work and keep this new "source" .java in line with what then become purely a "generated output" EEA, you would need BOTH a Maven plugin which during the build would transform this src/.java into target/.eea (you know what I mean), AND a (new) Eclipse plug-in which which works bi-directionally, so it would do the "generation" from .java to .eea (so that you can edit the .java in the workspace while you code and refine the EEA; that part alone you can probably even get with M2E integration just kicking off the same Maven plugin) but, in an ideal world, ALSO the reverse, a Builder which when the target/.eea gets touched correspondingly updates the src/.java (preserving any formatting and comments in it...). The latter would be useful to be able to still use the JDT Quick Fix stuff which creates/modifies the EEA. Or maybe that's just a nice to have later phase 27 could have idea, not critical for a first version... perhaps one would just get used to only directly editing the .java with this approach, and forget about letting the JDT quick fix update the EEA?

All this unless, of course, someone were to put in the work to change JDT to support the syntax above directly; but that's probably a long shot - and actually not required - we could well offer something "on top".

some sort of unit tests

Originally I wasn't even thinking that far, but more imagining that some... small new Maven plugin-in would be able to use JDT headless JAR to validate even just the syntax of EEA - that they are valid and loadable and not "corrupt", not necessarily "correct", yet. But if they were generated from .java (as in above), then that would be a non-issue, anyway.

unit test would be some piece of Java code which simply doesn't compile, due to null analysis

But perhaps we could as a convention start the other way around? Positive not negative testing... if you add a new EEA, it is (should be) because you are getting rid of a warning or error? So one would just put an example of that in examples/ ... we may have to change the example' config to fail for warnings, that should be possible.

not sure if there is a concept in maven for testing

yeah, I dunno either. Or if just a Maven trick / plugin that tests that a compilation fails. But then you would have to have a lot of very small individual Maven artifact projects, one for each annotation.. that's not going to scale.

@maggu2810
Copy link
Contributor

I don't know about discussions and things that are related to the creation of JDT nullness analysis and EEA files. But the format you suggest is IMHO the format the Checker Framework already uses for their astub files.
So, why reinvent the wheel and not using stuff that already exist?

@ctron
Copy link
Member

ctron commented Sep 27, 2017

What is better than 13 standards? 😁

So, why reinvent the wheel and not using stuff that already exist?

Do you have a pointer on it? So that we can have a look.

@maggu2810
Copy link
Contributor

@maggu2810
Copy link
Contributor

There are also tools to create a stub file from a class, so you only need to add your annotations and that in a readable text format...

@maggu2810
Copy link
Contributor

Under nullness you can find the annotated JDK:
https://github.com/typetools/checker-framework/tree/master/checker/jdk

@vorburger
Copy link
Member Author

@maggu2810 @ctron re. "There are also tools to create a stub file from a class" and all, see also new https://bugs.eclipse.org/bugs/show_bug.cgi?id=525352. The link above has a full JDK with annotation - do you happen to know, or would be willing to dig to find out, if the Checker project has these Stub files e.g. for the JDK somewhere? Or how one produces those from that?

@vorburger
Copy link
Member Author

@Bananeweizen
Copy link
Contributor

Bananeweizen commented Oct 29, 2017

I have just done a big diff/merge on EEA files, and therefore imagine something more simple actually: Can't we implement a simple editor without xtext, that derives from the builtin text editor, and just adds the following 2 features:

  • tooltip on text lines showing the actual meaning (i.e. the same you would see when hovering the same method in the Java editor or displaying it in the Javadoc view)
  • hyperlinking (from the EEA method signatures to the Java method declarations).

I imagine that to be sufficient for reviewing and merging. I left out more advanced editing on purpose, since I'm not sure that will ever be needed.

@vorburger
Copy link
Member Author

Guys, in #72 @rPraml contributes something which addresses one aspect we have previously discussed here - his work seems to cover the 'some sort of unit tests / imagining that some... small new Maven plugin-in would be able to use JDT headless JAR to validate even just the syntax of EEA - that they are valid and loadable and not "corrupt"' aspect!

@sebthom
Copy link
Contributor

sebthom commented Mar 13, 2023

I created an alternative EEAs repo with an advanced generator at https://github.com/vegardit/no-npe/. The generator can sort existing EEA files. PRs are validated to comply with the expected sorting order and that the declared method signatures match the bytecode. This makes PR reviewing very easy.

This is a commit where I locally bumped the version of one dependency and then executed the generator to add new message signatures vegardit/no-npe@9d615fe
This is a PR created by the generator bot configured in the repo: https://github.com/vegardit/no-npe/pull/49/files

@vorburger
Copy link
Member Author

@sebthom cool! Would you be interested in being invited to be a commiter and maintainer on this lastnpe org?

@sebthom
Copy link
Contributor

sebthom commented Mar 17, 2023

@vorburger thanks for the offer. While I am not interested in modifying the existing lastnpe project (our repo works fundamentally different) I would be willing to donate the content of our repo and refactor/rebrand it as lastnpe 3.x (ideally with some minor help from you regarding infrastructure stuff) and continue working from there.

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

No branches or pull requests

5 participants