From: Matthew Khouzam Date: Fri, 11 May 2012 21:49:09 +0000 (-0400) Subject: Clean up code. X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=07002e0a31a5e6dd39d5d2f4b9a92b2000764f90;p=deliverable%2Ftracecompass.git Clean up code. --- diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java index 4cb0a956c9..94759fc5a9 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDeclarationTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration; import org.junit.Test; @@ -18,24 +17,23 @@ public class FloatDeclarationTest { @Test public void ctorTest() { for( int i = 1; i < 20; i++) { - fixture = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), Encoding.NONE, 0); + fixture = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), 0); assertNotNull(fixture); } } @Test public void getterTest() { - fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0); + fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); assertEquals( fixture.getAlignment(), 0); assertEquals( fixture.getByteOrder(), ByteOrder.nativeOrder()); - assertEquals( fixture.getEncoding(), Encoding.NONE); assertEquals( fixture.getExponent(), 8); assertEquals( fixture.getMantissa(), 24); } @Test public void toStringTest() { - fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0); + fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); assertTrue(fixture.toString().contains("float")); //$NON-NLS-1$ } } diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java index d6c22d61a0..8513f2e4f0 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; -import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; @@ -64,8 +63,8 @@ public class FloatDefinitionTest { @Test public void testFloat248() { - parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), Encoding.NONE, 0); - singleFixture = (FloatDefinition) parent.createDefinition(null, fieldName); + parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); + singleFixture = parent.createDefinition(null, fieldName); assertNotNull(singleFixture); } @@ -73,8 +72,8 @@ public class FloatDefinitionTest { @Test public void testFloat5311() { - parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), Encoding.NONE, 0); - doubleFixture = (FloatDefinition) parent.createDefinition(null, fieldName); + parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), 0); + doubleFixture = parent.createDefinition(null, fieldName); assertNotNull(doubleFixture); } @@ -82,8 +81,8 @@ public class FloatDefinitionTest { public void testFloat32Bit(){ for(int i = 1; i < 31 ; i++) { - parent = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), Encoding.NONE, 0); - fixture = (FloatDefinition) parent.createDefinition(null, fieldName); + parent = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), 0); + fixture = parent.createDefinition(null, fieldName); assertNotNull(fixture); fixture.setValue(2.0); assertTrue(fixture.toString().contains("2")); //$NON-NLS-1$ @@ -94,8 +93,8 @@ public class FloatDefinitionTest { public void testFloat64Bit(){ for(int i = 1; i < 63 ; i++) { - parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), Encoding.NONE, 0); - fixture = (FloatDefinition) parent.createDefinition(null, fieldName); + parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), 0); + fixture = parent.createDefinition(null, fieldName); assertNotNull(fixture); BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); fixture.read(input); @@ -106,8 +105,8 @@ public class FloatDefinitionTest { @Test public void testFloat48Bit(){ - parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), Encoding.NONE, 0); - fixture = (FloatDefinition) parent.createDefinition(null, fieldName); + parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), 0); + fixture = parent.createDefinition(null, fieldName); assertNotNull(fixture); BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128)); fixture.read(input); diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java index 1b8a11c905..16e49198ec 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java @@ -91,7 +91,7 @@ public class VariantDefinitionTest { VariantDeclaration varDec = new VariantDeclaration(); EnumDeclaration tagDec = new EnumDeclaration(iDec); ArrayDeclaration arrDec = new ArrayDeclaration(2, iDec); - FloatDeclaration fDec = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, Encoding.NONE, 8); + FloatDeclaration fDec = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 8); tagDec.add(0, 1, ENUM_1); tagDec.add(2, 3, ENUM_2); tagDec.add(4, 5, ENUM_3); diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java index fc727a155e..0af919f6c2 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/CTFClock.java @@ -14,11 +14,24 @@ package org.eclipse.linuxtools.ctf.core.event; import java.util.HashMap; +/** + */ public class CTFClock { + /** + * Field properties. + */ final private HashMap properties = new HashMap(); + /** + * Field name. + */ private String name; + /** + * Method addAttribute. + * @param key String + * @param value Object + */ public void addAttribute(String key, Object value) { this.properties.put(key, value); if (key.equals("name")) { //$NON-NLS-1$ @@ -26,10 +39,19 @@ public class CTFClock { } } + /** + * Method getName. + * @return String + */ public String getName() { return name; } + /** + * Method getProperty. + * @param key String + * @return Object + */ public Object getProperty(String key) { return properties.get(key); } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java index e8f833b061..8a118a464f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDeclaration.java @@ -90,7 +90,7 @@ public class EventDeclaration { public synchronized static EventDeclaration getLostEventDeclaration(){ EventDeclaration lostEvent = new EventDeclaration(); lostEvent.fields = new StructDeclaration(1); - lostEvent.id = (long) -1; + lostEvent.id = -1L; lostEvent.name = "Lost event"; //$NON-NLS-1$ return lostEvent; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java index afc14bff55..455d6a8495 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/EventDefinition.java @@ -54,7 +54,7 @@ public class EventDefinition implements IDefinitionScope { /** * The StreamInputReader that reads this event definition. */ - public final StreamInputReader streamInputReader; + private final StreamInputReader streamInputReader; // ------------------------------------------------------------------------ // Constructors @@ -150,32 +150,33 @@ public class EventDefinition implements IDefinitionScope { @Override public String toString() { - HashMap f; + HashMap definitions; List list; - StringBuilder b = new StringBuilder(); + StringBuilder retString = new StringBuilder(); + final String cr = System.getProperty("line.separator");//$NON-NLS-1$ - b.append("Event type: " + declaration.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ - b.append("Timestamp: " + Long.toString(timestamp) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + retString.append("Event type: " + declaration.getName() + cr); //$NON-NLS-1$ + retString.append("Timestamp: " + Long.toString(timestamp) + cr); //$NON-NLS-1$ if (context != null) { - f = context.getDefinitions(); + definitions = context.getDefinitions(); list = context.getDeclaration().getFieldsList(); for (String field : list) { - b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + retString.append(field + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$ } } if (fields != null) { - f = fields.getDefinitions(); + definitions = fields.getDefinitions(); list = fields.getDeclaration().getFieldsList(); for (String field : list) { - b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + retString.append(field + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$ } } - return b.toString(); + return retString.toString(); } } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java index 52ea6ef366..a196611607 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java @@ -23,13 +23,13 @@ public abstract class Definition { // Attributes // ------------------------------------------------------------------------ - /* The name of the field in its container */ + /** The name of the field in its container */ protected final String fieldName; - /* The complete path of this field */ + /** The complete path of this field */ protected final String path; - /* + /** * The definition scope in which this definition is found. * * The complete path of a definition is thus the path of the definition diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java index 5576e3fdf4..293528f276 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java @@ -23,7 +23,6 @@ public class FloatDeclaration implements IDeclaration { private final int mant; private final int exp; private final ByteOrder byteOrder; - private final Encoding encoding; private final long alignment; // ------------------------------------------------------------------------ @@ -31,11 +30,10 @@ public class FloatDeclaration implements IDeclaration { // ------------------------------------------------------------------------ public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder, - Encoding encoding, long alignment) { + long alignment) { mant = mantissa; exp = exponent; this.byteOrder = byteOrder; - this.encoding = encoding; this.alignment = alignment; } @@ -65,13 +63,6 @@ public class FloatDeclaration implements IDeclaration { return byteOrder; } - /** - * @return the encoding - */ - public Encoding getEncoding() { - return encoding; - } - @Override public long getAlignment() { return alignment; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java index dfc55087c5..397be25d7e 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java @@ -30,6 +30,7 @@ public class FloatDefinition extends Definition { super(definitionScope, fieldName); this.declaration = declaration; } + // ------------------------------------------------------------------------ // Gettters/Setters/Predicates // ------------------------------------------------------------------------ @@ -50,34 +51,27 @@ public class FloatDefinition extends Definition { // Operations // ------------------------------------------------------------------------ - - @Override public void read(BitBuffer input) { int exp = declaration.getExponent(); int mant = declaration.getMantissa(); - if( (exp + mant) == 32 ){ - value = readRawFloat32(input, mant , exp); - } - else if((exp + mant) == 64) - { - value = readRawFloat64(input, mant,exp); - } - else - { + if ((exp + mant) == 32) { + value = readRawFloat32(input, mant, exp); + } else if ((exp + mant) == 64) { + value = readRawFloat64(input, mant, exp); + } else { value = Double.NaN; } } - - - private static double readRawFloat64(BitBuffer input, final int manBits, final int expBits) { - long low = input.getInt(32, false); - low = low & 0x00000000FFFFFFFFL; - long high = input.getInt(32, false); - high = high & 0x00000000FFFFFFFFL; - long temp = (high << 32) | low; - return createFloat(temp, manBits-1, expBits); + private static double readRawFloat64(BitBuffer input, final int manBits, + final int expBits) { + long low = input.getInt(32, false); + low = low & 0x00000000FFFFFFFFL; + long high = input.getInt(32, false); + high = high & 0x00000000FFFFFFFFL; + long temp = (high << 32) | low; + return createFloat(temp, manBits - 1, expBits); } /** @@ -85,12 +79,13 @@ public class FloatDefinition extends Definition { * @param manBits * @param expBits */ - private static double createFloat(long rawValue, final int manBits, final int expBits) { + private static double createFloat(long rawValue, final int manBits, + final int expBits) { long manShift = 1L << (manBits); long manMask = manShift - 1; long expMask = (1L << expBits) - 1; - int exp = (int) ((rawValue >> (manBits))&expMask)+1; + int exp = (int) ((rawValue >> (manBits)) & expMask) + 1; long man = (rawValue & manMask); double expPow = Math.pow(2.0, exp - (1 << (expBits - 1))); double ret = man * 1.0f; @@ -101,9 +96,9 @@ public class FloatDefinition extends Definition { } private static double readRawFloat32(BitBuffer input, final int manBits, - final int expBits) { + final int expBits) { long temp = input.getInt(32, false); - return createFloat(temp, manBits-1, expBits); + return createFloat(temp, manBits - 1, expBits); } @Override diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java index 32729d86b1..92283535ff 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java @@ -74,6 +74,7 @@ public class IntegerDeclaration implements IDeclaration { return length; } + @Override public long getAlignment(){ return alignment; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java index 9581988fdd..9317d55053 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -139,7 +139,7 @@ public class CTFTrace implements IDefinitionScope { /** Handlers for the metadata files */ private final static FileFilter metadataFileFilter = new MetadataFileFilter(); - private final static Comparator metadataComparator = new MetadataComparator(); + private final static Comparator metadataComparator = new MetadataComparator(); // $codepro.audit.disable fieldJavadoc /** map of all the event types */ private final HashMap events; @@ -240,6 +240,11 @@ public class CTFTrace implements IDefinitionScope { } } } + try { + super.finalize(); + } catch (Throwable e) { + // TODO Auto-generated catch block + } } // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java index 920b34d455..ac758b3a9e 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java @@ -516,7 +516,7 @@ public class CTFTraceReader { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (!(obj instanceof CTFTraceReader)) { return false; } CTFTraceReader other = (CTFTraceReader) obj; diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java index db82ea0521..0648c1194b 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -49,12 +49,12 @@ public class Metadata { /** * Name of the metadata file in the trace directory */ - final String METADATA_FILENAME = "metadata"; //$NON-NLS-1$ + final static String METADATA_FILENAME = "metadata"; //$NON-NLS-1$ /** * Size of the metadata packet header, in bytes, computed by hand. */ - final int METADATA_PACKET_HEADER_SIZE = 37; + final static int METADATA_PACKET_HEADER_SIZE = 37; // ------------------------------------------------------------------------ // Attributes diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/CTFStrings.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/CTFStrings.java new file mode 100644 index 0000000000..52e0d17833 --- /dev/null +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/CTFStrings.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal 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 + * + * Contributors: Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.ctf.core.event.metadata; + +public interface CTFStrings { + + public static final String NONE = "none"; //$NON-NLS-1$ + public static final String ASCII = "ASCII"; //$NON-NLS-1$ + public static final String UTF8 = "UTF8"; //$NON-NLS-1$ + public static final String BIN = "b"; //$NON-NLS-1$ + public static final String BINARY = "binary"; //$NON-NLS-1$ + public static final String OCTAL_CTE = "o"; //$NON-NLS-1$ + public static final String OCT = "oct"; //$NON-NLS-1$ + public static final String OCTAL = "octal"; //$NON-NLS-1$ + public static final String POINTER = "p"; //$NON-NLS-1$ + public static final String X2 = "X"; //$NON-NLS-1$ + public static final String X = "x"; //$NON-NLS-1$ + public static final String HEX = "hex"; //$NON-NLS-1$ + public static final String HEXADECIMAL = "hexadecimal"; //$NON-NLS-1$ + public static final String UNSIGNED_CTE = "u"; //$NON-NLS-1$ + public static final String DEC_CTE = "d"; //$NON-NLS-1$ + public static final String INT_MOD = "i"; //$NON-NLS-1$ + public static final String DEC = "dec"; //$NON-NLS-1$ + public static final String DECIMAL = "decimal"; //$NON-NLS-1$ + public static final String NATIVE = "native"; //$NON-NLS-1$ + public static final String NETWORK = "network"; //$NON-NLS-1$ + public static final String BE = "be"; //$NON-NLS-1$ + public static final String LE = "le"; //$NON-NLS-1$ + public static final String ALIGN = "align"; //$NON-NLS-1$ + public static final String MANT_DIG = "mant_dig"; //$NON-NLS-1$ + public static final String EXP_DIG = "exp_dig"; //$NON-NLS-1$ + public static final String LOGLEVEL2 = "loglevel"; //$NON-NLS-1$ + public static final String NAME2 = "name"; //$NON-NLS-1$ + public static final String EVENT_CONTEXT = "event.context"; //$NON-NLS-1$ + public static final String FIELDS_STRING = "fields"; //$NON-NLS-1$ + public static final String CONTEXT = "context"; //$NON-NLS-1$ + public static final String STREAM_ID = "stream_id"; //$NON-NLS-1$ + public static final String PACKET_CONTEXT = "packet.context"; //$NON-NLS-1$ + public static final String ID = "id"; //$NON-NLS-1$ + public static final String PACKET_HEADER = "packet.header"; //$NON-NLS-1$ + public static final String EVENT_HEADER = "event.header"; //$NON-NLS-1$ + public static final String BYTE_ORDER = "byte_order"; //$NON-NLS-1$ + public static final String UUID_STRING = "uuid"; //$NON-NLS-1$ + public static final String FALSE2 = "FALSE"; //$NON-NLS-1$ + public static final String FALSE = "false"; //$NON-NLS-1$ + public static final String TRUE2 = "TRUE"; //$NON-NLS-1$ + public static final String TRUE = "true"; //$NON-NLS-1$ + public static final String MINOR = "minor"; //$NON-NLS-1$ + public static final String MAJOR = "major"; //$NON-NLS-1$ + + +} diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java index 1380de49be..5039efbcd0 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java @@ -214,14 +214,11 @@ public class IOStructGen { } for (CommonTree event : events) { parseEvent(event); - CommonTree name = (CommonTree) event.getChild(0).getChild(1) - .getChild(0).getChild(0); - if (DEBUG_) { - out.write("Name = " + name); //$NON-NLS-1$ - } - CommonTree id = (CommonTree) event.getChild(1).getChild(1) - .getChild(0).getChild(0); if (DEBUG_) { + CommonTree name = (CommonTree) event.getChild(0).getChild(1) + .getChild(0).getChild(0); + CommonTree id = (CommonTree) event.getChild(1).getChild(1) + .getChild(0).getChild(0); out.write("Name = " + name + " Id = " + id + '\n'); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -348,19 +345,19 @@ public class IOStructGen { String left = concatenateUnaryStrings(leftStrings); - if (left.equals("major")) { //$NON-NLS-1$ + if (left.equals(CTFStrings.MAJOR)) { if (trace.majortIsSet()) { throw new ParseException("major is already set"); //$NON-NLS-1$ } trace.setMajor(getMajorOrMinor(rightNode)); - } else if (left.equals("minor")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.MINOR)) { if (trace.minorIsSet()) { throw new ParseException("minor is already set"); //$NON-NLS-1$ } trace.setMinor(getMajorOrMinor(rightNode)); - } else if (left.equals("uuid")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.UUID_STRING)) { UUID uuid = getUUID(rightNode); /* @@ -376,7 +373,7 @@ public class IOStructGen { trace.setUUID(uuid); } - } else if (left.equals("byte_order")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.BYTE_ORDER)) { ByteOrder byteOrder = getByteOrder(rightNode); /* @@ -393,7 +390,7 @@ public class IOStructGen { } else { trace.setByteOrder(byteOrder); } - } else if (left.equals("packet.header")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.PACKET_HEADER)) { if (trace.packetHeaderIsSet()) { throw new ParseException("packet.header already defined"); //$NON-NLS-1$ } @@ -450,7 +447,7 @@ public class IOStructGen { if (stream.idIsSet()) { if (!trace.packetHeaderIsSet() - || !trace.getPacketHeader().hasField("stream_id")) { //$NON-NLS-1$ + || !trace.getPacketHeader().hasField(CTFStrings.STREAM_ID)) { throw new ParseException( "Stream has an ID, but there is no stream_id field in packet header."); //$NON-NLS-1$ } @@ -484,7 +481,7 @@ public class IOStructGen { String left = concatenateUnaryStrings(leftStrings); - if (left.equals("id")) { //$NON-NLS-1$ + if (left.equals(CTFStrings.ID)) { if (stream.idIsSet()) { throw new ParseException("stream id already defined"); //$NON-NLS-1$ } @@ -492,7 +489,7 @@ public class IOStructGen { long streamID = getStreamID(rightNode); stream.setId(streamID); - } else if (left.equals("event.header")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.EVENT_HEADER)) { if (stream.eventHeaderIsSet()) { throw new ParseException("event.header already defined"); //$NON-NLS-1$ } @@ -512,7 +509,7 @@ public class IOStructGen { } stream.setEventHeader((StructDeclaration) eventHeaderDecl); - } else if (left.equals("event.context")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.EVENT_CONTEXT)) { if (stream.eventContextIsSet()) { throw new ParseException("event.context already defined"); //$NON-NLS-1$ } @@ -532,7 +529,7 @@ public class IOStructGen { } stream.setEventContext((StructDeclaration) eventContextDecl); - } else if (left.equals("packet.context")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.PACKET_CONTEXT)) { if (stream.packetContextIsSet()) { throw new ParseException("packet.context already defined"); //$NON-NLS-1$ } @@ -648,7 +645,7 @@ public class IOStructGen { String left = concatenateUnaryStrings(leftStrings); - if (left.equals("name")) { //$NON-NLS-1$ + if (left.equals(CTFStrings.NAME2)) { if (event.nameIsSet()) { throw new ParseException("name already defined"); //$NON-NLS-1$ } @@ -656,7 +653,7 @@ public class IOStructGen { String name = getEventName(rightNode); event.setName(name); - } else if (left.equals("id")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.ID)) { if (event.idIsSet()) { throw new ParseException("id already defined"); //$NON-NLS-1$ } @@ -664,7 +661,7 @@ public class IOStructGen { long id = getEventID(rightNode); event.setId(id); - } else if (left.equals("stream_id")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.STREAM_ID)) { if (event.streamIsSet()) { throw new ParseException("stream id already defined"); //$NON-NLS-1$ } @@ -678,7 +675,7 @@ public class IOStructGen { } event.setStream(stream); - } else if (left.equals("context")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.CONTEXT)) { if (event.contextIsSet()) { throw new ParseException("context already defined"); //$NON-NLS-1$ } @@ -697,7 +694,7 @@ public class IOStructGen { } event.setContext((StructDeclaration) contextDecl); - } else if (left.equals("fields")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.FIELDS_STRING)) { if (event.fieldsIsSet()) { throw new ParseException("fields already defined"); //$NON-NLS-1$ } @@ -721,7 +718,7 @@ public class IOStructGen { final StructDeclaration fields = (StructDeclaration) fieldsDecl; event.setFields(fields); } - else if (left.equals("loglevel")){ //$NON-NLS-1$ + else if (left.equals(CTFStrings.LOGLEVEL2)){ long logLevel = parseUnaryInteger((CommonTree) rightNode.getChild(0)) ; event.setLogLevel(logLevel); @@ -1196,12 +1193,9 @@ public class IOStructGen { FloatDeclaration floatDeclaration = null; ByteOrder byteOrder = trace.getByteOrder(); long alignment = 0; - int base = 2; int exponent = 8; int mantissa = 24; - Encoding encoding = Encoding.NONE; - /* Iterate on all integer children */ for (CommonTree child : children) { switch (child.getType()) { @@ -1225,13 +1219,13 @@ public class IOStructGen { } String left = concatenateUnaryStrings(leftStrings); - if (left.equals("exp_dig")) { //$NON-NLS-1$ + if (left.equals(CTFStrings.EXP_DIG)) { exponent = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0)); - } else if (left.equals("byte_order")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.BYTE_ORDER)) { byteOrder = getByteOrder(rightNode); - } else if (left.equals("mant_dig")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.MANT_DIG)) { mantissa = (int) parseUnaryInteger((CommonTree) rightNode.getChild(0)); - } else if (left.equals("align")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.ALIGN)) { alignment = getAlignment(rightNode); } else { throw new ParseException("Float: unknown attribute " + left); //$NON-NLS-1$ @@ -1256,7 +1250,7 @@ public class IOStructGen { } } - floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding, alignment); + floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, alignment); assert (floatDeclaration != null); return floatDeclaration; @@ -1351,11 +1345,11 @@ public class IOStructGen { if (left.equals("signed")) { //$NON-NLS-1$ signed = getSigned(rightNode); - } else if (left.equals("byte_order")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.BYTE_ORDER)) { byteOrder = getByteOrder(rightNode); } else if (left.equals("size")) { //$NON-NLS-1$ size = getSize(rightNode); - } else if (left.equals("align")) { //$NON-NLS-1$ + } else if (left.equals(CTFStrings.ALIGN)) { alignment = getAlignment(rightNode); } else if (left.equals("base")) { //$NON-NLS-1$ base = getBase(rightNode); @@ -2454,9 +2448,9 @@ public class IOStructGen { if (isUnaryString(firstChild)) { String strval = concatenateUnaryStrings(rightNode.getChildren()); - if (strval.equals("true") || strval.equals("TRUE")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (strval.equals(CTFStrings.TRUE) || strval.equals(CTFStrings.TRUE2)) { ret = true; - } else if (strval.equals("false") || strval.equals("FALSE")) { //$NON-NLS-1$ //$NON-NLS-2$ + } else if (strval.equals(CTFStrings.FALSE) || strval.equals(CTFStrings.FALSE2)) { ret = false; } else { throw new ParseException("Invalid boolean value " //$NON-NLS-1$ @@ -2502,11 +2496,11 @@ public class IOStructGen { if (isUnaryString(firstChild)) { String strval = concatenateUnaryStrings(rightNode.getChildren()); - if (strval.equals("le")) { //$NON-NLS-1$ + if (strval.equals(CTFStrings.LE)) { return ByteOrder.LITTLE_ENDIAN; - } else if (strval.equals("be") || strval.equals("network")) { //$NON-NLS-1$ //$NON-NLS-2$ + } else if (strval.equals(CTFStrings.BE) || strval.equals(CTFStrings.NETWORK)) { return ByteOrder.BIG_ENDIAN; - } else if (strval.equals("native")) { //$NON-NLS-1$ + } else if (strval.equals(CTFStrings.NATIVE)) { return trace.getByteOrder(); } else { throw new ParseException("Invalid value for byte order"); //$NON-NLS-1$ @@ -2618,18 +2612,18 @@ public class IOStructGen { } else if (isUnaryString(firstChild)) { String strval = concatenateUnaryStrings(rightNode.getChildren()); - if (strval.equals("decimal") || strval.equals("dec") //$NON-NLS-1$ //$NON-NLS-2$ - || strval.equals("d") || strval.equals("i") //$NON-NLS-1$ //$NON-NLS-2$ - || strval.equals("u")) { //$NON-NLS-1$ + if (strval.equals(CTFStrings.DECIMAL) || strval.equals(CTFStrings.DEC) + || strval.equals(CTFStrings.DEC_CTE) || strval.equals(CTFStrings.INT_MOD) + || strval.equals(CTFStrings.UNSIGNED_CTE)) { return 10; - } else if (strval.equals("hexadecimal") || strval.equals("hex") //$NON-NLS-1$ //$NON-NLS-2$ - || strval.equals("x") || strval.equals("X") //$NON-NLS-1$ //$NON-NLS-2$ - || strval.equals("p")) { //$NON-NLS-1$ + } else if (strval.equals(CTFStrings.HEXADECIMAL) || strval.equals(CTFStrings.HEX) + || strval.equals(CTFStrings.X) || strval.equals(CTFStrings.X2) + || strval.equals(CTFStrings.POINTER)) { return 16; - } else if (strval.equals("octal") || strval.equals("oct") //$NON-NLS-1$ //$NON-NLS-2$ - || strval.equals("o")) { //$NON-NLS-1$ + } else if (strval.equals(CTFStrings.OCTAL) || strval.equals(CTFStrings.OCT) + || strval.equals(CTFStrings.OCTAL_CTE)) { return 8; - } else if (strval.equals("binary") || strval.equals("b")) { //$NON-NLS-1$ //$NON-NLS-2$ + } else if (strval.equals(CTFStrings.BINARY) || strval.equals(CTFStrings.BIN)) { return 2; } else { throw new ParseException("Invalid value for base"); //$NON-NLS-1$ @@ -2656,11 +2650,11 @@ public class IOStructGen { if (isUnaryString(firstChild)) { String strval = concatenateUnaryStrings(rightNode.getChildren()); - if (strval.equals("UTF8")) { //$NON-NLS-1$ + if (strval.equals(CTFStrings.UTF8)) { return Encoding.UTF8; - } else if (strval.equals("ASCII")) { //$NON-NLS-1$ + } else if (strval.equals(CTFStrings.ASCII)) { return Encoding.ASCII; - } else if (strval.equals("none")) { //$NON-NLS-1$ + } else if (strval.equals(CTFStrings.NONE)) { return Encoding.NONE; } else { throw new ParseException("Invalid value for encoding"); //$NON-NLS-1$ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java index bcbabefccb..b2093c0d14 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java @@ -133,7 +133,7 @@ public class CtfTmfEventFieldTest { IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8); FloatDeclaration flDec = new FloatDeclaration(8, 24, - ByteOrder.BIG_ENDIAN, Encoding.NONE, 8); + ByteOrder.BIG_ENDIAN, 8); ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec); SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec); sDec.addField(INT, intDec);