KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > transform > inlining > compiler > CompilationInfo


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.transform.inlining.compiler;
5
6 import com.tc.aspectwerkz.joinpoint.management.AdviceInfoContainer;
7 import com.tc.aspectwerkz.transform.TransformationConstants;
8 import com.tc.aspectwerkz.transform.inlining.EmittedJoinPoint;
9 import com.tc.aspectwerkz.util.Strings;
10 import com.tc.aspectwerkz.reflect.ClassInfo;
11
12 /**
13  * Info needed for the compilation of the join point, holds both the initial model and the latest redefined model.
14  *
15  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
16  */

17 public final class CompilationInfo {
18   private final Model m_initialModel;
19   private Model m_redefinedModel;
20   private int m_redefinitionCounter = 0;
21
22   public CompilationInfo(final Model initialModel) {
23     m_initialModel = initialModel;
24   }
25
26   public Model getInitialModel() {
27     return m_initialModel;
28   }
29
30   public Model getRedefinedModel() {
31     return m_redefinedModel;
32   }
33
34   public void setRedefinedModel(final Model redefinedModel) {
35     m_redefinedModel = redefinedModel;
36   }
37
38   public int getRedefinitionCounter() {
39     return m_redefinitionCounter;
40   }
41
42   public void incrementRedefinitionCounter() {
43     m_redefinitionCounter += 1;
44   }
45
46   public boolean equals(Object JavaDoc o) {
47     if (this == o) {
48       return true;
49     }
50     if (!(o instanceof CompilationInfo)) {
51       return false;
52     }
53
54     final CompilationInfo compilationInfo = (CompilationInfo) o;
55
56     if (m_redefinitionCounter != compilationInfo.m_redefinitionCounter) {
57       return false;
58     }
59     if (m_initialModel != null ?
60             !m_initialModel.equals(compilationInfo.m_initialModel) :
61             compilationInfo.m_initialModel != null) {
62       return false;
63     }
64     if (m_redefinedModel != null ?
65             !m_redefinedModel.equals(compilationInfo.m_redefinedModel) :
66             compilationInfo.m_redefinedModel != null) {
67       return false;
68     }
69
70     return true;
71   }
72
73   public int hashCode() {
74     int result;
75     result = (m_initialModel != null ? m_initialModel.hashCode() : 0);
76     result = 29 * result + (m_redefinedModel != null ? m_redefinedModel.hashCode() : 0);
77     result = 29 * result + m_redefinitionCounter;
78     return result;
79   }
80
81   /**
82    * Represents the information needed to compile one joinpoint at a given time
83    *
84    * @author <a HREF="mailto:jboner@codehaus.org">Jonas Bonér </a>
85    */

86   public final static class Model {
87     private final String JavaDoc m_joinPointClassName;
88     private final EmittedJoinPoint m_emittedJoinPoint;
89     private final AdviceInfoContainer m_adviceInfoContainer;
90     private final ClassInfo m_thisClassInfo;
91
92     public Model(final EmittedJoinPoint emittedJoinPoint,
93                  final AdviceInfoContainer adviceInfoContainer,
94                  final ClassInfo thisClassInfo) {
95       m_emittedJoinPoint = emittedJoinPoint;
96       m_adviceInfoContainer = adviceInfoContainer;
97       m_joinPointClassName = m_emittedJoinPoint.getJoinPointClassName();
98       m_thisClassInfo = thisClassInfo;
99     }
100
101     public Model(final EmittedJoinPoint emittedJoinPoint,
102                  final AdviceInfoContainer adviceInfoContainer,
103                  final int redefinitionCounter,
104                  final ClassInfo thisClassInfo) {
105       m_emittedJoinPoint = emittedJoinPoint;
106       m_adviceInfoContainer = adviceInfoContainer;
107       m_joinPointClassName = Strings.replaceSubString(
108               m_emittedJoinPoint.getJoinPointClassName(),
109               TransformationConstants.JOIN_POINT_CLASS_SUFFIX,
110               new StringBuffer JavaDoc().append('_').append(redefinitionCounter).
111                       append(TransformationConstants.JOIN_POINT_CLASS_SUFFIX).toString()
112       );
113       m_thisClassInfo = thisClassInfo;
114     }
115
116     public String JavaDoc getJoinPointClassName() {
117       return m_joinPointClassName;
118     }
119
120     public EmittedJoinPoint getEmittedJoinPoint() {
121       return m_emittedJoinPoint;
122     }
123
124     public AdviceInfoContainer getAdviceInfoContainer() {
125       return m_adviceInfoContainer;
126     }
127
128     /**
129      * JoinPoint this class class info (caller)
130      *
131      * @return
132      */

133     public ClassInfo getThisClassInfo() {
134       return m_thisClassInfo;
135     }
136
137     public int hashCode() {
138       return m_emittedJoinPoint.hashCode();
139     }
140
141     public boolean equals(Object JavaDoc o) {
142       return ((Model) o).m_emittedJoinPoint == m_emittedJoinPoint;
143     }
144   }
145 }
Popular Tags