KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > expression > ast > ASTFieldPattern


1 package org.codehaus.aspectwerkz.expression.ast;
2
3 import org.codehaus.aspectwerkz.expression.SubtypePatternType;
4 import org.codehaus.aspectwerkz.expression.regexp.NamePattern;
5 import org.codehaus.aspectwerkz.expression.regexp.Pattern;
6 import org.codehaus.aspectwerkz.expression.regexp.TypePattern;
7
8 public class ASTFieldPattern extends SimpleNode {
9     private TypePattern m_fieldTypePattern;
10
11     private TypePattern m_declaringTypePattern;
12
13     private NamePattern m_fieldNamePattern;
14
15     public ASTFieldPattern(int id) {
16         super(id);
17     }
18
19     public ASTFieldPattern(ExpressionParser p, int id) {
20         super(p, id);
21     }
22
23     public Object JavaDoc jjtAccept(ExpressionParserVisitor visitor, Object JavaDoc data) {
24         return visitor.visit(this, data);
25     }
26
27     public void setFieldTypePattern(String JavaDoc pattern) {
28         if (pattern.endsWith("+")) {
29             pattern = pattern.substring(0, pattern.length() - 1);
30             m_fieldTypePattern = Pattern.compileTypePattern(pattern, SubtypePatternType.MATCH_ON_ALL_METHODS);
31         } else if (pattern.endsWith("#")) {
32             pattern = pattern.substring(0, pattern.length() - 1);
33             m_fieldTypePattern = Pattern
34                     .compileTypePattern(pattern, SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY);
35         } else {
36             m_fieldTypePattern = Pattern.compileTypePattern(pattern, SubtypePatternType.NOT_HIERARCHICAL);
37         }
38     }
39
40     public void setFullNamePattern(final String JavaDoc pattern) {
41         int index = pattern.lastIndexOf('.');
42         String JavaDoc classPattern = null;
43         //Aw-112 support for "field" and "com..field"
44
if (index > 0) {
45             classPattern = pattern.substring(0, index);
46             if (classPattern.endsWith(".")) {
47                 classPattern += ".*";
48             }
49         } else {
50             // unspecified classPattern like "method(..)"
51
classPattern = "*..*";
52         }
53         if (classPattern.endsWith("+")) {
54             classPattern = classPattern.substring(0, classPattern.length() - 1);
55             m_declaringTypePattern = Pattern.compileTypePattern(classPattern, SubtypePatternType.MATCH_ON_ALL_METHODS);
56         } else if (classPattern.endsWith("#")) {
57             classPattern = classPattern.substring(0, classPattern.length() - 1);
58             m_declaringTypePattern = Pattern.compileTypePattern(
59                     classPattern,
60                     SubtypePatternType.MATCH_ON_BASE_TYPE_METHODS_ONLY
61             );
62         } else {
63             m_declaringTypePattern = Pattern.compileTypePattern(classPattern, SubtypePatternType.NOT_HIERARCHICAL);
64         }
65         String JavaDoc namePattern = pattern.substring(index + 1, pattern.length());
66         m_fieldNamePattern = Pattern.compileNamePattern(namePattern);
67     }
68
69     public TypePattern getFieldTypePattern() {
70         return m_fieldTypePattern;
71     }
72
73     public TypePattern getDeclaringTypePattern() {
74         return m_declaringTypePattern;
75     }
76
77     public NamePattern getFieldNamePattern() {
78         return m_fieldNamePattern;
79     }
80 }
Popular Tags