001: /* Generated By:JJTree: Do not edit this line. ASTMethodPattern.java */
002: package org.codehaus.aspectwerkz.expression.ast;
003:
004: import org.codehaus.aspectwerkz.expression.SubtypePatternType;
005: import org.codehaus.aspectwerkz.expression.regexp.NamePattern;
006: import org.codehaus.aspectwerkz.expression.regexp.Pattern;
007: import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
008:
009: import java.util.ArrayList;
010: import java.util.List;
011:
012: public class ASTMethodPattern extends SimpleNode {
013: private TypePattern m_returnTypePattern;
014:
015: private TypePattern m_declaringTypePattern;
016:
017: private NamePattern m_methodNamePattern;
018:
019: private List m_modifiers = new ArrayList();
020:
021: public ASTMethodPattern(int id) {
022: super (id);
023: }
024:
025: public ASTMethodPattern(ExpressionParser p, int id) {
026: super (p, id);
027: }
028:
029: public Object jjtAccept(ExpressionParserVisitor visitor, Object data) {
030: return visitor.visit(this , data);
031: }
032:
033: public void addModifier(String modifier) {
034: m_modifiers.add(modifier);
035: }
036:
037: public void setReturnTypePattern(String pattern) {
038: if (pattern.endsWith("+")) {
039: pattern = pattern.substring(0, pattern.length() - 1);
040: m_returnTypePattern = Pattern.compileTypePattern(pattern,
041: SubtypePatternType.MATCH_ON_ALL_METHODS);
042: } else if (pattern.endsWith("#")) {
043: pattern = pattern.substring(0, pattern.length() - 1);
044: m_returnTypePattern = Pattern.compileTypePattern(pattern,
045: SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY);
046: } else {
047: m_returnTypePattern = Pattern.compileTypePattern(pattern,
048: SubtypePatternType.NOT_HIERARCHICAL);
049: }
050: }
051:
052: public void setFullNamePattern(final String pattern)
053: throws ParseException {
054: int index = pattern.lastIndexOf('.');
055: String classPattern = null;
056: //Aw-112 support for "method(..)" and "com..*(..)"
057: if (index > 0) {
058: classPattern = pattern.substring(0, index);
059: if (classPattern.endsWith(".")) {
060: classPattern += ".*";
061: }
062: } else {
063: // unspecified classPattern like "method(..)"
064: classPattern = "*..*";
065: }
066: if (classPattern.endsWith("+")) {
067: classPattern = classPattern.substring(0, classPattern
068: .length() - 1);
069: m_declaringTypePattern = Pattern.compileTypePattern(
070: classPattern,
071: SubtypePatternType.MATCH_ON_ALL_METHODS);
072: } else if (classPattern.endsWith("#")) {
073: classPattern = classPattern.substring(0, classPattern
074: .length() - 1);
075: m_declaringTypePattern = Pattern.compileTypePattern(
076: classPattern,
077: SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY);
078: } else {
079: m_declaringTypePattern = Pattern.compileTypePattern(
080: classPattern, SubtypePatternType.NOT_HIERARCHICAL);
081: }
082: String methodNamePattern = pattern.substring(index + 1, pattern
083: .length());
084: m_methodNamePattern = Pattern
085: .compileNamePattern(methodNamePattern);
086: if ("new".equals(methodNamePattern)) {
087: throw new ParseException(
088: "Using a constructor pattern with an explicit return type is not allowed");
089: }
090: }
091:
092: public TypePattern getReturnTypePattern() {
093: return m_returnTypePattern;
094: }
095:
096: public TypePattern getDeclaringTypePattern() {
097: return m_declaringTypePattern;
098: }
099:
100: public NamePattern getMethodNamePattern() {
101: return m_methodNamePattern;
102: }
103:
104: public List getModifiers() {
105: return m_modifiers;
106: }
107: }
|