001 /***************************************************************************** 002 * Copyright (c) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 *****************************************************************************/ 009 package org.picocontainer.injectors; 010 011 import org.picocontainer.NameBinding; 012 013 import java.lang.reflect.AccessibleObject; 014 import java.lang.reflect.Constructor; 015 import java.lang.reflect.Method; 016 import java.lang.reflect.Member; 017 018 import com.thoughtworks.paranamer.CachingParanamer; 019 import com.thoughtworks.paranamer.Paranamer; 020 021 public class ParameterNameBinding implements NameBinding { 022 private final AccessibleObject member; 023 private final int index; 024 private final Paranamer paranamer; 025 026 private String name; 027 028 public ParameterNameBinding(Paranamer paranamer, AccessibleObject member, int index) { 029 this.member = member; 030 this.paranamer = paranamer; 031 this.index = index; 032 } 033 034 public String getName() { 035 if (name != null) { 036 return name; 037 } 038 String[] strings = paranamer.lookupParameterNames(member, false); 039 name = strings.length == 0 ? "" : strings[index]; 040 return name; 041 } 042 } 043