View Javadoc

    1   /* Generated By:JJTree: Do not edit this line. ASTMethodPattern.java */
    2   package org.codehaus.aspectwerkz.expression.ast;
    3
    4   import org.codehaus.aspectwerkz.expression.SubtypePatternType;
    5   import org.codehaus.aspectwerkz.expression.regexp.NamePattern;
    6   import org.codehaus.aspectwerkz.expression.regexp.Pattern;
    7   import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
    8
    9   import java.util.ArrayList;
    10  import java.util.List;
    11
    12  public class ASTMethodPattern extends SimpleNode {
    13      private TypePattern m_returnTypePattern;
    14
    15      private TypePattern m_declaringTypePattern;
    16
    17      private NamePattern m_methodNamePattern;
    18
    19      private List m_modifiers = new ArrayList();
    20
    21      public ASTMethodPattern(int id) {
    22          super(id);
    23      }
    24
    25      public ASTMethodPattern(ExpressionParser p, int id) {
    26          super(p, id);
    27      }
    28
    29      public Object jjtAccept(ExpressionParserVisitor visitor, Object data) {
    30          return visitor.visit(this, data);
    31      }
    32
    33      public void addModifier(String modifier) {
    34          m_modifiers.add(modifier);
    35      }
    36
    37      public void setReturnTypePattern(String pattern) {
    38          if (pattern.endsWith("+")) {
    39              pattern = pattern.substring(0, pattern.length() - 1);
    40              m_returnTypePattern = Pattern.compileTypePattern(pattern, SubtypePatternType.MATCH_ON_ALL_METHODS);
    41          } else if (pattern.endsWith("#")) {
    42              pattern = pattern.substring(0, pattern.length() - 1);
    43              m_returnTypePattern = Pattern.compileTypePattern(
    44                      pattern,
    45                      SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY
    46              );
    47          } else {
    48              m_returnTypePattern = Pattern.compileTypePattern(pattern, SubtypePatternType.NOT_HIERARCHICAL);
    49          }
    50      }
    51
    52      public void setFullNamePattern(final String pattern) throws ParseException {
    53          int index = pattern.lastIndexOf('.');
    54          String classPattern = null;
    55          //Aw-112 support for "method(..)" and "com..*(..)"
    56          if (index > 0) {
    57              classPattern = pattern.substring(0, index);
    58              if (classPattern.endsWith(".")) {
    59                  classPattern += ".*";
    60              }
    61          } else {
    62              // unspecified classPattern like "method(..)"
    63              classPattern = "*..*";
    64          }
    65          if (classPattern.endsWith("+")) {
    66              classPattern = classPattern.substring(0, classPattern.length() - 1);
    67              m_declaringTypePattern = Pattern.compileTypePattern(classPattern, SubtypePatternType.MATCH_ON_ALL_METHODS);
    68          } else if (classPattern.endsWith("#")) {
    69              classPattern = classPattern.substring(0, classPattern.length() - 1);
    70              m_declaringTypePattern = Pattern.compileTypePattern(
    71                      classPattern,
    72                      SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY
    73              );
    74          } else {
    75              m_declaringTypePattern = Pattern.compileTypePattern(classPattern, SubtypePatternType.NOT_HIERARCHICAL);
    76          }
    77          String methodNamePattern = pattern.substring(index + 1, pattern.length());
    78          m_methodNamePattern = Pattern.compileNamePattern(methodNamePattern);
    79          if ("new".equals(methodNamePattern)) {
    80              throw new ParseException("Using a constructor pattern with an explicit return type is not allowed");
    81          }
    82      }
    83
    84      public TypePattern getReturnTypePattern() {
    85          return m_returnTypePattern;
    86      }
    87
    88      public TypePattern getDeclaringTypePattern() {
    89          return m_declaringTypePattern;
    90      }
    91
    92      public NamePattern getMethodNamePattern() {
    93          return m_methodNamePattern;
    94      }
    95
    96      public List getModifiers() {
    97          return m_modifiers;
    98      }
    99  }