jjg@309: /* jjg@1521: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. jjg@309: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@309: * jjg@309: * This code is free software; you can redistribute it and/or modify it jjg@309: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this jjg@309: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. jjg@309: * jjg@309: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@309: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@309: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@309: * version 2 for more details (a copy is included in the LICENSE file that jjg@309: * accompanied this code). jjg@309: * jjg@309: * You should have received a copy of the GNU General Public License version jjg@309: * 2 along with this work; if not, write to the Free Software Foundation, jjg@309: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@309: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@309: */ jjg@309: jjg@309: package com.sun.tools.javac.code; jjg@309: jjg@1521: import java.util.Iterator; jjg@1521: jjg@309: import com.sun.tools.javac.util.*; jjg@309: jjg@309: /** A type annotation position. jjg@309: * jjg@581: *
This is NOT part of any supported API.
jjg@581: * If you write code that depends on this, you do so at your own risk.
jjg@309: * This code and its internal interfaces are subject to change or
jjg@309: * deletion without notice.
jjg@309: */
jjg@1521: // Code duplicated in com.sun.tools.classfile.TypeAnnotation.Position
jjg@309: public class TypeAnnotationPosition {
jjg@309:
jjg@1521: public enum TypePathEntryKind {
jjg@1521: ARRAY(0),
jjg@1521: INNER_TYPE(1),
jjg@1521: WILDCARD(2),
jjg@1521: TYPE_ARGUMENT(3);
jjg@1521:
jjg@1521: public final int tag;
jjg@1521:
jjg@1521: private TypePathEntryKind(int tag) {
jjg@1521: this.tag = tag;
jjg@1521: }
jjg@1521: }
jjg@1521:
jjg@1521: public static class TypePathEntry {
jjg@1521: /** The fixed number of bytes per TypePathEntry. */
jjg@1521: public static final int bytesPerEntry = 2;
jjg@1521:
jjg@1521: public final TypePathEntryKind tag;
jjg@1521: public final int arg;
jjg@1521:
jjg@1521: public static final TypePathEntry ARRAY = new TypePathEntry(TypePathEntryKind.ARRAY);
jjg@1521: public static final TypePathEntry INNER_TYPE = new TypePathEntry(TypePathEntryKind.INNER_TYPE);
jjg@1521: public static final TypePathEntry WILDCARD = new TypePathEntry(TypePathEntryKind.WILDCARD);
jjg@1521:
jjg@1521: private TypePathEntry(TypePathEntryKind tag) {
jjg@1521: Assert.check(tag == TypePathEntryKind.ARRAY ||
jjg@1521: tag == TypePathEntryKind.INNER_TYPE ||
jjg@1521: tag == TypePathEntryKind.WILDCARD,
jjg@1521: "Invalid TypePathEntryKind: " + tag);
jjg@1521: this.tag = tag;
jjg@1521: this.arg = 0;
jjg@1521: }
jjg@1521:
jjg@1521: public TypePathEntry(TypePathEntryKind tag, int arg) {
jjg@1521: Assert.check(tag == TypePathEntryKind.TYPE_ARGUMENT,
jjg@1521: "Invalid TypePathEntryKind: " + tag);
jjg@1521: this.tag = tag;
jjg@1521: this.arg = arg;
jjg@1521: }
jjg@1521:
jjg@1521: public static TypePathEntry fromBinary(int tag, int arg) {
jjg@1521: Assert.check(arg == 0 || tag == TypePathEntryKind.TYPE_ARGUMENT.tag,
jjg@1521: "Invalid TypePathEntry tag/arg: " + tag + "/" + arg);
jjg@1521: switch (tag) {
jjg@1521: case 0:
jjg@1521: return ARRAY;
jjg@1521: case 1:
jjg@1521: return INNER_TYPE;
jjg@1521: case 2:
jjg@1521: return WILDCARD;
jjg@1521: case 3:
jjg@1521: return new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg);
jjg@1521: default:
jjg@1521: Assert.error("Invalid TypePathEntryKind tag: " + tag);
jjg@1521: return null;
jjg@1521: }
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public String toString() {
jjg@1521: return tag.toString() +
jjg@1521: (tag == TypePathEntryKind.TYPE_ARGUMENT ? ("(" + arg + ")") : "");
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public boolean equals(Object other) {
jjg@1521: if (! (other instanceof TypePathEntry)) {
jjg@1521: return false;
jjg@1521: }
jjg@1521: TypePathEntry tpe = (TypePathEntry) other;
jjg@1521: return this.tag == tpe.tag && this.arg == tpe.arg;
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public int hashCode() {
jjg@1521: return this.tag.hashCode() * 17 + this.arg;
jjg@1521: }
jjg@1521: }
jjg@1521:
jjg@309: public TargetType type = TargetType.UNKNOWN;
jjg@309:
jjg@309: // For generic/array types.
jjg@1521: public List