mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 23:25:26 +02:00
[219975] Fix implementations of clone()
This commit is contained in:
parent
78e2da4542
commit
445db07b51
8 changed files with 108 additions and 41 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,7 +12,7 @@
|
|||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.files.ui.resources;
|
||||
|
@ -21,7 +21,7 @@ package org.eclipse.rse.internal.files.ui.resources;
|
|||
* Class that keeps information about a remote resource. Clients should not
|
||||
* use this class.
|
||||
*/
|
||||
public class SystemRemoteResourceInfo implements Cloneable {
|
||||
public class SystemRemoteResourceInfo {
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,7 +12,7 @@
|
|||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.services.clientserver.archiveutils;
|
||||
|
@ -530,22 +530,22 @@ public class TarEntry implements Cloneable {
|
|||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
TarEntry newEntry = new TarEntry(getName());
|
||||
newEntry.mode = this.mode;
|
||||
newEntry.uid = this.uid;
|
||||
newEntry.gid = this.gid;
|
||||
newEntry.size = this.size;
|
||||
newEntry.mtime = this.mtime;
|
||||
newEntry.chksum = this.chksum;
|
||||
newEntry.typeflag = this.typeflag;
|
||||
newEntry.linkname = this.linkname;
|
||||
newEntry.magic = this.magic;
|
||||
newEntry.version = this.version;
|
||||
newEntry.uname = this.uname;
|
||||
newEntry.gname = this.gname;
|
||||
newEntry.devmajor = this.devmajor;
|
||||
newEntry.devminor = this.devminor;
|
||||
newEntry.prefix = this.prefix;
|
||||
TarEntry newEntry = (TarEntry)super.clone();
|
||||
newEntry.mode = (byte[])this.mode.clone();
|
||||
newEntry.uid = (byte[])this.uid.clone();
|
||||
newEntry.gid = (byte[])this.gid.clone();
|
||||
newEntry.size = (byte[])this.size.clone();
|
||||
newEntry.mtime = (byte[])this.mtime.clone();
|
||||
newEntry.chksum = (byte[])this.chksum.clone();
|
||||
//newEntry.typeflag = this.typeflag;
|
||||
newEntry.linkname = (byte[])this.linkname.clone();
|
||||
newEntry.magic = (byte[])this.magic.clone();
|
||||
newEntry.version = (byte[])this.version.clone();
|
||||
newEntry.uname = (byte[])this.uname.clone();
|
||||
newEntry.gname = (byte[])this.gname.clone();
|
||||
newEntry.devmajor = (byte[])this.devmajor.clone();
|
||||
newEntry.devminor = (byte[])this.devminor.clone();
|
||||
newEntry.prefix = (byte[])this.prefix.clone();
|
||||
return newEntry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,7 +12,7 @@
|
|||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.services.clientserver.processes;
|
||||
|
@ -36,7 +36,11 @@ import org.eclipse.rse.services.clientserver.NamePatternMatcher;
|
|||
* </sl>
|
||||
*
|
||||
* To get the actual filter string back from objects of this class, just call {@link #toString()}.
|
||||
*
|
||||
* <p>
|
||||
* Clients may use or subclass this class. When subclassing, clients need to
|
||||
* ensure that the subclass is always capable of performing a deep clone
|
||||
* operation with the {@link #clone()} method, so if they add fields of
|
||||
* complex type, these need to be dealt with by overriding {@link #clone()}.
|
||||
*/
|
||||
public class HostProcessFilterImpl implements IHostProcessFilter, Cloneable
|
||||
{
|
||||
|
@ -445,6 +449,7 @@ public class HostProcessFilterImpl implements IHostProcessFilter, Cloneable
|
|||
|
||||
public boolean getSpecificState(String stateCode)
|
||||
{
|
||||
if (anystatus) return true;
|
||||
Boolean state = (Boolean) states.get(stateCode);
|
||||
if (state == null) return false;
|
||||
return state.booleanValue();
|
||||
|
@ -453,6 +458,7 @@ public class HostProcessFilterImpl implements IHostProcessFilter, Cloneable
|
|||
public void setSpecificState(String stateCode)
|
||||
{
|
||||
anystatus = false;
|
||||
initStates();
|
||||
states.put(stateCode, new Boolean(true));
|
||||
}
|
||||
|
||||
|
@ -474,4 +480,26 @@ public class HostProcessFilterImpl implements IHostProcessFilter, Cloneable
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an identical (deep) copy of this filter.
|
||||
*
|
||||
* Subclasses must ensure that such a deep copy operation is always
|
||||
* possible, so their state must always be cloneable. Which should
|
||||
* always be possible to achieve, since this Object also needs to be
|
||||
* serializable.
|
||||
*/
|
||||
public Object clone() {
|
||||
HostProcessFilterImpl clone = null;
|
||||
try {
|
||||
clone = (HostProcessFilterImpl)super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
//assert false; //can never happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (states!=null) {
|
||||
clone.states = (HashMap)states.clone();
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* Contributors:
|
||||
* David McKnight (IBM) - [208951] new priority field
|
||||
* Martin Oberhuber (Wind River) - [220020][api][breaking] SystemFileTransferModeRegistry should be internal
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.subsystems.files.core.model;
|
||||
|
@ -159,7 +160,8 @@ public class SystemFileTransferModeMapping implements ISystemFileTransferModeMap
|
|||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
//assert false; //can never happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,7 +12,7 @@
|
|||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.subsystems.files.core.model;
|
||||
|
@ -405,7 +405,9 @@ public class RemoteFileFilterString implements Cloneable
|
|||
* Clone this into another filter string object with the same attributes.
|
||||
*
|
||||
* Subclasses must ensure that such a deep copy operation is always
|
||||
* possible, so their state must always be cloneable.
|
||||
* possible, so their state must always be cloneable. Which should
|
||||
* always be possible to achieve, since this Object also needs to be
|
||||
* serializable.
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* David McKnight (IBM) - [209660] use parent encoding as default, rather than system encoding
|
||||
* David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files
|
||||
* Martin Oberhuber (Wind River) - [220020][api][breaking] SystemFileTransferModeRegistry should be internal
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.subsystems.files.core.subsystems;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2002, 2006 IBM Corporation. All rights reserved.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others. All rights reserved.
|
||||
* This program and the accompanying materials are made available under the terms
|
||||
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||
|
@ -11,7 +11,7 @@
|
|||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.subsystems.shells.core.model;
|
||||
|
@ -42,6 +42,11 @@ import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystemConf
|
|||
* <p>
|
||||
* It is invalid to have both a comma and an asterisk in the same filter string.
|
||||
* It is also invalid to have both a comma and a period in the same filter string.
|
||||
* <p>
|
||||
* Clients may use or subclass this class. When subclassing, clients need to
|
||||
* ensure that the subclass is always capable of performing a deep clone
|
||||
* operation with the {@link #clone()} method, so if they add fields of
|
||||
* complex type, these need to be dealt with by overriding {@link #clone()}.
|
||||
*/
|
||||
public class RemoteCommandFilterString implements Cloneable
|
||||
{
|
||||
|
@ -140,7 +145,7 @@ public class RemoteCommandFilterString implements Cloneable
|
|||
}
|
||||
|
||||
/**
|
||||
* De-hydrate into a string capturing all the attributes
|
||||
* Serialize into a string capturing all the attributes
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
|
@ -149,17 +154,25 @@ public class RemoteCommandFilterString implements Cloneable
|
|||
|
||||
/**
|
||||
* Clone this into another filter string object with the same attributes.
|
||||
*
|
||||
* Subclasses must ensure that such a deep copy operation is always
|
||||
* possible, so their state must always be cloneable. Which should
|
||||
* always be possible to achieve, since this Object also needs to be
|
||||
* serializable.
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
RemoteCommandFilterString copy = new RemoteCommandFilterString();
|
||||
copy.shellStr = shellStr;
|
||||
copy.filterByTypes = filterByTypes;
|
||||
RemoteCommandFilterString copy = null;
|
||||
try {
|
||||
copy = (RemoteCommandFilterString)super.clone();
|
||||
} catch(CloneNotSupportedException e) {
|
||||
//assert false; //can never happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (types!=null)
|
||||
{
|
||||
copy.types = new String[types.length];
|
||||
for (int idx=0; idx<types.length; idx++)
|
||||
copy.types[idx] = types[idx]; // don't think we need to clone strings as they are immutable
|
||||
//duplicate the array in case somebody changes its contents
|
||||
copy.types = (String[])types.clone();
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Martin Oberhuber (Wind River) - [180562][api] dont implement ISystemCompileXMLConstants
|
||||
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.internal.useractions.ui.compile;
|
||||
|
||||
|
@ -362,11 +363,31 @@ public class SystemCompileCommand implements Cloneable, IAdaptable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Clone the object. Creates a new compile command and copies all its attributes.
|
||||
* If a subclass adds additional attributes, this method should be subclassed to clone those attributes.
|
||||
* Clone the object: creates a new compile command and copies all its attributes.
|
||||
*
|
||||
* During the process of cloning, the Nature is always set to be
|
||||
* User-supplied - so even if an IBM-Supplied compile command is cloned,
|
||||
* the result will be treated as User-supplied.
|
||||
*
|
||||
* Subclasses must ensure that such a deep copy operation is always
|
||||
* possible, so their state must always be cloneable. Which should
|
||||
* always be possible to achieve, since this Object also needs to be
|
||||
* serializable. If a subclass adds additional complex attributes,
|
||||
* this method should be subclassed to clone those attributes.
|
||||
*/
|
||||
public Object clone() {
|
||||
SystemCompileCommand clone = new SystemCompileCommand(getParentType(), getId(), getLabel(), ISystemCompileXMLConstants.NATURE_USER_VALUE, null, getCurrentString(), getMenuOption(), getOrder());
|
||||
////Old invalid method of cloning does not maintain runtime type
|
||||
//SystemCompileCommand clone = new SystemCompileCommand(getParentType(), getId(), getLabel(), ISystemCompileXMLConstants.NATURE_USER_VALUE, null, getCurrentString(), getMenuOption(), getOrder());
|
||||
SystemCompileCommand clone = null;
|
||||
try {
|
||||
clone = (SystemCompileCommand)super.clone();
|
||||
} catch(CloneNotSupportedException e) {
|
||||
//assert false; //can never happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
clone.setNature(ISystemCompileXMLConstants.NATURE_USER_VALUE);
|
||||
clone.setDefaultString(null);
|
||||
clone.configureId();
|
||||
if (jobEnv != null) clone.setJobEnvironment(jobEnv);
|
||||
return clone;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue