From b76e75c8bcc11d1e3f348166e2e9f83085154fc8 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sat, 10 Nov 2012 17:33:28 -0800 Subject: [PATCH] Implement hashCode and equals for encoded values --- .../value/BaseAnnotationEncodedValue.java | 54 +++++++++ .../base/value/BaseArrayEncodedValue.java | 52 +++++++++ .../base/value/BaseBooleanEncodedValue.java | 52 +++++++++ .../base/value/BaseByteEncodedValue.java | 52 +++++++++ .../base/value/BaseCharEncodedValue.java | 52 +++++++++ .../base/value/BaseDoubleEncodedValue.java | 54 +++++++++ .../base/value/BaseEnumEncodedValue.java | 52 +++++++++ .../base/value/BaseFieldEncodedValue.java | 52 +++++++++ .../base/value/BaseFloatEncodedValue.java | 52 +++++++++ .../base/value/BaseIntEncodedValue.java | 52 +++++++++ .../base/value/BaseLongEncodedValue.java | 54 +++++++++ .../base/value/BaseMethodEncodedValue.java | 52 +++++++++ .../base/value/BaseNullEncodedValue.java | 49 ++++++++ .../base/value/BaseShortEncodedValue.java | 52 +++++++++ .../base/value/BaseStringEncodedValue.java | 52 +++++++++ .../base/value/BaseTypeEncodedValue.java | 52 +++++++++ .../DexBackedAnnotationEncodedValue.java | 4 +- .../value/DexBackedArrayEncodedValue.java | 5 +- .../immutable/ImmutableAnnotationElement.java | 3 +- .../jf/dexlib2/immutable/ImmutableField.java | 3 +- .../ImmutableAnnotationEncodedValue.java | 7 +- .../value/ImmutableArrayEncodedValue.java | 17 +-- .../value/ImmutableBooleanEncodedValue.java | 10 +- .../value/ImmutableByteEncodedValue.java | 10 +- .../value/ImmutableCharEncodedValue.java | 10 +- .../value/ImmutableDoubleEncodedValue.java | 10 +- .../value/ImmutableEncodedValue.java | 81 +------------ .../value/ImmutableEncodedValueFactory.java | 106 ++++++++++++++++++ .../value/ImmutableEnumEncodedValue.java | 10 +- .../value/ImmutableFieldEncodedValue.java | 11 +- .../value/ImmutableFloatEncodedValue.java | 10 +- .../value/ImmutableIntEncodedValue.java | 10 +- .../value/ImmutableLongEncodedValue.java | 10 +- .../value/ImmutableMethodEncodedValue.java | 14 +-- .../value/ImmutableNullEncodedValue.java | 9 +- .../value/ImmutableShortEncodedValue.java | 10 +- .../value/ImmutableStringEncodedValue.java | 14 +-- .../value/ImmutableTypeEncodedValue.java | 14 +-- 38 files changed, 1019 insertions(+), 194 deletions(-) create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseAnnotationEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseArrayEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseBooleanEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseByteEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseCharEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseDoubleEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseEnumEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFieldEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFloatEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseIntEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseLongEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseMethodEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseNullEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseShortEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseStringEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseTypeEncodedValue.java create mode 100644 dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValueFactory.java diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseAnnotationEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseAnnotationEncodedValue.java new file mode 100644 index 00000000..8b660759 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseAnnotationEncodedValue.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.AnnotationEncodedValue; + +public abstract class BaseAnnotationEncodedValue implements AnnotationEncodedValue { + @Override + public int hashCode() { + int hashCode = getType().hashCode(); + return hashCode * 31 + getElements().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof AnnotationEncodedValue) { + return getType().equals(((AnnotationEncodedValue) o).getType()) && + getElements().equals(((AnnotationEncodedValue) o).getElements()); + } + return false; + } + + public int getValueType() { return ValueType.ANNOTATION; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseArrayEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseArrayEncodedValue.java new file mode 100644 index 00000000..3c1ae71e --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseArrayEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.ArrayEncodedValue; + +public abstract class BaseArrayEncodedValue implements ArrayEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof ArrayEncodedValue) { + return getValue().equals(((ArrayEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.ARRAY; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseBooleanEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseBooleanEncodedValue.java new file mode 100644 index 00000000..2070f5bd --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseBooleanEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.BooleanEncodedValue; + +public abstract class BaseBooleanEncodedValue implements BooleanEncodedValue { + @Override + public int hashCode() { + return getValue()?1:0; + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof BooleanEncodedValue) { + return getValue() == ((BooleanEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.BOOLEAN; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseByteEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseByteEncodedValue.java new file mode 100644 index 00000000..7d27b54a --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseByteEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.ByteEncodedValue; + +public abstract class BaseByteEncodedValue implements ByteEncodedValue { + @Override + public int hashCode() { + return getValue(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof ByteEncodedValue) { + return getValue() == ((ByteEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.BYTE; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseCharEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseCharEncodedValue.java new file mode 100644 index 00000000..ceb23dd1 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseCharEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.CharEncodedValue; + +public abstract class BaseCharEncodedValue implements CharEncodedValue { + @Override + public int hashCode() { + return getValue(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof CharEncodedValue) { + return getValue() == ((CharEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.CHAR; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseDoubleEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseDoubleEncodedValue.java new file mode 100644 index 00000000..73bcb85a --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseDoubleEncodedValue.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.DoubleEncodedValue; + +public abstract class BaseDoubleEncodedValue implements DoubleEncodedValue { + @Override + public int hashCode() { + long value = Double.doubleToRawLongBits(getValue()); + int hashCode = (int)value; + return hashCode*31 + (int)(value>>>32); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof DoubleEncodedValue) { + return getValue() == ((DoubleEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.DOUBLE; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseEnumEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseEnumEncodedValue.java new file mode 100644 index 00000000..88628101 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseEnumEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.EnumEncodedValue; + +public abstract class BaseEnumEncodedValue implements EnumEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof EnumEncodedValue) { + return getValue().equals(((EnumEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.ENUM; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFieldEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFieldEncodedValue.java new file mode 100644 index 00000000..bcbf6490 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFieldEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.FieldEncodedValue; + +public abstract class BaseFieldEncodedValue implements FieldEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof FieldEncodedValue) { + return getValue().equals(((FieldEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.FIELD; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFloatEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFloatEncodedValue.java new file mode 100644 index 00000000..ab2955fa --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseFloatEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.FloatEncodedValue; + +public abstract class BaseFloatEncodedValue implements FloatEncodedValue { + @Override + public int hashCode() { + return Float.floatToRawIntBits(getValue()); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof FloatEncodedValue) { + return getValue() == ((FloatEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.FLOAT; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseIntEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseIntEncodedValue.java new file mode 100644 index 00000000..6ebc475b --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseIntEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.IntEncodedValue; + +public abstract class BaseIntEncodedValue implements IntEncodedValue { + @Override + public int hashCode() { + return getValue(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof IntEncodedValue) { + return getValue() == ((IntEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.INT; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseLongEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseLongEncodedValue.java new file mode 100644 index 00000000..e0f34099 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseLongEncodedValue.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.LongEncodedValue; + +public abstract class BaseLongEncodedValue implements LongEncodedValue { + @Override + public int hashCode() { + long value = getValue(); + int hashCode = (int)value; + return hashCode*31 + (int)(value>>>32); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof LongEncodedValue) { + return getValue() == ((LongEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.LONG; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseMethodEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseMethodEncodedValue.java new file mode 100644 index 00000000..a7a5c7f7 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseMethodEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.MethodEncodedValue; + +public abstract class BaseMethodEncodedValue implements MethodEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof MethodEncodedValue) { + return getValue().equals(((MethodEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.METHOD; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseNullEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseNullEncodedValue.java new file mode 100644 index 00000000..526de226 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseNullEncodedValue.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.NullEncodedValue; + +public abstract class BaseNullEncodedValue implements NullEncodedValue { + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object o) { + return o != null && o instanceof NullEncodedValue; + } + + public int getValueType() { return ValueType.NULL; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseShortEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseShortEncodedValue.java new file mode 100644 index 00000000..e5849b8c --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseShortEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.ShortEncodedValue; + +public abstract class BaseShortEncodedValue implements ShortEncodedValue { + @Override + public int hashCode() { + return getValue(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof ShortEncodedValue) { + return getValue() == ((ShortEncodedValue) o).getValue(); + } + return false; + } + + public int getValueType() { return ValueType.SHORT; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseStringEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseStringEncodedValue.java new file mode 100644 index 00000000..9cfdf338 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseStringEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.StringEncodedValue; + +public abstract class BaseStringEncodedValue implements StringEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof StringEncodedValue) { + return getValue().equals(((StringEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.STRING; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseTypeEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseTypeEncodedValue.java new file mode 100644 index 00000000..88590620 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/base/value/BaseTypeEncodedValue.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.base.value; + +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.TypeEncodedValue; + +public abstract class BaseTypeEncodedValue implements TypeEncodedValue { + @Override + public int hashCode() { + return getValue().hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof TypeEncodedValue) { + return getValue().equals(((TypeEncodedValue) o).getValue()); + } + return false; + } + + public int getValueType() { return ValueType.TYPE; } +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedAnnotationEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedAnnotationEncodedValue.java index 5fd9d513..508d34cf 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedAnnotationEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedAnnotationEncodedValue.java @@ -32,6 +32,7 @@ package org.jf.dexlib2.dexbacked.value; import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue; import org.jf.dexlib2.dexbacked.DexBackedAnnotationElement; import org.jf.dexlib2.dexbacked.DexBuffer; import org.jf.dexlib2.dexbacked.DexReader; @@ -42,7 +43,7 @@ import org.jf.dexlib2.iface.value.AnnotationEncodedValue; import javax.annotation.Nonnull; import java.util.List; -public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue { +public class DexBackedAnnotationEncodedValue extends BaseAnnotationEncodedValue implements AnnotationEncodedValue { @Nonnull public final DexBuffer dexBuf; @Nonnull public final String type; private final int elementsOffset; @@ -67,7 +68,6 @@ public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue { } } - @Override public int getValueType() { return ValueType.ANNOTATION; } @Nonnull @Override public String getType() { return type; } @Nonnull diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedArrayEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedArrayEncodedValue.java index 2b5a8be3..76b13ba0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedArrayEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/value/DexBackedArrayEncodedValue.java @@ -32,6 +32,7 @@ package org.jf.dexlib2.dexbacked.value; import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseArrayEncodedValue; import org.jf.dexlib2.dexbacked.DexBuffer; import org.jf.dexlib2.dexbacked.DexReader; import org.jf.dexlib2.dexbacked.util.VariableSizeList; @@ -41,7 +42,7 @@ import org.jf.dexlib2.iface.value.EncodedValue; import javax.annotation.Nonnull; import java.util.List; -public class DexBackedArrayEncodedValue implements ArrayEncodedValue { +public class DexBackedArrayEncodedValue extends BaseArrayEncodedValue implements ArrayEncodedValue { @Nonnull public final DexBuffer dexBuf; private final int encodedArrayOffset; @@ -58,8 +59,6 @@ public class DexBackedArrayEncodedValue implements ArrayEncodedValue { } } - @Override public int getValueType() { return ValueType.ARRAY; } - @Nonnull @Override public List getValue() { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java index e3823c71..e95f25c2 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java @@ -35,6 +35,7 @@ import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.dexlib2.immutable.value.ImmutableEncodedValue; +import org.jf.dexlib2.immutable.value.ImmutableEncodedValueFactory; import org.jf.util.ImmutableListConverter; import javax.annotation.Nonnull; @@ -48,7 +49,7 @@ public class ImmutableAnnotationElement implements AnnotationElement { public ImmutableAnnotationElement(@Nonnull String name, @Nonnull EncodedValue value) { this.name = name; - this.value = ImmutableEncodedValue.of(value); + this.value = ImmutableEncodedValueFactory.of(value); } public ImmutableAnnotationElement(@Nonnull String name, diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java index ae96c74d..caa9b662 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java @@ -37,6 +37,7 @@ import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.Field; import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.dexlib2.immutable.value.ImmutableEncodedValue; +import org.jf.dexlib2.immutable.value.ImmutableEncodedValueFactory; import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListUtils; @@ -62,7 +63,7 @@ public class ImmutableField extends BaseFieldReference implements Field { this.name = name; this.type = type; this.accessFlags = accessFlags; - this.initialValue = ImmutableEncodedValue.of(initialValue); + this.initialValue = ImmutableEncodedValueFactory.of(initialValue); this.annotations = ImmutableAnnotation.immutableListOf(annotations); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java index b703da84..9f4a2b84 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java @@ -32,7 +32,7 @@ package org.jf.dexlib2.immutable.value; import com.google.common.collect.ImmutableList; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue; import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.value.AnnotationEncodedValue; import org.jf.dexlib2.immutable.ImmutableAnnotationElement; @@ -42,20 +42,19 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; -public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue implements AnnotationEncodedValue { +public class ImmutableAnnotationEncodedValue extends BaseAnnotationEncodedValue + implements ImmutableEncodedValue, AnnotationEncodedValue { @Nonnull public final String type; @Nonnull public final ImmutableList elements; public ImmutableAnnotationEncodedValue(@Nonnull String type, @Nullable List elements) { - super(ValueType.ANNOTATION); this.type = type; this.elements = ImmutableAnnotationElement.immutableListOf(elements); } public ImmutableAnnotationEncodedValue(@Nonnull String type, @Nullable ImmutableList elements) { - super(ValueType.ANNOTATION); this.type = type; this.elements = ImmutableListUtils.nullToEmptyList(elements); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableArrayEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableArrayEncodedValue.java index 77d8ad75..a3be24a7 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableArrayEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableArrayEncodedValue.java @@ -32,24 +32,22 @@ package org.jf.dexlib2.immutable.value; import com.google.common.collect.ImmutableList; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseArrayEncodedValue; import org.jf.dexlib2.iface.value.ArrayEncodedValue; import org.jf.dexlib2.iface.value.EncodedValue; import javax.annotation.Nonnull; import java.util.List; -public class ImmutableArrayEncodedValue extends ImmutableEncodedValue implements ArrayEncodedValue { - @Nonnull - public final ImmutableList value; +public class ImmutableArrayEncodedValue extends BaseArrayEncodedValue + implements ImmutableEncodedValue, ArrayEncodedValue { + @Nonnull public final ImmutableList value; public ImmutableArrayEncodedValue(@Nonnull List value) { - super(ValueType.ARRAY); - this.value = ImmutableEncodedValue.immutableListOf(value); + this.value = ImmutableEncodedValueFactory.immutableListOf(value); } public ImmutableArrayEncodedValue(@Nonnull ImmutableList value) { - super(ValueType.ARRAY); this.value = value; } @@ -60,8 +58,5 @@ public class ImmutableArrayEncodedValue extends ImmutableEncodedValue implements return new ImmutableArrayEncodedValue(arrayEncodedValue.getValue()); } - @Nonnull - public ImmutableList getValue() { - return value; - } + @Nonnull public ImmutableList getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableBooleanEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableBooleanEncodedValue.java index 30a95cdb..974d95c7 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableBooleanEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableBooleanEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseBooleanEncodedValue; import org.jf.dexlib2.iface.value.BooleanEncodedValue; -public class ImmutableBooleanEncodedValue extends ImmutableEncodedValue implements BooleanEncodedValue { +public class ImmutableBooleanEncodedValue extends BaseBooleanEncodedValue + implements ImmutableEncodedValue, BooleanEncodedValue { public final boolean value; public ImmutableBooleanEncodedValue(boolean value) { - super(ValueType.BOOLEAN); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableBooleanEncodedValue extends ImmutableEncodedValue implemen return new ImmutableBooleanEncodedValue(booleanEncodedValue.getValue()); } - public boolean getValue() { - return value; - } + @Override public boolean getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableByteEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableByteEncodedValue.java index 1f1d442f..f7b93eea 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableByteEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableByteEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseByteEncodedValue; import org.jf.dexlib2.iface.value.ByteEncodedValue; -public class ImmutableByteEncodedValue extends ImmutableEncodedValue implements ByteEncodedValue { +public class ImmutableByteEncodedValue extends BaseByteEncodedValue + implements ImmutableEncodedValue, ByteEncodedValue { public final byte value; public ImmutableByteEncodedValue(byte value) { - super(ValueType.BYTE); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableByteEncodedValue extends ImmutableEncodedValue implements return new ImmutableByteEncodedValue(byteEncodedValue.getValue()); } - public byte getValue() { - return value; - } + @Override public byte getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableCharEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableCharEncodedValue.java index 6e64ff83..4138a0e8 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableCharEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableCharEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseCharEncodedValue; import org.jf.dexlib2.iface.value.CharEncodedValue; -public class ImmutableCharEncodedValue extends ImmutableEncodedValue implements CharEncodedValue { +public class ImmutableCharEncodedValue extends BaseCharEncodedValue + implements ImmutableEncodedValue, CharEncodedValue { public final char value; public ImmutableCharEncodedValue(char value) { - super(ValueType.CHAR); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableCharEncodedValue extends ImmutableEncodedValue implements return new ImmutableCharEncodedValue(charEncodedValue.getValue()); } - public char getValue() { - return value; - } + @Override public char getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableDoubleEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableDoubleEncodedValue.java index 411bde6d..e862ceeb 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableDoubleEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableDoubleEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseDoubleEncodedValue; import org.jf.dexlib2.iface.value.DoubleEncodedValue; -public class ImmutableDoubleEncodedValue extends ImmutableEncodedValue implements DoubleEncodedValue { +public class ImmutableDoubleEncodedValue extends BaseDoubleEncodedValue + implements ImmutableEncodedValue, DoubleEncodedValue { public final double value; public ImmutableDoubleEncodedValue(double value) { - super(ValueType.DOUBLE); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableDoubleEncodedValue extends ImmutableEncodedValue implement return new ImmutableDoubleEncodedValue(doubleEncodedValue.getValue()); } - public double getValue() { - return value; - } + @Override public double getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java index 442efe4b..2e7fc364 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java @@ -31,84 +31,7 @@ package org.jf.dexlib2.immutable.value; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import org.jf.dexlib2.ValueType; -import org.jf.dexlib2.iface.value.*; -import org.jf.util.ImmutableListConverter; +import org.jf.dexlib2.iface.value.EncodedValue; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; - -public class ImmutableEncodedValue implements EncodedValue { - public final int type; - - protected ImmutableEncodedValue(int type) { - this.type = type; - } - - @Nullable - public static ImmutableEncodedValue of(@Nullable EncodedValue encodedValue) { - if (encodedValue == null) { - return null; - } - switch (encodedValue.getValueType()) { - case ValueType.BYTE: - return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue); - case ValueType.SHORT: - return ImmutableShortEncodedValue.of((ShortEncodedValue)encodedValue); - case ValueType.CHAR: - return ImmutableCharEncodedValue.of((CharEncodedValue)encodedValue); - case ValueType.INT: - return ImmutableIntEncodedValue.of((IntEncodedValue)encodedValue); - case ValueType.LONG: - return ImmutableLongEncodedValue.of((LongEncodedValue)encodedValue); - case ValueType.FLOAT: - return ImmutableFloatEncodedValue.of((FloatEncodedValue)encodedValue); - case ValueType.DOUBLE: - return ImmutableDoubleEncodedValue.of((DoubleEncodedValue)encodedValue); - case ValueType.STRING: - return ImmutableStringEncodedValue.of((StringEncodedValue)encodedValue); - case ValueType.TYPE: - return ImmutableTypeEncodedValue.of((TypeEncodedValue)encodedValue); - case ValueType.FIELD: - return ImmutableFieldEncodedValue.of((FieldEncodedValue)encodedValue); - case ValueType.METHOD: - return ImmutableMethodEncodedValue.of((MethodEncodedValue)encodedValue); - case ValueType.ENUM: - return ImmutableEnumEncodedValue.of((EnumEncodedValue)encodedValue); - case ValueType.ARRAY: - return ImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue); - case ValueType.ANNOTATION: - return ImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue); - case ValueType.NULL: - return ImmutableNullEncodedValue.INSTANCE; - case ValueType.BOOLEAN: - return ImmutableBooleanEncodedValue.of((BooleanEncodedValue)encodedValue); - default: - Preconditions.checkArgument(false); - return null; - } - } - - public int getValueType() { return type; } - - @Nonnull - public static ImmutableList immutableListOf(@Nullable List list) { - return CONVERTER.convert(list); - } - - private static final ImmutableListConverter CONVERTER = - new ImmutableListConverter() { - @Override - protected boolean isImmutable(EncodedValue item) { - return item instanceof ImmutableEncodedValue; - } - - @Override - protected ImmutableEncodedValue makeImmutable(EncodedValue item) { - return ImmutableEncodedValue.of(item); - } - }; +public interface ImmutableEncodedValue extends EncodedValue { } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValueFactory.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValueFactory.java new file mode 100644 index 00000000..633639f4 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValueFactory.java @@ -0,0 +1,106 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.immutable.value; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.iface.value.*; +import org.jf.util.ImmutableListConverter; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.List; + +public class ImmutableEncodedValueFactory { + @Nullable + public static ImmutableEncodedValue of(@Nullable EncodedValue encodedValue) { + if (encodedValue == null) { + return null; + } + switch (encodedValue.getValueType()) { + case ValueType.BYTE: + return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue); + case ValueType.SHORT: + return ImmutableShortEncodedValue.of((ShortEncodedValue)encodedValue); + case ValueType.CHAR: + return ImmutableCharEncodedValue.of((CharEncodedValue)encodedValue); + case ValueType.INT: + return ImmutableIntEncodedValue.of((IntEncodedValue)encodedValue); + case ValueType.LONG: + return ImmutableLongEncodedValue.of((LongEncodedValue)encodedValue); + case ValueType.FLOAT: + return ImmutableFloatEncodedValue.of((FloatEncodedValue)encodedValue); + case ValueType.DOUBLE: + return ImmutableDoubleEncodedValue.of((DoubleEncodedValue)encodedValue); + case ValueType.STRING: + return ImmutableStringEncodedValue.of((StringEncodedValue)encodedValue); + case ValueType.TYPE: + return ImmutableTypeEncodedValue.of((TypeEncodedValue)encodedValue); + case ValueType.FIELD: + return ImmutableFieldEncodedValue.of((FieldEncodedValue)encodedValue); + case ValueType.METHOD: + return ImmutableMethodEncodedValue.of((MethodEncodedValue)encodedValue); + case ValueType.ENUM: + return ImmutableEnumEncodedValue.of((EnumEncodedValue)encodedValue); + case ValueType.ARRAY: + return ImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue); + case ValueType.ANNOTATION: + return ImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue); + case ValueType.NULL: + return ImmutableNullEncodedValue.INSTANCE; + case ValueType.BOOLEAN: + return ImmutableBooleanEncodedValue.of((BooleanEncodedValue)encodedValue); + default: + Preconditions.checkArgument(false); + return null; + } + } + + @Nonnull + public static ImmutableList immutableListOf(@Nullable List list) { + return CONVERTER.convert(list); + } + + private static final ImmutableListConverter CONVERTER = + new ImmutableListConverter() { + @Override + protected boolean isImmutable(EncodedValue item) { + return item instanceof ImmutableEncodedValue; + } + + @Override + protected ImmutableEncodedValue makeImmutable(EncodedValue item) { + return of(item); + } + }; +} diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEnumEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEnumEncodedValue.java index c0a6736d..5e64389c 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEnumEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEnumEncodedValue.java @@ -31,16 +31,16 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseEnumEncodedValue; import org.jf.dexlib2.iface.value.EnumEncodedValue; import javax.annotation.Nonnull; -public class ImmutableEnumEncodedValue extends ImmutableEncodedValue implements EnumEncodedValue { +public class ImmutableEnumEncodedValue extends BaseEnumEncodedValue + implements ImmutableEncodedValue, EnumEncodedValue { @Nonnull public final String value; public ImmutableEnumEncodedValue(@Nonnull String value) { - super(ValueType.ENUM); this.value = value; } @@ -51,7 +51,5 @@ public class ImmutableEnumEncodedValue extends ImmutableEncodedValue implements return new ImmutableEnumEncodedValue(enumEncodedValue.getValue()); } - @Nonnull public String getValue() { - return value; - } + @Nonnull @Override public String getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFieldEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFieldEncodedValue.java index 5ce04fd2..4cb3b04a 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFieldEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFieldEncodedValue.java @@ -31,17 +31,17 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseFieldEncodedValue; import org.jf.dexlib2.iface.reference.FieldReference; import org.jf.dexlib2.iface.value.FieldEncodedValue; import javax.annotation.Nonnull; -public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements FieldEncodedValue { +public class ImmutableFieldEncodedValue extends BaseFieldEncodedValue + implements ImmutableEncodedValue, FieldEncodedValue { @Nonnull public final FieldReference value; public ImmutableFieldEncodedValue(@Nonnull FieldReference value) { - super(ValueType.FIELD); this.value = value; } @@ -52,8 +52,5 @@ public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements return new ImmutableFieldEncodedValue(fieldEncodedValue.getValue()); } - @Nonnull - public FieldReference getValue() { - return value; - } + @Nonnull @Override public FieldReference getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFloatEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFloatEncodedValue.java index dea80057..8ca8110e 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFloatEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableFloatEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseFloatEncodedValue; import org.jf.dexlib2.iface.value.FloatEncodedValue; -public class ImmutableFloatEncodedValue extends ImmutableEncodedValue implements FloatEncodedValue { +public class ImmutableFloatEncodedValue extends BaseFloatEncodedValue + implements ImmutableEncodedValue, FloatEncodedValue { public final float value; public ImmutableFloatEncodedValue(float value) { - super(ValueType.FLOAT); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableFloatEncodedValue extends ImmutableEncodedValue implements return new ImmutableFloatEncodedValue(floatEncodedValue.getValue()); } - public float getValue() { - return value; - } + @Override public float getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableIntEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableIntEncodedValue.java index 069302d3..8809aee5 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableIntEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableIntEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseIntEncodedValue; import org.jf.dexlib2.iface.value.IntEncodedValue; -public class ImmutableIntEncodedValue extends ImmutableEncodedValue implements IntEncodedValue { +public class ImmutableIntEncodedValue extends BaseIntEncodedValue + implements ImmutableEncodedValue, IntEncodedValue { public final int value; public ImmutableIntEncodedValue(int value) { - super(ValueType.INT); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableIntEncodedValue extends ImmutableEncodedValue implements I return new ImmutableIntEncodedValue(intEncodedValue.getValue()); } - public int getValue() { - return value; - } + @Override public int getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableLongEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableLongEncodedValue.java index 684d53c3..a5d645e7 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableLongEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableLongEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseLongEncodedValue; import org.jf.dexlib2.iface.value.LongEncodedValue; -public class ImmutableLongEncodedValue extends ImmutableEncodedValue implements LongEncodedValue { +public class ImmutableLongEncodedValue extends BaseLongEncodedValue + implements ImmutableEncodedValue, LongEncodedValue { public final long value; public ImmutableLongEncodedValue(long value) { - super(ValueType.LONG); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableLongEncodedValue extends ImmutableEncodedValue implements return new ImmutableLongEncodedValue(longEncodedValue.getValue()); } - public long getValue() { - return value; - } + @Override public long getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableMethodEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableMethodEncodedValue.java index 772ca9a1..948fde78 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableMethodEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableMethodEncodedValue.java @@ -31,18 +31,17 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseMethodEncodedValue; import org.jf.dexlib2.iface.reference.MethodReference; import org.jf.dexlib2.iface.value.MethodEncodedValue; import javax.annotation.Nonnull; -public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implements MethodEncodedValue { - @Nonnull - public final MethodReference value; +public class ImmutableMethodEncodedValue extends BaseMethodEncodedValue + implements ImmutableEncodedValue, MethodEncodedValue { + @Nonnull public final MethodReference value; public ImmutableMethodEncodedValue(@Nonnull MethodReference value) { - super(ValueType.METHOD); this.value = value; } @@ -53,8 +52,5 @@ public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implement return new ImmutableMethodEncodedValue(methodEncodedValue.getValue()); } - @Nonnull - public MethodReference getValue() { - return value; - } + @Nonnull @Override public MethodReference getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableNullEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableNullEncodedValue.java index d710a6d9..6258f605 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableNullEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableNullEncodedValue.java @@ -31,13 +31,12 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseNullEncodedValue; import org.jf.dexlib2.iface.value.NullEncodedValue; -public class ImmutableNullEncodedValue extends ImmutableEncodedValue implements NullEncodedValue { +public class ImmutableNullEncodedValue extends BaseNullEncodedValue + implements ImmutableEncodedValue, NullEncodedValue { public static final ImmutableNullEncodedValue INSTANCE = new ImmutableNullEncodedValue(); - public ImmutableNullEncodedValue() { - super(ValueType.NULL); - } + private ImmutableNullEncodedValue() {} } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableShortEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableShortEncodedValue.java index cfa975cc..eea38bdf 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableShortEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableShortEncodedValue.java @@ -31,14 +31,14 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseShortEncodedValue; import org.jf.dexlib2.iface.value.ShortEncodedValue; -public class ImmutableShortEncodedValue extends ImmutableEncodedValue implements ShortEncodedValue { +public class ImmutableShortEncodedValue extends BaseShortEncodedValue + implements ImmutableEncodedValue, ShortEncodedValue { public final short value; public ImmutableShortEncodedValue(short value) { - super(ValueType.SHORT); this.value = value; } @@ -49,7 +49,5 @@ public class ImmutableShortEncodedValue extends ImmutableEncodedValue implements return new ImmutableShortEncodedValue(shortEncodedValue.getValue()); } - public short getValue() { - return value; - } + @Override public short getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableStringEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableStringEncodedValue.java index fd2087b2..32a8932a 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableStringEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableStringEncodedValue.java @@ -31,17 +31,16 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseStringEncodedValue; import org.jf.dexlib2.iface.value.StringEncodedValue; import javax.annotation.Nonnull; -public class ImmutableStringEncodedValue extends ImmutableEncodedValue implements StringEncodedValue { - @Nonnull - public final String value; +public class ImmutableStringEncodedValue extends BaseStringEncodedValue + implements ImmutableEncodedValue, StringEncodedValue { + @Nonnull public final String value; public ImmutableStringEncodedValue(@Nonnull String value) { - super(ValueType.STRING); this.value = value; } @@ -52,8 +51,5 @@ public class ImmutableStringEncodedValue extends ImmutableEncodedValue implement return new ImmutableStringEncodedValue(stringEncodedValue.getValue()); } - @Nonnull - public String getValue() { - return value; - } + @Nonnull @Override public String getValue() { return value; } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableTypeEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableTypeEncodedValue.java index c8eec685..0be5df5a 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableTypeEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableTypeEncodedValue.java @@ -31,17 +31,16 @@ package org.jf.dexlib2.immutable.value; -import org.jf.dexlib2.ValueType; +import org.jf.dexlib2.base.value.BaseTypeEncodedValue; import org.jf.dexlib2.iface.value.TypeEncodedValue; import javax.annotation.Nonnull; -public class ImmutableTypeEncodedValue extends ImmutableEncodedValue implements TypeEncodedValue { - @Nonnull - public final String value; +public class ImmutableTypeEncodedValue extends BaseTypeEncodedValue + implements ImmutableEncodedValue, TypeEncodedValue { + @Nonnull public final String value; public ImmutableTypeEncodedValue(@Nonnull String value) { - super(ValueType.TYPE); this.value = value; } @@ -52,8 +51,5 @@ public class ImmutableTypeEncodedValue extends ImmutableEncodedValue implements return new ImmutableTypeEncodedValue(typeEncodedValue.getValue()); } - @Nonnull - public String getValue() { - return value; - } + @Nonnull @Override public String getValue() { return value; } }