langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
author emc
Fri, 09 May 2014 09:28:47 -0400
changeset 24396 3c36c6afcbca
parent 22702 1297fbaf34fa
permissions -rw-r--r--
8040327: Eliminate AnnotatedType Summary: Replace AnnotatedType with type annotations being stored in the Type class as metadata Reviewed-by: jjg, jfranck, wmdietl, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     1
/*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     4
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    10
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    15
 * accompanied this code).
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    16
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    20
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    23
 * questions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    24
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    25
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.code;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    27
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    28
import javax.lang.model.element.Element;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    29
import javax.lang.model.element.ElementKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    30
import javax.lang.model.type.TypeKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    31
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    32
import javax.tools.JavaFileObject;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    33
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.code.Attribute.TypeCompound;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.code.Type.ArrayType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.code.Type.CapturedType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    37
import com.sun.tools.javac.code.Type.ClassType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    38
import com.sun.tools.javac.code.Type.ErrorType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    39
import com.sun.tools.javac.code.Type.ForAll;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    40
import com.sun.tools.javac.code.Type.MethodType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    41
import com.sun.tools.javac.code.Type.PackageType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    42
import com.sun.tools.javac.code.Type.TypeVar;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    43
import com.sun.tools.javac.code.Type.UndetVar;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    44
import com.sun.tools.javac.code.Type.Visitor;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    45
import com.sun.tools.javac.code.Type.WildcardType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    46
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    47
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.code.Symbol.VarSymbol;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    49
import com.sun.tools.javac.code.Symbol.MethodSymbol;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    50
import com.sun.tools.javac.comp.Annotate;
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
    51
import com.sun.tools.javac.comp.Annotate.Worker;
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
    52
import com.sun.tools.javac.comp.Attr;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    53
import com.sun.tools.javac.comp.AttrContext;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    54
import com.sun.tools.javac.comp.Env;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    55
import com.sun.tools.javac.tree.JCTree;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    56
import com.sun.tools.javac.tree.TreeInfo;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    57
import com.sun.tools.javac.tree.JCTree.JCBlock;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    58
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    59
import com.sun.tools.javac.tree.JCTree.JCExpression;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    60
import com.sun.tools.javac.tree.JCTree.JCLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    61
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    62
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    63
import com.sun.tools.javac.tree.JCTree.JCNewClass;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    64
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    65
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    66
import com.sun.tools.javac.tree.TreeScanner;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    67
import com.sun.tools.javac.tree.JCTree.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    68
import com.sun.tools.javac.util.Assert;
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    69
import com.sun.tools.javac.util.Context;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    70
import com.sun.tools.javac.util.List;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    71
import com.sun.tools.javac.util.ListBuffer;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    72
import com.sun.tools.javac.util.Log;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    73
import com.sun.tools.javac.util.Names;
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
    74
import com.sun.tools.javac.util.Options;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    75
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    76
/**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    77
 * Contains operations specific to processing type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    78
 * This class has two functions:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    79
 * separate declaration from type annotations and insert the type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    80
 * annotations to their types;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    81
 * and determine the TypeAnnotationPositions for all type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    82
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    83
public class TypeAnnotations {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
    84
    protected static final Context.Key<TypeAnnotations> typeAnnosKey = new Context.Key<>();
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    85
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    86
    public static TypeAnnotations instance(Context context) {
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    87
        TypeAnnotations instance = context.get(typeAnnosKey);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    88
        if (instance == null)
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    89
            instance = new TypeAnnotations(context);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    90
        return instance;
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    91
    }
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    92
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    93
    final Log log;
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    94
    final Names names;
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    95
    final Symtab syms;
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    96
    final Annotate annotate;
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
    97
    final Attr attr;
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    98
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
    99
    protected TypeAnnotations(Context context) {
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   100
        context.put(typeAnnosKey, this);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   101
        names = Names.instance(context);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   102
        log = Log.instance(context);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   103
        syms = Symtab.instance(context);
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   104
        annotate = Annotate.instance(context);
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   105
        attr = Attr.instance(context);
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
   106
        Options options = Options.instance(context);
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   107
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   108
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   109
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   110
     * Separate type annotations from declaration annotations and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   111
     * determine the correct positions for type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   112
     * This version only visits types in signatures and should be
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   113
     * called from MemberEnter.
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   114
     * The method takes the Annotate object as parameter and
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   115
     * adds an Annotate.Worker to the correct Annotate queue for
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   116
     * later processing.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   117
     */
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   118
    public void organizeTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   119
        annotate.afterRepeated( new Worker() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   120
            @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   121
            public void run() {
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   122
                JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   123
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   124
                try {
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   125
                    new TypeAnnotationPositions(true).scan(tree);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   126
                } finally {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   127
                    log.useSource(oldSource);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   128
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   129
            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   130
        } );
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   131
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   132
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   133
    public void validateTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   134
        annotate.validate(new Worker() { //validate annotations
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   135
            @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   136
            public void run() {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   137
                JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   138
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   139
                try {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   140
                    attr.validateTypeAnnotations(tree, true);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   141
                } finally {
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   142
                    log.useSource(oldSource);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   143
                }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   144
            }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   145
        } );
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   146
    }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21010
diff changeset
   147
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   148
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   149
     * This version only visits types in bodies, that is, field initializers,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   150
     * top-level blocks, and method bodies, and should be called from Attr.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   151
     */
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   152
    public void organizeTypeAnnotationsBodies(JCClassDecl tree) {
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   153
        new TypeAnnotationPositions(false).scan(tree);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   154
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   155
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
   156
    public enum AnnotationType { DECLARATION, TYPE, BOTH }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   157
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   158
    /**
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   159
     * Determine whether an annotation is a declaration annotation,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   160
     * a type annotation, or both.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   161
     */
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   162
    public AnnotationType annotationType(Attribute.Compound a, Symbol s) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   163
        Attribute.Compound atTarget =
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   164
            a.type.tsym.attribute(syms.annotationTargetType.tsym);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   165
        if (atTarget == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   166
            return inferTargetMetaInfo(a, s);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   167
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   168
        Attribute atValue = atTarget.member(names.value);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   169
        if (!(atValue instanceof Attribute.Array)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   170
            Assert.error("annotationType(): bad @Target argument " + atValue +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   171
                    " (" + atValue.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   172
            return AnnotationType.DECLARATION; // error recovery
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   173
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   174
        Attribute.Array arr = (Attribute.Array) atValue;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   175
        boolean isDecl = false, isType = false;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   176
        for (Attribute app : arr.values) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   177
            if (!(app instanceof Attribute.Enum)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   178
                Assert.error("annotationType(): unrecognized Attribute kind " + app +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   179
                        " (" + app.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   180
                isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   181
                continue;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   182
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   183
            Attribute.Enum e = (Attribute.Enum) app;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   184
            if (e.value.name == names.TYPE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   185
                if (s.kind == Kinds.TYP)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   186
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   187
            } else if (e.value.name == names.FIELD) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   188
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   189
                        s.owner.kind != Kinds.MTH)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   190
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   191
            } else if (e.value.name == names.METHOD) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   192
                if (s.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   193
                        !s.isConstructor())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   194
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   195
            } else if (e.value.name == names.PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   196
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   197
                        s.owner.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   198
                        (s.flags() & Flags.PARAMETER) != 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   199
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   200
            } else if (e.value.name == names.CONSTRUCTOR) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   201
                if (s.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   202
                        s.isConstructor())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   203
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   204
            } else if (e.value.name == names.LOCAL_VARIABLE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   205
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   206
                        s.owner.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   207
                        (s.flags() & Flags.PARAMETER) == 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   208
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   209
            } else if (e.value.name == names.ANNOTATION_TYPE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   210
                if (s.kind == Kinds.TYP &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   211
                        (s.flags() & Flags.ANNOTATION) != 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   212
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   213
            } else if (e.value.name == names.PACKAGE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   214
                if (s.kind == Kinds.PCK)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   215
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   216
            } else if (e.value.name == names.TYPE_USE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   217
                if (s.kind == Kinds.TYP ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   218
                        s.kind == Kinds.VAR ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   219
                        (s.kind == Kinds.MTH && !s.isConstructor() &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   220
                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   221
                        (s.kind == Kinds.MTH && s.isConstructor()))
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   222
                    isType = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   223
            } else if (e.value.name == names.TYPE_PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   224
                /* Irrelevant in this case */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   225
                // TYPE_PARAMETER doesn't aid in distinguishing between
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   226
                // Type annotations and declaration annotations on an
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   227
                // Element
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   228
            } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   229
                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   230
                        " (" + e.value.name.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   231
                isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   232
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   233
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   234
        if (isDecl && isType) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   235
            return AnnotationType.BOTH;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   236
        } else if (isType) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   237
            return AnnotationType.TYPE;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   238
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   239
            return AnnotationType.DECLARATION;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   240
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   241
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   242
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   243
    /** Infer the target annotation kind, if none is give.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   244
     * We only infer declaration annotations.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   245
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   246
    private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   247
        return AnnotationType.DECLARATION;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   248
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   249
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   250
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   251
    private class TypeAnnotationPositions extends TreeScanner {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   252
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   253
        private final boolean sigOnly;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   254
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   255
        TypeAnnotationPositions(boolean sigOnly) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   256
            this.sigOnly = sigOnly;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   257
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   258
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   259
        /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   260
         * When traversing the AST we keep the "frames" of visited
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   261
         * trees in order to determine the position of annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   262
         */
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19651
diff changeset
   263
        private ListBuffer<JCTree> frames = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   264
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   265
        protected void push(JCTree t) { frames = frames.prepend(t); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   266
        protected JCTree pop() { return frames.next(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   267
        // could this be frames.elems.tail.head?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   268
        private JCTree peek2() { return frames.toList().tail.head; }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   269
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   270
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   271
        public void scan(JCTree tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   272
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   273
            super.scan(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   274
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   275
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   276
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   277
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   278
         * Separates type annotations from declaration annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   279
         * This step is needed because in certain locations (where declaration
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   280
         * and type annotations can be mixed, e.g. the type of a field)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   281
         * we never build an JCAnnotatedType. This step finds these
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   282
         * annotations and marks them as if they were part of the type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   283
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   284
        private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   285
                TypeAnnotationPosition pos) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   286
            List<Attribute.Compound> annotations = sym.getRawAttributes();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
   287
            ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
   288
            ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
   289
            ListBuffer<Attribute.TypeCompound> onlyTypeAnnos = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   290
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   291
            for (Attribute.Compound a : annotations) {
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   292
                switch (annotationType(a, sym)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   293
                case DECLARATION:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   294
                    declAnnos.append(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   295
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   296
                case BOTH: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   297
                    declAnnos.append(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   298
                    Attribute.TypeCompound ta = toTypeCompound(a, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   299
                    typeAnnos.append(ta);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   300
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   301
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   302
                case TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   303
                    Attribute.TypeCompound ta = toTypeCompound(a, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   304
                    typeAnnos.append(ta);
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   305
                    // Also keep track which annotations are only type annotations
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   306
                    onlyTypeAnnos.append(ta);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   307
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   308
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   309
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   310
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   311
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   312
            sym.resetAnnotations();
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   313
            sym.setDeclarationAttributes(declAnnos.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   314
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   315
            if (typeAnnos.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   316
                return;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   317
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   318
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   319
            List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   320
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   321
            if (type == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   322
                // When type is null, put the type annotations to the symbol.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   323
                // This is used for constructor return annotations, for which
21481
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   324
                // we use the type of the enclosing class.
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   325
                type = sym.getEnclosingElement().asType();
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   326
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   327
                // Declaration annotations are always allowed on constructor returns.
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   328
                // Therefore, use typeAnnotations instead of onlyTypeAnnos.
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   329
                type = typeWithAnnotations(typetree, type, typeAnnotations, typeAnnotations);
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   330
                // Note that we don't use the result, the call to
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   331
                // typeWithAnnotations side-effects the type annotation positions.
f0aeb1da97bd 8026791: wrong type_path encoded for method_return on an inner class constructor
jjg
parents: 21480
diff changeset
   332
                // This is important for constructors of nested classes.
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   333
                sym.appendUniqueTypeAttributes(typeAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   334
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   335
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   336
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   337
            // type is non-null and annotations are added to that type
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   338
            type = typeWithAnnotations(typetree, type, typeAnnotations, onlyTypeAnnos.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   339
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   340
            if (sym.getKind() == ElementKind.METHOD) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   341
                sym.type.asMethodType().restype = type;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   342
            } else if (sym.getKind() == ElementKind.PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   343
                sym.type = type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   344
                if (sym.getQualifiedName().equals(names._this)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   345
                    sym.owner.type.asMethodType().recvtype = type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   346
                    // note that the typeAnnotations will also be added to the owner below.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   347
                } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   348
                    MethodType methType = sym.owner.type.asMethodType();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   349
                    List<VarSymbol> params = ((MethodSymbol)sym.owner).params;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   350
                    List<Type> oldArgs = methType.argtypes;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
   351
                    ListBuffer<Type> newArgs = new ListBuffer<>();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   352
                    while (params.nonEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   353
                        if (params.head == sym) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   354
                            newArgs.add(type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   355
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   356
                            newArgs.add(oldArgs.head);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   357
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   358
                        oldArgs = oldArgs.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   359
                        params = params.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   360
                    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   361
                    methType.argtypes = newArgs.toList();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   362
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   363
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   364
                sym.type = type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   365
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   366
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   367
            sym.appendUniqueTypeAttributes(typeAnnotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   368
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   369
            if (sym.getKind() == ElementKind.PARAMETER ||
21499
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
   370
                sym.getKind() == ElementKind.LOCAL_VARIABLE ||
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
   371
                sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
   372
                sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   373
                // Make sure all type annotations from the symbol are also
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   374
                // on the owner.
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   375
                sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   376
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   377
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   378
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   379
        // This method has a similar purpose as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   380
        // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   381
        // We found a type annotation in a declaration annotation position,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   382
        // for example, on the return type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   383
        // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   384
        // need to set its position explicitly.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   385
        // The method returns a copy of type that contains these annotations.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   386
        //
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   387
        // As a side effect the method sets the type annotation position of "annotations".
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   388
        // Note that it is assumed that all annotations share the same position.
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   389
        private Type typeWithAnnotations(final JCTree typetree, final Type type,
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   390
                final List<Attribute.TypeCompound> annotations,
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   391
                final List<Attribute.TypeCompound> onlyTypeAnnotations) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   392
            //System.err.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s, onlyTypeAnnotations: %s)%n",
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   393
            //         typetree, type, annotations, onlyTypeAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   394
            if (annotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   395
                return type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   396
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   397
            if (type.hasTag(TypeTag.ARRAY)) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   398
                Type.ArrayType arType = (Type.ArrayType) type;
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   399
                Type.ArrayType tomodify = new Type.ArrayType(null, arType.tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   400
                                                             Type.noAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   401
                Type toreturn;
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   402
                if (type.isAnnotated()) {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   403
                    toreturn = tomodify.annotatedType(type.getAnnotationMirrors());
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   404
                } else {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   405
                    toreturn = tomodify;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   406
                }
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   407
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   408
                JCArrayTypeTree arTree = arrayTypeTree(typetree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   409
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19651
diff changeset
   410
                ListBuffer<TypePathEntry> depth = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   411
                depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   412
                while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
16556
f4adc5bb4652 8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents: 15718
diff changeset
   413
                    if (arType.elemtype.isAnnotated()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21043
diff changeset
   414
                        Type aelemtype = arType.elemtype;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   415
                        arType = (Type.ArrayType) aelemtype;
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   416
                        ArrayType prevToMod = tomodify;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   417
                        tomodify = new Type.ArrayType(null, arType.tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   418
                                                      Type.noAnnotations);
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21043
diff changeset
   419
                        prevToMod.elemtype = tomodify.annotatedType(arType.elemtype.getAnnotationMirrors());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   420
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   421
                        arType = (Type.ArrayType) arType.elemtype;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   422
                        tomodify.elemtype = new Type.ArrayType(null, arType.tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   423
                                                               Type.noAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   424
                        tomodify = (Type.ArrayType) tomodify.elemtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   425
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   426
                    arTree = arrayTypeTree(arTree.elemtype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   427
                    depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   428
                }
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   429
                Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, onlyTypeAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   430
                tomodify.elemtype = arelemType;
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   431
                {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   432
                    // All annotations share the same position; modify the first one.
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   433
                    Attribute.TypeCompound a = annotations.get(0);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   434
                    TypeAnnotationPosition p = a.position;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   435
                    p.location = p.location.prependList(depth.toList());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   436
                }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   437
                typetree.type = toreturn;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   438
                return toreturn;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   439
            } else if (type.hasTag(TypeTag.TYPEVAR)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   440
                // Nothing to do for type variables.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   441
                return type;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   442
            } else if (type.getKind() == TypeKind.UNION) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   443
                // There is a TypeKind, but no TypeTag.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   444
                JCTypeUnion tutree = (JCTypeUnion) typetree;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   445
                JCExpression fst = tutree.alternatives.get(0);
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   446
                Type res = typeWithAnnotations(fst, fst.type, annotations, onlyTypeAnnotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   447
                fst.type = res;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   448
                // TODO: do we want to set res as first element in uct.alternatives?
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   449
                // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   450
                // Return the un-annotated union-type.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   451
                return type;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   452
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   453
                Type enclTy = type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   454
                Element enclEl = type.asElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   455
                JCTree enclTr = typetree;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   456
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   457
                while (enclEl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   458
                        enclEl.getKind() != ElementKind.PACKAGE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   459
                        enclTy != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   460
                        enclTy.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   461
                        enclTy.getKind() != TypeKind.ERROR &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   462
                        (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   463
                         enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   464
                         enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   465
                    // Iterate also over the type tree, not just the type: the type is already
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   466
                    // completely resolved and we cannot distinguish where the annotation
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   467
                    // belongs for a nested type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   468
                    if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   469
                        // only change encl in this case.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   470
                        enclTy = enclTy.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   471
                        enclEl = enclEl.getEnclosingElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   472
                        enclTr = ((JCFieldAccess)enclTr).getExpression();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   473
                    } else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   474
                        enclTr = ((JCTypeApply)enclTr).getType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   475
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   476
                        // only other option because of while condition
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   477
                        enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   478
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   479
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   480
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   481
                /** We are trying to annotate some enclosing type,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   482
                 * but nothing more exists.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   483
                 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   484
                if (enclTy != null &&
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   485
                        enclTy.hasTag(TypeTag.NONE)) {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   486
                    switch (onlyTypeAnnotations.size()) {
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   487
                    case 0:
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   488
                        // Don't issue an error if all type annotations are
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   489
                        // also declaration annotations.
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   490
                        // If the annotations are also declaration annotations, they are
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   491
                        // illegal as type annotations but might be legal as declaration annotations.
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   492
                        // The normal declaration annotation checks make sure that the use is valid.
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   493
                        break;
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   494
                    case 1:
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   495
                        log.error(typetree.pos(), "cant.type.annotate.scoping.1",
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   496
                                onlyTypeAnnotations);
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   497
                        break;
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   498
                    default:
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   499
                        log.error(typetree.pos(), "cant.type.annotate.scoping",
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   500
                                onlyTypeAnnotations);
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   501
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   502
                    return type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   503
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   504
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   505
                // At this point we have visited the part of the nested
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   506
                // type that is written in the source code.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   507
                // Now count from here to the actual top-level class to determine
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   508
                // the correct nesting.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   509
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   510
                // The genericLocation for the annotation.
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19651
diff changeset
   511
                ListBuffer<TypePathEntry> depth = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   512
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   513
                Type topTy = enclTy;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   514
                while (enclEl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   515
                        enclEl.getKind() != ElementKind.PACKAGE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   516
                        topTy != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   517
                        topTy.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   518
                        topTy.getKind() != TypeKind.ERROR) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   519
                    topTy = topTy.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   520
                    enclEl = enclEl.getEnclosingElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   521
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   522
                    if (topTy != null && topTy.getKind() != TypeKind.NONE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   523
                        // Only count enclosing types.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   524
                        depth = depth.append(TypePathEntry.INNER_TYPE);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   525
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   526
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   527
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   528
                if (depth.nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   529
                    // Only need to change the annotation positions
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   530
                    // if they are on an enclosed type.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   531
                    // All annotations share the same position; modify the first one.
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   532
                    Attribute.TypeCompound a = annotations.get(0);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   533
                    TypeAnnotationPosition p = a.position;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   534
                    p.location = p.location.appendList(depth.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   535
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   536
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   537
                Type ret = typeWithAnnotations(type, enclTy, annotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   538
                typetree.type = ret;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   539
                return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   540
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   541
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   542
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   543
        private JCArrayTypeTree arrayTypeTree(JCTree typetree) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   544
            if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   545
                return (JCArrayTypeTree) typetree;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   546
            } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   547
                return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   548
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   549
                Assert.error("Could not determine array type from type tree: " + typetree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   550
                return null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   551
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   552
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   553
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   554
        /** Return a copy of the first type that only differs by
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   555
         * inserting the annotations to the left-most/inner-most type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   556
         * or the type given by stopAt.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   557
         *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   558
         * We need the stopAt parameter to know where on a type to
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   559
         * put the annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   560
         * If we have nested classes Outer > Middle > Inner, and we
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   561
         * have the source type "@A Middle.Inner", we will invoke
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   562
         * this method with type = Outer.Middle.Inner,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   563
         * stopAt = Middle.Inner, and annotations = @A.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   564
         *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   565
         * @param type The type to copy.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   566
         * @param stopAt The type to stop at.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   567
         * @param annotations The annotations to insert.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   568
         * @return A copy of type that contains the annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   569
         */
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   570
        private Type typeWithAnnotations(final Type type,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   571
                final Type stopAt,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   572
                final List<Attribute.TypeCompound> annotations) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   573
            //System.err.println("typeWithAnnotations " + type + " " + annotations + " stopAt " + stopAt);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   574
            Visitor<Type, List<TypeCompound>> visitor =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   575
                    new Type.Visitor<Type, List<Attribute.TypeCompound>>() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   576
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   577
                public Type visitClassType(ClassType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   578
                    // assert that t.constValue() == null?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   579
                    if (t == stopAt ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   580
                        t.getEnclosingType() == Type.noType) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   581
                        return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   582
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   583
                        ClassType ret = new ClassType(t.getEnclosingType().accept(this, s),
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   584
                                                      t.typarams_field, t.tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   585
                                                      t.getAnnotationMirrors());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   586
                        ret.all_interfaces_field = t.all_interfaces_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   587
                        ret.allparams_field = t.allparams_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   588
                        ret.interfaces_field = t.interfaces_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   589
                        ret.rank_field = t.rank_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   590
                        ret.supertype_field = t.supertype_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   591
                        return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   592
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   593
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   594
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   595
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   596
                public Type visitWildcardType(WildcardType t, List<TypeCompound> s) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   597
                    return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   598
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   599
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   600
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   601
                public Type visitArrayType(ArrayType t, List<TypeCompound> s) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   602
                    ArrayType ret = new ArrayType(t.elemtype.accept(this, s), t.tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 22702
diff changeset
   603
                                                  t.getAnnotationMirrors());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   604
                    return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   605
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   606
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   607
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   608
                public Type visitMethodType(MethodType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   609
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   610
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   611
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   612
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   613
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   614
                public Type visitPackageType(PackageType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   615
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   616
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   617
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   618
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   619
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   620
                public Type visitTypeVar(TypeVar t, List<TypeCompound> s) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   621
                    return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   622
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   623
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   624
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   625
                public Type visitCapturedType(CapturedType t, List<TypeCompound> s) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   626
                    return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   627
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   628
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   629
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   630
                public Type visitForAll(ForAll t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   631
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   632
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   633
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   634
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   635
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   636
                public Type visitUndetVar(UndetVar t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   637
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   638
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   639
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   640
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   641
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   642
                public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   643
                    return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   644
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   645
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   646
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   647
                public Type visitType(Type t, List<TypeCompound> s) {
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   648
                    return t.annotatedType(s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   649
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   650
            };
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   651
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   652
            return type.accept(visitor, annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   653
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   654
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
   655
        private Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   656
            // It is safe to alias the position.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   657
            return new Attribute.TypeCompound(a, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   658
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   659
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   660
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   661
        /* This is the beginning of the second part of organizing
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   662
         * type annotations: determine the type annotation positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   663
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   664
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   665
        // This method is considered deprecated, and will be removed
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   666
        // in the near future.  Don't use it for anything new.
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   667
        private TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   668
            resolveFrame(JCTree tree,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   669
                         JCTree frame,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   670
                         List<JCTree> path,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   671
                         JCLambda currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   672
                         int outer_type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   673
                         ListBuffer<TypePathEntry> location) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   674
            /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   675
            System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   676
            System.out.println("    Framing tree: " + frame + " kind: " + frame.getKind());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   677
            */
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   678
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   679
            // Note that p.offset is set in
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   680
            // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   681
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   682
            switch (frame.getKind()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   683
                case TYPE_CAST:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   684
                    return TypeAnnotationPosition.typeCast(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   685
                                                           currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   686
                                                           outer_type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   687
                                                           frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   688
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   689
                case INSTANCE_OF:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   690
                    return TypeAnnotationPosition.instanceOf(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   691
                                                             currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   692
                                                             frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   693
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   694
                case NEW_CLASS:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   695
                    final JCNewClass frameNewClass = (JCNewClass) frame;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   696
                    if (frameNewClass.def != null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   697
                        // Special handling for anonymous class instantiations
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   698
                        final JCClassDecl frameClassDecl = frameNewClass.def;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   699
                        if (frameClassDecl.extending == tree) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   700
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   701
                                .classExtends(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   702
                                              frame.pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   703
                        } else if (frameClassDecl.implementing.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   704
                            final int type_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   705
                                frameClassDecl.implementing.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   706
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   707
                                .classExtends(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   708
                                              type_index, frame.pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   709
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   710
                            // In contrast to CLASS below, typarams cannot occur here.
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   711
                            throw new AssertionError("Could not determine position of tree " + tree +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   712
                                                     " within frame " + frame);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   713
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   714
                    } else if (frameNewClass.typeargs.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   715
                        final int type_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   716
                            frameNewClass.typeargs.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   717
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   718
                            .constructorInvocationTypeArg(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   719
                                                          currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   720
                                                          type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   721
                                                          frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   722
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   723
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   724
                            .newObj(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   725
                                    frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   726
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   727
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   728
                case NEW_ARRAY:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   729
                    return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   730
                        .newObj(location.toList(), currentLambda, frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   731
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   732
                case ANNOTATION_TYPE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   733
                case CLASS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   734
                case ENUM:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   735
                case INTERFACE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   736
                    if (((JCClassDecl)frame).extending == tree) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   737
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   738
                            .classExtends(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   739
                                          frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   740
                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   741
                        final int type_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   742
                            ((JCClassDecl)frame).implementing.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   743
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   744
                            .classExtends(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   745
                                          type_index, frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   746
                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   747
                        final int parameter_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   748
                            ((JCClassDecl)frame).typarams.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   749
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   750
                            .typeParameter(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   751
                                           parameter_index, frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   752
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   753
                        throw new AssertionError("Could not determine position of tree " +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   754
                                                 tree + " within frame " + frame);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   755
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   756
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   757
                case METHOD: {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   758
                    final JCMethodDecl frameMethod = (JCMethodDecl) frame;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   759
                    if (frameMethod.thrown.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   760
                        final int type_index = frameMethod.thrown.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   761
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   762
                            .methodThrows(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   763
                                          type_index, frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   764
                    } else if (frameMethod.restype == tree) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   765
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   766
                            .methodReturn(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   767
                                          frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   768
                    } else if (frameMethod.typarams.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   769
                        final int parameter_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   770
                            frameMethod.typarams.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   771
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   772
                            .methodTypeParameter(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   773
                                                 currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   774
                                                 parameter_index, frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   775
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   776
                        throw new AssertionError("Could not determine position of tree " + tree +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   777
                                                 " within frame " + frame);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   778
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   779
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   780
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   781
                case PARAMETERIZED_TYPE: {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   782
                    List<JCTree> newPath = path.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   783
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   784
                    if (((JCTypeApply)frame).clazz == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   785
                        // generic: RAW; noop
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   786
                    } else if (((JCTypeApply)frame).arguments.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   787
                        JCTypeApply taframe = (JCTypeApply) frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   788
                        int arg = taframe.arguments.indexOf(tree);
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   789
                        location = location.prepend(
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   790
                            new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   791
                                              arg));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   792
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   793
                        Type typeToUse;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   794
                        if (newPath.tail != null &&
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   795
                            newPath.tail.head.hasTag(Tag.NEWCLASS)) {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   796
                            // If we are within an anonymous class
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   797
                            // instantiation, use its type, because it
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   798
                            // contains a correctly nested type.
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   799
                            typeToUse = newPath.tail.head.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   800
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   801
                            typeToUse = taframe.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   802
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   803
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   804
                        location = locateNestedTypes(typeToUse, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   805
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   806
                        throw new AssertionError("Could not determine type argument position of tree " + tree +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   807
                                                 " within frame " + frame);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   808
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   809
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   810
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   811
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   812
                                        outer_type_index, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   813
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   814
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   815
                case MEMBER_REFERENCE: {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   816
                    JCMemberReference mrframe = (JCMemberReference) frame;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   817
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   818
                    if (mrframe.expr == tree) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   819
                        switch (mrframe.mode) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   820
                        case INVOKE:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   821
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   822
                                .methodRef(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   823
                                           frame.pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   824
                        case NEW:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   825
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   826
                                .constructorRef(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   827
                                                currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   828
                                                frame.pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   829
                        default:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   830
                            throw new AssertionError("Unknown method reference mode " + mrframe.mode +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   831
                                                     " for tree " + tree + " within frame " + frame);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   832
                        }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   833
                    } else if (mrframe.typeargs != null &&
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   834
                            mrframe.typeargs.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   835
                        final int type_index = mrframe.typeargs.indexOf(tree);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   836
                        switch (mrframe.mode) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   837
                        case INVOKE:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   838
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   839
                                .methodRefTypeArg(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   840
                                                  currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   841
                                                  type_index, frame.pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   842
                        case NEW:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   843
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   844
                                .constructorRefTypeArg(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   845
                                                       currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   846
                                                       type_index, frame.pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   847
                        default:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   848
                            throw new AssertionError("Unknown method reference mode " + mrframe.mode +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   849
                                                   " for tree " + tree + " within frame " + frame);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   850
                        }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   851
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   852
                        throw new AssertionError("Could not determine type argument position of tree " + tree +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   853
                                               " within frame " + frame);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   854
                    }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   855
                }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   856
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   857
                case ARRAY_TYPE: {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   858
                    location = location.prepend(TypePathEntry.ARRAY);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   859
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   860
                    while (true) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   861
                        JCTree npHead = newPath.tail.head;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   862
                        if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   863
                            newPath = newPath.tail;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   864
                            location = location.prepend(TypePathEntry.ARRAY);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   865
                        } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   866
                            newPath = newPath.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   867
                        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   868
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   869
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   870
                    }
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   871
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   872
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   873
                                        outer_type_index, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   874
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   875
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   876
                case TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   877
                    if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   878
                        final JCClassDecl clazz =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   879
                            (JCClassDecl)path.tail.tail.head;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   880
                        final int parameter_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   881
                            clazz.typarams.indexOf(path.tail.head);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   882
                        final int bound_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   883
                            ((JCTypeParameter)frame).bounds.get(0)
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   884
                            .type.isInterface() ?
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   885
                            ((JCTypeParameter)frame).bounds.indexOf(tree) + 1:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   886
                            ((JCTypeParameter)frame).bounds.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   887
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   888
                            .typeParameterBound(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   889
                                                currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   890
                                                parameter_index, bound_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   891
                                                frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   892
                    } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   893
                        final JCMethodDecl method =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   894
                            (JCMethodDecl)path.tail.tail.head;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   895
                        final int parameter_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   896
                            method.typarams.indexOf(path.tail.head);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   897
                        final int bound_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   898
                            ((JCTypeParameter)frame).bounds.get(0)
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   899
                            .type.isInterface() ?
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   900
                            ((JCTypeParameter)frame).bounds.indexOf(tree) + 1:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   901
                            ((JCTypeParameter)frame).bounds.indexOf(tree);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   902
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   903
                            .methodTypeParameterBound(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   904
                                                      currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   905
                                                      parameter_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   906
                                                      bound_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   907
                                                      frame.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   908
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   909
                        throw new AssertionError("Could not determine position of tree " + tree +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   910
                                                 " within frame " + frame);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   911
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   912
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   913
                case VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   914
                    VarSymbol v = ((JCVariableDecl)frame).sym;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   915
                    if (v.getKind() != ElementKind.FIELD) {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   916
                        v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   917
                    }
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   918
                    switch (v.getKind()) {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   919
                        case LOCAL_VARIABLE:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   920
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   921
                                .localVariable(location.toList(), currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   922
                                               frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   923
                        case FIELD:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   924
                            return TypeAnnotationPosition.field(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   925
                                                                currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   926
                                                                frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   927
                        case PARAMETER:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   928
                            if (v.getQualifiedName().equals(names._this)) {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   929
                                return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   930
                                    .methodReceiver(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   931
                                                    currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   932
                                                    frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   933
                            } else {
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   934
                                final int parameter_index =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   935
                                    methodParamIndex(path, frame);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   936
                                return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   937
                                    .methodParameter(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   938
                                                     currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   939
                                                     parameter_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   940
                                                     frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   941
                            }
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   942
                        case EXCEPTION_PARAMETER:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   943
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   944
                                .exceptionParameter(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   945
                                                    currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   946
                                                    frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   947
                        case RESOURCE_VARIABLE:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   948
                            return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   949
                                .resourceVariable(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   950
                                                  currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   951
                                                  frame.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   952
                        default:
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   953
                            throw new AssertionError("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   954
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   955
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   956
                case ANNOTATED_TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   957
                    if (frame == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   958
                        // This is only true for the first annotated type we see.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   959
                        // For any other annotated types along the path, we do
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   960
                        // not care about inner types.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   961
                        JCAnnotatedType atypetree = (JCAnnotatedType) frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   962
                        final Type utype = atypetree.underlyingType.type;
22699
3b17c61ad5a1 8033218: Silent failure in TypeAnnotations.resolveFrame
emc
parents: 22163
diff changeset
   963
                        Assert.checkNonNull(utype);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   964
                        Symbol tsym = utype.tsym;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   965
                        if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   966
                                utype.getKind().equals(TypeKind.WILDCARD) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   967
                                utype.getKind().equals(TypeKind.ARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   968
                            // Type parameters, wildcards, and arrays have the declaring
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   969
                            // class/method as enclosing elements.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   970
                            // There is actually nothing to do for them.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   971
                        } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   972
                            location = locateNestedTypes(utype, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   973
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   974
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   975
                    List<JCTree> newPath = path.tail;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   976
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   977
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   978
                                        outer_type_index, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   979
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   980
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   981
                case UNION_TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   982
                    List<JCTree> newPath = path.tail;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   983
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   984
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   985
                                        outer_type_index, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   986
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   987
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   988
                case INTERSECTION_TYPE: {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   989
                    JCTypeIntersection isect = (JCTypeIntersection)frame;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   990
                    final List<JCTree> newPath = path.tail;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   991
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   992
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   993
                                        isect.bounds.indexOf(tree), location);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   994
                }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   995
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   996
                case METHOD_INVOCATION: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   997
                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   998
                    if (!invocation.typeargs.contains(tree)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
   999
                        throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1000
                    }
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
  1001
                    MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1002
                    final int type_index = invocation.typeargs.indexOf(tree);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
  1003
                    if (exsym == null) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1004
                        throw new AssertionError("could not determine symbol for {" + invocation + "}");
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
  1005
                    } else if (exsym.isConstructor()) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1006
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1007
                            .constructorInvocationTypeArg(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1008
                                                          currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1009
                                                          type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1010
                                                          invocation.pos);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
  1011
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1012
                        return TypeAnnotationPosition
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1013
                            .methodInvocationTypeArg(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1014
                                                     currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1015
                                                     type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1016
                                                     invocation.pos);
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
  1017
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1018
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1019
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1020
                case EXTENDS_WILDCARD:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1021
                case SUPER_WILDCARD: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1022
                    // Annotations in wildcard bounds
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1023
                    final List<JCTree> newPath = path.tail;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1024
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1025
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1026
                                        outer_type_index,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1027
                                        location.prepend(TypePathEntry.WILDCARD));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1028
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1029
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1030
                case MEMBER_SELECT: {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1031
                    final List<JCTree> newPath = path.tail;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1032
                    return resolveFrame(newPath.head, newPath.tail.head,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1033
                                        newPath, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1034
                                        outer_type_index, location);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1035
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1036
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1037
                default:
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1038
                    throw new AssertionError("Unresolved frame: " + frame +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1039
                                             " of kind: " + frame.getKind() +
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1040
                                             "\n    Looking for tree: " + tree);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1041
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1042
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1043
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1044
        private ListBuffer<TypePathEntry>
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1045
            locateNestedTypes(Type type,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1046
                              ListBuffer<TypePathEntry> depth) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1047
            Type encl = type.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1048
            while (encl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1049
                    encl.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1050
                    encl.getKind() != TypeKind.ERROR) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1051
                depth = depth.prepend(TypePathEntry.INNER_TYPE);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1052
                encl = encl.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1053
            }
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1054
            return depth;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1055
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1056
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
  1057
        private int methodParamIndex(List<JCTree> path, JCTree param) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1058
            List<JCTree> curr = path;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1059
            while (curr.head.getTag() != Tag.METHODDEF &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1060
                    curr.head.getTag() != Tag.LAMBDA) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1061
                curr = curr.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1062
            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1063
            if (curr.head.getTag() == Tag.METHODDEF) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1064
                JCMethodDecl method = (JCMethodDecl)curr.head;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1065
                return method.params.indexOf(param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1066
            } else if (curr.head.getTag() == Tag.LAMBDA) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1067
                JCLambda lambda = (JCLambda)curr.head;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1068
                return lambda.params.indexOf(param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1069
            } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1070
                Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1071
                return -1;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1072
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1073
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1074
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1075
        // Each class (including enclosed inner classes) is visited separately.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1076
        // This flag is used to prevent from visiting inner classes.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1077
        private boolean isInClass = false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1078
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1079
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1080
        public void visitClassDef(JCClassDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1081
            if (isInClass)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1082
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1083
            isInClass = true;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1084
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1085
            if (sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1086
                scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1087
                scan(tree.typarams);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1088
                scan(tree.extending);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1089
                scan(tree.implementing);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1090
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1091
            scan(tree.defs);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1092
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1093
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1094
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1095
         * Resolve declaration vs. type annotations in methods and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1096
         * then determine the positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1097
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1098
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1099
        public void visitMethodDef(final JCMethodDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1100
            if (tree.sym == null) {
21043
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
  1101
                Assert.error("Visiting tree node before memberEnter");
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
  1102
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1103
            if (sigOnly) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1104
                if (!tree.mods.annotations.isEmpty()) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1105
                    if (tree.sym.isConstructor()) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1106
                        final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1107
                            TypeAnnotationPosition.methodReturn(tree.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1108
                        // Use null to mark that the annotations go
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1109
                        // with the symbol.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1110
                        separateAnnotationsKinds(tree, null, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1111
                    } else {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1112
                        final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1113
                            TypeAnnotationPosition.methodReturn(tree.restype.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1114
                        separateAnnotationsKinds(tree.restype,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1115
                                                 tree.sym.type.getReturnType(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1116
                                                 tree.sym, pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1117
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1118
                }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1119
                if (tree.recvparam != null && tree.recvparam.sym != null &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1120
                        !tree.recvparam.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1121
                    // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1122
                    // there are no annotations of either kind.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1123
                    // TODO: make sure there are no declaration annotations.
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1124
                    final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1125
                        TypeAnnotationPosition.methodReceiver(tree.recvparam.vartype.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1126
                    separateAnnotationsKinds(tree.recvparam.vartype,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1127
                                             tree.recvparam.sym.type,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1128
                                             tree.recvparam.sym, pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1129
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1130
                int i = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1131
                for (JCVariableDecl param : tree.params) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1132
                    if (!param.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1133
                        // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1134
                        // there are no annotations of either kind.
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1135
                        final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1136
                            TypeAnnotationPosition.methodParameter(i, param.vartype.pos);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1137
                        separateAnnotationsKinds(param.vartype,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1138
                                                 param.sym.type,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1139
                                                 param.sym, pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1140
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1141
                    ++i;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1142
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1143
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1144
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1145
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1146
            // super.visitMethodDef(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1147
            if (sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1148
                scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1149
                scan(tree.restype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1150
                scan(tree.typarams);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1151
                scan(tree.recvparam);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1152
                scan(tree.params);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1153
                scan(tree.thrown);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1154
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1155
                scan(tree.defaultValue);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1156
                scan(tree.body);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1157
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1158
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1159
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1160
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1161
        /* Store a reference to the current lambda expression, to
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1162
         * be used by all type annotations within this expression.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1163
         */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1164
        private JCLambda currentLambda = null;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1165
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1166
        public void visitLambda(JCLambda tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1167
            JCLambda prevLambda = currentLambda;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1168
            try {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1169
                currentLambda = tree;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1170
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1171
                int i = 0;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1172
                for (JCVariableDecl param : tree.params) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1173
                    if (!param.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1174
                        // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1175
                        // there are no annotations of either kind.
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1176
                        final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1177
                            TypeAnnotationPosition.methodParameter(tree, i,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1178
                                                                   param.vartype.pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1179
                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1180
                    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1181
                    ++i;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1182
                }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1183
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1184
                push(tree);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1185
                scan(tree.body);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1186
                scan(tree.params);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1187
                pop();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1188
            } finally {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1189
                currentLambda = prevLambda;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1190
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1191
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1192
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1193
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1194
         * Resolve declaration vs. type annotations in variable declarations and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1195
         * then determine the positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1196
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1197
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1198
        public void visitVarDef(final JCVariableDecl tree) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1199
            if (tree.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1200
                // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1201
                // there are no annotations of either kind.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1202
            } else if (tree.sym == null) {
21043
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
  1203
                Assert.error("Visiting tree node before memberEnter");
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1204
            } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1205
                // Parameters are handled in visitMethodDef or visitLambda.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1206
            } else if (tree.sym.getKind() == ElementKind.FIELD) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1207
                if (sigOnly) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1208
                    TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1209
                        TypeAnnotationPosition.field(tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1210
                    separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1211
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1212
            } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1213
                final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1214
                    TypeAnnotationPosition.localVariable(currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1215
                                                         tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1216
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1217
            } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1218
                final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1219
                    TypeAnnotationPosition.exceptionParameter(currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1220
                                                              tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1221
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1222
            } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1223
                final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1224
                    TypeAnnotationPosition.resourceVariable(currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1225
                                                            tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1226
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1227
            } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1228
                // No type annotations can occur here.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1229
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1230
                // There is nothing else in a variable declaration that needs separation.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1231
                Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1232
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1233
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1234
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1235
            // super.visitVarDef(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1236
            scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1237
            scan(tree.vartype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1238
            if (!sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1239
                scan(tree.init);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1240
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1241
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1242
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1243
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1244
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1245
        public void visitBlock(JCBlock tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1246
            // Do not descend into top-level blocks when only interested
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1247
            // in the signature.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1248
            if (!sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1249
                scan(tree.stats);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1250
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1251
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1252
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1253
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1254
        public void visitAnnotatedType(JCAnnotatedType tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1255
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1256
            findPosition(tree, tree, tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1257
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1258
            super.visitAnnotatedType(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1259
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1260
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1261
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1262
        public void visitTypeParameter(JCTypeParameter tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1263
            findPosition(tree, peek2(), tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1264
            super.visitTypeParameter(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1265
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1266
21499
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1267
        private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1268
            Symbol sym = tree.def.sym;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1269
            final TypeAnnotationPosition pos =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1270
                TypeAnnotationPosition.newObj(tree.pos);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21499
diff changeset
  1271
            ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>();
21499
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1272
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1273
            for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1274
                newattrs.append(new Attribute.TypeCompound(old.type, old.values,
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1275
                                                           pos));
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1276
            }
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1277
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1278
            sym.owner.appendUniqueTypeAttributes(newattrs.toList());
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1279
        }
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1280
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1281
        @Override
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1282
        public void visitNewClass(JCNewClass tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1283
            if (tree.def != null &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1284
                    !tree.def.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1285
                JCClassDecl classdecl = tree.def;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1286
                TypeAnnotationPosition pos;
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1287
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1288
                if (classdecl.extending == tree.clazz) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1289
                    pos = TypeAnnotationPosition.classExtends(tree.pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1290
                } else if (classdecl.implementing.contains(tree.clazz)) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1291
                    final int index = classdecl.implementing.indexOf(tree.clazz);
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1292
                    pos = TypeAnnotationPosition.classExtends(index, tree.pos);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1293
                } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1294
                    // In contrast to CLASS elsewhere, typarams cannot occur here.
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1295
                    throw new AssertionError("Could not determine position of tree " + tree);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1296
                }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1297
                Type before = classdecl.sym.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1298
                separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
21499
203cfd174518 8023682: Incorrect attributes emitted for anonymous class declaration
emc
parents: 21481
diff changeset
  1299
                copyNewClassAnnotationsToOwner(tree);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1300
                // classdecl.sym.type now contains an annotated type, which
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1301
                // is not what we want there.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1302
                // TODO: should we put this type somewhere in the superclass/interface?
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1303
                classdecl.sym.type = before;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1304
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1305
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1306
            scan(tree.encl);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1307
            scan(tree.typeargs);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1308
            scan(tree.clazz);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1309
            scan(tree.args);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1310
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1311
            // The class body will already be scanned.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1312
            // scan(tree.def);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1313
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1314
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1315
        @Override
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1316
        public void visitNewArray(JCNewArray tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1317
            findPosition(tree, tree, tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1318
            int dimAnnosCount = tree.dimAnnotations.size();
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19651
diff changeset
  1319
            ListBuffer<TypePathEntry> depth = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1320
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1321
            // handle annotations associated with dimensions
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1322
            for (int i = 0; i < dimAnnosCount; ++i) {
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1323
                ListBuffer<TypePathEntry> location =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1324
                    new ListBuffer<TypePathEntry>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1325
                if (i != 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1326
                    depth = depth.append(TypePathEntry.ARRAY);
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1327
                    location = location.appendList(depth.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1328
                }
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1329
                final TypeAnnotationPosition p =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1330
                    TypeAnnotationPosition.newObj(location.toList(),
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1331
                                                  currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1332
                                                  tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1333
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1334
                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1335
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1336
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1337
            // handle "free" annotations
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1338
            // int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1339
            // TODO: is depth.size == i here?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1340
            JCExpression elemType = tree.elemtype;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1341
            depth = depth.append(TypePathEntry.ARRAY);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1342
            while (elemType != null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1343
                if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1344
                    JCAnnotatedType at = (JCAnnotatedType)elemType;
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1345
                    final ListBuffer<TypePathEntry> locationbuf =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1346
                        locateNestedTypes(elemType.type,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1347
                                          new ListBuffer<TypePathEntry>());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1348
                    final List<TypePathEntry> location =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1349
                        locationbuf.toList().prependList(depth.toList());
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1350
                    final TypeAnnotationPosition p =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1351
                        TypeAnnotationPosition.newObj(location, currentLambda,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1352
                                                      tree.pos);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1353
                    setTypeAnnotationPos(at.annotations, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1354
                    elemType = at.underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1355
                } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1356
                    depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1357
                    elemType = ((JCArrayTypeTree)elemType).elemtype;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1358
                } else if (elemType.hasTag(JCTree.Tag.SELECT)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1359
                    elemType = ((JCFieldAccess)elemType).selected;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1360
                } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1361
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1362
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1363
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1364
            scan(tree.elems);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1365
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1366
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1367
        private void findPosition(JCTree tree, JCTree frame, List<JCAnnotation> annotations) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1368
            if (!annotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1369
                /*
21010
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
  1370
                System.err.println("Finding pos for: " + annotations);
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
  1371
                System.err.println("    tree: " + tree + " kind: " + tree.getKind());
5ffe0d8a5e24 8008762: Type annotation on inner class in anonymous class show up as regular type annotations
emc
parents: 20258
diff changeset
  1372
                System.err.println("    frame: " + frame + " kind: " + frame.getKind());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1373
                */
22702
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1374
                final TypeAnnotationPosition p =
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1375
                    resolveFrame(tree, frame, frames.toList(), currentLambda, 0,
1297fbaf34fa 8033004: Make base TypeAnnotationPosition data immutable, create better methods for creating base TypeAnnotationPositions
emc
parents: 22699
diff changeset
  1376
                                 new ListBuffer<TypePathEntry>());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1377
                setTypeAnnotationPos(annotations, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1378
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1379
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1380
20258
bdaa691b4da4 8025407: TypeAnnotations does not use Context
jjg
parents: 20249
diff changeset
  1381
        private void setTypeAnnotationPos(List<JCAnnotation> annotations,
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1382
                TypeAnnotationPosition position) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1383
            for (JCAnnotation anno : annotations) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1384
                // attribute might be null during DeferredAttr;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1385
                // we will be back later.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1386
                if (anno.attribute != null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1387
                    ((Attribute.TypeCompound) anno.attribute).position = position;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1388
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1389
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1390
        }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1391
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1392
        @Override
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1393
        public String toString() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1394
            return super.toString() + ": sigOnly: " + sigOnly;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1395
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1396
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1397
}