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.compiler;
005:
006: import com.tc.aspectwerkz.joinpoint.management.AdviceInfoContainer;
007: import com.tc.aspectwerkz.transform.TransformationConstants;
008: import com.tc.aspectwerkz.transform.inlining.EmittedJoinPoint;
009: import com.tc.aspectwerkz.util.Strings;
010: import com.tc.aspectwerkz.reflect.ClassInfo;
011:
012: /**
013: * Info needed for the compilation of the join point, holds both the initial model and the latest redefined model.
014: *
015: * @author <a href="mailto:jboner@codehaus.org">Jonas Bonr </a>
016: */
017: public final class CompilationInfo {
018: private final Model m_initialModel;
019: private Model m_redefinedModel;
020: private int m_redefinitionCounter = 0;
021:
022: public CompilationInfo(final Model initialModel) {
023: m_initialModel = initialModel;
024: }
025:
026: public Model getInitialModel() {
027: return m_initialModel;
028: }
029:
030: public Model getRedefinedModel() {
031: return m_redefinedModel;
032: }
033:
034: public void setRedefinedModel(final Model redefinedModel) {
035: m_redefinedModel = redefinedModel;
036: }
037:
038: public int getRedefinitionCounter() {
039: return m_redefinitionCounter;
040: }
041:
042: public void incrementRedefinitionCounter() {
043: m_redefinitionCounter += 1;
044: }
045:
046: public boolean equals(Object o) {
047: if (this == o) {
048: return true;
049: }
050: if (!(o instanceof CompilationInfo)) {
051: return false;
052: }
053:
054: final CompilationInfo compilationInfo = (CompilationInfo) o;
055:
056: if (m_redefinitionCounter != compilationInfo.m_redefinitionCounter) {
057: return false;
058: }
059: if (m_initialModel != null ? !m_initialModel
060: .equals(compilationInfo.m_initialModel)
061: : compilationInfo.m_initialModel != null) {
062: return false;
063: }
064: if (m_redefinedModel != null ? !m_redefinedModel
065: .equals(compilationInfo.m_redefinedModel)
066: : compilationInfo.m_redefinedModel != null) {
067: return false;
068: }
069:
070: return true;
071: }
072:
073: public int hashCode() {
074: int result;
075: result = (m_initialModel != null ? m_initialModel.hashCode()
076: : 0);
077: result = 29
078: * result
079: + (m_redefinedModel != null ? m_redefinedModel
080: .hashCode() : 0);
081: result = 29 * result + m_redefinitionCounter;
082: return result;
083: }
084:
085: /**
086: * Represents the information needed to compile one joinpoint at a given time
087: *
088: * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
089: */
090: public final static class Model {
091: private final String m_joinPointClassName;
092: private final EmittedJoinPoint m_emittedJoinPoint;
093: private final AdviceInfoContainer m_adviceInfoContainer;
094: private final ClassInfo m_this ClassInfo;
095:
096: public Model(final EmittedJoinPoint emittedJoinPoint,
097: final AdviceInfoContainer adviceInfoContainer,
098: final ClassInfo this ClassInfo) {
099: m_emittedJoinPoint = emittedJoinPoint;
100: m_adviceInfoContainer = adviceInfoContainer;
101: m_joinPointClassName = m_emittedJoinPoint
102: .getJoinPointClassName();
103: m_this ClassInfo = this ClassInfo;
104: }
105:
106: public Model(final EmittedJoinPoint emittedJoinPoint,
107: final AdviceInfoContainer adviceInfoContainer,
108: final int redefinitionCounter,
109: final ClassInfo this ClassInfo) {
110: m_emittedJoinPoint = emittedJoinPoint;
111: m_adviceInfoContainer = adviceInfoContainer;
112: m_joinPointClassName = Strings
113: .replaceSubString(
114: m_emittedJoinPoint.getJoinPointClassName(),
115: TransformationConstants.JOIN_POINT_CLASS_SUFFIX,
116: new StringBuffer()
117: .append('_')
118: .append(redefinitionCounter)
119: .append(
120: TransformationConstants.JOIN_POINT_CLASS_SUFFIX)
121: .toString());
122: m_this ClassInfo = this ClassInfo;
123: }
124:
125: public String getJoinPointClassName() {
126: return m_joinPointClassName;
127: }
128:
129: public EmittedJoinPoint getEmittedJoinPoint() {
130: return m_emittedJoinPoint;
131: }
132:
133: public AdviceInfoContainer getAdviceInfoContainer() {
134: return m_adviceInfoContainer;
135: }
136:
137: /**
138: * JoinPoint this class class info (caller)
139: *
140: * @return
141: */
142: public ClassInfo getThisClassInfo() {
143: return m_this ClassInfo;
144: }
145:
146: public int hashCode() {
147: return m_emittedJoinPoint.hashCode();
148: }
149:
150: public boolean equals(Object o) {
151: return ((Model) o).m_emittedJoinPoint == m_emittedJoinPoint;
152: }
153: }
154: }
|