Add immutable implementations

Immutable implementations for all interfaces defined so far
This commit is contained in:
Ben Gruver 2012-10-14 22:51:33 -07:00
parent c05d8d40e0
commit e2f00f0eba
54 changed files with 4023 additions and 0 deletions

View File

@ -0,0 +1,92 @@
/*
* 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;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableAnnotation extends ImmutableBaseAnnotation implements Annotation {
public final int visibility;
public ImmutableAnnotation(int visibility,
@Nonnull String type,
@Nullable List<? extends AnnotationElement> elements) {
super(type, elements);
this.visibility = visibility;
}
public ImmutableAnnotation(int visibility,
@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
super(type, elements);
this.visibility = visibility;
}
public static ImmutableAnnotation of(Annotation annotation) {
if (annotation instanceof ImmutableAnnotation) {
return (ImmutableAnnotation)annotation;
}
return new ImmutableAnnotation(
annotation.getVisibility(),
annotation.getType(),
annotation.getElements());
}
@Override
public int getVisibility() {
return visibility;
}
@Nonnull
public static ImmutableList<ImmutableAnnotation> immutableListOf(List<? extends Annotation> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableAnnotation, Annotation> CONVERTER =
new ImmutableListConverter<ImmutableAnnotation, Annotation>() {
@Override
protected boolean isImmutable(Annotation item) {
return item instanceof ImmutableAnnotation;
}
@Override
protected ImmutableAnnotation makeImmutable(Annotation item) {
return ImmutableAnnotation.of(item);
}
};
}

View File

@ -0,0 +1,88 @@
/*
* 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;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import java.util.List;
public class ImmutableAnnotationElement implements AnnotationElement {
@Nonnull public final String name;
@Nonnull public final ImmutableEncodedValue value;
public ImmutableAnnotationElement(@Nonnull String name,
@Nonnull EncodedValue value) {
this.name = name;
this.value = ImmutableEncodedValue.of(value);
}
public ImmutableAnnotationElement(@Nonnull String name,
@Nonnull ImmutableEncodedValue value) {
this.name = name;
this.value = value;
}
public static ImmutableAnnotationElement of(AnnotationElement annotationElement) {
if (annotationElement instanceof ImmutableAnnotationElement) {
return (ImmutableAnnotationElement)annotationElement;
}
return new ImmutableAnnotationElement(
annotationElement.getName(),
annotationElement.getValue());
}
@Nonnull @Override public String getName() { return name; }
@Nonnull @Override public EncodedValue getValue() { return value; }
@Nonnull
public static ImmutableList<ImmutableAnnotationElement> immutableListOf(List<? extends AnnotationElement> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableAnnotationElement, AnnotationElement> CONVERTER =
new ImmutableListConverter<ImmutableAnnotationElement, AnnotationElement>() {
@Override
protected boolean isImmutable(AnnotationElement item) {
return item instanceof ImmutableAnnotationElement;
}
@Override
protected ImmutableAnnotationElement makeImmutable(AnnotationElement item) {
return ImmutableAnnotationElement.of(item);
}
};
}

View File

@ -0,0 +1,70 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.BaseAnnotation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableBaseAnnotation implements BaseAnnotation {
@Nonnull public final String type;
@Nonnull public final ImmutableList<? extends ImmutableAnnotationElement> elements;
public ImmutableBaseAnnotation(@Nonnull String type,
@Nullable List<? extends AnnotationElement> elements) {
this.type = type;
this.elements = ImmutableAnnotationElement.immutableListOf(elements);
}
public ImmutableBaseAnnotation(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of());
}
public static ImmutableBaseAnnotation of(BaseAnnotation baseAnnotation) {
if (baseAnnotation instanceof ImmutableBaseAnnotation) {
return (ImmutableBaseAnnotation)baseAnnotation;
}
return new ImmutableBaseAnnotation(
baseAnnotation.getType(),
baseAnnotation.getElements());
}
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotationElement> getElements() { return elements; }
}

View File

@ -0,0 +1,114 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
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 javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableClassDef implements ClassDef {
@Nonnull public final String name;
public final int accessFlags;
@Nullable public final String superclass;
@Nonnull public final ImmutableList<String> interfaces;
@Nullable public final String sourceFile;
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
@Nonnull public final ImmutableList<? extends ImmutableField> fields;
@Nonnull public final ImmutableList<? extends ImmutableMethod> methods;
public ImmutableClassDef(@Nonnull String name,
int accessFlags,
@Nullable String superclass,
@Nullable List<String> interfaces,
@Nullable String sourceFile,
@Nullable List<? extends Annotation> annotations,
@Nullable List<? extends Field> fields,
@Nullable List<? extends Method> methods) {
this.name = name;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = interfaces==null ? ImmutableList.<String>of() : ImmutableList.copyOf(interfaces);
this.sourceFile = sourceFile;
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
this.fields = ImmutableField.immutableListOf(fields);
this.methods = ImmutableMethod.immutableListOf(methods);
}
public ImmutableClassDef(@Nonnull String name,
int accessFlags,
@Nullable String superclass,
@Nullable ImmutableList<String> interfaces,
@Nullable String sourceFile,
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
@Nullable ImmutableList<? extends ImmutableField> fields,
@Nullable ImmutableList<? extends ImmutableMethod> methods) {
this.name = name;
this.accessFlags = accessFlags;
this.superclass = superclass;
this.interfaces = Objects.firstNonNull(interfaces, ImmutableList.<String>of());
this.sourceFile = sourceFile;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of());
this.fields = Objects.firstNonNull(fields, ImmutableList.<ImmutableField>of());
this.methods = Objects.firstNonNull(methods, ImmutableList.<ImmutableMethod>of());
}
public static ImmutableClassDef of(ClassDef classDef) {
if (classDef instanceof ImmutableClassDef) {
return (ImmutableClassDef)classDef;
}
return new ImmutableClassDef(
classDef.getName(),
classDef.getAccessFlags(),
classDef.getSuperclass(),
classDef.getInterfaces(),
classDef.getSourceFile(),
classDef.getAnnotations(),
classDef.getFields(),
classDef.getMethods());
}
@Nonnull @Override public String getName() { return name; }
@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 ImmutableList<? extends ImmutableAnnotation> getAnnotations() { return annotations; }
@Nonnull @Override public ImmutableList<? extends ImmutableField> getFields() { return fields; }
@Nonnull @Override public ImmutableList<? extends ImmutableMethod> getMethods() { return methods; }
}

View File

@ -0,0 +1,81 @@
/*
* 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;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.ExceptionHandler;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableExceptionHandler implements ExceptionHandler {
@Nullable public final String exceptionType;
public final int handlerIndex;
public ImmutableExceptionHandler(@Nullable String exceptionType,
int handlerIndex) {
this.exceptionType = exceptionType;
this.handlerIndex = handlerIndex;
}
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
if (exceptionHandler instanceof ImmutableExceptionHandler) {
return (ImmutableExceptionHandler)exceptionHandler;
}
return new ImmutableExceptionHandler(
exceptionHandler.getExceptionType(),
exceptionHandler.getHandlerIndex());
}
@Nullable @Override public String getExceptionType() { return exceptionType; }
@Override public int getHandlerIndex() { return handlerIndex; }
@Nonnull
public static ImmutableList<ImmutableExceptionHandler> immutableListOf(List<? extends ExceptionHandler> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableExceptionHandler, ExceptionHandler> CONVERTER =
new ImmutableListConverter<ImmutableExceptionHandler, ExceptionHandler>() {
@Override
protected boolean isImmutable(ExceptionHandler item) {
return item instanceof ImmutableExceptionHandler;
}
@Override
protected ImmutableExceptionHandler makeImmutable(ExceptionHandler item) {
return ImmutableExceptionHandler.of(item);
}
};
}

View File

@ -0,0 +1,112 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableField implements Field {
@Nonnull public final String name;
@Nonnull public final String type;
public final int accessFlags;
@Nullable public final ImmutableEncodedValue initialValue;
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
public ImmutableField(@Nonnull String name,
@Nonnull String type,
int accessFlags,
@Nullable EncodedValue initialValue,
@Nullable List<? extends Annotation> annotations) {
this.name = name;
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = ImmutableEncodedValue.of(initialValue);
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
}
public ImmutableField(@Nonnull String name,
@Nonnull String type,
int accessFlags,
@Nullable ImmutableEncodedValue initialValue,
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations) {
this.name = name;
this.type = type;
this.accessFlags = accessFlags;
this.initialValue = initialValue;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of());
}
public static ImmutableField of(Field field) {
if (field instanceof ImmutableField) {
return (ImmutableField)field;
}
return new ImmutableField(
field.getName(),
field.getType(),
field.getAccessFlags(),
field.getInitialValue(),
field.getAnnotations());
}
@Nonnull @Override public String getName() { return name; }
@Nonnull @Override public String getType() { return type; }
@Override public int getAccessFlags() { return accessFlags; }
@Override public EncodedValue getInitialValue() { return initialValue;}
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotation> getAnnotations() { return annotations; }
@Nonnull
public static ImmutableList<ImmutableField> immutableListOf(List<? extends Field> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableField, Field> CONVERTER =
new ImmutableListConverter<ImmutableField, Field>() {
@Override
protected boolean isImmutable(Field item) {
return item instanceof ImmutableField;
}
@Override
protected ImmutableField makeImmutable(Field item) {
return ImmutableField.of(item);
}
};
}

View File

@ -0,0 +1,119 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
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.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableMethod implements Method {
@Nonnull public final String name;
@Nonnull public final ImmutableList<? extends ImmutableMethodParameter> parameters;
@Nonnull public final String returnType;
public final int accessFlags;
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
@Nullable public final ImmutableMethodImplementation methodImplementation;
public ImmutableMethod(@Nonnull String name,
@Nullable List<? extends MethodParameter> parameters,
@Nonnull String returnType,
int accessFlags,
@Nullable List<? extends Annotation> annotations,
@Nullable MethodImplementation methodImplementation) {
this.name = name;
this.parameters = ImmutableMethodParameter.immutableListOf(parameters);
this.returnType = returnType;
this.accessFlags = accessFlags;
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
}
public ImmutableMethod(@Nonnull String name,
@Nullable ImmutableList<? extends ImmutableMethodParameter> parameters,
@Nonnull String returnType,
int accessFlags,
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
@Nullable ImmutableMethodImplementation methodImplementation) {
this.name = name;
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableMethodParameter>of());
this.returnType = returnType;
this.accessFlags = accessFlags;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of());
this.methodImplementation = methodImplementation;
}
public static ImmutableMethod of(Method method) {
if (method instanceof ImmutableMethod) {
return (ImmutableMethod)method;
}
return new ImmutableMethod(
method.getName(),
method.getParameters(),
method.getReturnType(),
method.getAccessFlags(),
method.getAnnotations(),
method.getImplementation());
}
@Nonnull public String getName() { return name; }
@Nonnull public ImmutableList<? extends ImmutableMethodParameter> getParameters() { return parameters; }
@Nonnull public String getReturnType() { return returnType; }
public int getAccessFlags() { return accessFlags; }
@Nonnull public ImmutableList<? extends ImmutableAnnotation> getAnnotations() { return annotations; }
@Nullable public ImmutableMethodImplementation getImplementation() { return methodImplementation; }
@Nonnull
public static ImmutableList<ImmutableMethod> immutableListOf(List<? extends Method> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableMethod, Method> CONVERTER =
new ImmutableListConverter<ImmutableMethod, Method>() {
@Override
protected boolean isImmutable(Method item) {
return item instanceof ImmutableMethod;
}
@Override
protected ImmutableMethod makeImmutable(Method item) {
return ImmutableMethod.of(item);
}
};
}

View File

@ -0,0 +1,79 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.MethodImplementation;
import org.jf.dexlib2.iface.TryBlock;
import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.immutable.instruction.ImmutableInstruction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableMethodImplementation implements MethodImplementation {
public final int registerCount;
@Nonnull public final ImmutableList<? extends ImmutableInstruction> instructions;
@Nonnull public final ImmutableList<? extends ImmutableTryBlock> tryBlocks;
public ImmutableMethodImplementation(int registerCount,
@Nullable List<? extends Instruction> instructions,
@Nullable List<? extends TryBlock> tryBlocks) {
this.registerCount = registerCount;
this.instructions = ImmutableInstruction.immutableListOf(instructions);
this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks);
}
public ImmutableMethodImplementation(int registerCount,
@Nullable ImmutableList<? extends ImmutableInstruction> instructions,
@Nullable ImmutableList<? extends ImmutableTryBlock> tryBlocks) {
this.registerCount = registerCount;
this.instructions = Objects.firstNonNull(instructions, ImmutableList.<ImmutableInstruction>of());
this.tryBlocks = Objects.firstNonNull(tryBlocks, ImmutableList.<ImmutableTryBlock>of());
}
public static ImmutableMethodImplementation of(MethodImplementation methodImplementation) {
if (methodImplementation instanceof ImmutableMethodImplementation) {
return (ImmutableMethodImplementation)methodImplementation;
}
return new ImmutableMethodImplementation(
methodImplementation.getRegisterCount(),
methodImplementation.getInstructions(),
methodImplementation.getTryBlocks());
}
@Override public int getRegisterCount() { return 0; }
@Nonnull @Override public ImmutableList<? extends ImmutableInstruction> getInstructions() { return instructions; }
@Nonnull @Override public ImmutableList<? extends ImmutableTryBlock> getTryBlocks() { return tryBlocks; }
}

View File

@ -0,0 +1,89 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.MethodParameter;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableMethodParameter implements MethodParameter {
@Nonnull public final String type;
@Nonnull public final ImmutableList<? extends ImmutableAnnotation> annotations;
public ImmutableMethodParameter(@Nonnull String type,
@Nullable List<? extends Annotation> annotations) {
this.type = type;
this.annotations = ImmutableAnnotation.immutableListOf(annotations);
}
public ImmutableMethodParameter(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations) {
this.type = type;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of());
}
public static ImmutableMethodParameter of(MethodParameter methodParameter) {
if (methodParameter instanceof ImmutableMethodParameter) {
return (ImmutableMethodParameter)methodParameter;
}
return new ImmutableMethodParameter(
methodParameter.getType(),
methodParameter.getAnnotations());
}
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public List<? extends Annotation> getAnnotations() { return annotations; }
@Nonnull
public static ImmutableList<ImmutableMethodParameter> immutableListOf(List<? extends MethodParameter> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableMethodParameter, MethodParameter> CONVERTER =
new ImmutableListConverter<ImmutableMethodParameter, MethodParameter>() {
@Override
protected boolean isImmutable(MethodParameter item) {
return item instanceof ImmutableMethodParameter;
}
@Override
protected ImmutableMethodParameter makeImmutable(MethodParameter item) {
return ImmutableMethodParameter.of(item);
}
};
}

View File

@ -0,0 +1,99 @@
/*
* 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;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.ExceptionHandler;
import org.jf.dexlib2.iface.TryBlock;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableTryBlock implements TryBlock {
public final int startIndex;
public final int instructionCount;
@Nonnull public final ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers;
public ImmutableTryBlock(int startIndex,
int instructionCount,
@Nullable List<? extends ExceptionHandler> exceptionHandlers) {
this.startIndex = startIndex;
this.instructionCount = instructionCount;
this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers);
}
public ImmutableTryBlock(int startIndex,
int instructionCount,
@Nullable ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers) {
this.startIndex = startIndex;
this.instructionCount = instructionCount;
this.exceptionHandlers = Objects.firstNonNull(exceptionHandlers, ImmutableList.<ImmutableExceptionHandler>of());
}
public static ImmutableTryBlock of(TryBlock tryBlock) {
if (tryBlock instanceof ImmutableTryBlock) {
return (ImmutableTryBlock)tryBlock;
}
return new ImmutableTryBlock(
tryBlock.getStartIndex(),
tryBlock.getInstructionCount(),
tryBlock.getExceptionHandlers());
}
@Override public int getStartIndex() { return startIndex; }
@Override public int getInstructionCount() { return instructionCount; }
@Nonnull @Override public ImmutableList<? extends ImmutableExceptionHandler> getExceptionHandlers() {
return exceptionHandlers;
}
@Nonnull
public static ImmutableList<ImmutableTryBlock> immutableListOf(List<? extends TryBlock> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableTryBlock, TryBlock> CONVERTER =
new ImmutableListConverter<ImmutableTryBlock, TryBlock>() {
@Override
protected boolean isImmutable(TryBlock item) {
return item instanceof ImmutableTryBlock;
}
@Override
protected ImmutableTryBlock makeImmutable(TryBlock item) {
return ImmutableTryBlock.of(item);
}
};
}

View File

@ -0,0 +1,138 @@
/*
* 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.instruction;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.iface.instruction.formats.*;
import org.jf.dexlib2.util.Preconditions;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import java.util.List;
public abstract class ImmutableInstruction implements Instruction {
public final Opcode opcode;
protected ImmutableInstruction(@Nonnull Opcode opcode) {
this.opcode = opcode;
//TODO: check performance. Move into subclasses if needed, where we can access the field directly
Preconditions.checkFormat(opcode, getFormat());
}
public static ImmutableInstruction of(Instruction instruction) {
if (instruction instanceof ImmutableInstruction) {
return (ImmutableInstruction)instruction;
}
switch (instruction.getOpcode().format) {
case Format10t:
return ImmutableInstruction10t.of((Instruction10t)instruction);
case Format10x:
return ImmutableInstruction10x.of((Instruction10x)instruction);
case Format11n:
return ImmutableInstruction11n.of((Instruction11n)instruction);
case Format11x:
return ImmutableInstruction11x.of((Instruction11x)instruction);
case Format12x:
return ImmutableInstruction12x.of((Instruction12x)instruction);
case Format20t:
return ImmutableInstruction20t.of((Instruction20t)instruction);
case Format21c:
return ImmutableInstruction21c.of((Instruction21c)instruction);
case Format21ih:
return ImmutableInstruction21ih.of((Instruction21ih)instruction);
case Format21lh:
return ImmutableInstruction21lh.of((Instruction21lh)instruction);
case Format21s:
return ImmutableInstruction21s.of((Instruction21s)instruction);
case Format21t:
return ImmutableInstruction21t.of((Instruction21t)instruction);
case Format22b:
return ImmutableInstruction22b.of((Instruction22b)instruction);
case Format22c:
return ImmutableInstruction22c.of((Instruction22c)instruction);
case Format22s:
return ImmutableInstruction22s.of((Instruction22s)instruction);
case Format22t:
return ImmutableInstruction22t.of((Instruction22t)instruction);
case Format22x:
return ImmutableInstruction22x.of((Instruction22x)instruction);
case Format23x:
return ImmutableInstruction23x.of((Instruction23x)instruction);
case Format30t:
return ImmutableInstruction30t.of((Instruction30t)instruction);
case Format31c:
return ImmutableInstruction31c.of((Instruction31c)instruction);
case Format31i:
return ImmutableInstruction31i.of((Instruction31i)instruction);
case Format31t:
return ImmutableInstruction31t.of((Instruction31t)instruction);
case Format32x:
return ImmutableInstruction32x.of((Instruction32x)instruction);
case Format35c:
return ImmutableInstruction35c.of((Instruction35c)instruction);
case Format3rc:
return ImmutableInstruction3rc.of((Instruction3rc)instruction);
case Format51l:
return ImmutableInstruction51l.of((Instruction51l)instruction);
}
//TODO: temporary, until we get all instructions implemented
throw new RuntimeException("Unexpected instruction type");
}
public Opcode getOpcode() {
return opcode;
}
public abstract Format getFormat();
@Nonnull
public static ImmutableList<ImmutableInstruction> immutableListOf(List<? extends Instruction> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableInstruction, Instruction> CONVERTER =
new ImmutableListConverter<ImmutableInstruction, Instruction>() {
@Override
protected boolean isImmutable(Instruction item) {
return item instanceof ImmutableInstruction;
}
@Override
protected ImmutableInstruction makeImmutable(Instruction item) {
return ImmutableInstruction.of(item);
}
};
}

View File

@ -0,0 +1,64 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction10t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction10t extends ImmutableInstruction implements Instruction10t {
public static final Format FORMAT = Format.Format12x;
public final int offset;
public ImmutableInstruction10t(@Nonnull Opcode opcode,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.offset = Preconditions.checkByteOffset(offset);
}
public static ImmutableInstruction10t of(Instruction10t instruction) {
if (instruction instanceof ImmutableInstruction10t) {
return (ImmutableInstruction10t)instruction;
}
return new ImmutableInstruction10t(
instruction.getOpcode(),
instruction.getOffset());
}
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,57 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction10x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction10x extends ImmutableInstruction implements Instruction10x {
public static final Format FORMAT = Format.Format12x;
public ImmutableInstruction10x(@Nonnull Opcode opcode) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
}
public static ImmutableInstruction10x of(Instruction10x instruction) {
if (instruction instanceof ImmutableInstruction10x) {
return (ImmutableInstruction10x)instruction;
}
return new ImmutableInstruction10x(instruction.getOpcode());
}
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,71 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction11n;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction11n extends ImmutableInstruction implements Instruction11n {
public static final Format FORMAT = Format.Format11n;
public final int registerA;
public final int literal;
public ImmutableInstruction11n(@Nonnull Opcode opcode,
int registerA,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.literal = Preconditions.checkNibbleLiteral(literal);
}
public static ImmutableInstruction11n of(Instruction11n instruction) {
if (instruction instanceof ImmutableInstruction11n) {
return (ImmutableInstruction11n)instruction;
}
return new ImmutableInstruction11n(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,65 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction11x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction11x extends ImmutableInstruction implements Instruction11x {
public static final Format FORMAT = Format.Format11x;
public final int registerA;
public ImmutableInstruction11x(@Nonnull Opcode opcode,
int registerA) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
}
public static ImmutableInstruction11x of(Instruction11x instruction) {
if (instruction instanceof ImmutableInstruction11x) {
return (ImmutableInstruction11x)instruction;
}
return new ImmutableInstruction11x(
instruction.getOpcode(),
instruction.getRegisterA());
}
@Override public int getRegisterA() { return registerA; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction12x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction12x extends ImmutableInstruction implements Instruction12x {
public static final Format FORMAT = Format.Format12x;
public final int registerA;
public final int registerB;
public ImmutableInstruction12x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.registerB = Preconditions.checkNibbleRegister(registerB);
}
public static ImmutableInstruction12x of(Instruction12x instruction) {
if (instruction instanceof ImmutableInstruction12x) {
return (ImmutableInstruction12x)instruction;
}
return new ImmutableInstruction12x(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,64 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction20t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction20t extends ImmutableInstruction implements Instruction20t {
public static final Format FORMAT = Format.Format12x;
public final int offset;
public ImmutableInstruction20t(@Nonnull Opcode opcode,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.offset = Preconditions.checkShortOffset(offset);
}
public static ImmutableInstruction20t of(Instruction20t instruction) {
if (instruction instanceof ImmutableInstruction20t) {
return (ImmutableInstruction20t)instruction;
}
return new ImmutableInstruction20t(
instruction.getOpcode(),
(byte)instruction.getOffset());
}
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction21c extends ImmutableInstruction implements Instruction21c {
public static final Format FORMAT = Format.Format21c;
public final int registerA;
@Nonnull public final String reference;
public ImmutableInstruction21c(@Nonnull Opcode opcode,
int registerA,
@Nonnull String reference) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
}
public static ImmutableInstruction21c of(Instruction21c instruction) {
if (instruction instanceof ImmutableInstruction21c) {
return (ImmutableInstruction21c)instruction;
}
return new ImmutableInstruction21c(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getReference());
}
@Override public int getRegisterA() { return registerA; }
@Nonnull @Override public String getReference() { return reference; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,72 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction21ih;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction21ih extends ImmutableInstruction implements Instruction21ih {
public static final Format FORMAT = Format.Format21ih;
public final int registerA;
public final int literal;
public ImmutableInstruction21ih(@Nonnull Opcode opcode,
int registerA,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.literal = Preconditions.checkIntegerHatLiteral(literal);
}
public static ImmutableInstruction21ih of(Instruction21ih instruction) {
if (instruction instanceof ImmutableInstruction21ih) {
return (ImmutableInstruction21ih)instruction;
}
return new ImmutableInstruction21ih(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public short getHatLiteral() { return (short)(literal >>> 16); }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,71 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction21lh;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction21lh extends ImmutableInstruction implements Instruction21lh {
public static final Format FORMAT = Format.Format21lh;
public final int registerA;
public final long literal;
public ImmutableInstruction21lh(@Nonnull Opcode opcode,
int registerA,
long literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.literal = Preconditions.checkLongHatLiteral(literal);
}
public static ImmutableInstruction21lh of(Instruction21lh instruction) {
if (instruction instanceof ImmutableInstruction21lh) {
return (ImmutableInstruction21lh)instruction;
}
return new ImmutableInstruction21lh(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getWideLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public long getWideLiteral() { return literal; }
@Override public short getHatLiteral() { return (short)(literal >>> 48); }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,71 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction21s;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction21s extends ImmutableInstruction implements Instruction21s {
public static final Format FORMAT = Format.Format21s;
public final int registerA;
public final int literal;
public ImmutableInstruction21s(@Nonnull Opcode opcode,
int registerA,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.literal = Preconditions.checkShortLiteral(literal);
}
public static ImmutableInstruction21s of(Instruction21s instruction) {
if (instruction instanceof ImmutableInstruction21s) {
return (ImmutableInstruction21s)instruction;
}
return new ImmutableInstruction21s(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction21t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction21t extends ImmutableInstruction implements Instruction21t {
public static final Format FORMAT = Format.Format21t;
public final int registerA;
public final int offset;
public ImmutableInstruction21t(@Nonnull Opcode opcode,
int registerA,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.offset = Preconditions.checkShortOffset(offset);
}
public static ImmutableInstruction21t of(Instruction21t instruction) {
if (instruction instanceof ImmutableInstruction21t) {
return (ImmutableInstruction21t)instruction;
}
return new ImmutableInstruction21t(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getOffset());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,76 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction22b;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction22b extends ImmutableInstruction implements Instruction22b {
public static final Format FORMAT = Format.Format22b;
public final int registerA;
public final int registerB;
public final int literal;
public ImmutableInstruction22b(@Nonnull Opcode opcode,
int registerA,
int registerB,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkByteRegister(registerA);
this.registerB = Preconditions.checkByteRegister(registerB);
this.literal = Preconditions.checkByteLiteral(literal);
}
public static ImmutableInstruction22b of(Instruction22b instruction) {
if (instruction instanceof ImmutableInstruction22b) {
return (ImmutableInstruction22b)instruction;
}
return new ImmutableInstruction22b(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,75 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction22c extends ImmutableInstruction implements Instruction22c {
public static final Format FORMAT = Format.Format22c;
public final int registerA;
public final int registerB;
public final String reference;
public ImmutableInstruction22c(@Nonnull Opcode opcode,
int registerA,
int registerB,
@Nonnull String reference) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.registerB = Preconditions.checkNibbleRegister(registerB);
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
}
public static ImmutableInstruction22c of(Instruction22c instruction) {
if (instruction instanceof ImmutableInstruction22c) {
return (ImmutableInstruction22c)instruction;
}
return new ImmutableInstruction22c(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB(),
instruction.getReference());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Nonnull @Override public String getReference() { return reference; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,76 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction22s;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction22s extends ImmutableInstruction implements Instruction22s {
public static final Format FORMAT = Format.Format22s;
public final int registerA;
public final int registerB;
public final int literal;
public ImmutableInstruction22s(@Nonnull Opcode opcode,
int registerA,
int registerB,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.registerB = Preconditions.checkNibbleRegister(registerB);
this.literal = Preconditions.checkShortLiteral(literal);
}
public static ImmutableInstruction22s of(Instruction22s instruction) {
if (instruction instanceof ImmutableInstruction22s) {
return (ImmutableInstruction22s)instruction;
}
return new ImmutableInstruction22s(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,75 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction22t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction22t extends ImmutableInstruction implements Instruction22t {
public static final Format FORMAT = Format.Format22t;
public final int registerA;
public final int registerB;
public final int offset;
public ImmutableInstruction22t(@Nonnull Opcode opcode,
int registerA,
int registerB,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkNibbleRegister(registerA);
this.registerB = Preconditions.checkNibbleRegister(registerB);
this.offset = Preconditions.checkShortOffset(offset);
}
public static ImmutableInstruction22t of(Instruction22t instruction) {
if (instruction instanceof ImmutableInstruction22t) {
return (ImmutableInstruction22t)instruction;
}
return new ImmutableInstruction22t(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB(),
instruction.getOffset());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction22x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction22x extends ImmutableInstruction implements Instruction22x {
public static final Format FORMAT = Format.Format22x;
public final int registerA;
public final int registerB;
public ImmutableInstruction22x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkByteRegister(registerA);
this.registerB = Preconditions.checkShortRegister(registerB);
}
public static ImmutableInstruction22x of(Instruction22x instruction) {
if (instruction instanceof ImmutableInstruction22x) {
return (ImmutableInstruction22x)instruction;
}
return new ImmutableInstruction22x(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,75 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction23x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction23x extends ImmutableInstruction implements Instruction23x {
public static final Format FORMAT = Format.Format23x;
public final int registerA;
public final int registerB;
public final int registerC;
public ImmutableInstruction23x(@Nonnull Opcode opcode,
int registerA,
int registerB,
int registerC) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkByteRegister(registerA);
this.registerB = Preconditions.checkByteRegister(registerB);
this.registerC = Preconditions.checkByteRegister(registerC);
}
public static ImmutableInstruction23x of(Instruction23x instruction) {
if (instruction instanceof ImmutableInstruction23x) {
return (ImmutableInstruction23x)instruction;
}
return new ImmutableInstruction23x(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB(),
instruction.getRegisterC());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public int getRegisterC() { return registerC; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,65 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction30t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction30t extends ImmutableInstruction implements Instruction30t {
public static final Format FORMAT = Format.Format12x;
public final int offset;
public ImmutableInstruction30t(@Nonnull Opcode opcode,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.offset = offset;
}
public static ImmutableInstruction30t of(Instruction30t instruction) {
if (instruction instanceof ImmutableInstruction30t) {
return (ImmutableInstruction30t)instruction;
}
return new ImmutableInstruction30t(
instruction.getOpcode(),
instruction.getOffset());
}
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction31c;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction31c extends ImmutableInstruction implements Instruction31c {
public static final Format FORMAT = Format.Format31c;
public final int registerA;
@Nonnull public final String reference;
public ImmutableInstruction31c(@Nonnull Opcode opcode,
int registerA,
@Nonnull String reference) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
}
public static ImmutableInstruction31c of(Instruction31c instruction) {
if (instruction instanceof ImmutableInstruction31c) {
return (ImmutableInstruction31c)instruction;
}
return new ImmutableInstruction31c(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getReference());
}
@Override public int getRegisterA() { return registerA; }
@Nonnull @Override public String getReference() { return reference; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,71 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction31i;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction31i extends ImmutableInstruction implements Instruction31i {
public static final Format FORMAT = Format.Format31i;
public final int registerA;
public final int literal;
public ImmutableInstruction31i(@Nonnull Opcode opcode,
int registerA,
int literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.literal = literal;
}
public static ImmutableInstruction31i of(Instruction31i instruction) {
if (instruction instanceof ImmutableInstruction31i) {
return (ImmutableInstruction31i)instruction;
}
return new ImmutableInstruction31i(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getNarrowLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getNarrowLiteral() { return literal; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,71 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction31t;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction31t extends ImmutableInstruction implements Instruction31t {
public static final Format FORMAT = Format.Format31t;
public final int registerA;
public final int offset;
public ImmutableInstruction31t(@Nonnull Opcode opcode,
int registerA,
int offset) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.offset = offset;
}
public static ImmutableInstruction31t of(Instruction31t instruction) {
if (instruction instanceof ImmutableInstruction31t) {
return (ImmutableInstruction31t)instruction;
}
return new ImmutableInstruction31t(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getOffset());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getOffset() { return offset; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction32x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction32x extends ImmutableInstruction implements Instruction32x {
public static final Format FORMAT = Format.Format32x;
public final int registerA;
public final int registerB;
public ImmutableInstruction32x(@Nonnull Opcode opcode,
int registerA,
int registerB) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerA = Preconditions.checkShortRegister(registerA);
this.registerB = Preconditions.checkShortRegister(registerB);
}
public static ImmutableInstruction32x of(Instruction32x instruction) {
if (instruction instanceof ImmutableInstruction32x) {
return (ImmutableInstruction32x)instruction;
}
return new ImmutableInstruction32x(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getRegisterB());
}
@Override public int getRegisterA() { return registerA; }
@Override public int getRegisterB() { return registerB; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,95 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction35c;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction35c extends ImmutableInstruction implements Instruction35c {
public static final Format FORMAT = Format.Format35c;
public final int registerCount;
public final int registerC;
public final int registerD;
public final int registerE;
public final int registerF;
public final int registerG;
@Nonnull public final String reference;
public ImmutableInstruction35c(@Nonnull Opcode opcode,
int registerCount,
int registerC,
int registerD,
int registerE,
int registerF,
int registerG,
@Nonnull String reference) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format35c);
this.registerCount = Preconditions.check35cRegisterCount(registerCount);
this.registerC = (registerCount>0) ? Preconditions.checkNibbleRegister(registerC) : 0;
this.registerD = (registerCount>1) ? Preconditions.checkNibbleRegister(registerD) : 0;
this.registerE = (registerCount>2) ? Preconditions.checkNibbleRegister(registerE) : 0;
this.registerF = (registerCount>3) ? Preconditions.checkNibbleRegister(registerF) : 0;
this.registerG = (registerCount>4) ? Preconditions.checkNibbleRegister(registerG) : 0;
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
}
public static ImmutableInstruction35c of(Instruction35c instruction) {
if (instruction instanceof ImmutableInstruction35c) {
return (ImmutableInstruction35c)instruction;
}
return new ImmutableInstruction35c(
instruction.getOpcode(),
instruction.getRegisterCount(),
instruction.getRegisterC(),
instruction.getRegisterD(),
instruction.getRegisterE(),
instruction.getRegisterF(),
instruction.getRegisterG(),
instruction.getReference());
}
@Override public int getRegisterCount() { return registerCount; }
@Override public int getRegisterC() { return registerC; }
@Override public int getRegisterD() { return registerD; }
@Override public int getRegisterE() { return registerE; }
@Override public int getRegisterF() { return registerF; }
@Override public int getRegisterG() { return registerG; }
@Nonnull @Override public String getReference() { return reference; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,77 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction3rc extends ImmutableInstruction implements Instruction3rc {
public static final Format FORMAT = Format.Format3rc;
public final int startRegister;
public final int registerCount;
@Nonnull public final String reference;
public ImmutableInstruction3rc(@Nonnull Opcode opcode,
int startRegister,
int registerCount,
@Nonnull String reference) {
super(opcode);
Preconditions.checkFormat(opcode, Format.Format3rc);
this.startRegister = Preconditions.checkShortRegister(startRegister);
this.registerCount = Preconditions.check3rcRegisterCount(registerCount);
this.reference = Preconditions.checkReference(reference, opcode.referenceType);
}
public static ImmutableInstruction3rc of(Instruction3rc instruction) {
if (instruction instanceof ImmutableInstruction3rc) {
return (ImmutableInstruction3rc)instruction;
}
return new ImmutableInstruction3rc(
instruction.getOpcode(),
instruction.getStartRegister(),
instruction.getRegisterCount(),
instruction.getReference());
}
@Override public int getStartRegister() { return startRegister; }
@Override public int getRegisterCount() { return registerCount; }
@Nonnull @Override public String getReference() { return reference; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,70 @@
/*
* 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.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.Instruction51l;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class ImmutableInstruction51l extends ImmutableInstruction implements Instruction51l {
public static final Format FORMAT = Format.Format51l;
public final int registerA;
public final long literal;
public ImmutableInstruction51l(@Nonnull Opcode opcode,
int registerA,
long literal) {
super(opcode);
Preconditions.checkFormat(opcode, FORMAT);
this.registerA = Preconditions.checkByteRegister(registerA);
this.literal = literal;
}
public static ImmutableInstruction51l of(Instruction51l instruction) {
if (instruction instanceof ImmutableInstruction51l) {
return (ImmutableInstruction51l)instruction;
}
return new ImmutableInstruction51l(
instruction.getOpcode(),
instruction.getRegisterA(),
instruction.getWideLiteral());
}
@Override public int getRegisterA() { return registerA; }
@Override public long getWideLiteral() { return literal; }
@Override public Format getFormat() { return FORMAT; }
}

View File

@ -0,0 +1,66 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.ImmutableBaseAnnotation;
import org.jf.dexlib2.iface.BaseAnnotation;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue implements AnnotationEncodedValue {
@Nonnull
public final ImmutableBaseAnnotation value;
public ImmutableAnnotationEncodedValue(@Nonnull BaseAnnotation value) {
super(EncodedValue.ANNOTATION);
this.value = ImmutableBaseAnnotation.of(value);
}
public ImmutableAnnotationEncodedValue(@Nonnull ImmutableBaseAnnotation value) {
super(EncodedValue.ANNOTATION);
this.value = value;
}
public static ImmutableAnnotationEncodedValue of(@Nonnull AnnotationEncodedValue annotationEncodedValue) {
if (annotationEncodedValue instanceof ImmutableAnnotationEncodedValue) {
return (ImmutableAnnotationEncodedValue)annotationEncodedValue;
}
return new ImmutableAnnotationEncodedValue(annotationEncodedValue.getValue());
}
@Nonnull
public ImmutableBaseAnnotation getValue() {
return value;
}
}

View File

@ -0,0 +1,66 @@
/*
* 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.collect.ImmutableList;
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<? extends ImmutableEncodedValue> value;
public ImmutableArrayEncodedValue(@Nonnull List<? extends EncodedValue> value) {
super(EncodedValue.ARRAY);
this.value = ImmutableEncodedValue.immutableListOf(value);
}
public ImmutableArrayEncodedValue(@Nonnull ImmutableList<ImmutableEncodedValue> value) {
super(EncodedValue.ARRAY);
this.value = value;
}
public static ImmutableArrayEncodedValue of(@Nonnull ArrayEncodedValue arrayEncodedValue) {
if (arrayEncodedValue instanceof ImmutableArrayEncodedValue) {
return (ImmutableArrayEncodedValue)arrayEncodedValue;
}
return new ImmutableArrayEncodedValue(arrayEncodedValue.getValue());
}
@Nonnull
public ImmutableList<? extends ImmutableEncodedValue> getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.BooleanEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
public class ImmutableBooleanEncodedValue extends ImmutableEncodedValue implements BooleanEncodedValue {
public final boolean value;
public ImmutableBooleanEncodedValue(boolean value) {
super(EncodedValue.BOOLEAN);
this.value = value;
}
public static ImmutableBooleanEncodedValue of(BooleanEncodedValue booleanEncodedValue) {
if (booleanEncodedValue instanceof ImmutableBooleanEncodedValue) {
return (ImmutableBooleanEncodedValue)booleanEncodedValue;
}
return new ImmutableBooleanEncodedValue(booleanEncodedValue.getValue());
}
public boolean getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.ByteEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
public class ImmutableByteEncodedValue extends ImmutableEncodedValue implements ByteEncodedValue {
public final byte value;
public ImmutableByteEncodedValue(byte value) {
super(EncodedValue.BYTE);
this.value = value;
}
public static ImmutableByteEncodedValue of(ByteEncodedValue byteEncodedValue) {
if (byteEncodedValue instanceof ImmutableByteEncodedValue) {
return (ImmutableByteEncodedValue)byteEncodedValue;
}
return new ImmutableByteEncodedValue(byteEncodedValue.getValue());
}
public byte getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.CharEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
public class ImmutableCharEncodedValue extends ImmutableEncodedValue implements CharEncodedValue {
public final char value;
public ImmutableCharEncodedValue(char value) {
super(EncodedValue.CHAR);
this.value = value;
}
public static ImmutableCharEncodedValue of(CharEncodedValue charEncodedValue) {
if (charEncodedValue instanceof ImmutableCharEncodedValue) {
return (ImmutableCharEncodedValue)charEncodedValue;
}
return new ImmutableCharEncodedValue(charEncodedValue.getValue());
}
public char getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.DoubleEncodedValue;
import org.jf.dexlib2.iface.value.EncodedValue;
public class ImmutableDoubleEncodedValue extends ImmutableEncodedValue implements DoubleEncodedValue {
public final double value;
public ImmutableDoubleEncodedValue(double value) {
super(EncodedValue.DOUBLE);
this.value = value;
}
public static ImmutableDoubleEncodedValue of(DoubleEncodedValue doubleEncodedValue) {
if (doubleEncodedValue instanceof ImmutableDoubleEncodedValue) {
return (ImmutableDoubleEncodedValue)doubleEncodedValue;
}
return new ImmutableDoubleEncodedValue(doubleEncodedValue.getValue());
}
public double getValue() {
return value;
}
}

View File

@ -0,0 +1,108 @@
/*
* 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.iface.value.*;
import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull;
import java.util.List;
public class ImmutableEncodedValue implements EncodedValue {
public final int type;
protected ImmutableEncodedValue(int type) {
this.type = type;
}
public static ImmutableEncodedValue of(EncodedValue encodedValue) {
switch (encodedValue.getType()) {
case BYTE:
return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue);
case SHORT:
return ImmutableShortEncodedValue.of((ShortEncodedValue)encodedValue);
case CHAR:
return ImmutableCharEncodedValue.of((CharEncodedValue)encodedValue);
case INT:
return ImmutableIntEncodedValue.of((IntEncodedValue)encodedValue);
case LONG:
return ImmutableLongEncodedValue.of((LongEncodedValue)encodedValue);
case FLOAT:
return ImmutableFloatEncodedValue.of((FloatEncodedValue)encodedValue);
case DOUBLE:
return ImmutableDoubleEncodedValue.of((DoubleEncodedValue)encodedValue);
case STRING:
return ImmutableStringEncodedValue.of((StringEncodedValue)encodedValue);
case TYPE:
return ImmutableTypeEncodedValue.of((TypeEncodedValue)encodedValue);
case FIELD:
return ImmutableFieldEncodedValue.of((FieldEncodedValue)encodedValue);
case METHOD:
return ImmutableMethodEncodedValue.of((MethodEncodedValue)encodedValue);
case ENUM:
return ImmutableEnumEncodedValue.of((EnumEncodedValue)encodedValue);
case ARRAY:
return ImmutableArrayEncodedValue.of((ArrayEncodedValue)encodedValue);
case ANNOTATION:
return ImmutableAnnotationEncodedValue.of((AnnotationEncodedValue)encodedValue);
case NULL:
return ImmutableNullEncodedValue.INSTANCE;
case BOOLEAN:
return ImmutableBooleanEncodedValue.of((BooleanEncodedValue)encodedValue);
default:
Preconditions.checkArgument(false);
return null;
}
}
public int getType() { return type; }
@Nonnull
public static ImmutableList<ImmutableEncodedValue> immutableListOf(List<? extends EncodedValue> list) {
return CONVERTER.convert(list);
}
private static final ImmutableListConverter<ImmutableEncodedValue, EncodedValue> CONVERTER =
new ImmutableListConverter<ImmutableEncodedValue, EncodedValue>() {
@Override
protected boolean isImmutable(EncodedValue item) {
return item instanceof ImmutableEncodedValue;
}
@Override
protected ImmutableEncodedValue makeImmutable(EncodedValue item) {
return ImmutableEncodedValue.of(item);
}
};
}

View File

@ -0,0 +1,57 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.EnumEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableEnumEncodedValue extends ImmutableEncodedValue implements EnumEncodedValue {
@Nonnull public final String value;
public ImmutableEnumEncodedValue(@Nonnull String value) {
super(EncodedValue.ENUM);
this.value = value;
}
public static ImmutableEnumEncodedValue of(EnumEncodedValue enumEncodedValue) {
if (enumEncodedValue instanceof ImmutableEnumEncodedValue) {
return (ImmutableEnumEncodedValue)enumEncodedValue;
}
return new ImmutableEnumEncodedValue(enumEncodedValue.getValue());
}
@Nonnull public String getValue() {
return value;
}
}

View File

@ -0,0 +1,58 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.FieldEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableFieldEncodedValue extends ImmutableEncodedValue implements FieldEncodedValue {
@Nonnull public final String value;
public ImmutableFieldEncodedValue(@Nonnull String value) {
super(EncodedValue.FIELD);
this.value = value;
}
public static ImmutableFieldEncodedValue of(@Nonnull FieldEncodedValue fieldEncodedValue) {
if (fieldEncodedValue instanceof ImmutableFieldEncodedValue) {
return (ImmutableFieldEncodedValue)fieldEncodedValue;
}
return new ImmutableFieldEncodedValue(fieldEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.FloatEncodedValue;
public class ImmutableFloatEncodedValue extends ImmutableEncodedValue implements FloatEncodedValue {
public final float value;
public ImmutableFloatEncodedValue(float value) {
super(EncodedValue.FLOAT);
this.value = value;
}
public static ImmutableFloatEncodedValue of(FloatEncodedValue floatEncodedValue) {
if (floatEncodedValue instanceof ImmutableFloatEncodedValue) {
return (ImmutableFloatEncodedValue)floatEncodedValue;
}
return new ImmutableFloatEncodedValue(floatEncodedValue.getValue());
}
public float getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.IntEncodedValue;
public class ImmutableIntEncodedValue extends ImmutableEncodedValue implements IntEncodedValue {
public final int value;
public ImmutableIntEncodedValue(int value) {
super(EncodedValue.INT);
this.value = value;
}
public static ImmutableIntEncodedValue of(IntEncodedValue intEncodedValue) {
if (intEncodedValue instanceof ImmutableIntEncodedValue) {
return (ImmutableIntEncodedValue)intEncodedValue;
}
return new ImmutableIntEncodedValue(intEncodedValue.getValue());
}
public int getValue() {
return value;
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.LongEncodedValue;
public class ImmutableLongEncodedValue extends ImmutableEncodedValue implements LongEncodedValue {
public final long value;
public ImmutableLongEncodedValue(long value) {
super(EncodedValue.LONG);
this.value = value;
}
public static ImmutableLongEncodedValue of(LongEncodedValue longEncodedValue) {
if (longEncodedValue instanceof ImmutableLongEncodedValue) {
return (ImmutableLongEncodedValue)longEncodedValue;
}
return new ImmutableLongEncodedValue(longEncodedValue.getValue());
}
public long getValue() {
return value;
}
}

View File

@ -0,0 +1,59 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.MethodEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableMethodEncodedValue extends ImmutableEncodedValue implements MethodEncodedValue {
@Nonnull
public final String value;
public ImmutableMethodEncodedValue(@Nonnull String value) {
super(EncodedValue.METHOD);
this.value = value;
}
public static ImmutableMethodEncodedValue of(@Nonnull MethodEncodedValue methodEncodedValue) {
if (methodEncodedValue instanceof ImmutableMethodEncodedValue) {
return (ImmutableMethodEncodedValue)methodEncodedValue;
}
return new ImmutableMethodEncodedValue(methodEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
}

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.immutable.value;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.NullEncodedValue;
public class ImmutableNullEncodedValue extends ImmutableEncodedValue implements NullEncodedValue {
public static final ImmutableNullEncodedValue INSTANCE = new ImmutableNullEncodedValue();
public ImmutableNullEncodedValue() {
super(EncodedValue.NULL);
}
}

View File

@ -0,0 +1,55 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.ShortEncodedValue;
public class ImmutableShortEncodedValue extends ImmutableEncodedValue implements ShortEncodedValue {
public final short value;
public ImmutableShortEncodedValue(short value) {
super(EncodedValue.SHORT);
this.value = value;
}
public static ImmutableShortEncodedValue of(ShortEncodedValue shortEncodedValue) {
if (shortEncodedValue instanceof ImmutableShortEncodedValue) {
return (ImmutableShortEncodedValue)shortEncodedValue;
}
return new ImmutableShortEncodedValue(shortEncodedValue.getValue());
}
public short getValue() {
return value;
}
}

View File

@ -0,0 +1,59 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.StringEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableStringEncodedValue extends ImmutableEncodedValue implements StringEncodedValue {
@Nonnull
public final String value;
public ImmutableStringEncodedValue(@Nonnull String value) {
super(EncodedValue.STRING);
this.value = value;
}
public static ImmutableStringEncodedValue of(@Nonnull StringEncodedValue stringEncodedValue) {
if (stringEncodedValue instanceof ImmutableStringEncodedValue) {
return (ImmutableStringEncodedValue)stringEncodedValue;
}
return new ImmutableStringEncodedValue(stringEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,59 @@
/*
* 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 org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.TypeEncodedValue;
import javax.annotation.Nonnull;
public class ImmutableTypeEncodedValue extends ImmutableEncodedValue implements TypeEncodedValue {
@Nonnull
public final String value;
public ImmutableTypeEncodedValue(@Nonnull String value) {
super(EncodedValue.TYPE);
this.value = value;
}
public static ImmutableTypeEncodedValue of(@Nonnull TypeEncodedValue typeEncodedValue) {
if (typeEncodedValue instanceof ImmutableTypeEncodedValue) {
return (ImmutableTypeEncodedValue)typeEncodedValue;
}
return new ImmutableTypeEncodedValue(typeEncodedValue.getValue());
}
@Nonnull
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,146 @@
/*
* 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.util;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.ReferenceType;
public class Preconditions {
public static void checkFormat(Opcode opcode, Format expectedFormat) {
if (opcode.format != expectedFormat) {
throw new IllegalArgumentException(
String.format("Invalid opcode %s for %s", opcode.name, expectedFormat.name()));
}
}
public static int checkNibbleRegister(int register) {
if ((register & 0xFFFFFFF0) != 0) {
throw new IllegalArgumentException(
String.format("Invalid register: v%d. Must be between v0 and v15, inclusive.", register));
}
return register;
}
public static int checkByteRegister(int register) {
if ((register & 0xFFFFFF00) != 0) {
throw new IllegalArgumentException(
String.format("Invalid register: v%d. Must be between v0 and v255, inclusive.", register));
}
return register;
}
public static int checkShortRegister(int register) {
if ((register & 0xFFFF0000) != 0) {
throw new IllegalArgumentException(
String.format("Invalid register: v%d. Must be between v0 and v65535, inclusive.", register));
}
return register;
}
public static int checkNibbleLiteral(int literal) {
if ((literal & 0xFFFFFFF0) != 0) {
throw new IllegalArgumentException(
String.format("Invalid literal value: %d. Must be between -8 and 7, inclusive.", literal));
}
return literal;
}
public static int checkByteLiteral(int literal) {
if ((literal & 0xFFFFFF00) != 0) {
throw new IllegalArgumentException(
String.format("Invalid literal value: %d. Must be between -128 and 127, inclusive.", literal));
}
return literal;
}
public static int checkShortLiteral(int literal) {
if ((literal & 0xFFFF0000) != 0) {
throw new IllegalArgumentException(
String.format("Invalid literal value: %d. Must be between -32768 and 32767, inclusive.", literal));
}
return literal;
}
public static int checkIntegerHatLiteral(int literal) {
if ((literal & 0xFFFF) != 0) {
throw new IllegalArgumentException(
String.format("Invalid literal value: %d. Low 16 bits must be zeroed out.", literal));
}
return literal;
}
public static long checkLongHatLiteral(long literal) {
if ((literal & 0xFFFFFFFFFFFFL) != 0) {
throw new IllegalArgumentException(
String.format("Invalid literal value: %d. Low 16 bits must be zeroed out.", literal));
}
return literal;
}
public static int checkByteOffset(int register) {
if ((register & 0xFFFFFF00) != 0) {
throw new IllegalArgumentException(
String.format("Invalid code offset: %d. Must be between -8 and 7, inclusive.", register));
}
return register;
}
public static int checkShortOffset(int register) {
if ((register & 0xFFFF0000) != 0) {
throw new IllegalArgumentException(
String.format("Invalid code offset: %d. Must be between -32768 and 32767, inclusive.", register));
}
return register;
}
public static String checkReference(String reference, int referenceType) {
//TODO: implement this
return reference;
}
public static int check35cRegisterCount(int registerCount) {
if (registerCount < 0 || registerCount > 5) {
throw new IllegalArgumentException(
String.format("Invalid register count: %d. Must be between 0 and 5, inclusive.", registerCount));
}
return registerCount;
}
public static int check3rcRegisterCount(int registerCount) {
if ((registerCount & 0xFFFFFF00) == 0) {
throw new IllegalArgumentException(
String.format("Invalid register count: %d. Must be between 0 and 255, inclusive.", registerCount));
}
return registerCount;
}
}