FixedValueGenerator.java revision 674060f01e9090cd21b3c5656cc3204912ad17a6
1/* 2 * Copyright 2003,2004 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package org.mockito.cglib.proxy; 17 18import java.util.*; 19 20import org.mockito.asm.Type; 21import org.mockito.cglib.core.*; 22 23class FixedValueGenerator implements CallbackGenerator { 24 public static final FixedValueGenerator INSTANCE = new FixedValueGenerator(); 25 private static final Type FIXED_VALUE = 26 TypeUtils.parseType("org.mockito.cglib.proxy.FixedValue"); 27 private static final Signature LOAD_OBJECT = 28 TypeUtils.parseSignature("Object loadObject()"); 29 30 public void generate(ClassEmitter ce, Context context, List methods) { 31 for (Iterator it = methods.iterator(); it.hasNext();) { 32 MethodInfo method = (MethodInfo)it.next(); 33 CodeEmitter e = context.beginMethod(ce, method); 34 context.emitCallback(e, context.getIndex(method)); 35 e.invoke_interface(FIXED_VALUE, LOAD_OBJECT); 36 e.unbox_or_zero(e.getReturnType()); 37 e.return_value(); 38 e.end_method(); 39 } 40 } 41 42 public void generateStatic(CodeEmitter e, Context context, List methods) { } 43} 44