From fbe6fa6fad1f8a21328f7f2bc97a79837904fe43 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Thu, 26 Mar 2015 11:53:51 -0400 Subject: [PATCH] Ctf: remove circular initialization issue in LexicalScope Introduce ILexicalScope, an interface to make a scope. May introduce performance regression, to be monitored Change-Id: I1c0838e8190a665db8a2aaf99e974348d4f98da4 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/44607 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse --- .../tests/event/CTFEventDefinitionTest.java | 12 +- .../core/tests/scope/LexicalScopeTest.java | 92 ++++++++- .../CTFStreamInputPacketIndexEntryTest.java | 16 +- .../core/tests/trace/CTFStreamInputTest.java | 2 +- .../tests/types/VariantDefinitionTest.java | 2 +- .../ctf/core/event/EventDefinition.java | 10 +- .../core/event/scope/EventHeaderScope.java | 17 +- .../core/event/scope/EventHeaderVScope.java | 23 +-- .../ctf/core/event/scope/FieldsScope.java | 16 +- .../core/event/scope/IDefinitionScope.java | 3 +- .../ctf/core/event/scope/ILexicalScope.java | 165 +++++++++++++++ .../ctf/core/event/scope/LexicalScope.java | 191 +++--------------- .../core/event/scope/PacketHeaderScope.java | 2 +- .../ctf/core/event/scope/RootScope.java | 14 +- .../ctf/core/event/types/Declaration.java | 14 +- .../ctf/core/event/types/Definition.java | 14 +- .../ctf/core/event/types/IDeclaration.java | 5 +- .../ctf/core/event/types/IDefinition.java | 5 +- .../core/event/types/ScopedDefinition.java | 5 +- .../core/event/types/StructDeclaration.java | 5 +- .../core/event/types/StructDefinition.java | 5 +- .../core/event/types/VariantDeclaration.java | 2 +- .../ctf/core/trace/CTFStreamInput.java | 7 +- .../trace/CTFStreamInputPacketReader.java | 17 +- .../tracecompass/ctf/core/trace/CTFTrace.java | 13 +- .../ctf/core/event/EventDeclaration.java | 8 +- .../composite/EventHeaderDefinition.java | 4 +- 27 files changed, 391 insertions(+), 278 deletions(-) create mode 100644 org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/ILexicalScope.java diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java index be48c95fae..9ef88f695e 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/event/CTFEventDefinitionTest.java @@ -11,10 +11,10 @@ package org.eclipse.tracecompass.ctf.core.tests.event; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.nio.ByteOrder; import java.util.ArrayList; @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.List; import org.eclipse.tracecompass.ctf.core.event.EventDefinition; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.Encoding; import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; @@ -78,10 +78,10 @@ public class CTFEventDefinitionTest { StructDeclaration pContextDec = new StructDeclaration(8); - StructDefinition sContext = new StructDefinition(streamContextDec, null, LexicalScope.STREAM_PACKET_CONTEXT.toString(), sFieldNames, sDefs); - StructDefinition eContext = new StructDefinition(eventContextDec, null, LexicalScope.STREAM_EVENT_CONTEXT.toString(), eFieldNames, eDefs); - StructDefinition pContext = new StructDefinition(pContextDec, null, LexicalScope.FIELDS.toString(), Collections.EMPTY_LIST, new Definition[0]); - StructDefinition fields = new StructDefinition(fDec, null, LexicalScope.FIELDS.toString(), fieldNames, fDefs); + StructDefinition sContext = new StructDefinition(streamContextDec, null, ILexicalScope.STREAM_PACKET_CONTEXT.getPath(), sFieldNames, sDefs); + StructDefinition eContext = new StructDefinition(eventContextDec, null, ILexicalScope.STREAM_EVENT_CONTEXT.getPath(), eFieldNames, eDefs); + StructDefinition pContext = new StructDefinition(pContextDec, null, ILexicalScope.FIELDS.getPath(), Collections.EMPTY_LIST, new Definition[0]); + StructDefinition fields = new StructDefinition(fDec, null, ILexicalScope.FIELDS.getPath(), fieldNames, fDefs); fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, null)); fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, fields)); diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/scope/LexicalScopeTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/scope/LexicalScopeTest.java index 1a50adc114..d24da6b881 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/scope/LexicalScopeTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/scope/LexicalScopeTest.java @@ -13,8 +13,11 @@ package org.eclipse.tracecompass.ctf.core.tests.scope; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; import org.junit.Test; @@ -29,8 +32,8 @@ public class LexicalScopeTest { * Root test */ @Test - public void testRoot(){ - LexicalScope scope = LexicalScope.ROOT; + public void testRoot() { + ILexicalScope scope = ILexicalScope.ROOT; assertNotNull(scope); } @@ -38,9 +41,88 @@ public class LexicalScopeTest { * Test a more complex node */ @Test - public void testComplexNode(){ - LexicalScope scope = LexicalScope.STREAM_EVENT_CONTEXT; + public void testComplexNode() { + ILexicalScope scope = ILexicalScope.STREAM_EVENT_CONTEXT; assertEquals("context", scope.getName()); - assertEquals("stream.event.context", scope.toString()); + assertEquals("stream.event.context", scope.getPath()); + } + + /** + * Test that getChild returns the same items for event headers + */ + @Test + public void testEventHeaders() { + ILexicalScope child = ILexicalScope.ROOT.getChild("event"); + assertNotNull(child); + ILexicalScope scope2 = child.getChild("header"); + ILexicalScope scope3 = ILexicalScope.ROOT.getChild("event.header"); + assertEquals(ILexicalScope.EVENT_HEADER, scope2); + assertEquals(ILexicalScope.EVENT_HEADER, scope3); + // they should be the same + assert (ILexicalScope.EVENT_HEADER == scope2); + + assertNotNull(scope2); + ILexicalScope id = scope2.getChild("id"); + assertNotNull(id); + assert (ILexicalScope.EVENT_HEADER_ID == id); + ILexicalScope ts = scope2.getChild("v.timestamp"); + ILexicalScope v = scope2.getChild("v"); + assert (ILexicalScope.EVENT_HEADER_V_TIMESTAMP == ts); + assert (ILexicalScope.EVENT_HEADER_V == v); + assertNotNull(v); + ILexicalScope ts2 = v.getChild("timestamp"); + assert (ILexicalScope.EVENT_HEADER_V_TIMESTAMP == ts2); + assertNotNull(v); + id = v.getChild("id"); + assert (ILexicalScope.EVENT_HEADER_V_ID == id); + assertNotNull(v); + ILexicalScope other = v.getChild("other"); + assertNull(other); + } + + /** + * Test that getChild returns the same items for event headers + */ + @Test + public void testFields() { + ILexicalScope child = ILexicalScope.ROOT.getChild("fields"); + assertNotNull(child); + ILexicalScope scope2 = child.getChild("_ret"); + ILexicalScope scope3 = child.getChild("_tid"); + ILexicalScope empty = child.getChild("other"); + + assertEquals(ILexicalScope.FIELDS_RET, scope2); + // they should be the same + assert (ILexicalScope.FIELDS_RET == scope2); + + assertEquals(ILexicalScope.FIELDS_TID, scope3); + // they should be the same + assert (ILexicalScope.FIELDS_TID == scope2); + + assertNull(empty); + } + + /** + * Check contexts are not equals + */ + @Test + public void testNotEquals() { + assertNotEquals(ILexicalScope.CONTEXT, ILexicalScope.EVENT); + LexicalScope context = new LexicalScope(ILexicalScope.CONTEXT, "context"); + LexicalScope otherContext = new LexicalScope(ILexicalScope.CONTEXT, "context2"); + assertNotEquals(context, otherContext); + assertNotEquals(context, null); + } + + /** + * Test to strings + */ + @Test + public void testGetPath() { + ILexicalScope child = ILexicalScope.ROOT.getChild("fields"); + assertNotNull(child); + ILexicalScope scope2 = child.getChild("_ret"); + assertNotNull(scope2); + assertEquals("fields._ret", scope2.getPath()); } } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java index 0f358c8d8a..ad9b4ebd30 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexEntryTest.java @@ -22,7 +22,7 @@ import java.nio.ByteOrder; import org.eclipse.tracecompass.ctf.core.CTFReaderException; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Encoding; import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration; @@ -91,7 +91,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().put(("Test").getBytes()); bb.getByteBuffer().put((byte) 0); bb.getByteBuffer().put((byte) 0); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); assertNull(sipie.getTarget()); assertEquals(100, sipie.getTimestampBegin()); @@ -120,7 +120,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().put(("Test").getBytes()); bb.getByteBuffer().put((byte) 0); bb.getByteBuffer().put((byte) 0); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); assertNull(sipie.getTarget()); assertEquals(100, sipie.getTimestampBegin()); @@ -150,7 +150,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().put(("Test").getBytes()); bb.getByteBuffer().put((byte) 0); bb.getByteBuffer().put((byte) 0); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); assertNull(sipie.getTarget()); assertEquals(100, sipie.getTimestampBegin()); @@ -178,7 +178,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().put(("Test").getBytes()); bb.getByteBuffer().put((byte) 0); bb.getByteBuffer().put((byte) 0); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); assertNull(sipie.getTarget()); assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); @@ -205,7 +205,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().put(("Test66").getBytes()); bb.getByteBuffer().put((byte) 0); bb.getByteBuffer().put((byte) 0); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 0); assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd()); @@ -232,7 +232,7 @@ public class CTFStreamInputPacketIndexEntryTest { bb.getByteBuffer().putInt(0); bb.getByteBuffer().putInt(66); bb.getByteBuffer().putInt(300); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(0, sdef, 128, 100); assertEquals(Long.MIN_VALUE, sipie.getTimestampBegin()); assertEquals(Long.MAX_VALUE, sipie.getTimestampEnd()); @@ -259,7 +259,7 @@ public class CTFStreamInputPacketIndexEntryTest { @SuppressWarnings("null") BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128)); - StructDefinition sdef = sd.createDefinition(null, LexicalScope.PACKET_HEADER, bb); + StructDefinition sdef = sd.createDefinition(null, ILexicalScope.PACKET_HEADER, bb); assertEquals(expectedResult, new StreamInputPacketIndexEntry(0, sdef, 10000, 0).toString()); } } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputTest.java index 259a8311fd..e778c30f6c 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputTest.java @@ -96,7 +96,7 @@ public class CTFStreamInputTest { */ @Test public void testGetPath() { - String result = fixture.getScopePath().toString(); + String result = fixture.getScopePath().getPath(); assertNotNull(result); } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDefinitionTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDefinitionTest.java index b330a876f2..6f6a56dc6a 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDefinitionTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDefinitionTest.java @@ -212,7 +212,7 @@ public class VariantDefinitionTest { */ @Test public void testGetPath() { - String result = fixture.getScopePath().toString(); + String result = fixture.getScopePath().getPath(); assertNotNull(result); } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java index 87730012d8..16652b7b6d 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/EventDefinition.java @@ -17,6 +17,7 @@ import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; @@ -113,15 +114,18 @@ public final class EventDefinition implements IDefinitionScope { // Getters/Setters/Predicates // ------------------------------------------------------------------------ + /** + * @since 1.0 + */ @Override - public LexicalScope getScopePath() { + public ILexicalScope getScopePath() { String eventName = fDeclaration.getName(); if (eventName == null) { return null; } - LexicalScope myScope = LexicalScope.EVENT.getChild(eventName); + ILexicalScope myScope = ILexicalScope.EVENT.getChild(eventName); if (myScope == null) { - myScope = new LexicalScope(LexicalScope.EVENT, eventName); + myScope = new LexicalScope(ILexicalScope.EVENT, eventName); } return myScope; } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderScope.java index f730dd731d..1b370e2626 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderScope.java @@ -22,17 +22,8 @@ import org.eclipse.jdt.annotation.Nullable; * @author Matthew Khouzam */ @NonNullByDefault -public class EventHeaderScope extends LexicalScope { +public final class EventHeaderScope extends LexicalScope { - /** - * Event header id string - */ - public static final LexicalScope EVENT_HEADER_ID = new LexicalScope(EVENT_HEADER, "id"); //$NON-NLS-1$ - - /** - * Event header v as in variant string - */ - public static final LexicalScope EVENT_HEADER_V = new EventHeaderVScope(EVENT_HEADER, "v"); //$NON-NLS-1$ /** * The scope constructor @@ -42,13 +33,13 @@ public class EventHeaderScope extends LexicalScope { * @param name * the name of the field */ - public EventHeaderScope(LexicalScope parent, String name) { + EventHeaderScope(ILexicalScope parent, String name) { super(parent, name); } @Override @Nullable - public LexicalScope getChild(String name) { + public ILexicalScope getChild(String name) { if (name.equals(EVENT_HEADER_ID.getName())) { return EVENT_HEADER_ID; } @@ -59,7 +50,7 @@ public class EventHeaderScope extends LexicalScope { } @Override - public String toString() { + public String getPath() { return "event.header"; //$NON-NLS-1$ } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderVScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderVScope.java index d73adf5fc9..5d3c2420d9 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderVScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/EventHeaderVScope.java @@ -22,16 +22,7 @@ import org.eclipse.jdt.annotation.Nullable; * @author Matthew Khouzam */ @NonNullByDefault -public class EventHeaderVScope extends LexicalScope { - - /** - * Packet header v id string - */ - public static final LexicalScope PACKET_HEADER_V_ID = new LexicalScope(PACKET_HEADER, "id"); //$NON-NLS-1$ - /** - * Packet header v timestamp string - */ - public static final LexicalScope PACKET_HEADER_V_TIMESTAMP = new LexicalScope(PACKET_HEADER, "timestamp"); //$NON-NLS-1$ +public final class EventHeaderVScope extends LexicalScope { /** * The scope constructor @@ -41,18 +32,18 @@ public class EventHeaderVScope extends LexicalScope { * @param name * the name of the field */ - public EventHeaderVScope(LexicalScope parent, String name) { + EventHeaderVScope(ILexicalScope parent, String name) { super(parent, name); } @Override @Nullable - public LexicalScope getChild(String name) { - if (name.equals(PACKET_HEADER_V_TIMESTAMP.getName())) { - return PACKET_HEADER_V_TIMESTAMP; + public ILexicalScope getChild(String name) { + if (name.equals(EVENT_HEADER_V_TIMESTAMP.getName())) { + return EVENT_HEADER_V_TIMESTAMP; } - if (name.equals(PACKET_HEADER_V_ID.getName())) { - return PACKET_HEADER_V_ID; + if (name.equals(EVENT_HEADER_V_ID.getName())) { + return EVENT_HEADER_V_ID; } return super.getChild(name); } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/FieldsScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/FieldsScope.java index ae766c90a7..982eb41a4c 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/FieldsScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/FieldsScope.java @@ -21,17 +21,7 @@ import org.eclipse.jdt.annotation.Nullable; * @author Matthew Khouzam */ @NonNullByDefault -public class FieldsScope extends LexicalScope { - - /** - * ret field - */ - public static final LexicalScope FIELDS_RET = new LexicalScope(FIELDS, "_ret"); //$NON-NLS-1$ - - /** - * tid field - */ - public static final LexicalScope FIELDS_TID = new LexicalScope(FIELDS, "_tid"); //$NON-NLS-1$ +public final class FieldsScope extends LexicalScope { /** * The scope constructor @@ -41,13 +31,13 @@ public class FieldsScope extends LexicalScope { * @param name * the name of the field */ - public FieldsScope(LexicalScope parent, String name) { + FieldsScope(ILexicalScope parent, String name) { super(parent, name); } @Override @Nullable - public LexicalScope getChild(String name) { + public ILexicalScope getChild(String name) { if (name.equals(FIELDS_RET.getName())) { return FIELDS_RET; } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/IDefinitionScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/IDefinitionScope.java index 099e788844..94648b6083 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/IDefinitionScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/IDefinitionScope.java @@ -27,8 +27,9 @@ public interface IDefinitionScope { * Gets the path in a C style for the scope. * * @return the path + * @since 1.0 */ - LexicalScope getScopePath(); + ILexicalScope getScopePath(); /** * Looks up in this definition scope. diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/ILexicalScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/ILexicalScope.java new file mode 100644 index 0000000000..cfaf2a6ba7 --- /dev/null +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/ILexicalScope.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2015 Ericsson + * + * 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.tracecompass.ctf.core.event.scope; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * @since 1.0 + */ +@NonNullByDefault +public interface ILexicalScope { + /** + * Empty string + */ + ILexicalScope ROOT = new RootScope(); + + /** + * Trace string + */ + ILexicalScope TRACE = new LexicalScope(ROOT, "trace"); //$NON-NLS-1$ + /** + * Env string + */ + ILexicalScope ENV = new LexicalScope(ROOT, "env"); //$NON-NLS-1$ + /** + * Stream string + */ + LexicalScope STREAM = new LexicalScope(ROOT, "stream"); //$NON-NLS-1$ + /** + * Event string + */ + LexicalScope EVENT = new LexicalScope(ROOT, "event"); //$NON-NLS-1$ + /** + * Variant string + */ + ILexicalScope VARIANT = new LexicalScope(ROOT, "variant"); //$NON-NLS-1$ + /** + * packet string + */ + LexicalScope PACKET = new LexicalScope(ROOT, "packet"); //$NON-NLS-1$ + /** + * Packet header string + */ + LexicalScope PACKET_HEADER = new PacketHeaderScope(); + + /** + * Packet header v id string + */ + ILexicalScope EVENT_HEADER_V_ID = new LexicalScope(PACKET_HEADER, "id"); //$NON-NLS-1$ + /** + * Packet header v timestamp string + */ + ILexicalScope EVENT_HEADER_V_TIMESTAMP = new LexicalScope(PACKET_HEADER, "timestamp"); //$NON-NLS-1$ + + /** + * Stream packet scope + */ + LexicalScope STREAM_PACKET = new LexicalScope(STREAM, "packet"); //$NON-NLS-1$ + /** + * Stream Packet header string + */ + ILexicalScope STREAM_PACKET_CONTEXT = new LexicalScope(STREAM_PACKET, "context"); //$NON-NLS-1$ + /** + * Trace packet scope + */ + LexicalScope TRACE_PACKET = new LexicalScope(TRACE, "packet"); //$NON-NLS-1$ + /** + * Stream event scope + */ + LexicalScope STREAM_EVENT = new LexicalScope(STREAM, "event"); //$NON-NLS-1$ + /** + * Trace packet header string + */ + ILexicalScope TRACE_PACKET_HEADER = new LexicalScope(TRACE_PACKET, "header"); //$NON-NLS-1$ + /** + * Stream event context + */ + ILexicalScope STREAM_EVENT_CONTEXT = new LexicalScope(STREAM_EVENT, "context"); //$NON-NLS-1$ + /** + * Stream event header + */ + ILexicalScope STREAM_EVENT_HEADER = new LexicalScope(STREAM_EVENT, "header"); //$NON-NLS-1$ + /** + * Context of an event + */ + LexicalScope CONTEXT = new LexicalScope(ROOT, "context"); //$NON-NLS-1$ + /** + * Event Header scope + */ + ILexicalScope EVENT_HEADER = new EventHeaderScope(EVENT, "header"); //$NON-NLS-1$ + + /** + * Event header id string + */ + ILexicalScope EVENT_HEADER_ID = new LexicalScope(EVENT_HEADER, "id"); //$NON-NLS-1$ + + /** + * Event header v as in variant string + */ + ILexicalScope EVENT_HEADER_V = new EventHeaderVScope(EVENT_HEADER, "v"); //$NON-NLS-1$ + + /** + * Fields in an event + */ + ILexicalScope FIELDS = new FieldsScope(ROOT, "fields"); //$NON-NLS-1$ + + /** + * ret field + */ + ILexicalScope FIELDS_RET = new LexicalScope(FIELDS, "_ret"); //$NON-NLS-1$ + + /** + * tid field + */ + ILexicalScope FIELDS_TID = new LexicalScope(FIELDS, "_tid"); //$NON-NLS-1$ + + /** + * Get the name + * + * @return the name + */ + String getName(); + + /** + * Gets a child of a given name + * + * @param name + * the child + * @return the scope, can be null + */ + @Nullable + ILexicalScope getChild(String name); + + // ------------------------------------------------------------------------- + // helpers + // ------------------------------------------------------------------------- + + /** + * Adds a child lexical scope + * + * @param name + * the name of the child + * @param child + * the child + */ + void addChild(String name, ILexicalScope child); + + /** + * Get the path of the scope + * + * @return the path of the scope + */ + String getPath(); + + +} \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java index a0935cdcfb..bd13dfd728 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java @@ -11,132 +11,33 @@ package org.eclipse.tracecompass.ctf.core.event.scope; -import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; - import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import com.google.common.base.Joiner; - /** * A node of a lexical scope * * @author Matthew Khouzam */ @NonNullByDefault -public class LexicalScope implements Comparable { - /** - * Empty string - */ - public static final LexicalScope ROOT = new RootScope(); - - /** - * Trace string - */ - public static final LexicalScope TRACE = new LexicalScope(ROOT, "trace"); //$NON-NLS-1$ - - /** - * Env string - */ - public static final LexicalScope ENV = new LexicalScope(ROOT, "env"); //$NON-NLS-1$ - - /** - * Stream string - */ - public static final LexicalScope STREAM = new LexicalScope(ROOT, "stream"); //$NON-NLS-1$ - - /** - * Event string - */ - public static final LexicalScope EVENT = new LexicalScope(ROOT, "event"); //$NON-NLS-1$ - - /** - * Variant string - */ - public static final LexicalScope VARIANT = new LexicalScope(ROOT, "variant"); //$NON-NLS-1$ - - /** - * packet string - */ - public static final LexicalScope PACKET = new LexicalScope(ROOT, "packet"); //$NON-NLS-1$ - - /** - * Packet header string - */ - public static final LexicalScope PACKET_HEADER = new PacketHeaderScope(); - - /** - * Stream packet scope - */ - public static final LexicalScope STREAM_PACKET = new LexicalScope(STREAM, "packet"); //$NON-NLS-1$ - - /** - * Stream Packet header string - */ - public static final LexicalScope STREAM_PACKET_CONTEXT = new LexicalScope(STREAM_PACKET, "context"); //$NON-NLS-1$ - - /** - * Trace packet scope - */ - public static final LexicalScope TRACE_PACKET = new LexicalScope(TRACE, "packet"); //$NON-NLS-1$ - - /** - * Stream event scope - */ - public static final LexicalScope STREAM_EVENT = new LexicalScope(STREAM, "event"); //$NON-NLS-1$ - - /** - * Trace packet header string - */ - public static final LexicalScope TRACE_PACKET_HEADER = new LexicalScope(TRACE_PACKET, "header"); //$NON-NLS-1$ - - /** - * Stream event context - */ - public static final LexicalScope STREAM_EVENT_CONTEXT = new LexicalScope(STREAM_EVENT, "context"); //$NON-NLS-1$ - - /** - * Stream event header - */ - public static final LexicalScope STREAM_EVENT_HEADER = new LexicalScope(STREAM_EVENT, "header"); //$NON-NLS-1$ - - /** - * Event header - */ - public static final LexicalScope EVENT_HEADER = new EventHeaderScope(EVENT, "header"); //$NON-NLS-1$ - - /** - * Fields in an event - */ - public static final LexicalScope FIELDS = new FieldsScope(ROOT, "fields"); //$NON-NLS-1$ - - /** - * Context of an event - */ - public static final LexicalScope CONTEXT = new LexicalScope(ROOT, "context"); //$NON-NLS-1$ - - /** - * Sorted list of parent paths - */ - public static final LexicalScope[] PARENT_PATHS = { - ROOT, - CONTEXT, - FIELDS, - PACKET_HEADER, - STREAM_EVENT_CONTEXT, - STREAM_EVENT_HEADER, - STREAM_PACKET_CONTEXT, - TRACE_PACKET_HEADER - }; - +public class LexicalScope implements ILexicalScope { private int hash = 0; private final String fName; private final String fPath; - private final Map fChildren = new ConcurrentHashMap<>(); + private final Map fChildren = new ConcurrentHashMap<>(); + + /** + * Hidden constructor for the root node only + * + * @since 1.0 + */ + protected LexicalScope() { + fPath = ""; //$NON-NLS-1$ + fName = ""; //$NON-NLS-1$ + } /** * The scope constructor @@ -145,77 +46,47 @@ public class LexicalScope implements Comparable { * The parent node, can be null, but shouldn't * @param name * the name of the field + * @since 1.0 */ - public LexicalScope(@Nullable LexicalScope parent, String name) { + public LexicalScope(ILexicalScope parent, String name) { fName = name; - if (parent != null) { - @NonNull String pathString = checkNotNull(Joiner.on('.').skipNulls().join(parent.fPath, parent.getName())); - /* - * if joiner return null, we get an NPE... so we won't assign fPath - * to null - */ - if (pathString.startsWith(".")) { //$NON-NLS-1$ - /* - * substring throws an exception or returns a string, it won't - * return null - */ - pathString = checkNotNull(pathString.substring(1)); - } - fPath = pathString; - parent.addChild(fName, this); - } else { - fPath = ""; //$NON-NLS-1$ - } + fPath = parent.getPath().isEmpty() ? fName : parent.getPath() + '.' + fName; + parent.addChild(name, this); } /** - * Adds a child lexical scope - * - * @param name - * the name of the child - * @param child - * the child + * @since 1.0 */ - private void addChild(String name, LexicalScope child) { + @Override + public void addChild(String name, ILexicalScope child) { fChildren.put(name, child); } - /** - * Get the name - * - * @return the name - */ + @Override public String getName() { return fName; } /** - * Gets a child of a given name - * - * @param name - * the child - * @return the scope, can be null + * @since 1.0 */ - @Nullable - public LexicalScope getChild(String name) { + @Override + public @Nullable ILexicalScope getChild(String name) { return fChildren.get(name); } + /** + * @since 1.0 + */ @Override - public String toString() { - return (fPath.isEmpty() ? fName : fPath + '.' + fName); + public String getPath() { + return fPath; } + // for debugging purposes @Override - public int compareTo(@Nullable LexicalScope other) { - if (other == null) { - throw new IllegalArgumentException(); - } - int comp = fPath.compareTo(other.fPath); - if (comp == 0) { - return fName.compareTo(other.fName); - } - return comp; + public String toString() { + return getPath(); } @Override diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/PacketHeaderScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/PacketHeaderScope.java index 1aafcae787..e8dc90c3f5 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/PacketHeaderScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/PacketHeaderScope.java @@ -31,7 +31,7 @@ public class PacketHeaderScope extends LexicalScope { } @Override - public String toString() { + public String getPath() { return "packet.header"; //$NON-NLS-1$ } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/RootScope.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/RootScope.java index 5dc5b939b9..76a2094873 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/RootScope.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/RootScope.java @@ -22,40 +22,40 @@ import org.eclipse.jdt.annotation.Nullable; * @author Matthew Khouzam */ @NonNullByDefault -public class RootScope extends LexicalScope { +public final class RootScope extends LexicalScope { /** * The scope constructor */ public RootScope() { - super(null, ""); //$NON-NLS-1$ + super(); } @Override @Nullable - public LexicalScope getChild(String name) { + public ILexicalScope getChild(String name) { /* * This happens ~40 % of the time */ - if (name.equals(EVENT_HEADER.toString())) { + if (name.equals(EVENT_HEADER.getPath())) { return EVENT_HEADER; } /* * This happens ~30 % of the time */ - if (name.equals(FIELDS.toString())) { + if (name.equals(FIELDS.getPath())) { return FIELDS; } /* * This happens ~30 % of the time */ - if (name.equals(CONTEXT.toString())) { + if (name.equals(CONTEXT.getPath())) { return CONTEXT; } /* * This happens ~1 % of the time */ - if (name.equals(PACKET_HEADER.toString())) { + if (name.equals(PACKET_HEADER.getPath())) { return PACKET_HEADER; } return super.getChild(name); diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java index 6517d52834..018acd24b1 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java @@ -15,6 +15,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.ctf.core.CTFReaderException; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; /** @@ -25,23 +26,26 @@ import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; */ public abstract class Declaration implements IDeclaration { + /** + * @since 1.0 + */ @Override - public LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName) { + public ILexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName) { if (definitionScope != null) { - final LexicalScope parentPath = definitionScope.getScopePath(); + final ILexicalScope parentPath = definitionScope.getScopePath(); if (parentPath != null) { - LexicalScope myScope = parentPath.getChild(fieldName); + ILexicalScope myScope = parentPath.getChild(fieldName); if (myScope == null) { myScope = new LexicalScope(parentPath, fieldName); } return myScope; } } - LexicalScope child = LexicalScope.ROOT.getChild(fieldName); + ILexicalScope child = ILexicalScope.ROOT.getChild(fieldName); if (child != null) { return child; } - return new LexicalScope(LexicalScope.ROOT, fieldName); + return new LexicalScope(ILexicalScope.ROOT, fieldName); } /** diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Definition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Definition.java index 9e5c4fcff4..425ca18efc 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Definition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Definition.java @@ -14,7 +14,7 @@ package org.eclipse.tracecompass.ctf.core.event.types; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; /** * A CTF definition @@ -40,7 +40,7 @@ public abstract class Definition implements IDefinition { private final String fFieldName; /** The complete path of this field */ - private final @NonNull LexicalScope fPath; + private final @NonNull ILexicalScope fPath; private final IDefinitionScope fDefinitionScope; @@ -82,8 +82,9 @@ public abstract class Definition implements IDefinition { * * @param scope * the scope + * @since 1.0 */ - public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull LexicalScope scope) { + public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull ILexicalScope scope) { fDeclaration = declaration; fDefinitionScope = definitionScope; fFieldName = fieldName; @@ -103,8 +104,11 @@ public abstract class Definition implements IDefinition { return fFieldName; } + /** + * @since 1.0 + */ @Override - public LexicalScope getScopePath() { + public ILexicalScope getScopePath() { return fPath; } @@ -131,6 +135,6 @@ public abstract class Definition implements IDefinition { @Override public String toString() { - return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']'; + return fPath.getPath() + '[' + Integer.toHexString(hashCode()) + ']'; } } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java index 7cd52d1771..be778153cf 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java @@ -16,7 +16,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.ctf.core.CTFReaderException; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; /** * A CTF data type declaration. @@ -57,8 +57,9 @@ public interface IDeclaration { * @param fieldName * the name of the definition * @return the path of the definition + * @since 1.0 */ - @NonNull LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName); + @NonNull ILexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName); /** * The minimum alignment. if the field is 32 bits, the definition will pad diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDefinition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDefinition.java index e7049093c7..29b793c91d 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDefinition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDefinition.java @@ -13,7 +13,7 @@ package org.eclipse.tracecompass.ctf.core.event.types; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; /** * Interface for data definitions. A definition is when a value is given to a @@ -28,8 +28,9 @@ public interface IDefinition { * Get the complete path of this field. * * @return The path + * @since 1.0 */ - LexicalScope getScopePath(); + ILexicalScope getScopePath(); /** * Get the declaration of this definition diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/ScopedDefinition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/ScopedDefinition.java index ed4e449673..0254e9ae1d 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/ScopedDefinition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/ScopedDefinition.java @@ -15,7 +15,7 @@ package org.eclipse.tracecompass.ctf.core.event.types; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; /** * Scoped defintion. a defintion where you can lookup various datatypes @@ -54,8 +54,9 @@ public abstract class ScopedDefinition extends Definition implements IDefinition * the field name * @param scope * the lexical scope + * @since 1.0 */ - public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, LexicalScope scope) { + public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, ILexicalScope scope) { super(declaration, definitionScope, fieldName, scope); } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java index 86b31e8376..809a26aff3 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java @@ -26,7 +26,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.ctf.core.CTFReaderException; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; /** * A CTF structure declaration. @@ -180,9 +180,10 @@ public class StructDeclaration extends Declaration { * @return a reference to the definition * @throws CTFReaderException * error in reading + * @since 1.0 */ public StructDefinition createDefinition(IDefinitionScope definitionScope, - LexicalScope fieldScope, @NonNull BitBuffer input) throws CTFReaderException { + ILexicalScope fieldScope, @NonNull BitBuffer input) throws CTFReaderException { alignRead(input); final Definition[] myFields = new Definition[fFieldMap.size()]; diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java index 5571a39e33..6e9d3b30b0 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java @@ -19,7 +19,7 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; @@ -122,9 +122,10 @@ public final class StructDefinition extends ScopedDefinition implements IComposi * the list of fields * @param definitions * the definitions + * @since 1.0 */ public StructDefinition(@NonNull StructDeclaration declaration, - IDefinitionScope definitionScope, @NonNull LexicalScope scope, + IDefinitionScope definitionScope, @NonNull ILexicalScope scope, @NonNull String structFieldName, @NonNull Iterable fieldNames, Definition[] definitions) { super(declaration, definitionScope, structFieldName, scope); fFieldNames = ImmutableList.copyOf(fieldNames); diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java index caef959861..f4907068c3 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java @@ -128,7 +128,7 @@ public class VariantDeclaration extends Declaration { fDeclarationToPopulate = fFields.get(varFieldName); if (fDeclarationToPopulate == null) { throw new CTFReaderException("Unknown enum selector for variant " + //$NON-NLS-1$ - definitionScope.getScopePath().toString()); + definitionScope.getScopePath().getPath()); } Definition fieldValue = fDeclarationToPopulate.createDefinition(definitionScope, fieldName, input); return new VariantDefinition(this, definitionScope, varFieldName, fieldName, fieldValue); diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInput.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInput.java index c6e05c3249..0c8c6cbc1a 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInput.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInput.java @@ -25,6 +25,7 @@ import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.ctf.core.CTFReaderException; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition; @@ -175,7 +176,7 @@ public class CTFStreamInput implements IDefinitionScope { */ @Override public LexicalScope getScopePath() { - return LexicalScope.STREAM; + return ILexicalScope.STREAM; } // ------------------------------------------------------------------------ @@ -311,7 +312,7 @@ public class CTFStreamInput implements IDefinitionScope { private StructDefinition parseTracePacketHeader( BitBuffer bitBuffer) throws CTFReaderException { - StructDefinition tracePacketHeaderDef = fTracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER, bitBuffer); + StructDefinition tracePacketHeaderDef = fTracePacketHeaderDecl.createDefinition(fStream.getTrace(), ILexicalScope.TRACE_PACKET_HEADER, bitBuffer); /* * Check the CTF magic number @@ -357,7 +358,7 @@ public class CTFStreamInput implements IDefinitionScope { private StreamInputPacketIndexEntry parsePacketContext(long dataOffsetBits, long fileSizeBytes, BitBuffer bitBuffer) throws CTFReaderException { StreamInputPacketIndexEntry packetIndex; - StructDefinition streamPacketContextDef = fStreamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT, bitBuffer); + StructDefinition streamPacketContextDef = fStreamPacketContextDecl.createDefinition(this, ILexicalScope.STREAM_PACKET_CONTEXT, bitBuffer); packetIndex = new StreamInputPacketIndexEntry(dataOffsetBits, streamPacketContextDef, fileSizeBytes, fLostSoFar); fLostSoFar = packetIndex.getLostEvents() + fLostSoFar; setTimestampEnd(packetIndex.getTimestampEnd()); diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java index 96eb65cb39..3dd76d2d56 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java @@ -23,6 +23,7 @@ import org.eclipse.tracecompass.ctf.core.event.EventDefinition; import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition; @@ -135,7 +136,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab * out of bounds exception or such */ public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fStreamEventContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_EVENT_CONTEXT, input); + return fStreamEventContextDecl.createDefinition(fStreamInputReader.getStreamInput(), ILexicalScope.STREAM_EVENT_CONTEXT, input); } /** @@ -153,7 +154,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab if (!(fStreamEventHeaderDecl instanceof StructDeclaration)) { throw new IllegalStateException("Definition is not a struct definition, this is a deprecated method that doesn't work so well, stop using it."); //$NON-NLS-1$ } - return ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(this, LexicalScope.STREAM_EVENT_HEADER, input); + return ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(this, ILexicalScope.STREAM_EVENT_HEADER, input); } /** @@ -166,7 +167,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab * out of bounds exception or such */ public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fStreamPacketContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_PACKET_CONTEXT, input); + return fStreamPacketContextDecl.createDefinition(fStreamInputReader.getStreamInput(), ILexicalScope.STREAM_PACKET_CONTEXT, input); } /** @@ -179,7 +180,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab * out of bounds exception or such */ public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException { - return fTracePacketHeaderDecl.createDefinition(fStreamInputReader.getStreamInput().getStream().getTrace(), LexicalScope.TRACE_PACKET_HEADER, input); + return fTracePacketHeaderDecl.createDefinition(fStreamInputReader.getStreamInput().getStream().getTrace(), ILexicalScope.TRACE_PACKET_HEADER, input); } /** @@ -214,7 +215,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab @Override public LexicalScope getScopePath() { - return LexicalScope.PACKET; + return ILexicalScope.PACKET; } // ------------------------------------------------------------------------ @@ -380,7 +381,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab eventID = ehd.getId(); timestamp = calculateTimestamp(ehd.getTimestamp(), ehd.getTimestampLength()); } else { - fCurrentStreamEventHeaderDef = ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(null, LexicalScope.EVENT_HEADER, currentBitBuffer); + fCurrentStreamEventHeaderDef = ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(null, ILexicalScope.EVENT_HEADER, currentBitBuffer); StructDefinition StructEventHeaderDef = (StructDefinition) fCurrentStreamEventHeaderDef; /* Check for the event id. */ IDefinition idDef = StructEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$ @@ -498,10 +499,10 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab @Override public Definition lookupDefinition(String lookupPath) { - if (lookupPath.equals(LexicalScope.STREAM_PACKET_CONTEXT.toString())) { + if (lookupPath.equals(ILexicalScope.STREAM_PACKET_CONTEXT.getPath())) { return (Definition) fCurrentStreamPacketContextDef; } - if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER.toString())) { + if (lookupPath.equals(ILexicalScope.TRACE_PACKET_HEADER.getPath())) { return (Definition) fCurrentTracePacketHeaderDef; } return null; diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java index e1eee14f70..235618d7cd 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFTrace.java @@ -39,7 +39,7 @@ import org.eclipse.tracecompass.ctf.core.event.CTFClock; import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.IDefinition; import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition; @@ -466,7 +466,7 @@ public class CTFTrace implements IDefinitionScope { if (fPacketHeaderDecl != null) { /* Read the packet header */ - fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, LexicalScope.PACKET_HEADER, streamBitBuffer); + fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, ILexicalScope.PACKET_HEADER, streamBitBuffer); } } catch (IOException e) { /* Shouldn't happen at this stage if every other check passed */ @@ -530,9 +530,12 @@ public class CTFTrace implements IDefinitionScope { // IDefinitionScope // ------------------------------------------------------------------------ + /** + * @since 1.0 + */ @Override - public LexicalScope getScopePath() { - return LexicalScope.TRACE; + public ILexicalScope getScopePath() { + return ILexicalScope.TRACE; } /** @@ -545,7 +548,7 @@ public class CTFTrace implements IDefinitionScope { */ @Override public Definition lookupDefinition(String lookupPath) { - if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER.toString())) { + if (lookupPath.equals(ILexicalScope.TRACE_PACKET_HEADER.getPath())) { return fPacketHeaderDef; } return null; diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java index 5cd2a153bd..9fbb31cae3 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java @@ -22,7 +22,7 @@ import org.eclipse.tracecompass.ctf.core.CTFStrings; import org.eclipse.tracecompass.ctf.core.event.EventDefinition; import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Declaration; import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; @@ -90,10 +90,10 @@ public class EventDeclaration implements IEventDeclaration { @Override public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException { StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl(); - StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), LexicalScope.STREAM_EVENT_CONTEXT, input) : null; + StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), ILexicalScope.STREAM_EVENT_CONTEXT, input) : null; StructDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader(); - StructDefinition eventContext = fContext != null ? fContext.createDefinition(fStream.getTrace(), LexicalScope.CONTEXT, input) : null; - StructDefinition eventPayload = fFields != null ? fFields.createDefinition(fStream.getTrace(), LexicalScope.FIELDS, input) : null; + StructDefinition eventContext = fContext != null ? fContext.createDefinition(fStream.getTrace(), ILexicalScope.CONTEXT, input) : null; + StructDefinition eventPayload = fFields != null ? fFields.createDefinition(fStream.getTrace(), ILexicalScope.FIELDS, input) : null; // a bit lttng specific // CTF doesn't require a timestamp, diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderDefinition.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderDefinition.java index 39ab1ab637..0ca7d58199 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderDefinition.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderDefinition.java @@ -15,7 +15,7 @@ package org.eclipse.tracecompass.internal.ctf.core.event.types.composite; import java.util.List; import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope; +import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope; import org.eclipse.tracecompass.ctf.core.event.types.Declaration; import org.eclipse.tracecompass.ctf.core.event.types.Definition; import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition; @@ -55,7 +55,7 @@ public final class EventHeaderDefinition extends Definition implements IComposit * the number of bits valid in the timestamp */ public EventHeaderDefinition(@NonNull Declaration eventHeaderDecl, int id, long timestamp, int timestampLength) { - super(eventHeaderDecl, null, LexicalScope.EVENT_HEADER.toString(), LexicalScope.EVENT_HEADER); + super(eventHeaderDecl, null, ILexicalScope.EVENT_HEADER.getPath(), ILexicalScope.EVENT_HEADER); fId = id; fTimestamp = timestamp; fTimestampLength = timestampLength; -- 2.34.1