Giter Club home page Giter Club logo

javaflow's People

Contributors

cvetanov avatar havardh avatar misino avatar pascalgn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

javaflow's Issues

Also parse parent class from 3rd party Jar files

Let's say we have the following java types:

public abstract class BaseDto {
    private int id;

    public int getId() {
        return id;
    }
}

public class UserDto extends BaseDto {
    private String name;

    public String getName() {
        return name;
    }
}

then javaflow will correctly generate

export UserDto = {
  id: number,
  name: string
};

However, when BaseDto is not from the same project, but actually only included via Jar file, javaflow will not be able to parse BaseDto (source code is not available) and the resulting type UserDto will be missing the id field.

Support type parameters in classes

The following model is not handled correctly:

public class ModelWithTypeParams {
  class Child<T> {
    private T field;

    public T getField() {
      return field;
    }
  }

  private Child<String> child1;
  private Child<Integer> child2;

  public Child<String> getChild1() {
    return child1;
  }

  public Child<Integer> getChild2() {
    return child2;
  }
}

as I can see, flow supports generics so I think it might be enough if we "simply" generate this:

export type Child<T> = {
  field: T
}

export type ModelWithTypeParams = {
  child1: Child<string>,
  child2: Child<number>
}

But maybe I'm missing something obvious here?

Support jackson annotations: @JsonIgnore, @JsonProperty, @JsonGetter

For example:

package domain.document;

import domain.person.Person;

public class Document {
    private long id;
    private Person person;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}
package domain.person;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import domain.document.Document;

import java.util.Set;

public class Person {
    private long id;
    @JsonProperty("documents")
    private Set<Document> documentSet;
    @JsonIgnore
    private String password;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Set<Document> getDocumentSet() {
        return documentSet;
    }

    public void setDocumentSet(Set<Document> documentSet) {
        this.documentSet = documentSet;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Result:
javaflow domain/

/* eslint-disable no-use-before-define */
/* Generated by javaflow 1.5.0 */
export type Document = {
  id: number,
  person: Person,
};

export type Person = {
  id: number,
  documentSet: Array<Document>,
  password: string,
};

But want:

  id: number,
  person: Person,
};

export type Person = {
  id: number,
  documents: Array<Document>,
};

Annotation for nullable field

Need some option for mark field as nullable. And after javaflow get something like this:

export type Document = {
  id: number,
  person: Person,
};

export type Person = {
  id: number,
  documentSet: Array<Document>,
  someNullableField: ?string,
};

Could not find or load main class com.github.havardh.javaflow.JavaFlow

jpomykala@Jakub-MBP:assortment/shortages ‹dev*›$ javaflow RefillFilterParams.java > param.js
Error: Could not find or load main class com.github.havardh.javaflow.JavaFlow
Caused by: java.lang.ClassNotFoundException: com.github.havardh.javaflow.JavaFlow

Build command: gradle assemble
Version: 1.4.2 (same on 1.5.2-SNAPSHOT)

import java.time.LocalDate;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class RefillFilterParams {
  private LocalDate startDate;
  private LocalDate endDate;
}

Correct package resolve in case when import with *

Version: javaflow -version
/* @flow /
/
eslint-disable no-use-before-define /
/
Generated by javaflow 1.5.0 */

Example:

package domain.document;

import domain.person.*;

public class Document {
    private long id;
    private Person person;
    
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}
package domain.person;

import domain.document.*;

import java.util.Set;

public class Person {
    private long id;
    private Set<Document> documentSet;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Set<Document> getDocumentSet() {
        return documentSet;
    }

    public void setDocumentSet(Set<Document> documentSet) {
        this.documentSet = documentSet;
    }
}

Command for execute: javaflow domain/
Result:

Exception in thread "main" com.github.havardh.javaflow.exceptions.AggregatedException: Verification failed:

Could not find types: {domain.document.Document=[person: domain.document.Person]}
  at com.github.havardh.javaflow.Execution.verify(Execution.java:119)
  at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:372)
  at java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:373)
  at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  at java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:419)
  at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
  at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
  at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
  at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
  at com.github.havardh.javaflow.Execution.run(Execution.java:98)
  at com.github.havardh.javaflow.JavaFlow.main(JavaFlow.java:71)

Include fields that only have getters

Currently, the main focus for generated fields in types is the Java field. But consider the following Java class:

public class User {
    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getName() {
        return firstName + " " + lastName;
    }
}

then usually (at least when using Jackson API), instances of that class will result in JSON like this:

{
  "firstName": "John",
  "lastName": "Smith",
  "name": "John Smith"
}

However, as there is no field name in class User, the resulting type will not include the name field:

export User = {
  firstName: string,
  lastName: string
};

Static fields included?

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?

Generic types in Maps and List types are not transformed

When field type contains generic, the generic type is not transformed to the corresponding type.
For example, expected transformation of Map<String, List<Integer>> field; is {[key: string]: Array<number>

Actual result is wrong {[key: string]: List<Integer>}

Created also a failing test for it in this pull request: #47

I am not sure how to solve it. Probably we will need to use some recursion and extract type from the string literal in TypeFactory.

Make Transformer for sorting all types

Sort types before writing them to flow types.

This will make the output more identical between runs.
Currently the order is based on the input order.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.