src/share/classes/com/sun/tools/javac/code/Kinds.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 80
5c9cdeb740f2
child 136
8eafba4f61be
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.code;
duke@1 27
mcimadamore@80 28 import java.util.EnumSet;
mcimadamore@80 29 import java.util.ResourceBundle;
mcimadamore@80 30
mcimadamore@80 31 import com.sun.tools.javac.api.Formattable;
mcimadamore@80 32
mcimadamore@80 33 import static com.sun.tools.javac.code.TypeTags.*;
mcimadamore@80 34 import static com.sun.tools.javac.code.Flags.*;
duke@1 35
duke@1 36 /** Internal symbol kinds, which distinguish between elements of
duke@1 37 * different subclasses of Symbol. Symbol kinds are organized so they can be
duke@1 38 * or'ed to sets.
duke@1 39 *
duke@1 40 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
duke@1 41 * you write code that depends on this, you do so at your own risk.
duke@1 42 * This code and its internal interfaces are subject to change or
duke@1 43 * deletion without notice.</b>
duke@1 44 */
duke@1 45 public class Kinds {
duke@1 46
duke@1 47 private Kinds() {} // uninstantiable
duke@1 48
duke@1 49 /** The empty set of kinds.
duke@1 50 */
duke@1 51 public final static int NIL = 0;
duke@1 52
duke@1 53 /** The kind of package symbols.
duke@1 54 */
duke@1 55 public final static int PCK = 1 << 0;
duke@1 56
duke@1 57 /** The kind of type symbols (classes, interfaces and type variables).
duke@1 58 */
duke@1 59 public final static int TYP = 1 << 1;
duke@1 60
duke@1 61 /** The kind of variable symbols.
duke@1 62 */
duke@1 63 public final static int VAR = 1 << 2;
duke@1 64
duke@1 65 /** The kind of values (variables or non-variable expressions), includes VAR.
duke@1 66 */
duke@1 67 public final static int VAL = (1 << 3) | VAR;
duke@1 68
duke@1 69 /** The kind of methods.
duke@1 70 */
duke@1 71 public final static int MTH = 1 << 4;
duke@1 72
duke@1 73 /** The error kind, which includes all other kinds.
duke@1 74 */
duke@1 75 public final static int ERR = (1 << 5) - 1;
duke@1 76
duke@1 77 /** The set of all kinds.
duke@1 78 */
duke@1 79 public final static int AllKinds = ERR;
duke@1 80
duke@1 81 /** Kinds for erroneous symbols that complement the above
duke@1 82 */
duke@1 83 public static final int ERRONEOUS = 1 << 6;
duke@1 84 public static final int AMBIGUOUS = ERRONEOUS+1; // ambiguous reference
duke@1 85 public static final int HIDDEN = ERRONEOUS+2; // hidden method or field
duke@1 86 public static final int STATICERR = ERRONEOUS+3; // nonstatic member from static context
duke@1 87 public static final int ABSENT_VAR = ERRONEOUS+4; // missing variable
duke@1 88 public static final int WRONG_MTHS = ERRONEOUS+5; // methods with wrong arguments
duke@1 89 public static final int WRONG_MTH = ERRONEOUS+6; // one method with wrong arguments
duke@1 90 public static final int ABSENT_MTH = ERRONEOUS+7; // missing method
duke@1 91 public static final int ABSENT_TYP = ERRONEOUS+8; // missing type
mcimadamore@80 92
mcimadamore@80 93 public enum KindName implements Formattable {
mcimadamore@80 94 ANNOTATION("kindname.interface"),
mcimadamore@80 95 CONSTRUCTOR("kindname.constructor"),
mcimadamore@80 96 INTERFACE("kindname.interface"),
mcimadamore@80 97 STATIC("kindname.static"),
mcimadamore@80 98 TYPEVAR("kindname.type.variable"),
mcimadamore@80 99 BOUND("kindname.type.variable.bound"),
mcimadamore@80 100 VAR("kindname.variable"),
mcimadamore@80 101 VAL("kindname.value"),
mcimadamore@80 102 METHOD("kindname.method"),
mcimadamore@80 103 CLASS("kindname.class"),
mcimadamore@80 104 PACKAGE("kindname.package");
mcimadamore@80 105
mcimadamore@80 106 private String name;
mcimadamore@80 107
mcimadamore@80 108 KindName(String name) {
mcimadamore@80 109 this.name = name;
mcimadamore@80 110 }
mcimadamore@80 111
mcimadamore@80 112 public String toString() {
mcimadamore@80 113 return name;
mcimadamore@80 114 }
mcimadamore@80 115
mcimadamore@80 116 public String getKind() {
mcimadamore@80 117 return "Kindname";
mcimadamore@80 118 }
mcimadamore@80 119
mcimadamore@80 120 public String toString(ResourceBundle bundle) {
mcimadamore@80 121 String s = toString();
mcimadamore@80 122 return bundle.getString("compiler.misc." + s);
mcimadamore@80 123 }
mcimadamore@80 124 }
mcimadamore@80 125
mcimadamore@80 126 /** A KindName representing a given symbol kind
mcimadamore@80 127 */
mcimadamore@80 128 public static KindName kindName(int kind) {
mcimadamore@80 129 switch (kind) {
mcimadamore@80 130 case PCK: return KindName.PACKAGE;
mcimadamore@80 131 case TYP: return KindName.CLASS;
mcimadamore@80 132 case VAR: return KindName.VAR;
mcimadamore@80 133 case VAL: return KindName.VAL;
mcimadamore@80 134 case MTH: return KindName.METHOD;
mcimadamore@80 135 default : throw new AssertionError("Unexpected kind: "+kind);
mcimadamore@80 136 }
mcimadamore@80 137 }
mcimadamore@80 138
mcimadamore@80 139 /** A KindName representing a given symbol
mcimadamore@80 140 */
mcimadamore@80 141 public static KindName kindName(Symbol sym) {
mcimadamore@80 142 switch (sym.getKind()) {
mcimadamore@80 143 case PACKAGE:
mcimadamore@80 144 return KindName.PACKAGE;
mcimadamore@80 145
mcimadamore@80 146 case ENUM:
mcimadamore@80 147 case ANNOTATION_TYPE:
mcimadamore@80 148 case INTERFACE:
mcimadamore@80 149 case CLASS:
mcimadamore@80 150 return KindName.CLASS;
mcimadamore@80 151
mcimadamore@80 152 case TYPE_PARAMETER:
mcimadamore@80 153 return KindName.TYPEVAR;
mcimadamore@80 154
mcimadamore@80 155 case ENUM_CONSTANT:
mcimadamore@80 156 case FIELD:
mcimadamore@80 157 case PARAMETER:
mcimadamore@80 158 case LOCAL_VARIABLE:
mcimadamore@80 159 case EXCEPTION_PARAMETER:
mcimadamore@80 160 return KindName.VAR;
mcimadamore@80 161
mcimadamore@80 162 case METHOD:
mcimadamore@80 163 case CONSTRUCTOR:
mcimadamore@80 164 case STATIC_INIT:
mcimadamore@80 165 case INSTANCE_INIT:
mcimadamore@80 166 return KindName.METHOD;
mcimadamore@80 167
mcimadamore@80 168 default:
mcimadamore@80 169 if (sym.kind == VAL)
mcimadamore@80 170 // I don't think this can happen but it can't harm
mcimadamore@80 171 // playing it safe --ahe
mcimadamore@80 172 return KindName.VAL;
mcimadamore@80 173 else
mcimadamore@80 174 throw new AssertionError("Unexpected kind: "+sym.getKind());
mcimadamore@80 175 }
mcimadamore@80 176 }
mcimadamore@80 177
mcimadamore@80 178 /** A set of KindName(s) representing a set of symbol's kinds.
mcimadamore@80 179 */
mcimadamore@80 180 public static EnumSet<KindName> kindNames(int kind) {
mcimadamore@80 181 EnumSet<KindName> kinds = EnumSet.noneOf(KindName.class);
mcimadamore@80 182 if ((kind & VAL) != 0)
mcimadamore@80 183 kinds.add(((kind & VAL) == VAR) ? KindName.VAR : KindName.VAL);
mcimadamore@80 184 if ((kind & MTH) != 0) kinds.add(KindName.METHOD);
mcimadamore@80 185 if ((kind & TYP) != 0) kinds.add(KindName.CLASS);
mcimadamore@80 186 if ((kind & PCK) != 0) kinds.add(KindName.PACKAGE);
mcimadamore@80 187 return kinds;
mcimadamore@80 188 }
mcimadamore@80 189
mcimadamore@80 190 /** A KindName representing the kind of a given class/interface type.
mcimadamore@80 191 */
mcimadamore@80 192 public static KindName typeKindName(Type t) {
mcimadamore@80 193 if (t.tag == TYPEVAR ||
mcimadamore@80 194 t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0)
mcimadamore@80 195 return KindName.BOUND;
mcimadamore@80 196 else if (t.tag == PACKAGE)
mcimadamore@80 197 return KindName.PACKAGE;
mcimadamore@80 198 else if ((t.tsym.flags_field & ANNOTATION) != 0)
mcimadamore@80 199 return KindName.ANNOTATION;
mcimadamore@80 200 else if ((t.tsym.flags_field & INTERFACE) != 0)
mcimadamore@80 201 return KindName.INTERFACE;
mcimadamore@80 202 else
mcimadamore@80 203 return KindName.CLASS;
mcimadamore@80 204 }
mcimadamore@80 205
mcimadamore@80 206 /** A KindName representing the kind of a a missing symbol, given an
mcimadamore@80 207 * error kind.
mcimadamore@80 208 * */
mcimadamore@80 209 public static KindName absentKind(int kind) {
mcimadamore@80 210 switch (kind) {
mcimadamore@80 211 case ABSENT_VAR:
mcimadamore@80 212 return KindName.VAR;
mcimadamore@80 213 case WRONG_MTHS: case WRONG_MTH: case ABSENT_MTH:
mcimadamore@80 214 return KindName.METHOD;
mcimadamore@80 215 case ABSENT_TYP:
mcimadamore@80 216 return KindName.CLASS;
mcimadamore@80 217 default:
mcimadamore@80 218 throw new AssertionError("Unexpected kind: "+kind);
mcimadamore@80 219 }
mcimadamore@80 220 }
duke@1 221 }

mercurial