1 /* 2 * Copyright 2018, Google LLC 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google LLC nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 package com.android.tools.smali.dexlib2.immutable.reference; 32 33 import com.android.tools.smali.util.ImmutableUtils; 34 import com.android.tools.smali.dexlib2.base.reference.BaseCallSiteReference; 35 import com.android.tools.smali.dexlib2.iface.reference.CallSiteReference; 36 import com.android.tools.smali.dexlib2.iface.reference.MethodHandleReference; 37 import com.android.tools.smali.dexlib2.iface.reference.MethodProtoReference; 38 import com.android.tools.smali.dexlib2.iface.value.EncodedValue; 39 import com.android.tools.smali.dexlib2.immutable.value.ImmutableEncodedValue; 40 import com.android.tools.smali.dexlib2.immutable.value.ImmutableEncodedValueFactory; 41 42 import javax.annotation.Nonnull; 43 import javax.annotation.Nullable; 44 import java.util.List; 45 46 public class ImmutableCallSiteReference extends BaseCallSiteReference implements ImmutableReference { 47 @Nonnull protected final String name; 48 @Nonnull protected final ImmutableMethodHandleReference methodHandle; 49 @Nonnull protected final String methodName; 50 @Nonnull protected final ImmutableMethodProtoReference methodProto; 51 @Nonnull protected final List<? extends ImmutableEncodedValue> extraArguments; 52 ImmutableCallSiteReference(@onnull String name, @Nonnull MethodHandleReference methodHandle, @Nonnull String methodName, @Nonnull MethodProtoReference methodProto, @Nonnull Iterable<? extends EncodedValue> extraArguments)53 public ImmutableCallSiteReference(@Nonnull String name, @Nonnull MethodHandleReference methodHandle, 54 @Nonnull String methodName, @Nonnull MethodProtoReference methodProto, 55 @Nonnull Iterable<? extends EncodedValue> extraArguments) { 56 this.name = name; 57 this.methodHandle = ImmutableMethodHandleReference.of(methodHandle); 58 this.methodName = methodName; 59 this.methodProto = ImmutableMethodProtoReference.of(methodProto); 60 this.extraArguments = ImmutableEncodedValueFactory.immutableListOf(extraArguments); 61 } 62 ImmutableCallSiteReference(@onnull String name, @Nonnull ImmutableMethodHandleReference methodHandle, @Nonnull String methodName, @Nonnull ImmutableMethodProtoReference methodProto, @Nullable List<? extends ImmutableEncodedValue> extraArguments)63 public ImmutableCallSiteReference(@Nonnull String name, @Nonnull ImmutableMethodHandleReference methodHandle, 64 @Nonnull String methodName, @Nonnull ImmutableMethodProtoReference methodProto, 65 @Nullable List<? extends ImmutableEncodedValue> extraArguments) { 66 this.name = name; 67 this.methodHandle = methodHandle; 68 this.methodName = methodName; 69 this.methodProto = methodProto; 70 this.extraArguments = ImmutableUtils.nullToEmptyList(extraArguments); 71 } 72 73 @Nonnull of(@onnull CallSiteReference callSiteReference)74 public static ImmutableCallSiteReference of(@Nonnull CallSiteReference callSiteReference) { 75 if (callSiteReference instanceof ImmutableCallSiteReference) { 76 return (ImmutableCallSiteReference) callSiteReference; 77 } 78 return new ImmutableCallSiteReference(callSiteReference.getName(), 79 ImmutableMethodHandleReference.of(callSiteReference.getMethodHandle()), 80 callSiteReference.getMethodName(), 81 ImmutableMethodProtoReference.of(callSiteReference.getMethodProto()), 82 ImmutableEncodedValueFactory.immutableListOf(callSiteReference.getExtraArguments())); 83 } 84 getName()85 @Nonnull @Override public String getName() { return name; } getMethodHandle()86 @Nonnull @Override public MethodHandleReference getMethodHandle() { return methodHandle; } getMethodName()87 @Nonnull @Override public String getMethodName() { return methodName; } getMethodProto()88 @Nonnull @Override public MethodProtoReference getMethodProto() { return methodProto; } getExtraArguments()89 @Nonnull @Override public List<? extends EncodedValue> getExtraArguments() { return extraArguments; } 90 } 91