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