01: /*****************************************************************************
02: * Copyright (c) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: *****************************************************************************/package org.picocontainer.injectors;
09:
10: import org.picocontainer.NameBinding;
11:
12: import java.lang.reflect.AccessibleObject;
13: import java.lang.reflect.Constructor;
14: import java.lang.reflect.Method;
15:
16: import com.thoughtworks.paranamer.CachingParanamer;
17: import com.thoughtworks.paranamer.Paranamer;
18:
19: public class ParameterNameBinding implements NameBinding {
20: private final Class impl;
21: private final AccessibleObject member;
22: private final int index;
23: private final CachingParanamer paranamer;
24:
25: private String name;
26:
27: public ParameterNameBinding(CachingParanamer paranamer, Class impl,
28: AccessibleObject member, int index) {
29: this .impl = impl;
30: this .member = member;
31: this .paranamer = paranamer;
32: this .index = index;
33: }
34:
35: public String getName() {
36: if (name != null) {
37: return name;
38: }
39: String[] strings = null;
40: if (paranamer.areParameterNamesAvailable(impl, "<init>") != Paranamer.PARAMETER_NAMES_FOUND) {
41: paranamer.switchtoAsm();
42: }
43: if (member instanceof Constructor) {
44: strings = paranamer
45: .lookupParameterNames((Constructor) member);
46: } else {
47: strings = paranamer.lookupParameterNames((Method) member);
48: }
49: name = strings.length == 0 ? "" : strings[index];
50: return name;
51: }
52: }
|