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