control: partly revert commit 0e7ea8ac and use clone in handlers
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 27 Nov 2015 18:41:48 +0000 (13:41 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Mon, 30 Nov 2015 19:47:07 +0000 (14:47 -0500)
The patch that will be reverted here used copy constructors instead
of clone. However, using copy constructors the class type gets lost
in certain cases and this will cause different errors to happen.

For example, add context on a UST channel will send the command with
-k instead of -u. This is because a instanceof check for
ChannelCommandParameter fails since the object to check is a
CommandParameter instance and not ChannelCommandParameter.

I'll add a subsequent patch with a unit test for the add context case.

Change-Id: I01177bc1fad7eb100b204997b4572bf14cb5be61
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/61491
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/BaseAddContextHandler.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/BaseEnableChannelHandler.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/BaseEnableEventHandler.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/CalibrateHandler.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/ChannelCommandParameter.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/CommandParameter.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/DomainCommandParameter.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/EventCommandParameter.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/ImportHandler.java

index c0eef9d997bb55214d4809cce340082e431ba0a1..bd0c2e0f02e7f546c16d211035859ce5ace4b175 100644 (file)
@@ -81,7 +81,7 @@ public abstract class BaseAddContextHandler extends BaseControlViewHandler {
             }
 
             // Make a copy for thread safety
-            final CommandParameter param = new CommandParameter(tmpParam);
+            final CommandParameter param = tmpParam.clone();
 
             UIJob getJob = new UIJob(Messages.TraceControl_GetContextJob) {
                 @Override
index d7c0073dc53d0f94404f8546143df72688668272..8eb382942b17a00046b237484ff0b099b083d95e 100644 (file)
@@ -85,7 +85,7 @@ abstract class BaseEnableChannelHandler extends BaseControlViewHandler {
             if (tmpParam == null) {
                 return null;
             }
-            tmpParam = new CommandParameter(tmpParam);
+            tmpParam = tmpParam.clone();
         } finally {
             fLock.unlock();
         }
index 59866fc9dab0c95cf4f7253a67fc76e57326de4b..1fe8a58df9e1df9ad1f927c1c7fadf19648d1c55 100644 (file)
@@ -148,7 +148,7 @@ public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
             if (tmpParam == null) {
                 return null;
             }
-            tmpParam = new CommandParameter(tmpParam);
+            tmpParam = tmpParam.clone();
         } finally {
             fLock.unlock();
         }
index b9c23ff0a10dcca89d740a9e5538dfe3ae0e9e25..70182d087b06d6382492dcd4b3adbc32c3d06837 100644 (file)
@@ -70,7 +70,7 @@ public class CalibrateHandler extends BaseControlViewHandler {
             }
 
             // Make a copy for thread safety
-            final DomainCommandParameter param = new DomainCommandParameter(tmpParam);
+            final DomainCommandParameter param = tmpParam.clone();
 
             Job addJob = new Job(Messages.TraceControl_AddCalibrateJob) {
                 @Override
index ec0187870470e1cda8be5d1520c6eeaba9179ff0..8118e2a0bf381a8dd2ae3d0fa1a947f67066de45 100644 (file)
@@ -44,17 +44,6 @@ public class ChannelCommandParameter extends CommandParameter {
         fChannel = channel;
     }
 
-    /**
-     * Copy constructor
-     *
-     * @param param
-     *            a channel command parameter to copy
-     */
-    public ChannelCommandParameter(ChannelCommandParameter param) {
-        super(param);
-        fChannel = param.fChannel;
-    }
-
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
@@ -66,4 +55,13 @@ public class ChannelCommandParameter extends CommandParameter {
         return fChannel;
     }
 
+    // ------------------------------------------------------------------------
+    // Cloneable interface
+    // ------------------------------------------------------------------------
+    @Override
+    public ChannelCommandParameter clone() {
+        ChannelCommandParameter clone = (ChannelCommandParameter) super.clone();
+        clone.fChannel = fChannel;
+        return clone;
+    }
 }
\ No newline at end of file
index 209374d8904189f31620adf1d8ec94f129b4c987..a274c7d8edb182fec33dddd8b78044c286ede7cc 100644 (file)
@@ -20,7 +20,7 @@ import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.Trac
  * @author Bernd Hufmann
  */
 @NonNullByDefault
-public class CommandParameter {
+public class CommandParameter implements Cloneable {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -43,16 +43,6 @@ public class CommandParameter {
         fSession = session;
     }
 
-    /**
-     * Copy constructor
-     *
-     * @param param
-     *            a command parameter to copy
-     */
-    public CommandParameter(CommandParameter param) {
-        fSession = param.fSession;
-    }
-
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
@@ -63,4 +53,19 @@ public class CommandParameter {
     public TraceSessionComponent getSession() {
         return fSession;
     }
+
+    // ------------------------------------------------------------------------
+    // Cloneable interface
+    // ------------------------------------------------------------------------
+    @Override
+    protected CommandParameter clone() {
+        CommandParameter clone;
+        try {
+            clone = (CommandParameter) super.clone();
+            clone.fSession = fSession;
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException();
+        }
+        return clone;
+    }
 }
\ No newline at end of file
index 76407486bdf2e8c80dd74d9f44f18ea044e234f6..b3f66787cbb616850fe20e65b107c4690210e72e 100644 (file)
@@ -55,15 +55,14 @@ public class DomainCommandParameter extends CommandParameter {
         return fDomain;
     }
 
-    /**
-     * Copy constructor
-     *
-     * @param param
-     *            a domain command parameter to copy
-     */
-    public DomainCommandParameter(DomainCommandParameter param) {
-        super(param);
-        fDomain = param.fDomain;
+    // ------------------------------------------------------------------------
+    // Cloneable interface
+    // ------------------------------------------------------------------------
+    @Override
+    public DomainCommandParameter clone() {
+        DomainCommandParameter clone = (DomainCommandParameter) super.clone();
+        clone.fDomain = fDomain;
+        return clone;
     }
 
 }
\ No newline at end of file
index 5ce825f5e534e50544b79718b67e5ff6d018fa5c..98988b07923f1a46374322ca702454b7da89a521 100644 (file)
@@ -43,17 +43,6 @@ public class EventCommandParameter extends CommandParameter {
         fEvent = event;
     }
 
-    /**
-     * Copy constructor
-     *
-     * @param param
-     *            a event command parameter to copy
-     */
-    public EventCommandParameter(EventCommandParameter param) {
-        super(param);
-        fEvent = param.fEvent;
-    }
-
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
@@ -64,4 +53,15 @@ public class EventCommandParameter extends CommandParameter {
     public TraceEventComponent getEvent() {
         return fEvent;
     }
+
+    // ------------------------------------------------------------------------
+    // Cloneable interface
+    // ------------------------------------------------------------------------
+    @Override
+    public EventCommandParameter clone() {
+        EventCommandParameter clone = (EventCommandParameter) super.clone();
+        clone.fEvent = fEvent;
+        return clone;
+    }
+
 }
\ No newline at end of file
index 6b3182716bc5e1d3ec8e49674438f8ed60d2767e..5f899e7e063d3d560c6af8fb21318edd8a06df4c 100644 (file)
@@ -119,7 +119,7 @@ public class ImportHandler extends BaseControlViewHandler {
             if (param == null) {
                 return null;
             }
-            param = new CommandParameter(param);
+            param = param.clone();
         } finally {
             fLock.unlock();
         }
This page took 0.060554 seconds and 5 git commands to generate.