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