1 35 package org.codehaus.groovy.runtime; 36 37 import groovy.lang.MetaMethod; 38 39 import java.lang.reflect.Modifier ; 40 41 51 public class NewInstanceMetaMethod extends MetaMethod { 52 53 private static final Class [] EMPTY_TYPE_ARRAY = {}; 54 55 private MetaMethod metaMethod; 56 private Class [] logicalParameterTypes; 57 58 public NewInstanceMetaMethod(MetaMethod metaMethod) { 59 super(metaMethod); 60 this.metaMethod = metaMethod; 61 Class [] realParameterTypes = metaMethod.getParameterTypes(); 62 int size = realParameterTypes.length; 63 if (size <= 1) { 64 logicalParameterTypes = EMPTY_TYPE_ARRAY; 65 } 66 else { 67 logicalParameterTypes = new Class [--size]; 68 System.arraycopy(realParameterTypes, 1, logicalParameterTypes, 0, size); 69 } 70 } 71 72 public Class getDeclaringClass() { 73 return getBytecodeParameterTypes()[0]; 74 } 75 76 public boolean isStatic() { 77 return false; 78 } 79 80 public int getModifiers() { 81 return super.getModifiers() ^ Modifier.STATIC; 83 } 84 85 public Class [] getParameterTypes() { 86 return logicalParameterTypes; 87 } 88 89 public Class [] getBytecodeParameterTypes() { 90 return super.getParameterTypes(); 91 } 92 93 public Object invoke(Object object, Object [] arguments) throws Exception { 94 int size = arguments.length; 96 Object [] newArguments = new Object [size + 1]; 97 newArguments[0] = object; 98 System.arraycopy(arguments, 0, newArguments, 1, size); 99 return metaMethod.invoke(null, newArguments); 100 } 101 } 102 | Popular Tags |