tmf: Annotate methods in ITmfEventField
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / TmfEventPropertySource.java
index b680a4c21ea3ac492613567fbe438d36f870771a..2e88c5a80c64dd007fa6f04a16e9baac66beeb92 100644 (file)
@@ -19,6 +19,7 @@ import java.util.List;
 import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite;
 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
@@ -126,7 +127,7 @@ public class TmfEventPropertySource implements IPropertySource {
         @Override
         public Object getPropertyValue(Object id) {
             ITmfEventField field = (ITmfEventField) id;
-            if (field.getFields() != null && field.getFields().size() > 0) {
+            if (!field.getFields().isEmpty()) {
                 return new ContentPropertySource(field);
             }
             return field.getFormattedValue();
@@ -164,8 +165,9 @@ public class TmfEventPropertySource implements IPropertySource {
 
         @Override
         public Object getEditableValue() {
-            if (fSourceLookup.getCallsite() != null) {
-                return fSourceLookup.getCallsite().toString();
+            ITmfCallsite cs = fSourceLookup.getCallsite();
+            if (cs != null) {
+                return cs.toString();
             }
             return null;
         }
@@ -173,11 +175,12 @@ public class TmfEventPropertySource implements IPropertySource {
         @Override
         public IPropertyDescriptor[] getPropertyDescriptors() {
             List<IPropertyDescriptor> descriptors= new ArrayList<>();
-            if (fSourceLookup.getCallsite() != null) {
+            ITmfCallsite cs = fSourceLookup.getCallsite();
+            if (cs != null) {
                 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME));
                 descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER));
                 // only display function if available
-                if (fSourceLookup.getCallsite().getFunctionName() != null) {
+                if (cs.getFunctionName() != null) {
                     descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME));
                 }
             }
@@ -186,14 +189,29 @@ public class TmfEventPropertySource implements IPropertySource {
 
         @Override
         public Object getPropertyValue(Object id) {
-            if  (id.equals(ID_FILE_NAME)) {
-                return fSourceLookup.getCallsite().getFileName();
-            } else if (id.equals(ID_FUNCTION_NAME)) {
-                return fSourceLookup.getCallsite().getFunctionName();
-            } else if (id.equals(ID_LINE_NUMBER)) {
-                return Long.valueOf(fSourceLookup.getCallsite().getLineNumber());
+            ITmfCallsite cs = fSourceLookup.getCallsite();
+            if (cs == null) {
+                /*
+                 * The callsite should not be null here, we would not have
+                 * created the descriptors otherwise
+                 */
+                throw new IllegalStateException();
+            }
+
+            if (!(id instanceof String)) {
+                return null;
+            }
+
+            switch ((String) id) {
+            case ID_FILE_NAME:
+                return cs.getFileName();
+            case ID_FUNCTION_NAME:
+                return cs.getFunctionName();
+            case ID_LINE_NUMBER:
+                return Long.valueOf(cs.getLineNumber());
+            default:
+                return null;
             }
-            return null;
         }
 
         @Override
This page took 0.025513 seconds and 5 git commands to generate.