KickJava   Java API By Example, From Geeks To Geeks.

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


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

39 public class TargetPcd extends Pcd {
40     public String JavaDoc toShortString() {
41         return "target(" + getTypeName().toShortString() + ")";
42     }
43
44     public boolean allowsNameBinding() { return true; }
45     public void checkStatic() { showNonStaticError(); }
46
47     public JpPlanner makePlanner(PlanData planData) {
48         return new JpPlanner() {
49             public FuzzyBoolean fastMatch(JoinPoint jp) {
50                 //System.out.println(toShortString() + ": " + jp.getTargetType() + ", " + getTypeName());
51
//XXX want to make this method more accurate
52
if (jp.getTargetExprType() == null) return FuzzyBoolean.NO;
53                 return getTypeName().matchesInstance(jp.getTargetExprType());
54             }
55             public JpPlan makePlan(JoinPoint jp) {
56                 if (jp.makeTargetExpr() == null) return JpPlan.NO_PLAN;
57                 return getTypeName().makePlan(jp, jp.makeTargetExpr());
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 TargetPcd(SourceLocation location, GenTypeName _typeName) {
71         super(location);
72         setTypeName(_typeName);
73     }
74     protected TargetPcd(SourceLocation source) {
75         super(source);
76     }
77     
78     public ASTObject copyWalk(CopyWalker walker) {
79         TargetPcd ret = new TargetPcd(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 "TargetPcd()";
109     }
110     
111     //END: Generated from @child and @property
112
}
113
114
Popular Tags