Add the basic structures necessary to support invoke-custom

This commit is contained in:
Ben Gruver 2018-01-30 13:48:13 -08:00
parent dfdde5ee21
commit b575410a8a
12 changed files with 742 additions and 3 deletions

View File

@ -0,0 +1,82 @@
/*
* Copyright 2018, 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;
import org.jf.util.ExceptionWithContext;
import javax.annotation.Nonnull;
public class MethodHandleType {
public static final int STATIC_PUT = 0;
public static final int STATIC_GET = 1;
public static final int INSTANCE_PUT = 2;
public static final int INSTANCE_GET = 3;
public static final int INVOKE_STATIC = 4;
public static final int INVOKE_INSTANCE = 5;
@Nonnull public static String toString(int methodHandleType) {
switch (methodHandleType) {
case STATIC_PUT:
return "static_put";
case STATIC_GET:
return "static_get";
case INSTANCE_PUT:
return "instance_put";
case INSTANCE_GET:
return "instance_get";
case INVOKE_STATIC:
return "invoke_static";
case INVOKE_INSTANCE:
return "invoke_instance";
default:
throw new InvalidMethodHandleTypeException(methodHandleType);
}
}
public static class InvalidMethodHandleTypeException extends ExceptionWithContext {
private final int methodHandleType;
public InvalidMethodHandleTypeException(int methodHandleType) {
super("Invalid method handle type: %d", methodHandleType);
this.methodHandleType = methodHandleType;
}
public InvalidMethodHandleTypeException(int methodHandleType, String message, Object... formatArgs) {
super(message, formatArgs);
this.methodHandleType = methodHandleType;
}
public int getMethodHandleType() {
return methodHandleType;
}
}
}

View File

@ -306,7 +306,10 @@ public enum Opcode
ARRAY_PAYLOAD(0x300, "array-payload", ReferenceType.NONE, Format.ArrayPayload, 0),
INVOKE_POLYMORPHIC(firstArtVersion(0xfa, 87), "invoke-polymorphic", ReferenceType.METHOD, ReferenceType.METHOD_PROTO, Format.Format45cc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
INVOKE_POLYMORPHIC_RANGE(firstArtVersion(0xfb, 87), "invoke-polymorphic/range", ReferenceType.METHOD, ReferenceType.METHOD_PROTO, Format.Format4rcc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT);
INVOKE_POLYMORPHIC_RANGE(firstArtVersion(0xfb, 87), "invoke-polymorphic/range", ReferenceType.METHOD, ReferenceType.METHOD_PROTO, Format.Format4rcc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
INVOKE_CUSTOM(firstArtVersion(0xfc, 111), "invoke-custom", ReferenceType.CALL_SITE, Format.Format35c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
INVOKE_CUSTOM_RANGE(firstArtVersion(0xfd, 111), "invoke-custom/range", ReferenceType.CALL_SITE, Format.Format3rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT);
//if the instruction can throw an exception
public static final int CAN_THROW = 0x1;
@ -392,7 +395,6 @@ public enum Opcode
}
private static List<VersionConstraint> lastApi(int opcodeValue, int api) {
Range range;
return Lists.newArrayList(new VersionConstraint(Range.atMost(api), Range.openClosed(0, 0), opcodeValue));
}

View File

@ -40,7 +40,9 @@ public final class ReferenceType {
public static final int FIELD = 2;
public static final int METHOD = 3;
public static final int METHOD_PROTO = 4;
public static final int NONE = 5;
public static final int CALL_SITE = 5;
public static final int METHOD_HANDLE = 6;
public static final int NONE = 7;
public static String toString(int referenceType) {
switch (referenceType) {
@ -54,6 +56,10 @@ public final class ReferenceType {
return "method";
case METHOD_PROTO:
return "method_proto";
case CALL_SITE:
return "call_site";
case METHOD_HANDLE:
return "method_handle";
default:
throw new InvalidReferenceTypeException(referenceType);
}
@ -70,6 +76,10 @@ public final class ReferenceType {
return METHOD;
} else if (reference instanceof MethodProtoReference) {
return METHOD_PROTO;
} else if (reference instanceof CallSiteReference) {
return CALL_SITE;
} else if (reference instanceof MethodHandleReference) {
return METHOD_HANDLE;
} else {
throw new IllegalStateException("Invalid reference");
}

View File

@ -39,6 +39,8 @@ public final class ValueType {
public static final int LONG = 0x06;
public static final int FLOAT = 0x10;
public static final int DOUBLE = 0x11;
public static final int METHOD_TYPE = 0x15;
public static final int METHOD_HANDLE = 0x16;
public static final int STRING = 0x17;
public static final int TYPE = 0x18;
public static final int FIELD = 0x19;

View File

@ -0,0 +1,58 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.reference;
import org.jf.dexlib2.iface.reference.CallSiteReference;
public abstract class BaseCallSiteReference implements CallSiteReference {
@Override
public int hashCode() {
int hashCode = getName().hashCode();
hashCode = hashCode*31 + getMethodHandle().hashCode();
hashCode = hashCode*31 + getMethodName().hashCode();
hashCode = hashCode*31 + getMethodProto().hashCode();
hashCode = hashCode*31 + getExtraArguments().hashCode();
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof CallSiteReference) {
CallSiteReference other = (CallSiteReference) o;
return getMethodHandle().equals(other.getMethodHandle()) &&
getMethodName().equals(other.getMethodName()) &&
getMethodProto().equals(other.getMethodProto()) &&
getExtraArguments().equals(other.getExtraArguments());
}
return false;
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.reference;
import com.google.common.primitives.Ints;
import org.jf.dexlib2.iface.reference.FieldReference;
import org.jf.dexlib2.iface.reference.MethodHandleReference;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.dexlib2.iface.reference.Reference;
import javax.annotation.Nonnull;
public abstract class BaseMethodHandleReference implements MethodHandleReference {
@Override
public int hashCode() {
int hashCode = getMethodHandleType();
hashCode = hashCode*31 + getMemberReference().hashCode();
return hashCode;
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof MethodHandleReference) {
MethodHandleReference other = (MethodHandleReference) o;
return getMethodHandleType() == other.getMethodHandleType() &&
getMemberReference().equals(other.getMemberReference());
}
return false;
}
@Override
public int compareTo(@Nonnull MethodHandleReference o) {
int res = Ints.compare(getMethodHandleType(), o.getMethodHandleType());
if (res != 0) return res;
Reference reference = getMemberReference();
if (reference instanceof FieldReference) {
// "This should never happen", but if it does, we'll arbitrarily say a field reference compares less than
// a method reference
if (!(o.getMemberReference() instanceof FieldReference)) {
return -1;
}
return ((FieldReference) reference).compareTo((FieldReference) o.getMemberReference());
} else {
if (!(o.getMemberReference() instanceof MethodReference)) {
return 1;
}
return ((MethodReference) reference).compareTo((MethodReference) o.getMemberReference());
}
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import com.google.common.primitives.Ints;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.MethodHandleEncodedValue;
import javax.annotation.Nonnull;
public abstract class BaseMethodHandleEncodedValue implements MethodHandleEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o instanceof MethodHandleEncodedValue) {
return getValue().equals(((MethodHandleEncodedValue) o).getValue());
}
return false;
}
@Override
public int compareTo(@Nonnull EncodedValue o) {
int res = Ints.compare(getValueType(), o.getValueType());
if (res != 0) return res;
return getValue().compareTo(((MethodHandleEncodedValue) o).getValue());
}
@Override
public int getValueType() {
return ValueType.METHOD_HANDLE;
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.base.value;
import com.google.common.primitives.Ints;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.iface.value.MethodTypeEncodedValue;
import javax.annotation.Nonnull;
public abstract class BaseMethodTypeEncodedValue implements MethodTypeEncodedValue {
@Override
public int hashCode() {
return getValue().hashCode();
}
@Override
public boolean equals(Object o) {
if (o instanceof MethodTypeEncodedValue) {
return getValue().equals(((MethodTypeEncodedValue) o).getValue());
}
return false;
}
@Override
public int compareTo(@Nonnull EncodedValue o) {
int res = Ints.compare(getValueType(), o.getValueType());
if (res != 0) return res;
return getValue().compareTo(((MethodTypeEncodedValue) o).getValue());
}
@Override
public int getValueType() {
return ValueType.METHOD_TYPE;
}
}

View File

@ -0,0 +1,109 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.iface.reference;
import org.jf.dexlib2.iface.value.EncodedValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* This class represents a reference to a call site
*/
public interface CallSiteReference extends Reference {
/**
* Gets a name for this call site.
*
* This is an arbitrary synthetic string that serves to differentiate call sites that would otherwise be identical.
*
* It can be any arbitrary string, with the only requirement being that 2 different, but otherwise identical call
* sites in the same dex file must not share the same name. Multiple non-identical call sites may use the same name
* however.
*
* @return The name for this call site.
*/
@Nonnull String getName();
/**
* Gets a reference to a method handle for the bootstrap linker method
*
* @return A MethodHandleReference to the bootstrap linker method
*/
@Nonnull MethodHandleReference getMethodHandle();
/**
* @return A method name that the bootstrap linker should resolve.
*/
@Nonnull String getMethodName();
/**
* @return A MethodProtoReference corresponding to the prototype of the method that the bootstrap linker should
* resolve
*/
@Nonnull MethodProtoReference getMethodProto();
/**
* @return A list of extra arguments to pass to the bootstrap linker
*/
@Nonnull List<? extends EncodedValue> getExtraArguments();
/**
* Returns a hashcode for this CallSiteReference.
*
* This hashCode is defined to be the following:
*
* <pre>
* {@code
* int hashCode = getName().hashCode();
* hashCode = hashCode*31 + getMethodHandle().hashCode();
* hashCode = hashCode*31 + getMethodName().hashCode();
* hashCode = hashCode*31 + getMethodProto().hashCode();
* hashCode = hashCode*31 + getExtraArguments().hashCode();
* }</pre>
*
* @return The hash code value for this MethodReference
*/
@Override int hashCode();
/**
* Compares this CallSiteReference to another CallSiteReference for equality.
*
* This CallSiteReference is equal to another CallSiteReference if all of its fields are equal. That is, if
* the return values of getMethodHandle(), getMethodName(), getMethodProto() and getExtraArguments() are all equal.
*
* @param o The object to be compared for equality with this CallSiteReference
* @return true if the specified object is equal to this CallSiteReference
*/
@Override boolean equals(@Nullable Object o);
}

View File

@ -0,0 +1,94 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.iface.reference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This class represents a reference to a method handle
*/
public interface MethodHandleReference extends Reference, Comparable<MethodHandleReference> {
/**
* Gets the method handle type.
*
* @return One of the MethodHandleType values
*/
int getMethodHandleType();
/**
* Gets the member that is being referenced by this method handle.
*
* For INVOKE_STATIC and INVOKE_INSTANCE method handle types, this should be a MethodReference.
* For the other method handle types, this should be a FieldReference.
*
* @return A MethodReference or FieldReference, depending on the method handle type
*/
@Nonnull Reference getMemberReference();
/**
* Returns a hashcode for this MethodHandleReference.
*
* This hashCode is defined to be the following:
*
* <pre>
* {@code
* int hashCode = getMethodHandleType();
* hashCode = hashCode*31 + getMemberReference().hashCode();
* }</pre>
*
* @return The hash code value for this MethodHandleReference
*/
@Override int hashCode();
/**
* Compares this MethodHandleReference to another MethodHandleReference for equality.
*
* This MethodHandleReference is equal to another MethodHandleReference if all of its fields are equal. That is, if
* the return values of getMethodHandleType() and getMemberReference() are all equal.
*
* @param o The object to be compared for equality with this MethodHandleReference
* @return true if the specified object is equal to this MethodHandleReference
*/
@Override boolean equals(@Nullable Object o);
/**
* Compare this MethodHandleReference to another MethodHandleReference.
*
* The comparison is based on the comparison of the return values of getMethodHandleType() and getMemberReference()
* in that order.
*
* @param o The MethodHandleReference to compare with this MethodHandleReference
* @return An integer representing the result of the comparison
*/
@Override int compareTo(@Nonnull MethodHandleReference o);
}

View File

@ -0,0 +1,85 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.reference.MethodHandleReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This class represents an encoded method type value.
*/
public interface MethodHandleEncodedValue extends EncodedValue {
/**
* Gets the method handle value.
*
* @return the method handle value as a MethodHandleReference
*/
@Nonnull MethodHandleReference getValue();
/**
* Returns a hashcode for this MethodHandleEncodedValue.
*
* This hashCode is defined to be the following:
*
* <pre>
* {@code
* int hashCode = getValue.hashCode();
* }</pre>
*
* @return The hash code value for this MethodHandleEncodedValue
*/
@Override int hashCode();
/**
* Compares this MethodHandleEncodedValue to another MethodHandleEncodedValue for equality.
*
* This MethodHandleEncodedValue is equal to another MethodHandleEncodedValue if the values returned by getValue()
* are equal.
*
* @param o The object to be compared for equality with this MethodHandleEncodedValue
* @return true if the specified object is equal to this MethodHandleEncodedValue
*/
@Override boolean equals(@Nullable Object o);
/**
* Compare this MethodHandleEncodedValue to another EncodedValue.
*
* The comparison is first done on the return values of getValueType(). If the other value is another
* MethodHandleEncodedValue, the return values of getValue() are compared.
*
* @param o The EncodedValue to compare with this MethodHandleEncodedValue
* @return An integer representing the result of the comparison
*/
@Override int compareTo(@Nonnull EncodedValue o);
}

View File

@ -0,0 +1,85 @@
/*
* Copyright 2018, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.iface.value;
import org.jf.dexlib2.iface.reference.MethodProtoReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This class represents an encoded method type value.
*/
public interface MethodTypeEncodedValue extends EncodedValue {
/**
* Gets the method type value.
*
* @return the method type value as a MethodProtoReference
*/
@Nonnull MethodProtoReference getValue();
/**
* Returns a hashcode for this MethodTypeEncodedValue.
*
* This hashCode is defined to be the following:
*
* <pre>
* {@code
* int hashCode = getValue.hashCode();
* }</pre>
*
* @return The hash code value for this MethodTypeEncodedValue
*/
@Override int hashCode();
/**
* Compares this MethodTypeEncodedValue to another MethodTypeEncodedValue for equality.
*
* This MethodTypeEncodedValue is equal to another MethodTypeEncodedValue if the values returned by getValue()
* are equal.
*
* @param o The object to be compared for equality with this MethodTypeEncodedValue
* @return true if the specified object is equal to this MethodTypeEncodedValue
*/
@Override boolean equals(@Nullable Object o);
/**
* Compare this MethodTypeEncodedValue to another EncodedValue.
*
* The comparison is first done on the return values of getValueType(). If the other value is another
* MethodTypeEncodedValue, the return values of getValue() are compared.
*
* @param o The EncodedValue to compare with this MethodTypeEncodedValue
* @return An integer representing the result of the comparison
*/
@Override int compareTo(@Nonnull EncodedValue o);
}