001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package org.codehaus.aspectwerkz.transform.inlining;
008:
009: import org.codehaus.aspectwerkz.joinpoint.management.JoinPointType;
010: import org.codehaus.aspectwerkz.transform.Context;
011: import org.objectweb.asm.Label;
012:
013: /**
014: * A structure that keeps required information needed to regenerate a JIT joinpoint. The weaver emits this
015: * information so that we can add initalization code to the weaved class. Note that EmittedJP are really Emitted -
016: * and can be a subset of actual JP (f.e. call, where information is lost in between each weave phase).
017: *
018: * FIXME equals and hashcode are wrong if 2 JP in same withincode - should depend on line number f.e. but that won't
019: * even be enough. Muts have a static variable and trust that creation of EmittedJP is ok.
020: * Check where those are used in a map for hashcode / equals to be used.
021: *
022: *
023: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
024: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
025: */
026: public final class EmittedJoinPoint {
027:
028: public final static Label NO_LINE_NUMBER = new Label();
029:
030: private final int joinPointType;
031: private final String callerClassName;
032: private final String callerMethodName;
033: private final String callerMethodDesc;
034: private final int callerMethodModifiers;
035: private final String calleeClassName;
036: private final String calleeMemberName;
037: private final String calleeMemberDesc;
038: private final int calleeMemberModifiers;
039: private final int joinPointHash;
040: private final String joinPointClassName;
041: private final Label lineNumberLabel;
042:
043: /**
044: * Line number for call / get / set / handler joinpoint
045: * The lineNumber is 0 unless available and resolveLineNumber(Context) has been called.
046: */
047: private int lineNumber = 0;
048:
049: /**
050: * Creates a new instance.
051: *
052: * @param joinPointType
053: * @param callerClassName
054: * @param callerMethodName
055: * @param callerMethodDesc
056: * @param callerMethodModifiers
057: * @param calleeClassName
058: * @param calleeMemberName
059: * @param calleeMemberDesc
060: * @param calleeMemberModifiers
061: * @param joinPointHash
062: * @param joinPointClassName
063: * @param lineNumberLabel
064: */
065: public EmittedJoinPoint(final int joinPointType,
066: final String callerClassName,
067: final String callerMethodName,
068: final String callerMethodDesc,
069: final int callerMethodModifiers,
070: final String calleeClassName,
071: final String calleeMemberName,
072: final String calleeMemberDesc,
073: final int calleeMemberModifiers, final int joinPointHash,
074: final String joinPointClassName, final Label lineNumberLabel) {
075: this .joinPointType = joinPointType;
076: this .callerClassName = callerClassName;
077: this .callerMethodName = callerMethodName;
078: this .callerMethodDesc = callerMethodDesc;
079: this .callerMethodModifiers = callerMethodModifiers;
080: this .calleeClassName = calleeClassName;
081: this .calleeMemberName = calleeMemberName;
082: this .calleeMemberDesc = calleeMemberDesc;
083: this .calleeMemberModifiers = calleeMemberModifiers;
084: this .joinPointHash = joinPointHash;
085: this .joinPointClassName = joinPointClassName;
086: this .lineNumberLabel = lineNumberLabel;
087: }
088:
089: /**
090: * Creates a new instance.
091: *
092: * @param joinPointType
093: * @param callerClassName
094: * @param callerMethodName
095: * @param callerMethodDesc
096: * @param callerMethodModifiers
097: * @param calleeClassName
098: * @param calleeMemberName
099: * @param calleeMemberDesc
100: * @param calleeMemberModifiers
101: * @param joinPointHash
102: * @param joinPointClassName
103: */
104: public EmittedJoinPoint(final int joinPointType,
105: final String callerClassName,
106: final String callerMethodName,
107: final String callerMethodDesc,
108: final int callerMethodModifiers,
109: final String calleeClassName,
110: final String calleeMemberName,
111: final String calleeMemberDesc,
112: final int calleeMemberModifiers, final int joinPointHash,
113: final String joinPointClassName) {
114: this (joinPointType, callerClassName, callerMethodName,
115: callerMethodDesc, callerMethodModifiers,
116: calleeClassName, calleeMemberName, calleeMemberDesc,
117: calleeMemberModifiers, joinPointHash,
118: joinPointClassName, NO_LINE_NUMBER);
119: }
120:
121: public int getJoinPointType() {
122: return joinPointType;
123: }
124:
125: public String getCallerClassName() {
126: return callerClassName;
127: }
128:
129: public String getCallerMethodName() {
130: return callerMethodName;
131: }
132:
133: public String getCallerMethodDesc() {
134: return callerMethodDesc;
135: }
136:
137: public int getCallerMethodModifiers() {
138: return callerMethodModifiers;
139: }
140:
141: public String getCalleeClassName() {
142: return calleeClassName;
143: }
144:
145: public String getCalleeMemberName() {
146: return calleeMemberName;
147: }
148:
149: public String getCalleeMemberDesc() {
150: return calleeMemberDesc;
151: }
152:
153: public int getCalleeMemberModifiers() {
154: return calleeMemberModifiers;
155: }
156:
157: public int getJoinPointHash() {
158: return joinPointHash;
159: }
160:
161: public String getJoinPointClassName() {
162: return joinPointClassName;
163: }
164:
165: public int getLineNumber() {
166: return lineNumber;
167: }
168:
169: public void resolveLineNumber(Context context) {
170: lineNumber = context.resolveLineNumberInfo(lineNumberLabel);
171: }
172:
173: public boolean equals(Object o) {
174: if (this == o) {
175: return true;
176: }
177: if (!(o instanceof EmittedJoinPoint)) {
178: return false;
179: }
180:
181: final EmittedJoinPoint emittedJoinPoint = (EmittedJoinPoint) o;
182:
183: if (calleeMemberModifiers != emittedJoinPoint.calleeMemberModifiers) {
184: return false;
185: }
186: if (callerMethodModifiers != emittedJoinPoint.callerMethodModifiers) {
187: return false;
188: }
189: if (joinPointHash != emittedJoinPoint.joinPointHash) {
190: return false;
191: }
192: if (joinPointType != emittedJoinPoint.joinPointType) {
193: return false;
194: }
195: if (!calleeClassName.equals(emittedJoinPoint.calleeClassName)) {
196: return false;
197: }
198: if (!calleeMemberDesc.equals(emittedJoinPoint.calleeMemberDesc)) {
199: return false;
200: }
201: if (!calleeMemberName.equals(emittedJoinPoint.calleeMemberName)) {
202: return false;
203: }
204: if (!callerClassName.equals(emittedJoinPoint.callerClassName)) {
205: return false;
206: }
207: if (!callerMethodDesc.equals(emittedJoinPoint.callerMethodDesc)) {
208: return false;
209: }
210: if (!callerMethodName.equals(emittedJoinPoint.callerMethodName)) {
211: return false;
212: }
213: if (!joinPointClassName
214: .equals(emittedJoinPoint.joinPointClassName)) {
215: return false;
216: }
217:
218: return true;
219: }
220:
221: public int hashCode() {
222: int result;
223: result = joinPointType;
224: result = 29 * result + callerClassName.hashCode();
225: result = 29 * result + callerMethodName.hashCode();
226: result = 29 * result + callerMethodDesc.hashCode();
227: result = 29 * result + callerMethodModifiers;
228: result = 29 * result + calleeClassName.hashCode();
229: result = 29 * result + calleeMemberName.hashCode();
230: result = 29 * result + calleeMemberDesc.hashCode();
231: result = 29 * result + calleeMemberModifiers;
232: result = 29 * result + joinPointHash;
233: result = 29 * result + joinPointClassName.hashCode();
234: return result;
235: }
236:
237: public String toString() {
238: StringBuffer sb = new StringBuffer();
239: sb.append(JoinPointType.fromInt(getJoinPointType()).toString());
240: sb.append(" , caller ");
241: sb.append(getCallerClassName());
242: sb.append('.').append(getCallerMethodName());
243: sb.append(getCallerMethodDesc());
244: sb.append(" , callee ");
245: sb.append(getCalleeClassName());
246: sb.append('.').append(getCalleeMemberName());
247: sb.append(' ').append(getCalleeMemberDesc());
248: sb.append(" , line ").append(getLineNumber());
249: return sb.toString();
250: }
251: }
|