KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.util.FuzzyBoolean;
31
32 import java.util.*;
33
34 /**
35   * @grammar within(typeName)
36   * @child GenTypeName typeName
37   */

38 public class WithinPcd extends Pcd {
39     public String JavaDoc toShortString() {
40         return "within(" + getTypeName().toShortString() + ")";
41     }
42     public void checkStatic() { }
43
44     /**
45      * within(C) should match both code in C and code in any classes contained by
46      * C including local classes
47      */

48     private TypeDec matchingEnclosingTypeDec(TypeDec typeDec) {
49         while (typeDec != null) {
50             if (getTypeName().matches(typeDec.getType())) return typeDec;
51             typeDec = typeDec.getEnclosingTypeDec();
52         }
53         return null;
54     }
55     
56
57     public JpPlanner makePlanner(PlanData planData) {
58         return new JpPlanner() {
59             public FuzzyBoolean fastMatch(JoinPoint jp) {
60                 ASTObject sourceLocation = jp.getSourceLocation();
61                 if (sourceLocation == null) return FuzzyBoolean.NEVER;
62                 TypeDec typeDec = sourceLocation.getLexicalType().getTypeDec();
63                 TypeDec matchingTypeDec = matchingEnclosingTypeDec(typeDec);
64                 if (matchingTypeDec == null) return FuzzyBoolean.NO;
65                 else return FuzzyBoolean.YES;
66             }
67         };
68     }
69     
70     //BEGIN: Generated from @child and @property
71
protected GenTypeName typeName;
72     public GenTypeName getTypeName() { return typeName; }
73     public void setTypeName(GenTypeName _typeName) {
74         if (_typeName != null) _typeName.setParent(this);
75         typeName = _typeName;
76     }
77     
78     public WithinPcd(SourceLocation location, GenTypeName _typeName) {
79         super(location);
80         setTypeName(_typeName);
81     }
82     protected WithinPcd(SourceLocation source) {
83         super(source);
84     }
85     
86     public ASTObject copyWalk(CopyWalker walker) {
87         WithinPcd ret = new WithinPcd(getSourceLocation());
88         ret.preCopy(walker, this);
89         if (typeName != null) ret.setTypeName( (GenTypeName)walker.process(typeName) );
90         return ret;
91     }
92     
93     public ASTObject getChildAt(int childIndex) {
94         switch(childIndex) {
95         case 0: return typeName;
96         default: return super.getChildAt(childIndex);
97         }
98     }
99      public String JavaDoc getChildNameAt(int childIndex) {
100         switch(childIndex) {
101         case 0: return "typeName";
102         default: return super.getChildNameAt(childIndex);
103         }
104     }
105      public void setChildAt(int childIndex, ASTObject child) {
106         switch(childIndex) {
107         case 0: setTypeName((GenTypeName)child); return;
108         default: super.setChildAt(childIndex, child); return;
109         }
110     }
111      public int getChildCount() {
112         return 1;
113     }
114     
115     public String JavaDoc getDefaultDisplayName() {
116         return "WithinPcd()";
117     }
118     
119     //END: Generated from @child and @property
120
}
121
122
Popular Tags