Comments (3)
It generates something like this when there's no field:
package xsbti.api;
public final class This extends xsbti.api.PathComponent {
public static This create() {
return new This();
}
public static This of() {
return new This();
}
protected This() {
super();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (!(obj instanceof This)) {
return false;
} else {
This o = (This)obj;
return true;
}
}
public int hashCode() {
return 37 * (17 + "xsbti.api.This".hashCode());
}
public String toString() {
return "This(" + ")";
}
}
from contraband.
Yeah, but I would like the case where there are fields but it sticks in a no-arg constructor in as well. Something like this:
import java.util.List;
import java.util.Objects;
/** Represents a city : name, weather, population, country, capital, geo coordinates. */
public class City {
private String name;
private String state;
private String country;
private Boolean capital;
private Long population;
private List<String> regions;
// [START fs_class_definition]
public City() {
// Must have a public no-argument constructor
}
// Initialize all fields of a city
public City(String name, String state, String country,
Boolean capital, Long population, List<String> regions) {
this.name = name;
this.state = state;
this.country = country;
this.capital = capital;
this.population = population;
this.regions = regions;
}
// [END fs_class_definition]
public City(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Boolean getCapital() {
return capital;
}
public void setCapital(Boolean capital) {
this.capital = capital;
}
public Long getPopulation() {
return population;
}
public void setPopulation(Long population) {
this.population = population;
}
public List<String> getRegions() {
return regions;
}
public void setRegions(List<String> regions) {
this.regions = regions;
}
private String getDefinedValue(String s) {
if (s != null) {
return s;
} else {
return "";
}
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (name != null) {
sb.append(name);
}
if (state != null) {
sb.append(" state : ");
sb.append(state);
sb.append(",");
}
if (country != null) {
sb.append(", ");
sb.append(country);
}
sb.append(" : [");
if (population != null) {
sb.append(" population : ");
sb.append(population);
sb.append(",");
}
if (capital != null) {
sb.append(" capital : ");
sb.append(capital);
sb.append(",");
}
if (regions != null) {
sb.append(" regions : [");
for (String r : regions) {
sb.append(r);
sb.append(", ");
}
sb.append("],");
}
//remove trailing comma
if (sb.lastIndexOf(",") >= sb.length() - 1) {
sb.deleteCharAt(sb.length() - 1);
}
sb.append(" ]");
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof City)) {
return false;
}
City city = (City) obj;
return Objects.equals(name, city.name)
&& Objects.equals(state, city.state)
&& Objects.equals(country, city.country)
&& Objects.equals(population, city.population)
&& Objects.equals(capital, city.capital)
&& Objects.equals(regions, city.regions);
}
@Override
public int hashCode() {
return Objects.hash(name, state, country, capital, population, regions);
}
}
from contraband.
zero-field builder
Contraband generates multiple of
methods using @since
but I didn't think about the blank case where at some version X there are no fields, and version Y adds some fields. This needs to be fixed first.
package com.example
@target(Scala)
type City {
name: String! = "" @since("0.2.0")
}
Maybe we can introduce @since
to records:
package com.example
@target(Scala)
type City
@since("0.1.0")
{
name: String! = "" @since("0.2.0")
}
of
vs constructor
We currently don't directly expose the constructor, and use factory method of
.
Generally I think it's better to add indirection here for potentially being able to change the implementation (historically Contraband was created to workaround Scala's inability to grow case classes). We could potentially add some setting for this, but I am not sure if having a no-arg constructor would be useful since Contraband objects don't act like POJO. See below.
setter
We also don't support setters. All objects are immutable.
from contraband.
Related Issues (20)
- Generated code causes compiler warnings HOT 1
- Generate Shapeless Generic instances HOT 5
- Can't define singleton types
- maven plugin
- equal / hashCode inconsistencies around Array HOT 1
- always use \n for line breaks HOT 5
- Is it possible to define a Map within a type? HOT 1
- Incorrect Scaladoc
- Allow modifier to be changed from final class to sealed class
- use "boxed type".hashCode(value) instead of "boxed type".valueOf(value).hashCode() HOT 1
- Identifier conflict on "js" field when generating JSON codec with sjson new
- gh-pages could use a publish HOT 1
- +generateContrabands doesn't work with crossScalaVersions HOT 2
- Cannot resolve symbol ScalaKeywords
- Some generated code does not compile with -Xfatal-warnings
- Allow sealed interface
- Travis CI dropped
- self type specification is not enough for Scala 3
- remove lightbend-cla-validator
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contraband.