havardh / javaflow

Java model to flowtype converter
22 stars 5 forks source link

Static fields included? #56

Closed pascalgn closed 5 years ago

pascalgn commented 5 years ago

I noticed that during type generation, static fields are not excluded, so for example this Java class:

public class SomeClass {
    private static final long serialVersionUID = 3210616069586284583L;

    public static final String CONSTANT = "some constant";

    private String someField;
}

currently results in this type:

export type SomeClass = {
  serialVersionUID: number,
  SOME_CONSTANT: string,
  someField: string
};

whereas I would expect it to result in this type:

export type SomeClass = {
  someField: string
};

WDYT?

havardh commented 5 years ago

I agree with you about the expectation here.

I propose to make this an option on the JavaParser, with a default value to exclude static fields.

This flag should in turn be passed into the ClassVisitor through the convert static method. I guess it is the visit(FieldDeclaration, ClassBuilder) in ClassVisitor which should exclude these fields based on the content of field.getModifiers().

Do you want/have time to make a PR for this?

pascalgn commented 5 years ago

Sure, will create a PR for it!

havardh commented 5 years ago

@pascalgn: I've released javaflow@1.5.0 and javaflow-maven-plugin@1.4.0 with the all changes included. Please, when you have time, let me know if the release works on your project 🙏

And thank you so much for these contributions 💯

PS: it might take a little while before the updated plugin show up the maven repositories.

pascalgn commented 5 years ago

@havardh Thanks a lot for the quick release! Sorry for not getting back to you sooner, but I had a lot to do in the last few days. However, I have just finished implementing javaflow in our project and it is working. It's not perfect and there are a few workarounds we had to do, but we get the generated types and can use them and that's already helping us a lot!

So thank you again for this nice project! 👍

I will create issues for the workarounds we currently have to do, both here and over in javaflow-maven-plugin. Some might be easy to resolve, others I'm not sure about, so let's have a look at them together. Of course, when you feel a feature/issue does not fit the direction of the project, just say so and/or close it!

havardh commented 5 years ago

Do not worry about getting back in time. :) Lets allow each other the slack we need ;) I'm in no hurry.

Its great to hear that you are already benefiting from javaflow, now lets get to a 100% ;)