langtools/src/share/classes/com/sun/tools/javac/code/Type.java
changeset 8032 e1aa25ccdabb
parent 7681 1f0819a3341f
child 8044 7fd529d4472c
equal deleted inserted replaced
8031:d5fe2c1cecfc 8032:e1aa25ccdabb
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   136     /** Define a constant type, of the same kind as this type
   136     /** Define a constant type, of the same kind as this type
   137      *  and with given constant value
   137      *  and with given constant value
   138      */
   138      */
   139     public Type constType(Object constValue) {
   139     public Type constType(Object constValue) {
   140         final Object value = constValue;
   140         final Object value = constValue;
   141         assert tag <= BOOLEAN;
   141         Assert.check(tag <= BOOLEAN);
   142         return new Type(tag, tsym) {
   142         return new Type(tag, tsym) {
   143                 @Override
   143                 @Override
   144                 public Object constValue() {
   144                 public Object constValue() {
   145                     return value;
   145                     return value;
   146                 }
   146                 }
   200 
   200 
   201     /**
   201     /**
   202      * The constant value of this type, converted to String
   202      * The constant value of this type, converted to String
   203      */
   203      */
   204     public String stringValue() {
   204     public String stringValue() {
   205         assert constValue() != null;
   205         Object cv = Assert.checkNonNull(constValue());
   206         if (tag == BOOLEAN)
   206         if (tag == BOOLEAN)
   207             return ((Integer) constValue()).intValue() == 0 ? "false" : "true";
   207             return ((Integer) cv).intValue() == 0 ? "false" : "true";
   208         else if (tag == CHAR)
   208         else if (tag == CHAR)
   209             return String.valueOf((char) ((Integer) constValue()).intValue());
   209             return String.valueOf((char) ((Integer) cv).intValue());
   210         else
   210         else
   211             return constValue().toString();
   211             return cv.toString();
   212     }
   212     }
   213 
   213 
   214     /**
   214     /**
   215      * This method is analogous to isSameType, but weaker, since we
   215      * This method is analogous to isSameType, but weaker, since we
   216      * never complete classes. Where isSameType would complete a
   216      * never complete classes. Where isSameType would complete a
   426             return v.visitWildcardType(this, s);
   426             return v.visitWildcardType(this, s);
   427         }
   427         }
   428 
   428 
   429         public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
   429         public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
   430             super(WILDCARD, tsym);
   430             super(WILDCARD, tsym);
   431             assert(type != null);
   431             this.type = Assert.checkNonNull(type);
   432             this.kind = kind;
   432             this.kind = kind;
   433             this.type = type;
       
   434         }
   433         }
   435         public WildcardType(WildcardType t, TypeVar bound) {
   434         public WildcardType(WildcardType t, TypeVar bound) {
   436             this(t.type, t.kind, t.tsym, bound);
   435             this(t.type, t.kind, t.tsym, bound);
   437         }
   436         }
   438 
   437 
  1019                             Symbol owner,
  1018                             Symbol owner,
  1020                             Type upper,
  1019                             Type upper,
  1021                             Type lower,
  1020                             Type lower,
  1022                             WildcardType wildcard) {
  1021                             WildcardType wildcard) {
  1023             super(name, owner, lower);
  1022             super(name, owner, lower);
  1024             assert lower != null;
  1023             this.lower = Assert.checkNonNull(lower);
  1025             this.bound = upper;
  1024             this.bound = upper;
  1026             this.lower = lower;
       
  1027             this.wildcard = wildcard;
  1025             this.wildcard = wildcard;
  1028         }
  1026         }
  1029 
  1027 
  1030         @Override
  1028         @Override
  1031         public <R,S> R accept(Type.Visitor<R,S> v, S s) {
  1029         public <R,S> R accept(Type.Visitor<R,S> v, S s) {