jkovacs / copyconstructorplugin Goto Github PK
View Code? Open in Web Editor NEWAn IntelliJ IDEA plugin that adds the option to generate a copy constructor to the "Generate" menu
License: MIT License
An IntelliJ IDEA plugin that adds the option to generate a copy constructor to the "Generate" menu
License: MIT License
The inspection should recognize that using a copy constructor within a copy constructor is necessary when dealing with non-primitive fields.
class SomeObject {
private SomeOtherObject someObjectField;
public SomeObject(SomeObject other) {
this.someObjectField = new SomeOtherObject(other.someObjectField);
}
}
class SomeOtherObject {
private String field;
public SomeOtherObject(SomeOtherObject other) {
this.field = other.field;
}
}
Hi,
it would be great to be able to use getter/ setter instead of direct references. So we cold use this to copy properties between beans by simply changing the parameter type.
brgds
Papick
I implemented a copy constructor that needed to do a deep copy of on of acollection
neither of my classes are implementing the clonable interaface (don't need this ^^ )
Lets pretend I have follwing both classes
public class Bar {
private int field1;
private String field2;
public Bar() {
}
public Bar(Bar other) {
this.field1 = other.field1;
this.field2 = other.field2;
}
}
public class Foo {
private List<Bar> bars;
public Foo() {
}
public Foo(Foo other) {
this.bars = other.bars
.stream()
.map(Bar::new)
.collect(Collectors.toList());
}
}
Basically the copy constructor of Foo is not doing any dark magic.
It makes a deep copy of the other object collection.
IMO the copy constructor of Foo class should not print any warning at all
For some reason plugin is generating new constructor somewhere in the middle of the file.
I would expect it to insert new constructor at cursor location.
can you make this work for kotlin files ?
i think it will be easy to use because kotlin has default params. so you could write:
class MYOBJECT(
var symbol: String? = null,
var name: String? = null,
var selected: Boolean = false
) : Parcelable{
fun deepCopy(symbol: String? = this.symbol, name: String? = this.name, selected:Boolean=this.selected) = MYOBJECT(symbol, name, selected)
}
and only have to call someObject.deepCopy() and let it use the defaults
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.