KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > PrimitiveType


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.base.ast;
26
27 import org.aspectj.compiler.base.*;
28 import java.io.IOException JavaDoc;
29
30 import org.aspectj.compiler.base.bcg.CodeBuilder;
31 import org.aspectj.compiler.base.bcg.Label;
32
33 public abstract class PrimitiveType extends Type {
34
35     public abstract String JavaDoc getName();
36
37     public PrimitiveType(JavaCompiler compiler) {
38         super(compiler);
39     }
40
41     protected void showNotFoundError(String JavaDoc id, ASTObject fromWhere, String JavaDoc kind) {
42         getCompiler().showError(fromWhere, "no " + kind + "s on primitive type: " + getName());
43     }
44
45     public Expr getClassExpr() {
46         return getAST().makeStaticGet(getRefType(), "TYPE");
47     }
48
49     public Expr makeObject(Expr expr) {
50         //XXX???expr.typeD = this;
51
return getAST().makeNew(getRefType(), expr);
52     }
53
54     public Expr fromObject(Expr expr) {
55         //??? can this ever be wrong?
56
if (expr.getType().isPrimitive()) return getAST().makeCast(this, expr);
57         
58         return getAST().makeStaticCall(getTypeManager().getConversionsType(),
59                                        getName() + "Value", expr);
60     }
61         
62 // Expr castExpr = getAST().makeCast(getRefType(), expr);
63
// return getAST().makeCall(castExpr, getName()+"Value");
64
// }
65

66     public String JavaDoc toShortString() {
67         return getName();
68     }
69
70     public boolean isEquivalent(Type other) {
71         if (other.isAnyType()) return true;
72         // Types are guaranteed to have only one instance per
73
return this == other;
74     }
75
76     public final boolean isCoercableTo(Type other) {
77         return this.isEquivalent(other) || this.isCoercableToOtherType(other);
78     }
79     protected boolean isCoercableToOtherType(Type other) { return false; }
80
81     public final boolean isAssignableFrom(Type other) {
82         return this.isEquivalent(other) || this.isAssignableFromOtherType(other);
83     }
84     protected boolean isAssignableFromOtherType(Type other) { return false; }
85
86     public String JavaDoc toString() {
87         return "PrimitiveType(" + getName() + ")";
88     }
89
90     public void unparse(CodeWriter writer) throws IOException JavaDoc {
91         writer.write(getString());
92     }
93
94     // ------------------------------
95
// code gen
96
final void emitNewarray(CodeBuilder cb) { cb.emitNEWARRAY(getTypeIndex()); }
97
98     final void emitInstanceof(CodeBuilder cb) { unsupportedEmit(); }
99 }
100
Popular Tags