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

changeset 309
664edca41e34
child 310
7c154fdc3547
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Fri Jun 26 19:12:41 2009 -0700
     1.3 @@ -0,0 +1,180 @@
     1.4 +/*
     1.5 + * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.code;
    1.30 +
    1.31 +import com.sun.tools.javac.util.*;
    1.32 +
    1.33 +/** A type annotation position.
    1.34 +*
    1.35 +*  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
    1.36 +*  you write code that depends on this, you do so at your own risk.
    1.37 +*  This code and its internal interfaces are subject to change or
    1.38 +*  deletion without notice.</b>
    1.39 +*/
    1.40 +public class TypeAnnotationPosition {
    1.41 +
    1.42 +    public TargetType type = TargetType.UNKNOWN;
    1.43 +
    1.44 +    // For generic/array types.
    1.45 +    public List<Integer> location = List.nil();
    1.46 +
    1.47 +    // Tree position.
    1.48 +    public int pos = -1;
    1.49 +
    1.50 +    // For typecasts, type tests, new (and locals, as start_pc).
    1.51 +    public int offset = -1;
    1.52 +
    1.53 +    // For locals. arrays same length
    1.54 +    public int[] lvarOffset = new int[] { -1 };
    1.55 +    public int[] lvarLength = new int[] { -1 };
    1.56 +    public int[] lvarIndex = new int[] { -1 };
    1.57 +
    1.58 +    // For type parameter bound
    1.59 +    public int bound_index = -1;
    1.60 +
    1.61 +    // For type parameter and method parameter
    1.62 +    public int parameter_index = -1;
    1.63 +
    1.64 +    // For class extends, implements, and throws classes
    1.65 +    public int type_index = -2;
    1.66 +
    1.67 +    // For wildcards
    1.68 +    public TypeAnnotationPosition wildcard_position = null;
    1.69 +
    1.70 +    @Override
    1.71 +    public String toString() {
    1.72 +        StringBuilder sb = new StringBuilder();
    1.73 +        sb.append('[');
    1.74 +        sb.append(type);
    1.75 +
    1.76 +        switch (type) {
    1.77 +        // type case
    1.78 +        case TYPECAST:
    1.79 +        case TYPECAST_GENERIC_OR_ARRAY:
    1.80 +            // object creation
    1.81 +        case INSTANCEOF:
    1.82 +        case INSTANCEOF_GENERIC_OR_ARRAY:
    1.83 +            // new expression
    1.84 +        case NEW:
    1.85 +        case NEW_GENERIC_OR_ARRAY:
    1.86 +        case NEW_TYPE_ARGUMENT:
    1.87 +        case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
    1.88 +            sb.append(", offset = ");
    1.89 +            sb.append(offset);
    1.90 +            break;
    1.91 +            // local variable
    1.92 +        case LOCAL_VARIABLE:
    1.93 +        case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
    1.94 +            sb.append(", {");
    1.95 +            for (int i = 0; i < lvarOffset.length; ++i) {
    1.96 +                if (i != 0) sb.append("; ");
    1.97 +                sb.append(", start_pc = ");
    1.98 +                sb.append(lvarOffset[i]);
    1.99 +                sb.append(", length = ");
   1.100 +                sb.append(lvarLength[i]);
   1.101 +                sb.append(", index = ");
   1.102 +                sb.append(lvarIndex[i]);
   1.103 +            }
   1.104 +            sb.append("}");
   1.105 +            break;
   1.106 +            // method receiver
   1.107 +        case METHOD_RECEIVER:
   1.108 +            // Do nothing
   1.109 +            break;
   1.110 +            // type parameters
   1.111 +        case CLASS_TYPE_PARAMETER:
   1.112 +        case METHOD_TYPE_PARAMETER:
   1.113 +            sb.append(", param_index = ");
   1.114 +            sb.append(parameter_index);
   1.115 +            break;
   1.116 +            // type parameters bound
   1.117 +        case CLASS_TYPE_PARAMETER_BOUND:
   1.118 +        case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
   1.119 +        case METHOD_TYPE_PARAMETER_BOUND:
   1.120 +        case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
   1.121 +            sb.append(", param_index = ");
   1.122 +            sb.append(parameter_index);
   1.123 +            sb.append(", bound_index = ");
   1.124 +            sb.append(bound_index);
   1.125 +            break;
   1.126 +            // wildcard
   1.127 +        case WILDCARD_BOUND:
   1.128 +        case WILDCARD_BOUND_GENERIC_OR_ARRAY:
   1.129 +            sb.append(", wild_card = ");
   1.130 +            sb.append(wildcard_position);
   1.131 +            break;
   1.132 +            // Class extends and implements clauses
   1.133 +        case CLASS_EXTENDS:
   1.134 +        case CLASS_EXTENDS_GENERIC_OR_ARRAY:
   1.135 +            sb.append(", type_index = ");
   1.136 +            sb.append(type_index);
   1.137 +            break;
   1.138 +            // throws
   1.139 +        case THROWS:
   1.140 +            sb.append(", type_index = ");
   1.141 +            sb.append(type_index);
   1.142 +            break;
   1.143 +        case CLASS_LITERAL:
   1.144 +            sb.append(", offset = ");
   1.145 +            sb.append(offset);
   1.146 +            break;
   1.147 +            // method parameter: not specified
   1.148 +        case METHOD_PARAMETER_GENERIC_OR_ARRAY:
   1.149 +            sb.append(", param_index = ");
   1.150 +            sb.append(parameter_index);
   1.151 +            break;
   1.152 +            // method type argument: wasn't specified
   1.153 +        case METHOD_TYPE_ARGUMENT:
   1.154 +        case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
   1.155 +            sb.append(", offset = ");
   1.156 +            sb.append(offset);
   1.157 +            sb.append(", type_index = ");
   1.158 +            sb.append(type_index);
   1.159 +            break;
   1.160 +            // We don't need to worry abut these
   1.161 +        case METHOD_RETURN_GENERIC_OR_ARRAY:
   1.162 +        case FIELD_GENERIC_OR_ARRAY:
   1.163 +            break;
   1.164 +        case UNKNOWN:
   1.165 +            break;
   1.166 +        default:
   1.167 +            //                throw new AssertionError("unknown type: " + type);
   1.168 +        }
   1.169 +
   1.170 +        // Append location data for generics/arrays.
   1.171 +        if (type.hasLocation()) {
   1.172 +            sb.append(", location = (");
   1.173 +            sb.append(location);
   1.174 +            sb.append(")");
   1.175 +        }
   1.176 +
   1.177 +        sb.append(", pos = ");
   1.178 +        sb.append(pos);
   1.179 +
   1.180 +        sb.append(']');
   1.181 +        return sb.toString();
   1.182 +    }
   1.183 +}

mercurial