KickJava   Java API By Example, From Geeks To Geeks.

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


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 this(typeNamePattern)
36   * @child GenTypeName typeName
37   */

38 public class ThisPcd extends Pcd {
39     public String JavaDoc toShortString() {
40         return "this(" + getTypeName().toShortString() + ")";
41     }
42
43     public boolean allowsNameBinding() { return true; }
44     public void checkStatic() { showNonStaticError(); }
45
46     public JpPlanner makePlanner(PlanData planData) {
47         return new JpPlanner() {
48             public FuzzyBoolean fastMatch(JoinPoint jp) {
49                 //System.out.println(toShortString() + ": " + jp.getThisType());
50
//XXX want to make this method more accurate
51
if (jp.getThisExprType() == null) return FuzzyBoolean.NO;
52                 return getTypeName().matchesInstance(jp.getThisExprType());
53             }
54             public JpPlan makePlan(JoinPoint jp) {
55                 if (jp.getSourceLocation() == null) return JpPlan.NEVER_PLAN;
56                 if (jp.makeThisExpr() == null) return JpPlan.NO_PLAN;
57                 return getTypeName().makePlan(jp, jp.makeThisExpr());
58             }
59         };
60     }
61     
62     //BEGIN: Generated from @child and @property
63
protected GenTypeName typeName;
64     public GenTypeName getTypeName() { return typeName; }
65     public void setTypeName(GenTypeName _typeName) {
66         if (_typeName != null) _typeName.setParent(this);
67         typeName = _typeName;
68     }
69     
70     public ThisPcd(SourceLocation location, GenTypeName _typeName) {
71         super(location);
72         setTypeName(_typeName);
73     }
74     protected ThisPcd(SourceLocation source) {
75         super(source);
76     }
77     
78     public ASTObject copyWalk(CopyWalker walker) {
79         ThisPcd ret = new ThisPcd(getSourceLocation());
80         ret.preCopy(walker, this);
81         if (typeName != null) ret.setTypeName( (GenTypeName)walker.process(typeName) );
82         return ret;
83     }
84     
85     public ASTObject getChildAt(int childIndex) {
86         switch(childIndex) {
87         case 0: return typeName;
88         default: return super.getChildAt(childIndex);
89         }
90     }
91      public String JavaDoc getChildNameAt(int childIndex) {
92         switch(childIndex) {
93         case 0: return "typeName";
94         default: return super.getChildNameAt(childIndex);
95         }
96     }
97      public void setChildAt(int childIndex, ASTObject child) {
98         switch(childIndex) {
99         case 0: setTypeName((GenTypeName)child); return;
100         default: super.setChildAt(childIndex, child); return;
101         }
102     }
103      public int getChildCount() {
104         return 1;
105     }
106     
107     public String JavaDoc getDefaultDisplayName() {
108         return "ThisPcd()";
109     }
110     
111     //END: Generated from @child and @property
112
}
113
114
Popular Tags