01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2006-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.guard;
13:
14: import java.lang.reflect.Constructor;
15: import java.lang.reflect.Method;
16:
17: import net.sf.oval.exception.ReflectionException;
18:
19: import com.thoughtworks.paranamer.CachingParanamer;
20: import com.thoughtworks.paranamer.Paranamer;
21:
22: /**
23: * This implementation that uses com.thoughtworks.paranamer.Paranamer (ttp://paranamer.codehaus.org/)
24: * to determinethe names of paramater names as a fallback the results of a
25: * ParameterNameResolverEnumerationImpl are returned
26: *
27: * @author Sebastian Thomschke
28: */
29: public class ParameterNameResolverParanamerImpl implements
30: ParameterNameResolver {
31: private static final ParameterNameResolver fallback = new ParameterNameResolverEnumerationImpl();
32:
33: private final Paranamer paranamer;
34:
35: public ParameterNameResolverParanamerImpl() {
36: paranamer = new CachingParanamer();
37: }
38:
39: public ParameterNameResolverParanamerImpl(final Paranamer paranamer) {
40: this .paranamer = paranamer;
41: }
42:
43: public String[] getParameterNames(final Constructor constructor)
44: throws ReflectionException {
45: return fallback.getParameterNames(constructor);
46: }
47:
48: public String[] getParameterNames(final Method method)
49: throws ReflectionException {
50: final String[] parameterNames = paranamer
51: .lookupParameterNames(method);
52:
53: if (parameterNames == null)
54: return fallback.getParameterNames(method);
55:
56: return parameterNames;
57: }
58: }
|