01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-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.context;
13:
14: import java.lang.reflect.Method;
15:
16: import net.sf.oval.internal.MessageResolverHolder;
17: import net.sf.oval.internal.util.SerializableMethod;
18: import net.sf.oval.internal.util.StringUtils;
19:
20: /**
21: * @author Sebastian Thomschke
22: */
23: public class MethodParameterContext extends OValContext {
24: private static final long serialVersionUID = 1L;
25:
26: private final SerializableMethod method;
27: private final int parameterIndex;
28: private final String parameterName;
29:
30: public MethodParameterContext(final Method method,
31: final int parameterIndex, final String parameterName) {
32: this .method = SerializableMethod.getInstance(method);
33: this .parameterIndex = parameterIndex;
34: this .parameterName = parameterName == null ? "param"
35: + parameterIndex : parameterName;
36: }
37:
38: /**
39: * @return Returns the method.
40: */
41: public Method getMethod() {
42: return method.getMethod();
43: }
44:
45: /**
46: * @return Returns the parameterIndex.
47: */
48: public int getParameterIndex() {
49: return parameterIndex;
50: }
51:
52: /**
53: * @return the parameterName
54: */
55: public String getParameterName() {
56: return parameterName;
57: }
58:
59: @Override
60: public String toString() {
61: return method.getDeclaringClass().getName()
62: + "."
63: + method.getName()
64: + "("
65: + StringUtils.implode(method.getParameterTypes(), ",")
66: + ") "
67: + MessageResolverHolder
68: .getMessageResolver()
69: .getMessage(
70: "net.sf.oval.context.MethodParameterContext.parameter")
71: + " "
72: + parameterIndex
73: + (parameterName == null || parameterName.length() == 0 ? ""
74: : " (" + parameterName + ")");
75: }
76: }
|