KickJava   Java API By Example, From Geeks To Geeks.

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


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 FormalDec formalDec
36  */

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

70         if (formalType.isObject()) {
71             if (exprType.isPrimitive()) {
72                 expr = exprType.makeObject(expr);
73             }
74             plan.bindExpr(formalDec, expr);
75             return plan;
76         }
77         
78         if (formalType.isAssignableFrom(exprType)) {
79             plan.bindExpr(formalDec, expr);
80             return plan;
81         }
82         
83         if (exprType.isCoercableTo(formalType)) {
84             final AST ast = getAST();
85             
86             Expr testExpr = ast.makeParen(ast.makeInstanceof(expr, formalType));
87             plan.addExprTest(testExpr);
88             plan.bindExpr(formalDec, expr);
89             return plan;
90         }
91         
92         return JpPlan.NO_PLAN;
93     }
94     
95     //BEGIN: Generated from @child and @property
96
protected FormalDec formalDec;
97     public FormalDec getFormalDec() { return formalDec; }
98     public void setFormalDec(FormalDec _formalDec) { formalDec = _formalDec; }
99     
100     public VarTypeName(SourceLocation location, FormalDec _formalDec) {
101         super(location);
102         setFormalDec(_formalDec);
103     }
104     protected VarTypeName(SourceLocation source) {
105         super(source);
106     }
107     
108     public ASTObject copyWalk(CopyWalker walker) {
109         VarTypeName ret = new VarTypeName(getSourceLocation());
110         ret.preCopy(walker, this);
111         ret.formalDec = formalDec;
112         return ret;
113     }
114     
115     
116     public String JavaDoc getDefaultDisplayName() {
117         return "VarTypeName(formalDec: "+formalDec+")";
118     }
119     
120     //END: Generated from @child and @property
121
}
122
123
Popular Tags