1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import java.io.IOException ; 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 getName(); 36 37 public PrimitiveType(JavaCompiler compiler) { 38 super(compiler); 39 } 40 41 protected void showNotFoundError(String id, ASTObject fromWhere, String 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 return getAST().makeNew(getRefType(), expr); 52 } 53 54 public Expr fromObject(Expr expr) { 55 if (expr.getType().isPrimitive()) return getAST().makeCast(this, expr); 57 58 return getAST().makeStaticCall(getTypeManager().getConversionsType(), 59 getName() + "Value", expr); 60 } 61 62 66 public String toShortString() { 67 return getName(); 68 } 69 70 public boolean isEquivalent(Type other) { 71 if (other.isAnyType()) return true; 72 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 toString() { 87 return "PrimitiveType(" + getName() + ")"; 88 } 89 90 public void unparse(CodeWriter writer) throws IOException { 91 writer.write(getString()); 92 } 93 94 final void emitNewarray(CodeBuilder cb) { cb.emitNEWARRAY(getTypeIndex()); } 97 98 final void emitInstanceof(CodeBuilder cb) { unsupportedEmit(); } 99 } 100 | Popular Tags |