01: //
02: // This file is part of the prose package.
03: //
04: // The contents of this file are subject to the Mozilla Public License
05: // Version 1.1 (the "License"); you may not use this file except in
06: // compliance with the License. You may obtain a copy of the License at
07: // http://www.mozilla.org/MPL/
08: //
09: // Software distributed under the License is distributed on an "AS IS" basis,
10: // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11: // for the specific language governing rights and limitations under the
12: // License.
13: //
14: // The Original Code is prose.
15: //
16: // The Initial Developer of the Original Code is Andrei Popovici. Portions
17: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
18: // All Rights Reserved.
19: //
20: // Contributor(s):
21: package ch.ethz.prose.crosscut;
22:
23: import java.io.Serializable;
24: import java.lang.reflect.Field;
25:
26: class SetGetSignaturePattern extends SignaturePattern implements
27: Serializable {
28: private static final long serialVersionUID = 3256438127408394296L;
29: private final AbstractCrosscut crosscut;
30:
31: /**
32: * Create an <code>UserDefinedMCSignature</code> that encapsulates the
33: * method to be executed.
34: * <p>
35: * Postcondition: methodObj is properly initialized
36: * <p>
37: * Implementation:
38: * <ul>
39: * <li> if <code>crsc</code> (i.e., a subclass of FunctionalCrossscut)
40: * <em>defines</em> exaclty one method, this method is
41: * the advice method.
42: *
43: * <li> If <code>crsc</code> defines several methods, the one whose
44: * name corresponds to <code>crsc.ADVICE_NAME()</code> is the advice method
45: * </ul>
46: * @throws MissingInformationExeception crsc does not define a method at all,
47: * or if it defines several, none of them matches <code>crsc.ADVICE_NAME()</code>.
48: *
49: */
50: protected SetGetSignaturePattern(SetCut crsc)
51: throws MissingInformationException {
52: this .crosscut = crsc;
53: initFromMethod(crsc.getClass(), "SET_ARGS", ANY.class,
54: SetCut.class);
55: }
56:
57: protected SetGetSignaturePattern(GetCut crsc)
58: throws MissingInformationException {
59: this .crosscut = crsc;
60: initFromMethod(crsc.getClass(), "GET_ARGS", ANY.class,
61: GetCut.class);
62: }
63:
64: /** Returns <code>true</code> if the signature of
65: * <code>methoObj</code>, seen as a pattern,
66: * matches the signature (the parameter types) for
67: * <code>actualMehtod</code>.
68: */
69: protected boolean matchesOperationOnField(Field field) {
70: if (signatureCathegory == SIGNATURE__EMPTY)
71: return true;
72: else {
73: return getLength() == 2
74: && // must have the format (Receiver,TYPE)
75: matchesTarget(field.getDeclaringClass())
76: && isAssignable(field.getType(), signature[1]);
77: }
78: }
79:
80: public String toString() {
81: return methodObj.toString();
82: }
83: }
|