langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
author jjg
Fri, 29 Oct 2010 12:47:49 -0700
changeset 7077 55689b828dc5
parent 7072 4863847e93a5
child 7681 1f0819a3341f
permissions -rw-r--r--
6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE} Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     4
 *
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    10
 *
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    15
 * accompanied this code).
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    16
 *
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4877
diff changeset
    23
 * questions.
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    24
 */
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    25
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.code;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    27
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    28
import javax.lang.model.element.ElementKind;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    29
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    30
import com.sun.tools.javac.code.Symbol.VarSymbol;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    31
import com.sun.tools.javac.tree.JCTree;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    32
import com.sun.tools.javac.tree.TreeInfo;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    33
import com.sun.tools.javac.tree.TreeScanner;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.tree.JCTree.*;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.util.Context;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.util.List;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    37
import com.sun.tools.javac.util.ListBuffer;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    38
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    39
/**
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    40
 * Contains operations specific to processing type annotations
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    41
 */
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    42
public class TypeAnnotations {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    43
    private static final Context.Key<TypeAnnotations> key
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    44
        = new Context.Key<TypeAnnotations>();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    45
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    46
    public static TypeAnnotations instance(Context context) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    47
        TypeAnnotations instance = context.get(key);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    48
        if (instance == null)
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    49
            instance = new TypeAnnotations(context);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    50
        return instance;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    51
    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    52
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    53
    protected TypeAnnotations(Context context) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    54
        context.put(key, this);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    55
    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    56
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    57
    public void taFillAndLift(JCClassDecl tree, boolean visitBodies) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
    58
//308        new TypeAnnotationPositions().scan(tree);
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
    59
//308        new TypeAnnotationLift().scan(tree);
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    60
    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    61
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    62
    private static class TypeAnnotationPositions extends TreeScanner {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    63
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    64
        private ListBuffer<JCTree> frames = ListBuffer.lb();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    65
        private void push(JCTree t) { frames = frames.prepend(t); }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    66
        private JCTree pop() { return frames.next(); }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    67
        private JCTree peek2() { return frames.toList().tail.head; }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    68
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    69
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    70
        public void scan(JCTree tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    71
            push(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    72
            super.scan(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    73
            pop();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    74
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    75
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    76
        private boolean inClass = false;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    77
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    78
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    79
        public void visitClassDef(JCClassDecl tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    80
           if (!inClass) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    81
               // Do not recurse into nested and inner classes since
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    82
               // TransTypes.visitClassDef makes an invocation for each class
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    83
               // separately.
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    84
               inClass = true;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    85
               try {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    86
                   super.visitClassDef(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    87
               } finally {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    88
                   inClass = false;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    89
               }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    90
           }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    91
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    92
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    93
        private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame,
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    94
                List<JCTree> path, TypeAnnotationPosition p) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    95
            switch (frame.getKind()) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    96
                case TYPE_CAST:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    97
                    p.type = TargetType.TYPECAST;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    98
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
    99
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   100
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   101
                case INSTANCE_OF:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   102
                    p.type = TargetType.INSTANCEOF;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   103
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   104
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   105
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   106
                case NEW_CLASS:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   107
                    p.type = TargetType.NEW;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   108
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   109
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   110
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   111
                case NEW_ARRAY:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   112
                    p.type = TargetType.NEW;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   113
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   114
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   115
7077
55689b828dc5 6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents: 7072
diff changeset
   116
                case ANNOTATION_TYPE:
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   117
                case CLASS:
7077
55689b828dc5 6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents: 7072
diff changeset
   118
                case ENUM:
6600
b3bb16faccc2 6985181: Annotations lost from classfile
jjg
parents: 5520
diff changeset
   119
                case INTERFACE:
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   120
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   121
                    if (((JCClassDecl)frame).extending == tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   122
                        p.type = TargetType.CLASS_EXTENDS;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   123
                        p.type_index = -1;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   124
                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   125
                        p.type = TargetType.CLASS_EXTENDS;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   126
                        p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   127
                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   128
                        p.type = TargetType.CLASS_TYPE_PARAMETER;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   129
                        p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   130
                    } else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   131
                        throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   132
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   133
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   134
                case METHOD: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   135
                    JCMethodDecl frameMethod = (JCMethodDecl)frame;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   136
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   137
                    if (frameMethod.receiverAnnotations.contains(tree))
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   138
                        p.type = TargetType.METHOD_RECEIVER;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   139
                    else if (frameMethod.thrown.contains(tree)) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   140
                        p.type = TargetType.THROWS;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   141
                        p.type_index = frameMethod.thrown.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   142
                    } else if (((JCMethodDecl)frame).restype == tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   143
                        p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   144
                    } else if (frameMethod.typarams.contains(tree)) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   145
                        p.type = TargetType.METHOD_TYPE_PARAMETER;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   146
                        p.parameter_index = frameMethod.typarams.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   147
                    } else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   148
                        throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   149
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   150
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   151
                case MEMBER_SELECT: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   152
                    JCFieldAccess fieldFrame = (JCFieldAccess)frame;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   153
                    if ("class".contentEquals(fieldFrame.name)) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   154
                        p.type = TargetType.CLASS_LITERAL;
4872
6c49b0ac56a6 6919986: [308] change size of type_index (of CLASS_EXTENDS and THROWS) from byte to short
jjg
parents: 4865
diff changeset
   155
                        p.pos = TreeInfo.innermostType(fieldFrame.selected).pos;
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   156
                    } else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   157
                        throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   158
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   159
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   160
                case PARAMETERIZED_TYPE: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   161
                    TypeAnnotationPosition nextP;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   162
                    if (((JCTypeApply)frame).clazz == tree)
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   163
                        nextP = p; // generic: RAW; noop
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   164
                    else if (((JCTypeApply)frame).arguments.contains(tree))
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   165
                        p.location = p.location.prepend(
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   166
                                ((JCTypeApply)frame).arguments.indexOf(tree));
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   167
                    else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   168
                        throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   169
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   170
                    List<JCTree> newPath = path.tail;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   171
                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   172
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   173
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   174
                case ARRAY_TYPE: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   175
                    p.location = p.location.prepend(0);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   176
                    List<JCTree> newPath = path.tail;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   177
                    return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   178
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   179
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   180
                case TYPE_PARAMETER:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   181
                    if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   182
                        JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   183
                        p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   184
                        p.parameter_index = clazz.typarams.indexOf(path.tail.head);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   185
                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   186
                    } else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   187
                        JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   188
                        p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   189
                        p.parameter_index = method.typarams.indexOf(path.tail.head);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   190
                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   191
                    } else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   192
                        throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   193
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   194
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   195
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   196
                case VARIABLE:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   197
                    VarSymbol v = ((JCVariableDecl)frame).sym;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   198
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   199
                    switch (v.getKind()) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   200
                        case LOCAL_VARIABLE:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   201
                            p.type = TargetType.LOCAL_VARIABLE; break;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   202
                        case FIELD:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   203
                            p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   204
                        case PARAMETER:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   205
                            p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   206
                            p.parameter_index = methodParamIndex(path, frame);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   207
                            break;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   208
                        default: throw new AssertionError();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   209
                    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   210
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   211
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
   212
//308                case ANNOTATED_TYPE: {
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
   213
//308                    List<JCTree> newPath = path.tail;
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
   214
//308                    return resolveFrame(newPath.head, newPath.tail.head,
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
   215
//308                            newPath, p);
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6600
diff changeset
   216
//308                }
4865
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   217
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   218
                case METHOD_INVOCATION: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   219
                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   220
                    if (!invocation.typeargs.contains(tree))
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   221
                        throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   222
                    p.type = TargetType.METHOD_TYPE_ARGUMENT;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   223
                    p.pos = invocation.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   224
                    p.type_index = invocation.typeargs.indexOf(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   225
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   226
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   227
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   228
                case EXTENDS_WILDCARD:
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   229
                case SUPER_WILDCARD: {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   230
                    p.type = TargetType.WILDCARD_BOUND;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   231
                    List<JCTree> newPath = path.tail;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   232
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   233
                    TypeAnnotationPosition wildcard =
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   234
                        resolveFrame(newPath.head, newPath.tail.head, newPath,
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   235
                                new TypeAnnotationPosition());
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   236
                    if (!wildcard.location.isEmpty())
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   237
                        wildcard.type = wildcard.type.getGenericComplement();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   238
                    p.wildcard_position = wildcard;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   239
                    p.pos = frame.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   240
                    return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   241
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   242
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   243
            return p;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   244
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   245
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   246
        private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   247
            for (JCTypeAnnotation anno : annotations) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   248
                anno.annotation_position = position;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   249
                anno.attribute_field.position = position;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   250
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   251
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   252
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   253
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   254
        public void visitNewArray(JCNewArray tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   255
            findPosition(tree, tree, tree.annotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   256
            int dimAnnosCount = tree.dimAnnotations.size();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   257
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   258
            // handle annotations associated with dimentions
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   259
            for (int i = 0; i < dimAnnosCount; ++i) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   260
                TypeAnnotationPosition p = new TypeAnnotationPosition();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   261
                p.type = TargetType.NEW_GENERIC_OR_ARRAY;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   262
                p.pos = tree.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   263
                p.location = p.location.append(i);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   264
                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   265
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   266
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   267
            // handle "free" annotations
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   268
            int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   269
            JCExpression elemType = tree.elemtype;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   270
            while (elemType != null) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   271
                if (elemType.getTag() == JCTree.ANNOTATED_TYPE) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   272
                    JCAnnotatedType at = (JCAnnotatedType)elemType;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   273
                    TypeAnnotationPosition p = new TypeAnnotationPosition();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   274
                    p.type = TargetType.NEW_GENERIC_OR_ARRAY;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   275
                    p.pos = tree.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   276
                    p.location = p.location.append(i);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   277
                    setTypeAnnotationPos(at.annotations, p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   278
                    elemType = at.underlyingType;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   279
                } else if (elemType.getTag() == JCTree.TYPEARRAY) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   280
                    ++i;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   281
                    elemType = ((JCArrayTypeTree)elemType).elemtype;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   282
                } else
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   283
                    break;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   284
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   285
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   286
            // find annotations locations of initializer elements
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   287
            scan(tree.elems);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   288
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   289
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   290
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   291
        public void visitAnnotatedType(JCAnnotatedType tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   292
            findPosition(tree, peek2(), tree.annotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   293
            super.visitAnnotatedType(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   294
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   295
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   296
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   297
        public void visitMethodDef(JCMethodDecl tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   298
            TypeAnnotationPosition p = new TypeAnnotationPosition();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   299
            p.type = TargetType.METHOD_RECEIVER;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   300
            setTypeAnnotationPos(tree.receiverAnnotations, p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   301
            super.visitMethodDef(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   302
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   303
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   304
        public void visitTypeParameter(JCTypeParameter tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   305
            findPosition(tree, peek2(), tree.annotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   306
            super.visitTypeParameter(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   307
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   308
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   309
        void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   310
            if (!annotations.isEmpty()) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   311
                TypeAnnotationPosition p =
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   312
                        resolveFrame(tree, frame, frames.toList(),
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   313
                                new TypeAnnotationPosition());
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   314
                if (!p.location.isEmpty())
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   315
                    p.type = p.type.getGenericComplement();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   316
                setTypeAnnotationPos(annotations, p);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   317
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   318
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   319
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   320
        private int methodParamIndex(List<JCTree> path, JCTree param) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   321
            List<JCTree> curr = path;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   322
            if (curr.head != param)
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   323
                curr = path.tail;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   324
            JCMethodDecl method = (JCMethodDecl)curr.tail.head;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   325
            return method.params.indexOf(param);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   326
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   327
    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   328
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   329
    private static class TypeAnnotationLift extends TreeScanner {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   330
        List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   331
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   332
        boolean isInner = false;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   333
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   334
        public void visitClassDef(JCClassDecl tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   335
            if (isInner) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   336
                // tree is an inner class tree.  stop now.
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   337
                // TransTypes.visitClassDef makes an invocation for each class
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   338
                // separately.
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   339
                return;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   340
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   341
            isInner = true;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   342
            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   343
            recordedTypeAnnotations = List.nil();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   344
            try {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   345
                super.visitClassDef(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   346
            } finally {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   347
                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   348
                recordedTypeAnnotations = prevTAs;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   349
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   350
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   351
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   352
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   353
        public void visitMethodDef(JCMethodDecl tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   354
            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   355
            recordedTypeAnnotations = List.nil();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   356
            try {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   357
                super.visitMethodDef(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   358
            } finally {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   359
                tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   360
                recordedTypeAnnotations = prevTAs;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   361
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   362
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   363
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   364
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   365
        public void visitVarDef(JCVariableDecl tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   366
            List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   367
            recordedTypeAnnotations = List.nil();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   368
            ElementKind kind = tree.sym.getKind();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   369
            if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   370
                // need to lift the annotations
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   371
                TypeAnnotationPosition position = new TypeAnnotationPosition();
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   372
                position.pos = tree.pos;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   373
                position.type = TargetType.LOCAL_VARIABLE;
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   374
                for (Attribute.Compound attribute : tree.sym.attributes_field) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   375
                    Attribute.TypeCompound tc =
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   376
                        new Attribute.TypeCompound(attribute.type, attribute.values, position);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   377
                    recordedTypeAnnotations = recordedTypeAnnotations.append(tc);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   378
                }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   379
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   380
            try {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   381
                super.visitVarDef(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   382
            } finally {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   383
                if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE)
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   384
                    tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   385
                recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   386
            }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   387
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   388
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   389
        @Override
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   390
        public void visitApply(JCMethodInvocation tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   391
            scan(tree.meth);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   392
            scan(tree.typeargs);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   393
            scan(tree.args);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   394
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   395
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   396
        public void visitAnnotation(JCAnnotation tree) {
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   397
            if (tree instanceof JCTypeAnnotation)
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   398
                recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   399
            super.visitAnnotation(tree);
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   400
        }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   401
    }
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   402
1e4422ac2495 6917067: refactor type annotations code from TransTypes into new TypeAnnotations class
jjg
parents:
diff changeset
   403
}