test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/data/ParamValueExtractor.java
changeset 50243 4fac3c99487d
equal deleted inserted replaced
50242:9a87afc49148 50243:4fac3c99487d
       
     1 /*
       
     2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package vm.runtime.defmeth.shared.data;
       
    25 
       
    26 import vm.runtime.defmeth.shared.data.AbstractVisitor;
       
    27 import vm.runtime.defmeth.shared.data.method.param.*;
       
    28 import vm.runtime.defmeth.shared.executor.AbstractReflectionTest;
       
    29 
       
    30 /**
       
    31  * Extracts a value from Param object.
       
    32  * It is used when method is invoked using Reflection API
       
    33  * or through MethodHandle.invokeWithArguments.
       
    34  */
       
    35 public class ParamValueExtractor extends AbstractVisitor {
       
    36     private Object value;
       
    37     private AbstractReflectionTest methodInvokeTest;
       
    38 
       
    39     public Object value() {
       
    40         param.visit(this);
       
    41         return value;
       
    42     }
       
    43 
       
    44     private Param param;
       
    45     public ParamValueExtractor(AbstractReflectionTest methodInvokeTest, Param param) {
       
    46         this.methodInvokeTest = methodInvokeTest;
       
    47         this.param = param; }
       
    48 
       
    49     @Override public void visitParamInt(IntParam i) { value = i.value(); }
       
    50     @Override public void visitParamLong(LongParam l) { value = l.value(); }
       
    51     @Override public void visitParamFloat(FloatParam f) { value = f.value(); }
       
    52     @Override public void visitParamDouble(DoubleParam d) { value = d.value(); }
       
    53     @Override public void visitParamString(StringParam str) { value = str.value(); }
       
    54     @Override public void visitParamNull() { value = null; }
       
    55     @Override public void visitParamNewInstance(NewInstanceParam type) {
       
    56         try {
       
    57             value = methodInvokeTest.resolve(type.clazz()).newInstance();
       
    58         } catch (InstantiationException | IllegalAccessException e) {
       
    59             throw new Error(e);
       
    60         }
       
    61     }
       
    62 }