Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.byteCode.instruction;
 
 
 import java.util.List;
 
 import static com.facebook.presto.byteCode.MethodDefinition.methodDescription;
 import static com.facebook.presto.byteCode.OpCode.INVOKEDYNAMIC;
 import static com.facebook.presto.byteCode.OpCode.INVOKEINTERFACE;
 import static com.facebook.presto.byteCode.OpCode.INVOKESPECIAL;
 import static com.facebook.presto.byteCode.OpCode.INVOKESTATIC;
 import static com.facebook.presto.byteCode.OpCode.INVOKEVIRTUAL;
 import static com.facebook.presto.byteCode.ParameterizedType.type;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.Iterables.transform;
 
 @SuppressWarnings("UnusedDeclaration")
 public class InvokeInstruction
         implements InstructionNode
 {
     //
     // Invoke Static
     //
 
     public static InstructionNode invokeStatic(Method method)
     {
         return invoke(method);
     }
 
     public static InstructionNode invokeStatic(MethodDefinition method)
     {
         return invoke(method);
     }
 
     public static InstructionNode invokeStatic(Class<?> targetString nameClass<?> returnTypeClass<?>... parameterTypes)
     {
         return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
     }
 
     public static InstructionNode invokeStatic(Class<?> targetString nameClass<?> returnTypeIterable<Class<?>> parameterTypes)
     {
         return invoke(targetnamereturnTypeparameterTypes);
     }
 
     public static InstructionNode invokeStatic(ParameterizedType targetString nameParameterizedType returnTypeParameterizedType... parameterTypes)
     {
         return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
     }
 
     public static InstructionNode invokeStatic(ParameterizedType targetString nameParameterizedType returnTypeIterable<ParameterizedTypeparameterTypes)
     {
         return invoke(targetnamereturnTypeparameterTypes);
     }
 
     //
     // Invoke Virtual
     //
 
     public static InstructionNode invokeVirtual(Method method)
     {
         return invoke(method);
     }
 
     public static InstructionNode invokeVirtual(MethodDefinition method)
     {
         return invoke(method);
     }
 
     public static InstructionNode invokeVirtual(Class<?> targetString nameClass<?> returnTypeClass<?>... parameterTypes)
     {
         return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
     }
    public static InstructionNode invokeVirtual(Class<?> targetString nameClass<?> returnTypeIterable<Class<?>> parameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    public static InstructionNode invokeVirtual(ParameterizedType targetString nameParameterizedType returnTypeParameterizedType... parameterTypes)
    {
        return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeVirtual(ParameterizedType targetString nameParameterizedType returnTypeIterable<ParameterizedTypeparameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    //
    // Invoke Interface
    //
    public static InstructionNode invokeInterface(Method method)
    {
        return invoke(method);
    }
    public static InstructionNode invokeInterface(MethodDefinition method)
    {
        return invoke(method);
    }
    public static InstructionNode invokeInterface(Class<?> targetString nameClass<?> returnTypeClass<?>... parameterTypes)
    {
        return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeInterface(Class<?> targetString nameClass<?> returnTypeIterable<Class<?>> parameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    public static InstructionNode invokeInterface(ParameterizedType targetString nameParameterizedType returnTypeParameterizedType... parameterTypes)
    {
        return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeInterface(ParameterizedType targetString nameParameterizedType returnTypeIterable<ParameterizedTypeparameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    //
    // Invoke Constructor
    //
    public static InstructionNode invokeConstructor(Constructor<?> constructor)
    {
        return invokeConstructor(constructor.getDeclaringClass(), constructor.getParameterTypes());
    }
    public static InstructionNode invokeConstructor(Class<?> targetClass<?>... parameterTypes)
    {
        return invokeConstructor(type(target), transform(ImmutableList.copyOf(parameterTypes), ParameterizedType::type));
    }
    public static InstructionNode invokeConstructor(Class<?> targetIterable<Class<?>> parameterTypes)
    {
        return invokeConstructor(type(target), transform(parameterTypes, ParameterizedType::type));
    }
    public static InstructionNode invokeConstructor(ParameterizedType targetParameterizedType... parameterTypes)
    {
        return invokeConstructor(target, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeConstructor(ParameterizedType targetIterable<ParameterizedTypeparameterTypes)
    {
        return invokeSpecial(target"<init>"type(void.class), parameterTypes);
    }
    //
    // Invoke Special
    //
    public static InstructionNode invokeSpecial(Method method)
    {
        return invoke(method);
    }
    public static InstructionNode invokeSpecial(MethodDefinition method)
    {
        return invoke(method);
    }
    public static InstructionNode invokeSpecial(Class<?> targetString nameClass<?> returnTypeClass<?>... parameterTypes)
    {
        return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeSpecial(Class<?> targetString nameClass<?> returnTypeIterable<Class<?>> parameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    public static InstructionNode invokeSpecial(ParameterizedType targetString nameParameterizedType returnTypeParameterizedType... parameterTypes)
    {
        return invoke(targetnamereturnType, ImmutableList.copyOf(parameterTypes));
    }
    public static InstructionNode invokeSpecial(ParameterizedType targetString nameParameterizedType returnTypeIterable<ParameterizedTypeparameterTypes)
    {
        return invoke(targetnamereturnTypeparameterTypes);
    }
    //
    // Generic
    //
    private static InstructionNode invoke(OpCode invocationTypeMethod method)
    {
        return new InvokeInstruction(invocationType,
                type(method.getDeclaringClass()),
                method.getName(),
                type(method.getReturnType()),
                transform(ImmutableList.copyOf(method.getParameterTypes()), ParameterizedType::type));
    }
    private static InstructionNode invoke(OpCode invocationTypeMethodDefinition method)
    {
        return new InvokeInstruction(invocationType,
                method.getDeclaringClass().getType(),
                method.getName(),
                method.getReturnType(),
                method.getParameterTypes());
    }
    private static InstructionNode invoke(OpCode invocationTypeParameterizedType targetString nameParameterizedType returnTypeIterable<ParameterizedTypeparameterTypes)
    {
        return new InvokeInstruction(invocationType,
                target,
                name,
                returnType,
                parameterTypes);
    }
    private static InstructionNode invoke(OpCode invocationTypeClass<?> targetString nameClass<?> returnTypeIterable<Class<?>> parameterTypes)
    {
        return new InvokeInstruction(invocationType,
                type(target),
                name,
                type(returnType),
                transform(parameterTypes, ParameterizedType::type));
    }
    //
    // Invoke Dynamic
    //
    public static InstructionNode invokeDynamic(String name,
            ParameterizedType returnType,
            Iterable<ParameterizedTypeparameterTypes,
            Method bootstrapMethod,
            Iterable<ObjectbootstrapArguments)
    {
        return new InvokeDynamicInstruction(name,
                returnType,
                parameterTypes,
                bootstrapMethod,
                ImmutableList.copyOf(bootstrapArguments));
    }
    public static InstructionNode invokeDynamic(String name,
            ParameterizedType returnType,
            Iterable<ParameterizedTypeparameterTypes,
            Method bootstrapMethod,
            Object... bootstrapArguments)
    {
        return new InvokeDynamicInstruction(name,
                returnType,
                parameterTypes,
                bootstrapMethod,
                ImmutableList.copyOf(bootstrapArguments));
    }
    public static InstructionNode invokeDynamic(String name,
            MethodType methodType,
            Method bootstrapMethod,
            Iterable<ObjectbootstrapArguments)
    {
        return new InvokeDynamicInstruction(name,
                type(methodType.returnType()),
                transform(methodType.parameterList(), ParameterizedType::type),
                bootstrapMethod,
                ImmutableList.copyOf(bootstrapArguments));
    }
    public static InstructionNode invokeDynamic(String name,
            MethodType methodType,
            Method bootstrapMethod,
            Object... bootstrapArguments)
    {
        return new InvokeDynamicInstruction(name,
                type(methodType.returnType()),
                transform(methodType.parameterList(), ParameterizedType::type),
                bootstrapMethod,
                ImmutableList.copyOf(bootstrapArguments));
    }
    private final OpCode opCode;
    private final ParameterizedType target;
    private final String name;
    private final ParameterizedType returnType;
    private final List<ParameterizedTypeparameterTypes;
    public InvokeInstruction(OpCode opCode,
            ParameterizedType target,
            String name,
            ParameterizedType returnType,
            Iterable<ParameterizedTypeparameterTypes)
    {
        checkUnqualifiedName(name);
        this. = opCode;
        this. = target;
        this. = name;
        this. = returnType;
        this. = ImmutableList.copyOf(parameterTypes);
    }
    public OpCode getOpCode()
    {
        return ;
    }
    public ParameterizedType getTarget()
    {
        return ;
    }
    public String getName()
    {
        return ;
    }
    {
        return ;
    }
    {
        return ;
    }
    public String getMethodDescription()
    {
        return methodDescription();
    }
    @Override
    public void accept(MethodVisitor visitorMethodGenerationContext generationContext)
    {
    }
    @Override
    public List<ByteCodeNodegetChildNodes()
    {
        return ImmutableList.of();
    }
    @Override
    public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
    {
        return visitor.visitInvoke(parentthis);
    }
    public static class InvokeDynamicInstruction
            extends InvokeInstruction
    {
        private final Method bootstrapMethod;
        private final List<ObjectbootstrapArguments;
        public InvokeDynamicInstruction(String name,
                ParameterizedType returnType,
                Iterable<ParameterizedTypeparameterTypes,
                Method bootstrapMethod,
                List<ObjectbootstrapArguments)
        {
            super(nullnamereturnTypeparameterTypes);
            this. = bootstrapMethod;
            this. = ImmutableList.copyOf(bootstrapArguments);
        }
        @Override
        public void accept(MethodVisitor visitorMethodGenerationContext generationContext)
        {
            Handle bootstrapMethodHandle = new Handle(.,
                    type(.getDeclaringClass()).getClassName(),
                    .getName(),
                    methodDescription(
                            .getReturnType(),
                            .getParameterTypes()));
            visitor.visitInvokeDynamicInsn(getName(),
                    getMethodDescription(),
                    bootstrapMethodHandle,
                    .toArray(new Object[.size()]));
        }
        public Method getBootstrapMethod()
        {
            return ;
        }
        public List<ObjectgetBootstrapArguments()
        {
            return ;
        }
        @Override
        public List<ByteCodeNodegetChildNodes()
        {
            return ImmutableList.of();
        }
        @Override
        public <T> T accept(ByteCodeNode parentByteCodeVisitor<T> visitor)
        {
            return visitor.visitInvokeDynamic(parentthis);
        }
    }
    private static void checkUnqualifiedName(String name)
    {
        // JVM Specification 4.2.2 Unqualified Names
        checkNotNull(name"name is null");
        checkArgument(!name.isEmpty(), "name is empty");
        if (name.equals("<init>") || name.equals("<clinit>")) {
            return;
        }
        CharMatcher invalid = CharMatcher.anyOf(".;[/<>");
        checkArgument(invalid.matchesNoneOf(name), "invalid name: %s"name);
    }
New to GrepCode? Check out our FAQ X