From 9377d173cdf42d0c84dd9156181996f8515a10cb Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Mon, 28 Jul 2014 15:56:43 -0400 Subject: [PATCH] ctf: remove duplicate code in array/sequence declarations Change-Id: I6fcb6325ae24de3984412a151137f8a5dca83deb Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/30837 Tested-by: Hudson CI Reviewed-by: Patrick Tasse --- .../tests/types/ArrayDeclaration2Test.java | 3 +- .../tests/types/ArrayDefinition2Test.java | 8 ++-- .../tests/types/VariantDefinitionTest.java | 3 +- .../core/event/types/ArrayDeclaration.java | 37 ++----------------- .../core/event/types/CompoundDeclaration.java | 21 +++++++++++ .../core/event/types/SequenceDeclaration.java | 31 +--------------- .../core/event/types/ArrayDeclaration.java | 27 -------------- .../core/event/types/SequenceDeclaration.java | 23 ------------ 8 files changed, 35 insertions(+), 118 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java index 7fc30296b6..d453cae205 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDeclaration2Test.java @@ -22,6 +22,7 @@ import java.nio.ByteOrder; import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; @@ -122,7 +123,7 @@ public class ArrayDeclaration2Test { public void testIsString_complex() { final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8); - ArrayDeclaration ad = new ArrayDeclaration(0, id); + CompoundDeclaration ad = new ArrayDeclaration(0, id); boolean result = ad.isString(); diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java index ddc2ad5e6a..dd01911cc2 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinition2Test.java @@ -88,7 +88,7 @@ public class ArrayDefinition2Test { private ArrayDefinition setUpDeclaration(IDeclaration decl, @NonNull List defs) { - ArrayDeclaration ad = new ArrayDeclaration(0, decl); + CompoundDeclaration ad = new ArrayDeclaration(0, decl); ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs); return temp; } @@ -122,7 +122,7 @@ public class ArrayDefinition2Test { */ @Test public void testArrayDefinition_baseDeclaration() { - ArrayDeclaration declaration = (ArrayDeclaration) charArrayFixture.getDeclaration(); + CompoundDeclaration declaration = (CompoundDeclaration) charArrayFixture.getDeclaration(); String fieldName = ""; @SuppressWarnings("null") @@ -136,7 +136,7 @@ public class ArrayDefinition2Test { */ @Test public void testArrayDefinition_newDeclaration() { - ArrayDeclaration declaration = new ArrayDeclaration(0, + CompoundDeclaration declaration = new ArrayDeclaration(0, new StringDeclaration()); IDefinitionScope definitionScope = getDefinitionScope(); @@ -151,7 +151,7 @@ public class ArrayDefinition2Test { */ @Test public void testGetDeclaration() { - ArrayDeclaration result = (ArrayDeclaration) charArrayFixture.getDeclaration(); + CompoundDeclaration result = (CompoundDeclaration) charArrayFixture.getDeclaration(); assertNotNull(result); } 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 c149d9d130..8c690bad89 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 @@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer; import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope; import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition; +import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.Encoding; import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration; @@ -87,7 +88,7 @@ public class VariantDefinitionTest { EnumDeclaration enDec = new EnumDeclaration(iDec); VariantDeclaration varDec = new VariantDeclaration(); EnumDeclaration tagDec = new EnumDeclaration(iDec); - ArrayDeclaration arrDec = new ArrayDeclaration(2, iDec); + CompoundDeclaration arrDec = new ArrayDeclaration(2, iDec); FloatDeclaration fDec = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 8); tagDec.add(0, 1, ENUM_1); tagDec.add(2, 3, ENUM_2); diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java index 2a729ac412..fcbc3f3c76 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java @@ -32,13 +32,14 @@ import com.google.common.collect.Multimap; * can refer to any type not containing the type of the array being declared (no * circular dependency). The length is the number of elements in an array. * - * @deprecated use {@link org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration} + * @deprecated use + * {@link org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDeclaration} * @version 1.0 * @author Matthew Khouzam * @author Simon Marchi */ @Deprecated -public class ArrayDeclaration extends Declaration { +public class ArrayDeclaration extends CompoundDeclaration { // ------------------------------------------------------------------------ // Attributes @@ -80,10 +81,7 @@ public class ArrayDeclaration extends Declaration { // Getters/Setters/Predicates // ------------------------------------------------------------------------ - /** - * - * @return the type of element in the array - */ + @Override public IDeclaration getElementType() { return fElemType; } @@ -96,33 +94,6 @@ public class ArrayDeclaration extends Declaration { return fLength; } - /** - * Sometimes, strings are encoded as an array of 1-byte integers (each one - * being an UTF-8 byte). - * - * @return true if this array is in fact an UTF-8 string. false if it's a - * "normal" array of generic Definition's. - * @since 3.0 - */ - public boolean isString() { - if (fElemType instanceof IntegerDeclaration) { - /* - * If the first byte is a "character", we'll consider the whole - * array a character string. - */ - IntegerDeclaration elemInt = (IntegerDeclaration) fElemType; - if (elemInt.isCharacter()) { - return true; - } - } - return false; - } - - @Override - public long getAlignment() { - return getElementType().getAlignment(); - } - // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java index 2f6ab4fefc..fc4c0c02c9 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/CompoundDeclaration.java @@ -28,4 +28,25 @@ public abstract class CompoundDeclaration extends Declaration { */ public abstract IDeclaration getElementType(); + @Override + public long getAlignment() { + return getElementType().getAlignment(); + } + + /** + * Sometimes, strings are encoded as an array of 1-byte integers (each one + * being an UTF-8 byte). + * + * @return true if this array is in fact an UTF-8 string. false if it's a + * "normal" array of generic Definition's. + */ + public boolean isString(){ + IDeclaration elementType = getElementType(); + if (elementType instanceof IntegerDeclaration) { + IntegerDeclaration elemInt = (IntegerDeclaration) elementType; + return elemInt.isCharacter(); + } + return false; + } + } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java index e1131e1db1..8920af3ad3 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java @@ -35,7 +35,7 @@ import com.google.common.collect.Multimap; * @author Simon Marchi */ @Deprecated -public class SequenceDeclaration extends Declaration { +public class SequenceDeclaration extends CompoundDeclaration { // ------------------------------------------------------------------------ // Attributes @@ -66,11 +66,7 @@ public class SequenceDeclaration extends Declaration { // Getters/Setters/Predicates // ------------------------------------------------------------------------ - /** - * Gets the element type - * - * @return the element type - */ + @Override public IDeclaration getElementType() { return fElemType; } @@ -84,33 +80,10 @@ public class SequenceDeclaration extends Declaration { return fLengthName; } - @Override - public long getAlignment() { - return getElementType().getAlignment(); - } - - // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ - /** - * Is the Sequence a string? - * @return true, if the elements are chars, false otherwise - * @since 3.0 - */ - public boolean isString(){ - IntegerDeclaration elemInt; - IDeclaration elementType = getElementType(); - if (elementType instanceof IntegerDeclaration) { - elemInt = (IntegerDeclaration) elementType; - if (elemInt.isCharacter()) { - return true; - } - } - return false; - } - /** * @since 3.0 */ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java index 44755528ea..8979f609d7 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/ArrayDeclaration.java @@ -21,7 +21,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.AbstractArrayDefinition; import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import com.google.common.collect.ArrayListMultimap; @@ -95,32 +94,6 @@ public final class ArrayDeclaration extends CompoundDeclaration { return fLength; } - /** - * Sometimes, strings are encoded as an array of 1-byte integers (each one - * being an UTF-8 byte). - * - * @return true if this array is in fact an UTF-8 string. false if it's a - * "normal" array of generic Definition's. - */ - public boolean isString() { - if (fElemType instanceof IntegerDeclaration) { - /* - * If the first byte is a "character", we'll consider the whole - * array a character string. - */ - IntegerDeclaration elemInt = (IntegerDeclaration) fElemType; - if (elemInt.isCharacter()) { - return true; - } - } - return false; - } - - @Override - public long getAlignment() { - return getElementType().getAlignment(); - } - // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java index 9c854b873b..5dd35bb609 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/types/SequenceDeclaration.java @@ -22,7 +22,6 @@ import org.eclipse.linuxtools.ctf.core.event.types.CompoundDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; @@ -85,32 +84,10 @@ public class SequenceDeclaration extends CompoundDeclaration { return fLengthName; } - @Override - public long getAlignment() { - return getElementType().getAlignment(); - } - // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ - /** - * Is the Sequence a string? - * - * @return true, if the elements are chars, false otherwise - */ - public boolean isString() { - IntegerDeclaration elemInt; - IDeclaration elementType = getElementType(); - if (elementType instanceof IntegerDeclaration) { - elemInt = (IntegerDeclaration) elementType; - if (elemInt.isCharacter()) { - return true; - } - } - return false; - } - @Override public AbstractArrayDefinition createDefinition( IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException { -- 2.34.1