ss: Replace AttributeNotFoundException with IOOBE for quark parameters
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / ui / views / xychart / XmlXYViewer.java
index 17ef228453fa3fce35604603155346061cb3c07f..31c7cae0af15d24aa6f78d9e4469fa6140d76d8a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others.
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal 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
@@ -23,26 +23,25 @@ import java.util.regex.Pattern;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfCommonXLineChartViewer;
@@ -62,7 +61,7 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
     /** Timeout between updates in the updateData thread */
     private static final long BUILD_UPDATE_TIMEOUT = 500;
 
-    private static final Pattern WILDCARD_PATTERN = checkNotNull(Pattern.compile("\\*")); //$NON-NLS-1$
+    private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); //$NON-NLS-1$
 
     private final ITmfXmlModelFactory fFactory = TmfXmlReadOnlyModelFactory.getInstance();
     private final Map<Integer, SeriesData> fSeriesData = new HashMap<>();
@@ -85,7 +84,7 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
     private class SeriesData {
 
         private final double[] fYValues;
-        private final @Nullable double[] fYAbsoluteValues;
+        private final double @Nullable [] fYAbsoluteValues;
         private final Integer fDisplayQuark;
         private final String fName;
         private final DisplayType fType;
@@ -177,7 +176,7 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
         }
 
         @Override
-        public @Nullable Iterable<TmfXmlLocation> getLocations() {
+        public @NonNull Iterable<@NonNull TmfXmlLocation> getLocations() {
             return Collections.EMPTY_SET;
         }
 
@@ -188,24 +187,16 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
         public List<Integer> getQuarks() {
             /* Get the list of quarks to process with this path */
             String[] paths = fPath.split(SPLIT_STRING);
-            List<Integer> quarks = checkNotNull(Collections.singletonList(IXmlStateSystemContainer.ROOT_QUARK));
-
-            try {
-                for (String path : paths) {
-                    List<Integer> subQuarks = new LinkedList<>();
-                    /* Replace * by .* to have a regex string */
-                    String name = WILDCARD_PATTERN.matcher(path).replaceAll(".*"); //$NON-NLS-1$
-                    for (int relativeQuark : quarks) {
-                        subQuarks.addAll(fStateSystem.getSubAttributes(relativeQuark, false, name));
-                    }
-                    quarks = subQuarks;
+            List<Integer> quarks = Collections.singletonList(IXmlStateSystemContainer.ROOT_QUARK);
+
+            for (String path : paths) {
+                List<Integer> subQuarks = new LinkedList<>();
+                /* Replace * by .* to have a regex string */
+                String name = WILDCARD_PATTERN.matcher(path).replaceAll(".*"); //$NON-NLS-1$
+                for (int relativeQuark : quarks) {
+                    subQuarks.addAll(fStateSystem.getSubAttributes(relativeQuark, false, name));
                 }
-            } catch (AttributeNotFoundException e) {
-                /*
-                 * We get all attributes from the state system itself, this
-                 * should not happen.
-                 */
-                throw new IllegalStateException();
+                quarks = subQuarks;
             }
             return quarks;
         }
@@ -260,7 +251,7 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
                     if (seriesNameAttrib == null) {
                         seriesName = ss.getAttributeName(quark);
                     } else {
-                        int seriesNameQuark = seriesNameAttrib.getAttributeQuark(quark);
+                        int seriesNameQuark = seriesNameAttrib.getAttributeQuark(quark, null);
                         try {
                             ITmfStateValue seriesNameValue = ss.querySingleState(start, seriesNameQuark).getStateValue();
                             if (!seriesNameValue.isNull()) {
@@ -277,9 +268,8 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
                             seriesName = ss.getAttributeName(quark);
                         }
                     }
-                    fSeriesData.put(quark, new SeriesData(xvalues.length, display.getAttributeQuark(quark), seriesName, entry.getType()));
+                    fSeriesData.put(quark, new SeriesData(xvalues.length, display.getAttributeQuark(quark, null), seriesName, entry.getType()));
                 }
-                double yvalue = 0.0;
                 for (int i = 0; i < xvalues.length; i++) {
                     if (monitor != null && monitor.isCanceled()) {
                         return;
@@ -292,9 +282,26 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
                     time = time > traceEnd ? traceEnd : time;
 
                     for (int quark : quarks) {
+                        double yvalue = 0.0;
                         SeriesData data = checkNotNull(fSeriesData.get(quark));
                         try {
-                            yvalue = ss.querySingleState(time, data.getDisplayQuark()).getStateValue().unboxLong();
+                            ITmfStateValue value = ss.querySingleState(time, data.getDisplayQuark()).getStateValue();
+                            switch (value.getType()) {
+                            case DOUBLE:
+                                yvalue = value.unboxDouble();
+                                break;
+                            case LONG:
+                                yvalue = value.unboxLong();
+                                break;
+                            case INTEGER:
+                                yvalue = value.unboxInt();
+                                break;
+                            case NULL:
+                            case STRING:
+                            case CUSTOM:
+                            default:
+                                break;
+                            }
                             data.setYValue(i, yvalue);
                         } catch (TimeRangeException e) {
                             data.setYValue(i, 0);
@@ -306,7 +313,7 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
                     setSeries(data.getSeriesName(), data.getYValues());
                 }
                 updateDisplay();
-            } catch (AttributeNotFoundException | StateValueTypeException e) {
+            } catch (StateValueTypeException e) {
                 Activator.logError("Error updating the data of XML XY view", e); //$NON-NLS-1$
             } catch (StateSystemDisposedException e) {
                 return;
@@ -341,7 +348,6 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
             }
         } else {
             for (String moduleId : analysisIds) {
-                moduleId = checkNotNull(moduleId);
                 ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, moduleId);
                 if (module != null) {
                     stateSystemModules.add(module);
@@ -361,14 +367,12 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
             if (!status.isOK()) {
                 return;
             }
-            if (module instanceof TmfStateSystemAnalysisModule) {
-                ((TmfStateSystemAnalysisModule) module).waitForInitialization();
+            if (!module.waitForInitialization()) {
+                return;
             }
             for (ITmfStateSystem ssq : module.getStateSystems()) {
-                if (ssq != null) {
-                    ss = ssq;
-                    break;
-                }
+                ss = ssq;
+                break;
             }
         }
         if (ss == null) {
@@ -389,24 +393,18 @@ public class XmlXYViewer extends TmfCommonXLineChartViewer {
         fEntry = entry;
 
         /* Get the display element to use */
-        List<Element> displayElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.DISPLAY_ELEMENT);
+        List<@NonNull Element> displayElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.DISPLAY_ELEMENT);
         if (displayElements.isEmpty()) {
             Activator.logWarning(String.format("XML view: entry for %s should have a display element", path)); //$NON-NLS-1$
             return;
         }
         Element displayElement = displayElements.get(0);
-        if (displayElement == null) {
-            throw new IllegalStateException();
-        }
         fDisplay = fFactory.createStateAttribute(displayElement, entry);
 
         /* Get the series name element to use */
         List<Element> seriesNameElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.NAME_ELEMENT);
         if (!seriesNameElements.isEmpty()) {
             Element seriesNameElement = seriesNameElements.get(0);
-            if (seriesNameElement == null) {
-                throw new IllegalStateException();
-            }
             fSeriesName = fFactory.createStateAttribute(seriesNameElement, entry);
         }
 
This page took 0.028551 seconds and 5 git commands to generate.