Giter Club home page Giter Club logo

copyconstructorplugin's People

Contributors

dallasgutauckis avatar jkovacs avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

copyconstructorplugin's Issues

Suspicious assignment warning is triggered when using the Copy Constructor of a field within an object

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;
	}
}

Request: option to use getter/ setter

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

The copy constructor is showing inspection about suspicous copy or not all field copied if you try to do a deep copy.

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

Request to this work for Kotlin

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

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.