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

Fri, 26 Jun 2009 19:12:41 -0700

author
jjg
date
Fri, 26 Jun 2009 19:12:41 -0700
changeset 309
664edca41e34
child 310
7c154fdc3547
permissions
-rw-r--r--

6855544: add missing files
Reviewed-by: jjg, mcimadamore, darcy
Contributed-by: mernst@cs.washington.edu, mali@csail.mit.edu, mpapi@csail.mit.edu

jjg@309 1 /*
jjg@309 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@309 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@309 4 *
jjg@309 5 * This code is free software; you can redistribute it and/or modify it
jjg@309 6 * under the terms of the GNU General Public License version 2 only, as
jjg@309 7 * published by the Free Software Foundation. Sun designates this
jjg@309 8 * particular file as subject to the "Classpath" exception as provided
jjg@309 9 * by Sun in the LICENSE file that accompanied this code.
jjg@309 10 *
jjg@309 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@309 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@309 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@309 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@309 15 * accompanied this code).
jjg@309 16 *
jjg@309 17 * You should have received a copy of the GNU General Public License version
jjg@309 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@309 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@309 20 *
jjg@309 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@309 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@309 23 * have any questions.
jjg@309 24 */
jjg@309 25
jjg@309 26 package com.sun.tools.javac.code;
jjg@309 27
jjg@309 28 import com.sun.tools.javac.util.*;
jjg@309 29
jjg@309 30 /** A type annotation position.
jjg@309 31 *
jjg@309 32 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
jjg@309 33 * you write code that depends on this, you do so at your own risk.
jjg@309 34 * This code and its internal interfaces are subject to change or
jjg@309 35 * deletion without notice.</b>
jjg@309 36 */
jjg@309 37 public class TypeAnnotationPosition {
jjg@309 38
jjg@309 39 public TargetType type = TargetType.UNKNOWN;
jjg@309 40
jjg@309 41 // For generic/array types.
jjg@309 42 public List<Integer> location = List.nil();
jjg@309 43
jjg@309 44 // Tree position.
jjg@309 45 public int pos = -1;
jjg@309 46
jjg@309 47 // For typecasts, type tests, new (and locals, as start_pc).
jjg@309 48 public int offset = -1;
jjg@309 49
jjg@309 50 // For locals. arrays same length
jjg@309 51 public int[] lvarOffset = new int[] { -1 };
jjg@309 52 public int[] lvarLength = new int[] { -1 };
jjg@309 53 public int[] lvarIndex = new int[] { -1 };
jjg@309 54
jjg@309 55 // For type parameter bound
jjg@309 56 public int bound_index = -1;
jjg@309 57
jjg@309 58 // For type parameter and method parameter
jjg@309 59 public int parameter_index = -1;
jjg@309 60
jjg@309 61 // For class extends, implements, and throws classes
jjg@309 62 public int type_index = -2;
jjg@309 63
jjg@309 64 // For wildcards
jjg@309 65 public TypeAnnotationPosition wildcard_position = null;
jjg@309 66
jjg@309 67 @Override
jjg@309 68 public String toString() {
jjg@309 69 StringBuilder sb = new StringBuilder();
jjg@309 70 sb.append('[');
jjg@309 71 sb.append(type);
jjg@309 72
jjg@309 73 switch (type) {
jjg@309 74 // type case
jjg@309 75 case TYPECAST:
jjg@309 76 case TYPECAST_GENERIC_OR_ARRAY:
jjg@309 77 // object creation
jjg@309 78 case INSTANCEOF:
jjg@309 79 case INSTANCEOF_GENERIC_OR_ARRAY:
jjg@309 80 // new expression
jjg@309 81 case NEW:
jjg@309 82 case NEW_GENERIC_OR_ARRAY:
jjg@309 83 case NEW_TYPE_ARGUMENT:
jjg@309 84 case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
jjg@309 85 sb.append(", offset = ");
jjg@309 86 sb.append(offset);
jjg@309 87 break;
jjg@309 88 // local variable
jjg@309 89 case LOCAL_VARIABLE:
jjg@309 90 case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
jjg@309 91 sb.append(", {");
jjg@309 92 for (int i = 0; i < lvarOffset.length; ++i) {
jjg@309 93 if (i != 0) sb.append("; ");
jjg@309 94 sb.append(", start_pc = ");
jjg@309 95 sb.append(lvarOffset[i]);
jjg@309 96 sb.append(", length = ");
jjg@309 97 sb.append(lvarLength[i]);
jjg@309 98 sb.append(", index = ");
jjg@309 99 sb.append(lvarIndex[i]);
jjg@309 100 }
jjg@309 101 sb.append("}");
jjg@309 102 break;
jjg@309 103 // method receiver
jjg@309 104 case METHOD_RECEIVER:
jjg@309 105 // Do nothing
jjg@309 106 break;
jjg@309 107 // type parameters
jjg@309 108 case CLASS_TYPE_PARAMETER:
jjg@309 109 case METHOD_TYPE_PARAMETER:
jjg@309 110 sb.append(", param_index = ");
jjg@309 111 sb.append(parameter_index);
jjg@309 112 break;
jjg@309 113 // type parameters bound
jjg@309 114 case CLASS_TYPE_PARAMETER_BOUND:
jjg@309 115 case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
jjg@309 116 case METHOD_TYPE_PARAMETER_BOUND:
jjg@309 117 case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
jjg@309 118 sb.append(", param_index = ");
jjg@309 119 sb.append(parameter_index);
jjg@309 120 sb.append(", bound_index = ");
jjg@309 121 sb.append(bound_index);
jjg@309 122 break;
jjg@309 123 // wildcard
jjg@309 124 case WILDCARD_BOUND:
jjg@309 125 case WILDCARD_BOUND_GENERIC_OR_ARRAY:
jjg@309 126 sb.append(", wild_card = ");
jjg@309 127 sb.append(wildcard_position);
jjg@309 128 break;
jjg@309 129 // Class extends and implements clauses
jjg@309 130 case CLASS_EXTENDS:
jjg@309 131 case CLASS_EXTENDS_GENERIC_OR_ARRAY:
jjg@309 132 sb.append(", type_index = ");
jjg@309 133 sb.append(type_index);
jjg@309 134 break;
jjg@309 135 // throws
jjg@309 136 case THROWS:
jjg@309 137 sb.append(", type_index = ");
jjg@309 138 sb.append(type_index);
jjg@309 139 break;
jjg@309 140 case CLASS_LITERAL:
jjg@309 141 sb.append(", offset = ");
jjg@309 142 sb.append(offset);
jjg@309 143 break;
jjg@309 144 // method parameter: not specified
jjg@309 145 case METHOD_PARAMETER_GENERIC_OR_ARRAY:
jjg@309 146 sb.append(", param_index = ");
jjg@309 147 sb.append(parameter_index);
jjg@309 148 break;
jjg@309 149 // method type argument: wasn't specified
jjg@309 150 case METHOD_TYPE_ARGUMENT:
jjg@309 151 case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
jjg@309 152 sb.append(", offset = ");
jjg@309 153 sb.append(offset);
jjg@309 154 sb.append(", type_index = ");
jjg@309 155 sb.append(type_index);
jjg@309 156 break;
jjg@309 157 // We don't need to worry abut these
jjg@309 158 case METHOD_RETURN_GENERIC_OR_ARRAY:
jjg@309 159 case FIELD_GENERIC_OR_ARRAY:
jjg@309 160 break;
jjg@309 161 case UNKNOWN:
jjg@309 162 break;
jjg@309 163 default:
jjg@309 164 // throw new AssertionError("unknown type: " + type);
jjg@309 165 }
jjg@309 166
jjg@309 167 // Append location data for generics/arrays.
jjg@309 168 if (type.hasLocation()) {
jjg@309 169 sb.append(", location = (");
jjg@309 170 sb.append(location);
jjg@309 171 sb.append(")");
jjg@309 172 }
jjg@309 173
jjg@309 174 sb.append(", pos = ");
jjg@309 175 sb.append(pos);
jjg@309 176
jjg@309 177 sb.append(']');
jjg@309 178 return sb.toString();
jjg@309 179 }
jjg@309 180 }

mercurial