KickJava   Java API By Example, From Geeks To Geeks.

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


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.base.*;
28 import org.aspectj.compiler.crosscuts.joinpoints.*;
29 import org.aspectj.compiler.base.cst.*;
30
31 import org.aspectj.util.FuzzyBoolean;
32
33 /**
34  * @grammar id
35  * @property Type type
36  * @property boolean includeSubTypes
37  */

38
39 public class SimpleTypeName extends GenTypeName {
40     public String JavaDoc toShortString() {
41         //System.out.println("type: " + type);
42
if (includeSubTypes) return type.getPrettyString() + "+";
43         else return type.getPrettyString();
44     }
45     
46     
47     public boolean matches(Type type) {
48         if (includeSubTypes) return type.isSubtypeOf(getType());
49         else return type == getType();
50     }
51
52     
53     public FuzzyBoolean matchesInstance(Type exprType) {
54         Type formalType = getType();
55         //System.out.println("plan: " + exprType + ", " + formalType);
56
if (formalType.isObject()) return FuzzyBoolean.YES;
57         
58         if (formalType.isAssignableFrom(exprType)) return FuzzyBoolean.YES;
59         
60         // this is a conditional true based on the needed dynamic test
61
if (exprType.isCoercableTo(formalType)) return FuzzyBoolean.MAYBE;
62         
63         return FuzzyBoolean.NO;
64     }
65
66     public JpPlan makePlan(JoinPoint jp, Expr expr) {
67         Type exprType = expr.getType();
68         Type formalType = getType();
69         //System.out.println("plan: " + jp + ", " + exprType + ", " + formalType);
70

71         if (matchesInstance(exprType).alwaysFalse()) return JpPlan.NO_PLAN;
72         
73         JpPlan plan = new JpPlan(jp);
74         
75
76         
77         if (formalType.isObject()) {
78             return plan;
79         }
80         
81         if (formalType.isAssignableFrom(exprType)) {
82             return plan;
83         }
84         
85         if (exprType.isCoercableTo(formalType)) {
86             final AST ast = getAST();
87             
88             Expr testExpr = ast.makeParen(ast.makeInstanceof(expr, formalType));
89             plan.addExprTest(testExpr);
90             return plan;
91         }
92         
93         return JpPlan.NO_PLAN;
94     }
95     
96     //BEGIN: Generated from @child and @property
97
protected Type type;
98     public Type getType() { return type; }
99     public void setType(Type _type) { type = _type; }
100     
101     protected boolean includeSubTypes;
102     public boolean getIncludeSubTypes() { return includeSubTypes; }
103     public void setIncludeSubTypes(boolean _includeSubTypes) { includeSubTypes = _includeSubTypes; }
104     
105     public SimpleTypeName(SourceLocation location, Type _type, boolean _includeSubTypes) {
106         super(location);
107         setType(_type);
108         setIncludeSubTypes(_includeSubTypes);
109     }
110     protected SimpleTypeName(SourceLocation source) {
111         super(source);
112     }
113     
114     public ASTObject copyWalk(CopyWalker walker) {
115         SimpleTypeName ret = new SimpleTypeName(getSourceLocation());
116         ret.preCopy(walker, this);
117         ret.type = type;
118         ret.includeSubTypes = includeSubTypes;
119         return ret;
120     }
121     
122     
123     public String JavaDoc getDefaultDisplayName() {
124         return "SimpleTypeName(type: "+type+", "+"includeSubTypes: "+includeSubTypes+")";
125     }
126     
127     //END: Generated from @child and @property
128
}
129
130
Popular Tags