01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04:
05: package com.tc.aspectwerkz.expression.ast;
06:
07: import com.tc.aspectwerkz.expression.regexp.NamePattern;
08: import com.tc.aspectwerkz.expression.regexp.Pattern;
09: import com.tc.aspectwerkz.expression.regexp.TypePattern;
10: import com.tc.aspectwerkz.expression.SubtypePatternType;
11:
12: public class ASTFieldPattern extends SimpleNode {
13: private TypePattern m_fieldTypePattern;
14:
15: private TypePattern m_declaringTypePattern;
16:
17: private NamePattern m_fieldNamePattern;
18:
19: public ASTFieldPattern(int id) {
20: super (id);
21: }
22:
23: public ASTFieldPattern(ExpressionParser p, int id) {
24: super (p, id);
25: }
26:
27: public Object jjtAccept(ExpressionParserVisitor visitor, Object data) {
28: return visitor.visit(this , data);
29: }
30:
31: public void setFieldTypePattern(String pattern) {
32: if (pattern.endsWith("+")) {
33: pattern = pattern.substring(0, pattern.length() - 1);
34: m_fieldTypePattern = Pattern.compileTypePattern(pattern,
35: SubtypePatternType.MATCH_ON_ALL_METHODS);
36: } else if (pattern.endsWith("#")) {
37: pattern = pattern.substring(0, pattern.length() - 1);
38: m_fieldTypePattern = Pattern.compileTypePattern(pattern,
39: SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY);
40: } else {
41: m_fieldTypePattern = Pattern.compileTypePattern(pattern,
42: SubtypePatternType.NOT_HIERARCHICAL);
43: }
44: }
45:
46: public void setFullNamePattern(final String pattern) {
47: int index = pattern.lastIndexOf('.');
48: String classPattern = null;
49: //Aw-112 support for "field" and "com..field"
50: if (index > 0) {
51: classPattern = pattern.substring(0, index);
52: if (classPattern.endsWith(".")) {
53: classPattern += ".*";
54: }
55: } else {
56: // unspecified classPattern like "method(..)"
57: classPattern = "*..*";
58: }
59: if (classPattern.endsWith("+")) {
60: classPattern = classPattern.substring(0, classPattern
61: .length() - 1);
62: m_declaringTypePattern = Pattern.compileTypePattern(
63: classPattern,
64: SubtypePatternType.MATCH_ON_ALL_METHODS);
65: } else if (classPattern.endsWith("#")) {
66: classPattern = classPattern.substring(0, classPattern
67: .length() - 1);
68: m_declaringTypePattern = Pattern.compileTypePattern(
69: classPattern,
70: SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY);
71: } else {
72: m_declaringTypePattern = Pattern.compileTypePattern(
73: classPattern, SubtypePatternType.NOT_HIERARCHICAL);
74: }
75: String namePattern = pattern.substring(index + 1, pattern
76: .length());
77: m_fieldNamePattern = Pattern.compileNamePattern(namePattern);
78: }
79:
80: public TypePattern getFieldTypePattern() {
81: return m_fieldTypePattern;
82: }
83:
84: public TypePattern getDeclaringTypePattern() {
85: return m_declaringTypePattern;
86: }
87:
88: public NamePattern getFieldNamePattern() {
89: return m_fieldNamePattern;
90: }
91: }
|