View Javadoc

    1   /***************************************************************************************
    2    * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
    3    * http://aspectwerkz.codehaus.org                                                    *
    4    * ---------------------------------------------------------------------------------- *
    5    * The software in this package is published under the terms of the LGPL license      *
    6    * a copy of which has been included with this distribution in the license.txt file.  *
    7    **************************************************************************************/
    8   package org.codehaus.aspectwerkz.transform.inlining.compiler;
    9
    10  import org.codehaus.aspectwerkz.joinpoint.management.AdviceInfoContainer;
    11  import org.codehaus.aspectwerkz.util.Strings;
    12  import org.codehaus.aspectwerkz.transform.TransformationConstants;
    13  import org.codehaus.aspectwerkz.transform.inlining.EmittedJoinPoint;
    14  import org.codehaus.aspectwerkz.reflect.ClassInfo;
    15
    16  /***
    17   * Info needed for the compilation of the join point, holds both the initial model and the latest redefined model.
    18   *
    19   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
    20   */
    21  public final class CompilationInfo {
    22      private final Model m_initialModel;
    23      private Model m_redefinedModel;
    24      private int m_redefinitionCounter = 0;
    25
    26      public CompilationInfo(final Model initialModel) {
    27          m_initialModel = initialModel;
    28      }
    29
    30      public Model getInitialModel() {
    31          return m_initialModel;
    32      }
    33
    34      public Model getRedefinedModel() {
    35          return m_redefinedModel;
    36      }
    37
    38      public void setRedefinedModel(final Model redefinedModel) {
    39          m_redefinedModel = redefinedModel;
    40      }
    41
    42      public int getRedefinitionCounter() {
    43          return m_redefinitionCounter;
    44      }
    45
    46      public void incrementRedefinitionCounter() {
    47          m_redefinitionCounter += 1;
    48      }
    49
    50      public boolean equals(Object o) {
    51          if (this == o) {
    52              return true;
    53          }
    54          if (!(o instanceof CompilationInfo)) {
    55              return false;
    56          }
    57
    58          final CompilationInfo compilationInfo = (CompilationInfo) o;
    59
    60          if (m_redefinitionCounter != compilationInfo.m_redefinitionCounter) {
    61              return false;
    62          }
    63          if (m_initialModel != null ?
    64              !m_initialModel.equals(compilationInfo.m_initialModel) :
    65              compilationInfo.m_initialModel != null) {
    66              return false;
    67          }
    68          if (m_redefinedModel != null ?
    69              !m_redefinedModel.equals(compilationInfo.m_redefinedModel) :
    70              compilationInfo.m_redefinedModel != null) {
    71              return false;
    72          }
    73
    74          return true;
    75      }
    76
    77      public int hashCode() {
    78          int result;
    79          result = (m_initialModel != null ? m_initialModel.hashCode() : 0);
    80          result = 29 * result + (m_redefinedModel != null ? m_redefinedModel.hashCode() : 0);
    81          result = 29 * result + m_redefinitionCounter;
    82          return result;
    83      }
    84
    85      /***
    86       * Represents the information needed to compile one joinpoint at a given time
    87       *
    88       * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
    89       */
    90      public final static class Model {
    91          private final String m_joinPointClassName;
    92          private final EmittedJoinPoint m_emittedJoinPoint;
    93          private final AdviceInfoContainer m_adviceInfoContainer;
    94          private final ClassInfo m_thisClassInfo;
    95
    96          public Model(final EmittedJoinPoint emittedJoinPoint,
    97                       final AdviceInfoContainer adviceInfoContainer,
    98                       final ClassInfo thisClassInfo) {
    99              m_emittedJoinPoint = emittedJoinPoint;
    100             m_adviceInfoContainer = adviceInfoContainer;
    101             m_joinPointClassName = m_emittedJoinPoint.getJoinPointClassName();
    102             m_thisClassInfo = thisClassInfo;
    103         }
    104
    105         public Model(final EmittedJoinPoint emittedJoinPoint,
    106                      final AdviceInfoContainer adviceInfoContainer,
    107                      final int redefinitionCounter,
    108                      final ClassInfo thisClassInfo) {
    109             m_emittedJoinPoint = emittedJoinPoint;
    110             m_adviceInfoContainer = adviceInfoContainer;
    111             m_joinPointClassName = Strings.replaceSubString(
    112                     m_emittedJoinPoint.getJoinPointClassName(),
    113                     TransformationConstants.JOIN_POINT_CLASS_SUFFIX,
    114                     new StringBuffer().append('_').append(redefinitionCounter).
    115                     append(TransformationConstants.JOIN_POINT_CLASS_SUFFIX).toString()
    116             );
    117             m_thisClassInfo = thisClassInfo;
    118         }
    119
    120         public String getJoinPointClassName() {
    121             return m_joinPointClassName;
    122         }
    123
    124         public EmittedJoinPoint getEmittedJoinPoint() {
    125             return m_emittedJoinPoint;
    126         }
    127
    128         public AdviceInfoContainer getAdviceInfoContainer() {
    129             return m_adviceInfoContainer;
    130         }
    131
    132         /***
    133          * JoinPoint this class class info (caller)
    134          * @return
    135          */
    136         public ClassInfo getThisClassInfo() {
    137             return m_thisClassInfo;
    138         }
    139
    140         public int hashCode() {
    141             return m_emittedJoinPoint.hashCode();
    142         }
    143
    144         public boolean equals(Object o) {
    145             return ((Model) o).m_emittedJoinPoint == m_emittedJoinPoint;
    146         }
    147     }
    148 }