KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > pao > extension > PaoInstanceofDel_c


1 package polyglot.ext.pao.extension;
2
3 import polyglot.ast.Instanceof;
4 import polyglot.ast.Node;
5 import polyglot.ext.jl.ast.JL_c;
6 import polyglot.types.SemanticException;
7 import polyglot.types.Type;
8 import polyglot.visit.TypeChecker;
9
10 /**
11  * The implementation of the delegate for the
12  * <code>InstanceOf</code> AST node. Overrides the
13  * {@link #typeCheck(TypeChecker) typeCheck(TypeChecker)} method.
14  */

15 public class PaoInstanceofDel_c extends JL_c {
16     /**
17      * Removes the restriction that the compare type must be a
18      * <code>ReferenceType</code>.
19      * @see polyglot.ast.NodeOps#typeCheck(TypeChecker)
20      * @see polyglot.ext.jl.ast.Instanceof_c#typeCheck(TypeChecker)
21      */

22     public Node typeCheck(TypeChecker tc) throws SemanticException {
23         Instanceof n = (Instanceof) node();
24         Type rtype = n.compareType().type();
25         Type ltype = n.expr().type();
26         
27         if (! tc.typeSystem().isCastValid(ltype, rtype)) {
28             throw new SemanticException(
29                     "Left operand of \"instanceof\" must be castable to "
30                     + "the right operand.");
31         }
32         
33         return n.type(tc.typeSystem().Boolean());
34     }
35 }
36
Popular Tags