KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > ast > FieldPattern


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.crosscuts.ast;
26 import org.aspectj.compiler.base.ast.*;
27 import org.aspectj.compiler.crosscuts.joinpoints.*;
28
29 import org.aspectj.compiler.base.JavaCompiler;
30
31 import java.util.*;
32 import org.aspectj.util.FuzzyBoolean;
33
34 /**
35   * @grammar modifiers fieldTypeName declaringType.id
36   * @child GenTypeName fieldTypeName
37   * @property NamePattern id
38   */

39 public class FieldPattern extends DecPattern {
40     public String JavaDoc toShortString() {
41         String JavaDoc mods = modifiers.toShortString();
42         if (mods.length() > 0) mods += " ";
43         mods += fieldTypeName.toShortString()+" ";
44         if (declaringTypeName != null) mods += declaringTypeName.toShortString() + ".";
45         String JavaDoc ret = mods + id.toShortString();
46
47         return ret;
48     }
49
50     public String JavaDoc getLookupId() { return id.getLookupString(); }
51
52     public FuzzyBoolean matches(JoinPoint jp) {
53         if (! (jp.getTargetSO() instanceof Field) ) {
54             return FuzzyBoolean.NO;
55         }
56         
57         Field m = (Field)jp.getTargetSO();
58         
59         //System.out.println("matching: " + toShortString() + " == " + m.toShortString());
60

61         if (!id.matches(m.getName())) return FuzzyBoolean.NO;
62         //System.out.println("matched id");
63
if (!fieldTypeName.matches(m.getFieldType())) return FuzzyBoolean.NO;
64         
65         //System.out.println(" matching in super");
66

67         return super.matches(jp);
68     }
69     
70     protected boolean isStaticMatch(SemanticObject so) {
71         return true;
72     }
73     
74     //BEGIN: Generated from @child and @property
75
protected GenTypeName fieldTypeName;
76     public GenTypeName getFieldTypeName() { return fieldTypeName; }
77     public void setFieldTypeName(GenTypeName _fieldTypeName) {
78         if (_fieldTypeName != null) _fieldTypeName.setParent(this);
79         fieldTypeName = _fieldTypeName;
80     }
81     
82     protected NamePattern id;
83     public NamePattern getId() { return id; }
84     public void setId(NamePattern _id) { id = _id; }
85     
86     public FieldPattern(SourceLocation location, Modifiers _modifiers, GenTypeName _declaringTypeName, GenTypeName _fieldTypeName, NamePattern _id) {
87         super(location, _modifiers, _declaringTypeName);
88         setFieldTypeName(_fieldTypeName);
89         setId(_id);
90     }
91     protected FieldPattern(SourceLocation source) {
92         super(source);
93     }
94     
95     public ASTObject copyWalk(CopyWalker walker) {
96         FieldPattern ret = new FieldPattern(getSourceLocation());
97         ret.preCopy(walker, this);
98         if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) );
99         if (declaringTypeName != null) ret.setDeclaringTypeName( (GenTypeName)walker.process(declaringTypeName) );
100         if (fieldTypeName != null) ret.setFieldTypeName( (GenTypeName)walker.process(fieldTypeName) );
101         ret.id = id;
102         return ret;
103     }
104     
105     public ASTObject getChildAt(int childIndex) {
106         switch(childIndex) {
107         case 2: return fieldTypeName;
108         default: return super.getChildAt(childIndex);
109         }
110     }
111      public String JavaDoc getChildNameAt(int childIndex) {
112         switch(childIndex) {
113         case 2: return "fieldTypeName";
114         default: return super.getChildNameAt(childIndex);
115         }
116     }
117      public void setChildAt(int childIndex, ASTObject child) {
118         switch(childIndex) {
119         case 2: setFieldTypeName((GenTypeName)child); return;
120         default: super.setChildAt(childIndex, child); return;
121         }
122     }
123      public int getChildCount() {
124         return 3;
125     }
126     
127     public String JavaDoc getDefaultDisplayName() {
128         return "FieldPattern(id: "+id+")";
129     }
130     
131     //END: Generated from @child and @property
132
}
133
134
Popular Tags