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