Add sorted interface and immutable implementations

This commit is contained in:
Ben Gruver
2012-11-12 22:55:06 -08:00
parent ddf2021942
commit 2d7e111135
64 changed files with 1887 additions and 61 deletions

View File

@ -0,0 +1,41 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.Annotation;
import javax.annotation.Nonnull;
import java.util.SortedSet;
public interface SortedAnnotation extends Annotation {
@Nonnull SortedSet<? extends SortedAnnotationElement> getElements();
}

View File

@ -0,0 +1,41 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface SortedAnnotationElement extends AnnotationElement {
@Nonnull SortedEncodedValue getValue();
}

View File

@ -0,0 +1,43 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.ClassDef;
import javax.annotation.Nonnull;
import java.util.SortedSet;
public interface SortedClassDef extends ClassDef {
@Nonnull SortedSet<? extends SortedAnnotation> getAnnotations();
@Nonnull SortedSet<? extends SortedField> getFields();
@Nonnull SortedSet<? extends SortedMethod> getMethods();
}

View File

@ -0,0 +1,44 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.SortedSet;
public interface SortedField extends Field {
@Nullable SortedEncodedValue getInitialValue();
@Nonnull SortedSet<? extends SortedAnnotation> getAnnotations();
}

View File

@ -0,0 +1,43 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.Method;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.SortedSet;
public interface SortedMethod extends Method {
@Nonnull Collection<? extends SortedMethodParameter> getParameters();
@Nonnull SortedSet<? extends SortedAnnotation> getAnnotations();
}

View File

@ -0,0 +1,41 @@
/*
* 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.iface.sorted;
import org.jf.dexlib2.iface.MethodParameter;
import javax.annotation.Nonnull;
import java.util.SortedSet;
public interface SortedMethodParameter extends MethodParameter {
@Nonnull SortedSet<? extends SortedAnnotation> getAnnotations();
}

View File

@ -0,0 +1,42 @@
/*
* 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.iface.sorted.value;
import org.jf.dexlib2.iface.sorted.SortedAnnotationElement;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import javax.annotation.Nonnull;
import java.util.SortedSet;
public interface SortedAnnotationEncodedValue extends SortedEncodedValue, AnnotationEncodedValue {
@Nonnull SortedSet<? extends SortedAnnotationElement> getElements();
}

View File

@ -0,0 +1,41 @@
/*
* 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.iface.sorted.value;
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
import javax.annotation.Nonnull;
import java.util.Collection;
public interface SortedArrayEncodedValue extends SortedEncodedValue, ArrayEncodedValue{
@Nonnull Collection<? extends SortedEncodedValue> getValue();
}

View File

@ -0,0 +1,37 @@
/*
* 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.iface.sorted.value;
import org.jf.dexlib2.iface.value.EncodedValue;
public interface SortedEncodedValue extends EncodedValue {
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface BooleanEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface BooleanEncodedValue extends EncodedValue, SortedEncodedValue {
boolean getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface ByteEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface ByteEncodedValue extends EncodedValue, SortedEncodedValue {
byte getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface CharEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface CharEncodedValue extends EncodedValue, SortedEncodedValue {
char getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface DoubleEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface DoubleEncodedValue extends EncodedValue, SortedEncodedValue {
double getValue();
}

View File

@ -32,9 +32,10 @@
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface EnumEncodedValue extends EncodedValue {
public interface EnumEncodedValue extends EncodedValue, SortedEncodedValue {
@Nonnull FieldReference getValue();
}

View File

@ -32,9 +32,10 @@
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface FieldEncodedValue extends EncodedValue {
public interface FieldEncodedValue extends EncodedValue, SortedEncodedValue {
@Nonnull FieldReference getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface FloatEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface FloatEncodedValue extends EncodedValue, SortedEncodedValue {
float getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface IntEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface IntEncodedValue extends EncodedValue, SortedEncodedValue {
int getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface LongEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface LongEncodedValue extends EncodedValue, SortedEncodedValue {
long getValue();
}

View File

@ -32,9 +32,10 @@
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface MethodEncodedValue extends EncodedValue {
public interface MethodEncodedValue extends EncodedValue, SortedEncodedValue {
@Nonnull MethodReference getValue();
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface NullEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface NullEncodedValue extends EncodedValue, SortedEncodedValue {
//no value
}

View File

@ -31,6 +31,8 @@
package org.jf.dexlib2.iface.value;
public interface ShortEncodedValue extends EncodedValue {
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
public interface ShortEncodedValue extends EncodedValue, SortedEncodedValue {
short getValue();
}

View File

@ -31,8 +31,10 @@
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface StringEncodedValue extends EncodedValue {
public interface StringEncodedValue extends EncodedValue, SortedEncodedValue {
@Nonnull String getValue();
}

View File

@ -31,8 +31,10 @@
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import javax.annotation.Nonnull;
public interface TypeEncodedValue extends EncodedValue {
public interface TypeEncodedValue extends EncodedValue, SortedEncodedValue {
@Nonnull String getValue();
}

View File

@ -36,7 +36,7 @@ import org.jf.dexlib2.base.BaseAnnotation;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -60,7 +60,7 @@ public class ImmutableAnnotation extends BaseAnnotation {
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
this.visibility = visibility;
this.type = type;
this.elements = ImmutableListUtils.nullToEmptyList(elements);
this.elements = ImmutableUtils.nullToEmptyList(elements);
}
public static ImmutableAnnotation of(Annotation annotation) {

View File

@ -38,7 +38,7 @@ import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.Method;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -84,11 +84,11 @@ public class ImmutableClassDef extends BaseTypeReference implements ClassDef {
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = ImmutableListUtils.nullToEmptyList(interfaces);
this.interfaces = ImmutableUtils.nullToEmptyList(interfaces);
this.sourceFile = sourceFile;
this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.fields = ImmutableListUtils.nullToEmptyList(fields);
this.methods = ImmutableListUtils.nullToEmptyList(methods);
this.annotations = ImmutableUtils.nullToEmptyList(annotations);
this.fields = ImmutableUtils.nullToEmptyList(fields);
this.methods = ImmutableUtils.nullToEmptyList(methods);
}
public static ImmutableClassDef of(ClassDef classDef) {

View File

@ -34,7 +34,7 @@ package org.jf.dexlib2.immutable;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.DexFile;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -48,7 +48,7 @@ public class ImmutableDexFile implements DexFile {
}
public ImmutableDexFile(@Nullable ImmutableList<? extends ImmutableClassDef> classes) {
this.classes = ImmutableListUtils.nullToEmptyList(classes);
this.classes = ImmutableUtils.nullToEmptyList(classes);
}
public static ImmutableDexFile of(DexFile dexFile) {

View File

@ -39,7 +39,7 @@ 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;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -78,7 +78,7 @@ public class ImmutableField extends BaseFieldReference implements Field {
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = initialValue;
this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.annotations = ImmutableUtils.nullToEmptyList(annotations);
}
public static ImmutableField of(Field field) {

View File

@ -38,7 +38,7 @@ import org.jf.dexlib2.iface.Method;
import org.jf.dexlib2.iface.MethodImplementation;
import org.jf.dexlib2.iface.MethodParameter;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -78,10 +78,10 @@ public class ImmutableMethod extends BaseMethodReference implements Method {
@Nullable ImmutableMethodImplementation methodImplementation) {
this.containingClass = containingClass;
this.name = name;
this.parameters = ImmutableListUtils.nullToEmptyList(parameters);
this.parameters = ImmutableUtils.nullToEmptyList(parameters);
this.returnType = returnType;
this.accessFlags = accessFlags;
this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.annotations = ImmutableUtils.nullToEmptyList(annotations);
this.methodImplementation = methodImplementation;
}

View File

@ -38,7 +38,7 @@ import org.jf.dexlib2.iface.debug.DebugItem;
import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.immutable.debug.ImmutableDebugItem;
import org.jf.dexlib2.immutable.instruction.ImmutableInstruction;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -65,9 +65,9 @@ public class ImmutableMethodImplementation implements MethodImplementation {
@Nullable ImmutableList<? extends ImmutableTryBlock> tryBlocks,
@Nullable ImmutableList<? extends ImmutableDebugItem> debugItems) {
this.registerCount = registerCount;
this.instructions = ImmutableListUtils.nullToEmptyList(instructions);
this.tryBlocks = ImmutableListUtils.nullToEmptyList(tryBlocks);
this.debugItems = ImmutableListUtils.nullToEmptyList(debugItems);
this.instructions = ImmutableUtils.nullToEmptyList(instructions);
this.tryBlocks = ImmutableUtils.nullToEmptyList(tryBlocks);
this.debugItems = ImmutableUtils.nullToEmptyList(debugItems);
}
@Nullable

View File

@ -36,7 +36,7 @@ import org.jf.dexlib2.base.BaseMethodParameter;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.MethodParameter;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -60,7 +60,7 @@ public class ImmutableMethodParameter extends BaseMethodParameter {
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
@Nullable String name) {
this.type = type;
this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.annotations = ImmutableUtils.nullToEmptyList(annotations);
this.name = name;
}

View File

@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.ExceptionHandler;
import org.jf.dexlib2.iface.TryBlock;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -60,7 +60,7 @@ public class ImmutableTryBlock implements TryBlock {
@Nullable ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers) {
this.startCodeOffset = startCodeOffset;
this.codeUnitCount = codeUnitCount;
this.exceptionHandlers = ImmutableListUtils.nullToEmptyList(exceptionHandlers);
this.exceptionHandlers = ImmutableUtils.nullToEmptyList(exceptionHandlers);
}
public static ImmutableTryBlock of(TryBlock tryBlock) {

View File

@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -60,7 +60,7 @@ public class ImmutableArrayPayload extends ImmutableInstruction implements Array
//TODO: need to ensure this is a valid width (1, 2, 4, 8)
this.elementWidth = elementWidth;
//TODO: need to validate the elements fit within the width
this.arrayElements = ImmutableListUtils.nullToEmptyList(arrayElements);
this.arrayElements = ImmutableUtils.nullToEmptyList(arrayElements);
}
@Nonnull

View File

@ -36,7 +36,7 @@ import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -56,7 +56,7 @@ public class ImmutablePackedSwitchPayload extends ImmutableInstruction implement
public ImmutablePackedSwitchPayload(
@Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) {
super(OPCODE);
this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements);
this.switchElements = ImmutableUtils.nullToEmptyList(switchElements);
}
@Nonnull

View File

@ -36,7 +36,7 @@ import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -55,7 +55,7 @@ public class ImmutableSparseSwitchPayload extends ImmutableInstruction implement
public ImmutableSparseSwitchPayload(
@Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) {
super(OPCODE);
this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements);
this.switchElements = ImmutableUtils.nullToEmptyList(switchElements);
}
@Nonnull

View File

@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.base.reference.BaseMethodReference;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.reference.TypeReference;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -63,7 +63,7 @@ public class ImmutableMethodReference extends BaseMethodReference implements Imm
@Nonnull String returnType) {
this.containingClass = containingClass;
this.name = name;
this.parameters = ImmutableListUtils.nullToEmptyList(parameters);
this.parameters = ImmutableUtils.nullToEmptyList(parameters);
this.returnType = returnType;
}

View File

@ -0,0 +1,124 @@
/*
* 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.sorted;
import com.google.common.collect.ImmutableSortedMultiset;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multiset;
import org.jf.dexlib2.base.BaseAnnotation;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.sorted.SortedAnnotation;
import org.jf.util.ImmutableSortedSetConverter;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Comparator;
public class SortedImmutableAnnotation extends BaseAnnotation implements SortedAnnotation {
public final int visibility;
@Nonnull public final String type;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotationElement> elements;
public SortedImmutableAnnotation(int visibility,
@Nonnull String type,
@Nullable Collection<? extends AnnotationElement> elements) {
this.visibility = visibility;
this.type = type;
this.elements = SortedImmutableAnnotationElement.immutableSortedSetOf(elements);
}
public SortedImmutableAnnotation(
int visibility,
@Nonnull String type,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotationElement> elements) {
this.visibility = visibility;
this.type = type;
this.elements = ImmutableUtils.nullToEmptySortedSet(elements);
}
public static SortedImmutableAnnotation of(Annotation annotation) {
if (annotation instanceof SortedImmutableAnnotation) {
return (SortedImmutableAnnotation)annotation;
}
return new SortedImmutableAnnotation(
annotation.getVisibility(),
annotation.getType(),
annotation.getElements());
}
@Override public int getVisibility() { return visibility; }
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableAnnotationElement> getElements() {
return elements;
}
public static final Comparator<Annotation> COMPARE_BY_TYPE = new Comparator<Annotation>() {
@Override
public int compare(Annotation annotation1, Annotation annotation2) {
return annotation1.getType().compareTo(annotation2.getType());
}
};
@Nonnull
public static ImmutableSortedSet<SortedImmutableAnnotation> immutableSortedSetOf(
@Nullable Collection<? extends Annotation> list) {
ImmutableSortedSet<SortedImmutableAnnotation> set = CONVERTER.convert(COMPARE_BY_TYPE, list);
if (list != null && set.size() < list.size()) {
// There were duplicate annotations. Let's find them and print a warning.
ImmutableSortedMultiset<Annotation> multiset = ImmutableSortedMultiset.copyOf(COMPARE_BY_TYPE, list);
for (Multiset.Entry<Annotation> entry: multiset.entrySet()) {
Annotation annotation = entry.getElement();
// TODO: need to provide better context
System.err.println(String.format("Ignoring duplicate annotation definition for annotation type: %s",
annotation.getType()));
}
}
return set;
}
private static final ImmutableSortedSetConverter<SortedImmutableAnnotation, Annotation> CONVERTER =
new ImmutableSortedSetConverter<SortedImmutableAnnotation, Annotation>() {
@Override
protected boolean isImmutable(@Nonnull Annotation item) {
return item instanceof SortedImmutableAnnotation;
}
@Nonnull
@Override
protected SortedImmutableAnnotation makeImmutable(@Nonnull Annotation item) {
return SortedImmutableAnnotation.of(item);
}
};
}

View File

@ -0,0 +1,116 @@
/*
* 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.sorted;
import com.google.common.collect.ImmutableSortedMultiset;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multiset;
import org.jf.dexlib2.base.BaseAnnotationElement;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.sorted.SortedAnnotationElement;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValueFactory;
import org.jf.util.ImmutableSortedSetConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Comparator;
public class SortedImmutableAnnotationElement extends BaseAnnotationElement implements SortedAnnotationElement {
@Nonnull public final String name;
@Nonnull public final SortedImmutableEncodedValue value;
public SortedImmutableAnnotationElement(@Nonnull String name,
@Nonnull EncodedValue value) {
this.name = name;
this.value = SortedImmutableEncodedValueFactory.of(value);
}
public SortedImmutableAnnotationElement(@Nonnull String name,
@Nonnull SortedImmutableEncodedValue value) {
this.name = name;
this.value = value;
}
public static SortedImmutableAnnotationElement of(AnnotationElement annotationElement) {
if (annotationElement instanceof SortedImmutableAnnotationElement) {
return (SortedImmutableAnnotationElement)annotationElement;
}
return new SortedImmutableAnnotationElement(
annotationElement.getName(),
annotationElement.getValue());
}
@Nonnull @Override public String getName() { return name; }
@Nonnull @Override public SortedEncodedValue getValue() { return value; }
public static final Comparator<AnnotationElement> COMPARE_BY_NAME = new Comparator<AnnotationElement>() {
@Override
public int compare(@Nonnull AnnotationElement element1, @Nonnull AnnotationElement element2) {
return element1.getName().compareTo(element2.getName());
}
};
@Nonnull
public static ImmutableSortedSet<SortedImmutableAnnotationElement> immutableSortedSetOf(
@Nullable Collection<? extends AnnotationElement> list) {
ImmutableSortedSet<SortedImmutableAnnotationElement> set = CONVERTER.convert(COMPARE_BY_NAME, list);
if (list != null && set.size() < list.size()) {
// There were duplicate annotations. Let's find them and print a warning.
ImmutableSortedMultiset<AnnotationElement> multiset = ImmutableSortedMultiset.copyOf(COMPARE_BY_NAME, list);
for (Multiset.Entry<AnnotationElement> entry: multiset.entrySet()) {
AnnotationElement annotationElement = entry.getElement();
// TODO: need to provide better context
System.err.println(String.format("Ignoring duplicate annotation value for name: %s",
annotationElement.getName()));
}
}
return set;
}
private static final ImmutableSortedSetConverter<SortedImmutableAnnotationElement, AnnotationElement> CONVERTER =
new ImmutableSortedSetConverter<SortedImmutableAnnotationElement, AnnotationElement>() {
@Override
protected boolean isImmutable(@Nonnull AnnotationElement item) {
return item instanceof SortedImmutableAnnotationElement;
}
@Nonnull
@Override
protected SortedImmutableAnnotationElement makeImmutable(@Nonnull AnnotationElement item) {
return SortedImmutableAnnotationElement.of(item);
}
};
}

View File

@ -0,0 +1,140 @@
/*
* 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.sorted;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import org.jf.dexlib2.base.reference.BaseTypeReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.Method;
import org.jf.dexlib2.iface.sorted.SortedClassDef;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
public class SortedImmutableClassDef extends BaseTypeReference implements SortedClassDef {
@Nonnull public final String type;
public final int accessFlags;
@Nullable public final String superclass;
@Nonnull public final ImmutableList<String> interfaces;
@Nullable public final String sourceFile;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableField> fields;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableMethod> methods;
public SortedImmutableClassDef(@Nonnull String type,
int accessFlags,
@Nullable String superclass,
@Nullable List<String> interfaces,
@Nullable String sourceFile,
@Nullable Collection<? extends Annotation> annotations,
@Nullable Collection<? extends Field> fields,
@Nullable Collection<? extends Method> methods) {
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = interfaces==null ? ImmutableList.<String>of() : ImmutableList.copyOf(interfaces);
this.sourceFile = sourceFile;
this.annotations = SortedImmutableAnnotation.immutableSortedSetOf(annotations);
this.fields = SortedImmutableField.immutableSortedSetOf(fields);
this.methods = SortedImmutableMethod.immutableSortedSetOf(methods);
}
public SortedImmutableClassDef(@Nonnull String type,
int accessFlags,
@Nullable String superclass,
@Nullable ImmutableList<String> interfaces,
@Nullable String sourceFile,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations,
@Nullable ImmutableSortedSet<? extends SortedImmutableField> fields,
@Nullable ImmutableSortedSet<? extends SortedImmutableMethod> methods) {
this.type = type;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = ImmutableUtils.nullToEmptyList(interfaces);
this.sourceFile = sourceFile;
this.annotations = ImmutableUtils.nullToEmptySortedSet(annotations);
this.fields = ImmutableUtils.nullToEmptySortedSet(fields);
this.methods = ImmutableUtils.nullToEmptySortedSet(methods);
}
public static SortedImmutableClassDef of(ClassDef classDef) {
if (classDef instanceof SortedImmutableClassDef) {
return (SortedImmutableClassDef)classDef;
}
return new SortedImmutableClassDef(
classDef.getType(),
classDef.getAccessFlags(),
classDef.getSuperclass(),
classDef.getInterfaces(),
classDef.getSourceFile(),
classDef.getAnnotations(),
classDef.getFields(),
classDef.getMethods());
}
@Nonnull @Override public String getType() { return type; }
@Override public int getAccessFlags() { return accessFlags; }
@Nullable @Override public String getSuperclass() { return superclass; }
@Nonnull @Override public ImmutableList<String> getInterfaces() { return interfaces; }
@Nullable @Override public String getSourceFile() { return sourceFile; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableField> getFields() { return fields; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableMethod> getMethods() { return methods; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableAnnotation> getAnnotations() {
return annotations;
}
@Nonnull
public static ImmutableList<SortedImmutableClassDef> immutableListOf(@Nullable List<? extends ClassDef> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<SortedImmutableClassDef, ClassDef> CONVERTER =
new ImmutableListConverter<SortedImmutableClassDef, ClassDef>() {
@Override
protected boolean isImmutable(@Nonnull ClassDef item) {
return item instanceof SortedImmutableClassDef;
}
@Nonnull
@Override
protected SortedImmutableClassDef makeImmutable(@Nonnull ClassDef item) {
return SortedImmutableClassDef.of(item);
}
};
}

View File

@ -0,0 +1,158 @@
/*
* 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.sorted;
import com.google.common.collect.ImmutableSortedMultiset;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multiset;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.base.reference.BaseFieldReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.sorted.SortedField;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValueFactory;
import org.jf.util.ImmutableSortedSetConverter;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Comparator;
public class SortedImmutableField extends BaseFieldReference implements SortedField {
@Nonnull public final String containingClass;
@Nonnull public final String name;
@Nonnull public final String type;
public final int accessFlags;
@Nullable public final SortedImmutableEncodedValue initialValue;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations;
public SortedImmutableField(@Nonnull String containingClass,
@Nonnull String name,
@Nonnull String type,
int accessFlags,
@Nullable EncodedValue initialValue,
@Nullable Collection<? extends Annotation> annotations) {
this.containingClass = containingClass;
this.name = name;
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = SortedImmutableEncodedValueFactory.ofNullable(initialValue);
this.annotations = SortedImmutableAnnotation.immutableSortedSetOf(annotations);
}
public SortedImmutableField(@Nonnull String containingClass,
@Nonnull String name,
@Nonnull String type,
int accessFlags,
@Nullable SortedImmutableEncodedValue initialValue,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations) {
this.containingClass = containingClass;
this.name = name;
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = initialValue;
this.annotations = ImmutableUtils.nullToEmptySortedSet(annotations);
}
public static SortedImmutableField of(Field field) {
if (field instanceof SortedImmutableField) {
return (SortedImmutableField)field;
}
return new SortedImmutableField(
field.getContainingClass(),
field.getName(),
field.getType(),
field.getAccessFlags(),
field.getInitialValue(),
field.getAnnotations());
}
@Nonnull @Override public String getContainingClass() { return containingClass; }
@Nonnull @Override public String getName() { return name; }
@Nonnull @Override public String getType() { return type; }
@Override public int getAccessFlags() { return accessFlags; }
@Nullable @Override public SortedImmutableEncodedValue getInitialValue() { return initialValue;}
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableAnnotation> getAnnotations() {
return annotations;
}
public static final Comparator<FieldReference> COMPARE_BY_SIGNATURE = new Comparator<FieldReference>() {
@Override
public int compare(FieldReference field1, FieldReference field2) {
int res = field1.getContainingClass().compareTo(field2.getContainingClass());
if (res != 0) {
return res;
}
res = field1.getName().compareTo(field2.getName());
if (res != 0) {
return res;
}
return field1.getType().compareTo(field2.getType());
}
};
@Nonnull
public static ImmutableSortedSet<SortedImmutableField> immutableSortedSetOf(
@Nullable Collection<? extends Field> list) {
ImmutableSortedSet<SortedImmutableField> set = CONVERTER.convert(COMPARE_BY_SIGNATURE, list);
if (list != null && set.size() < list.size()) {
// There were duplicate fields. Let's find them and print a warning.
ImmutableSortedMultiset<Field> multiset = ImmutableSortedMultiset.copyOf(COMPARE_BY_SIGNATURE, list);
for (Multiset.Entry<Field> entry: multiset.entrySet()) {
Field field = entry.getElement();
String fieldType = AccessFlags.STATIC.isSet(field.getAccessFlags())?"static":"instance";
// TODO: need to provide better context
System.err.println(String.format("Ignoring duplicate %s field definition for field: %s:%s", fieldType,
field.getName(), field.getType()));
}
}
return set;
}
private static final ImmutableSortedSetConverter<SortedImmutableField, Field> CONVERTER =
new ImmutableSortedSetConverter<SortedImmutableField, Field>() {
@Override
protected boolean isImmutable(@Nonnull Field item) {
return item instanceof SortedImmutableField;
}
@Nonnull
@Override
protected SortedImmutableField makeImmutable(@Nonnull Field item) {
return SortedImmutableField.of(item);
}
};
}

View File

@ -0,0 +1,195 @@
/*
* 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.sorted;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMultiset;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multiset;
import org.jf.dexlib2.base.reference.BaseMethodReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Method;
import org.jf.dexlib2.iface.MethodImplementation;
import org.jf.dexlib2.iface.MethodParameter;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.reference.TypeReference;
import org.jf.dexlib2.iface.sorted.SortedMethod;
import org.jf.dexlib2.iface.sorted.SortedMethodParameter;
import org.jf.dexlib2.immutable.ImmutableMethodImplementation;
import org.jf.dexlib2.util.MethodUtil;
import org.jf.dexlib2.util.ReferenceUtil;
import org.jf.util.ImmutableSortedSetConverter;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
public class SortedImmutableMethod extends BaseMethodReference implements SortedMethod {
@Nonnull public final String containingClass;
@Nonnull public final String name;
@Nonnull public final ImmutableList<? extends SortedImmutableMethodParameter> parameters;
@Nonnull public final String returnType;
public final int accessFlags;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations;
@Nullable public final ImmutableMethodImplementation methodImplementation;
public SortedImmutableMethod(@Nonnull String containingClass,
@Nonnull String name,
@Nullable Collection<? extends MethodParameter> parameters,
@Nonnull String returnType,
int accessFlags,
@Nullable Collection<? extends Annotation> annotations,
@Nullable MethodImplementation methodImplementation) {
this.containingClass = containingClass;
this.name = name;
this.parameters = SortedImmutableMethodParameter.immutableListOf(parameters);
this.returnType = returnType;
this.accessFlags = accessFlags;
this.annotations = SortedImmutableAnnotation.immutableSortedSetOf(annotations);
this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
}
public SortedImmutableMethod(@Nonnull String containingClass,
@Nonnull String name,
@Nullable ImmutableList<? extends SortedImmutableMethodParameter> parameters,
@Nonnull String returnType,
int accessFlags,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations,
@Nullable ImmutableMethodImplementation methodImplementation) {
this.containingClass = containingClass;
this.name = name;
this.parameters = ImmutableUtils.nullToEmptyList(parameters);
this.returnType = returnType;
this.accessFlags = accessFlags;
this.annotations = ImmutableUtils.nullToEmptySortedSet(annotations);
this.methodImplementation = methodImplementation;
}
public static SortedImmutableMethod of(Method method) {
if (method instanceof SortedImmutableMethod) {
return (SortedImmutableMethod)method;
}
return new SortedImmutableMethod(
method.getContainingClass(),
method.getName(),
method.getParameters(),
method.getReturnType(),
method.getAccessFlags(),
method.getAnnotations(),
method.getImplementation());
}
@Nonnull public String getContainingClass() { return containingClass; }
@Nonnull public String getName() { return name; }
@Nonnull public ImmutableList<? extends SortedMethodParameter> getParameters() { return parameters; }
@Nonnull public String getReturnType() { return returnType; }
public int getAccessFlags() { return accessFlags; }
@Nonnull public ImmutableSortedSet<? extends SortedImmutableAnnotation> getAnnotations() { return annotations; }
@Nullable public ImmutableMethodImplementation getImplementation() { return methodImplementation; }
public static final Comparator<MethodReference> COMPARE_BY_SIGNATURE = new Comparator<MethodReference>() {
@Override
public int compare(MethodReference method1, MethodReference method2) {
int res = method1.getContainingClass().compareTo(method2.getContainingClass());
if (res != 0) {
return res;
}
res = method1.getName().compareTo(method2.getName());
if (res != 0) {
return res;
}
res = method1.getReturnType().compareTo(method2.getReturnType());
if (res != 0) {
return res;
}
Collection<? extends TypeReference> params1 = method1.getParameters();
Collection<? extends TypeReference> params2 = method2.getParameters();
int params1Size = params1.size();
int params2Size = params2.size();
int minSize = Math.min(params1Size, params2Size);
Iterator<? extends TypeReference> paramIter1 = params1.iterator();
Iterator<? extends TypeReference> paramIter2 = params2.iterator();
for (int i=0; i<minSize; i++) {
res = paramIter1.next().getType().compareTo(paramIter2.next().getType());
if (res != 0) {
return res;
}
}
if (params1Size < params2Size) {
return -1;
} else if (params1Size > params2Size) {
return 1;
} else {
return 0;
}
}
};
@Nonnull
public static ImmutableSortedSet<SortedImmutableMethod> immutableSortedSetOf(
@Nullable Collection<? extends Method> list) {
ImmutableSortedSet<SortedImmutableMethod> set = CONVERTER.convert(COMPARE_BY_SIGNATURE, list);
if (list != null && set.size() < list.size()) {
// There were duplicate methods. Let's find them and print a warning.
ImmutableSortedMultiset<Method> multiset = ImmutableSortedMultiset.copyOf(COMPARE_BY_SIGNATURE, list);
for (Multiset.Entry<Method> entry: multiset.entrySet()) {
Method method = entry.getElement();
String methodType = MethodUtil.isDirect(method)?"direct":"virtual";
// TODO: need to provide better context
System.err.println(String.format("Ignoring duplicate %s method definition for method: %s", methodType,
ReferenceUtil.getMethodDescriptor(method)));
}
}
return set;
}
private static final ImmutableSortedSetConverter<SortedImmutableMethod, Method> CONVERTER =
new ImmutableSortedSetConverter<SortedImmutableMethod, Method>() {
@Override
protected boolean isImmutable(@Nonnull Method item) {
return item instanceof SortedImmutableMethod;
}
@Nonnull
@Override
protected SortedImmutableMethod makeImmutable(@Nonnull Method item) {
return SortedImmutableMethod.of(item);
}
};
}

View File

@ -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.sorted;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import org.jf.dexlib2.base.reference.BaseTypeReference;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.MethodParameter;
import org.jf.dexlib2.iface.sorted.SortedMethodParameter;
import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
public class SortedImmutableMethodParameter extends BaseTypeReference implements SortedMethodParameter {
@Nonnull public final String type;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations;
@Nullable public final String name;
public SortedImmutableMethodParameter(@Nonnull String type,
@Nullable Collection<? extends Annotation> annotations,
@Nullable String name) {
this.type = type;
this.annotations = SortedImmutableAnnotation.immutableSortedSetOf(annotations);
this.name = name;
}
public SortedImmutableMethodParameter(@Nonnull String type,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotation> annotations,
@Nullable String name) {
this.type = type;
this.annotations = ImmutableUtils.nullToEmptySortedSet(annotations);
this.name = name;
}
public static SortedImmutableMethodParameter of(MethodParameter methodParameter) {
if (methodParameter instanceof SortedImmutableMethodParameter) {
return (SortedImmutableMethodParameter)methodParameter;
}
return new SortedImmutableMethodParameter(
methodParameter.getType(),
methodParameter.getAnnotations(),
methodParameter.getName());
}
@Nonnull @Override public String getType() { return type; }
@Nullable @Override public String getName() { return name; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedImmutableAnnotation> getAnnotations() {
return annotations;
}
//TODO: iterate over the annotations to get the signature
@Nullable @Override public String getSignature() { return null; }
@Nonnull
public static ImmutableList<SortedImmutableMethodParameter> immutableListOf(
@Nullable Iterable<? extends MethodParameter> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<SortedImmutableMethodParameter, MethodParameter> CONVERTER =
new ImmutableListConverter<SortedImmutableMethodParameter, MethodParameter>() {
@Override
protected boolean isImmutable(@Nonnull MethodParameter item) {
return item instanceof SortedImmutableMethodParameter;
}
@Nonnull
@Override
protected SortedImmutableMethodParameter makeImmutable(@Nonnull MethodParameter item) {
return SortedImmutableMethodParameter.of(item);
}
};
}

View File

@ -0,0 +1,78 @@
/*
* 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.sorted.value;
import com.google.common.collect.ImmutableSortedSet;
import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.sorted.SortedAnnotationElement;
import org.jf.dexlib2.iface.sorted.value.SortedAnnotationEncodedValue;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import org.jf.dexlib2.immutable.sorted.SortedImmutableAnnotationElement;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
public class SortedImmutableAnnotationEncodedValue extends BaseAnnotationEncodedValue
implements SortedImmutableEncodedValue, SortedAnnotationEncodedValue {
@Nonnull public final String type;
@Nonnull public final ImmutableSortedSet<? extends SortedImmutableAnnotationElement> elements;
public SortedImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable Collection<? extends AnnotationElement> elements) {
this.type = type;
this.elements = SortedImmutableAnnotationElement.immutableSortedSetOf(elements);
}
public SortedImmutableAnnotationEncodedValue(
@Nonnull String type,
@Nullable ImmutableSortedSet<? extends SortedImmutableAnnotationElement> elements) {
this.type = type;
this.elements = ImmutableUtils.nullToEmptySortedSet(elements);
}
public static SortedImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) {
if (annotationEncodedValue instanceof SortedImmutableAnnotationEncodedValue) {
return (SortedImmutableAnnotationEncodedValue)annotationEncodedValue;
}
return new SortedImmutableAnnotationEncodedValue(
annotationEncodedValue.getType(),
annotationEncodedValue.getElements());
}
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public ImmutableSortedSet<? extends SortedAnnotationElement> getElements() {
return elements;
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.sorted.value;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.base.value.BaseArrayEncodedValue;
import org.jf.dexlib2.iface.sorted.value.SortedArrayEncodedValue;
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
import javax.annotation.Nonnull;
import java.util.Collection;
public class SortedImmutableArrayEncodedValue extends BaseArrayEncodedValue
implements SortedImmutableEncodedValue, SortedArrayEncodedValue {
@Nonnull public final ImmutableList<? extends SortedImmutableEncodedValue> value;
public SortedImmutableArrayEncodedValue(@Nonnull Collection<? extends EncodedValue> value) {
this.value = SortedImmutableEncodedValueFactory.immutableListOf(value);
}
public SortedImmutableArrayEncodedValue(@Nonnull ImmutableList<SortedImmutableEncodedValue> value) {
this.value = value;
}
public static SortedImmutableArrayEncodedValue of(@Nonnull ArrayEncodedValue arrayEncodedValue) {
if (arrayEncodedValue instanceof SortedImmutableArrayEncodedValue) {
return (SortedImmutableArrayEncodedValue)arrayEncodedValue;
}
return new SortedImmutableArrayEncodedValue(arrayEncodedValue.getValue());
}
@Nonnull public ImmutableList<? extends SortedImmutableEncodedValue> getValue() { return value; }
}

View File

@ -0,0 +1,38 @@
/*
* 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.sorted.value;
import org.jf.dexlib2.iface.sorted.value.SortedEncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
public interface SortedImmutableEncodedValue extends SortedEncodedValue, ImmutableEncodedValue {
}

View File

@ -0,0 +1,85 @@
/*
* 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.sorted.value;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import org.jf.dexlib2.iface.value.ArrayEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValueFactory;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class SortedImmutableEncodedValueFactory {
@Nonnull
public static SortedImmutableEncodedValue of(@Nonnull EncodedValue encodedValue) {
switch (encodedValue.getValueType()) {
case ValueType.ARRAY:
return SortedImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue);
case ValueType.ANNOTATION:
return SortedImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue);
default:
return (SortedImmutableEncodedValue)ImmutableEncodedValueFactory.of(encodedValue);
}
}
@Nullable
public static SortedImmutableEncodedValue ofNullable(@Nullable EncodedValue encodedValue) {
if (encodedValue == null) {
return null;
}
return of(encodedValue);
}
@Nonnull
public static ImmutableList<SortedImmutableEncodedValue> immutableListOf(
@Nullable Iterable<? extends EncodedValue> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<SortedImmutableEncodedValue, EncodedValue> CONVERTER =
new ImmutableListConverter<SortedImmutableEncodedValue, EncodedValue>() {
@Override
protected boolean isImmutable(@Nonnull EncodedValue item) {
return item instanceof SortedImmutableEncodedValue;
}
@Nonnull
@Override
protected SortedImmutableEncodedValue makeImmutable(@Nonnull EncodedValue item) {
return of(item);
}
};
}

View File

@ -36,7 +36,7 @@ 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;
import org.jf.util.ImmutableListUtils;
import org.jf.util.ImmutableUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -56,7 +56,7 @@ public class ImmutableAnnotationEncodedValue extends BaseAnnotationEncodedValue
public ImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
this.type = type;
this.elements = ImmutableListUtils.nullToEmptyList(elements);
this.elements = ImmutableUtils.nullToEmptyList(elements);
}
public static ImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseBooleanEncodedValue;
import org.jf.dexlib2.iface.value.BooleanEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableBooleanEncodedValue extends BaseBooleanEncodedValue
implements ImmutableEncodedValue, BooleanEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, BooleanEncodedValue {
public final boolean value;
public ImmutableBooleanEncodedValue(boolean value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseByteEncodedValue;
import org.jf.dexlib2.iface.value.ByteEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableByteEncodedValue extends BaseByteEncodedValue
implements ImmutableEncodedValue, ByteEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, ByteEncodedValue {
public final byte value;
public ImmutableByteEncodedValue(byte value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseCharEncodedValue;
import org.jf.dexlib2.iface.value.CharEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableCharEncodedValue extends BaseCharEncodedValue
implements ImmutableEncodedValue, CharEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, CharEncodedValue {
public final char value;
public ImmutableCharEncodedValue(char value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseDoubleEncodedValue;
import org.jf.dexlib2.iface.value.DoubleEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableDoubleEncodedValue extends BaseDoubleEncodedValue
implements ImmutableEncodedValue, DoubleEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, DoubleEncodedValue {
public final double value;
public ImmutableDoubleEncodedValue(double value) {

View File

@ -34,11 +34,12 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseEnumEncodedValue;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.value.EnumEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableEnumEncodedValue extends BaseEnumEncodedValue
implements ImmutableEncodedValue, EnumEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, EnumEncodedValue {
@Nonnull public final FieldReference value;
public ImmutableEnumEncodedValue(@Nonnull FieldReference value) {

View File

@ -34,11 +34,12 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseFieldEncodedValue;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.value.FieldEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableFieldEncodedValue extends BaseFieldEncodedValue
implements ImmutableEncodedValue, FieldEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, FieldEncodedValue {
@Nonnull public final FieldReference value;
public ImmutableFieldEncodedValue(@Nonnull FieldReference value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseFloatEncodedValue;
import org.jf.dexlib2.iface.value.FloatEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableFloatEncodedValue extends BaseFloatEncodedValue
implements ImmutableEncodedValue, FloatEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, FloatEncodedValue {
public final float value;
public ImmutableFloatEncodedValue(float value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseIntEncodedValue;
import org.jf.dexlib2.iface.value.IntEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableIntEncodedValue extends BaseIntEncodedValue
implements ImmutableEncodedValue, IntEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, IntEncodedValue {
public final int value;
public ImmutableIntEncodedValue(int value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseLongEncodedValue;
import org.jf.dexlib2.iface.value.LongEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableLongEncodedValue extends BaseLongEncodedValue
implements ImmutableEncodedValue, LongEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, LongEncodedValue {
public final long value;
public ImmutableLongEncodedValue(long value) {

View File

@ -34,11 +34,12 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseMethodEncodedValue;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.value.MethodEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableMethodEncodedValue extends BaseMethodEncodedValue
implements ImmutableEncodedValue, MethodEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, MethodEncodedValue {
@Nonnull public final MethodReference value;
public ImmutableMethodEncodedValue(@Nonnull MethodReference value) {

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseNullEncodedValue;
import org.jf.dexlib2.iface.value.NullEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableNullEncodedValue extends BaseNullEncodedValue
implements ImmutableEncodedValue, NullEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, NullEncodedValue {
public static final ImmutableNullEncodedValue INSTANCE = new ImmutableNullEncodedValue();
private ImmutableNullEncodedValue() {}

View File

@ -33,9 +33,10 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseShortEncodedValue;
import org.jf.dexlib2.iface.value.ShortEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
public class ImmutableShortEncodedValue extends BaseShortEncodedValue
implements ImmutableEncodedValue, ShortEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, ShortEncodedValue {
public final short value;
public ImmutableShortEncodedValue(short value) {

View File

@ -33,11 +33,12 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseStringEncodedValue;
import org.jf.dexlib2.iface.value.StringEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableStringEncodedValue extends BaseStringEncodedValue
implements ImmutableEncodedValue, StringEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, StringEncodedValue {
@Nonnull public final String value;
public ImmutableStringEncodedValue(@Nonnull String value) {

View File

@ -33,11 +33,12 @@ package org.jf.dexlib2.immutable.value;
import org.jf.dexlib2.base.value.BaseTypeEncodedValue;
import org.jf.dexlib2.iface.value.TypeEncodedValue;
import org.jf.dexlib2.immutable.sorted.value.SortedImmutableEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableTypeEncodedValue extends BaseTypeEncodedValue
implements ImmutableEncodedValue, TypeEncodedValue {
implements ImmutableEncodedValue, SortedImmutableEncodedValue, TypeEncodedValue {
@Nonnull public final String value;
public ImmutableTypeEncodedValue(@Nonnull String value) {

View File

@ -31,6 +31,7 @@
package org.jf.dexlib2.util;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.Method;
import org.jf.dexlib2.iface.MethodParameter;
@ -50,4 +51,11 @@ public class MethodUtil {
sb.append(method.getReturnType());
return sb.toString();
}
private static int directMask = AccessFlags.STATIC.getValue() | AccessFlags.PRIVATE.getValue() |
AccessFlags.CONSTRUCTOR.getValue();
public static boolean isDirect(Method method) {
return (method.getAccessFlags() | directMask) != 0;
}
}