langtools/src/share/classes/com/sun/tools/javac/comp/Annotate.java
author jlahoda
Wed, 09 Jul 2014 16:32:05 +0200
changeset 25443 9187d77f2c64
parent 24895 dd091d389fbf
permissions -rw-r--r--
8031569: Refactor javac scope implementation to enable lazy imports Summary: Introducing an internal API for Scope; rewriting ImportScopes to extend CompoundScopes. Reviewed-by: mcimadamore, jjg, jfranck Contributed-by: maurizio.cimadamore@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22439
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    28
import java.util.HashMap;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    29
import java.util.LinkedHashMap;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
    30
import java.util.Map;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    31
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
    32
import javax.lang.model.element.ElementKind;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
    33
import javax.lang.model.type.TypeKind;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    34
import javax.tools.JavaFileObject;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    35
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.*;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
    37
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.Symbol.*;
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
    40
import com.sun.tools.javac.code.TypeAnnotationPosition.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    44
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14054
diff changeset
    45
import static com.sun.tools.javac.code.TypeTag.ARRAY;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14054
diff changeset
    46
import static com.sun.tools.javac.code.TypeTag.CLASS;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
    47
import static com.sun.tools.javac.tree.JCTree.Tag.*;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
    48
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
/** Enter annotations on symbols.  Annotations accumulate in a queue,
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  which is processed at the top level of any set of recursive calls
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  requesting it be processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    53
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    54
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
public class Annotate {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
    59
    protected static final Context.Key<Annotate> annotateKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public static Annotate instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        Annotate instance = context.get(annotateKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            instance = new Annotate(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    68
    private final Attr attr;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    69
    private final TreeMaker make;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    70
    private final Log log;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    71
    private final Symtab syms;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    72
    private final Names names;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    73
    private final Resolve rs;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    74
    private final Types types;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    75
    private final ConstFold cfolder;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    76
    private final Check chk;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    77
    private final Lint lint;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    78
    private final DeferredLintHandler deferredLintHandler;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    79
    private final Source source;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    80
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    81
    private boolean allowTypeAnnos;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    82
    private boolean allowRepeatedAnnos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    protected Annotate(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        context.put(annotateKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        make = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        syms = Symtab.instance(context);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    90
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        rs = Resolve.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        types = Types.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        cfolder = ConstFold.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        chk = Check.instance(context);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    95
        source = Source.instance(context);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    96
        lint = Lint.instance(context);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    97
        deferredLintHandler = DeferredLintHandler.instance(context);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    98
        allowRepeatedAnnos = source.allowRepeatedAnnotations();
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    99
        allowTypeAnnos = source.allowTypeAnnotations();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 * Queue maintenance
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    private int enterCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   108
    ListBuffer<Worker> q = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   109
    ListBuffer<Worker> typesQ = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   110
    ListBuffer<Worker> repeatedQ = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   111
    ListBuffer<Worker> afterRepeatedQ = new ListBuffer<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   112
    ListBuffer<Worker> validateQ = new ListBuffer<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   113
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   114
    public void earlier(Worker a) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   115
        q.prepend(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   116
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   118
    public void normal(Worker a) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        q.append(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   122
    public void typeAnnotation(Worker a) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   123
        typesQ.append(a);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   126
    public void repeated(Worker a) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   127
        repeatedQ.append(a);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   128
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   129
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   130
    public void afterRepeated(Worker a) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   131
        afterRepeatedQ.append(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   132
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   133
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   134
    public void validate(Worker a) {
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   135
        validateQ.append(a);
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   136
    }
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   137
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    /** Called when the Enter phase starts. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    public void enterStart() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        enterCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    /** Called after the Enter phase completes. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    public void enterDone() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        enterCount--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
21043
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   149
    /** Variant which allows for a delayed flush of annotations.
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   150
     * Needed by ClassReader */
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   151
    public void enterDoneWithoutFlush() {
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   152
        enterCount--;
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   153
    }
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   154
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public void flush() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        if (enterCount != 0) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        enterCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        try {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   159
            while (q.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   160
                q.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   161
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   162
            while (typesQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   163
                typesQ.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   164
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   165
            while (repeatedQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   166
                repeatedQ.next().run();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   167
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   168
            while (afterRepeatedQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   169
                afterRepeatedQ.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   170
            }
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   171
            while (validateQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   172
                validateQ.next().run();
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   173
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            enterCount--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   179
    /** A client that needs to run during {@link #flush()} registers an worker
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   180
     *  into one of the queues defined in this class. The queues are: {@link #earlier(Worker)},
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   181
     *  {@link #normal(Worker)}, {@link #typeAnnotation(Worker)}, {@link #repeated(Worker)},
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   182
     *  {@link #afterRepeated(Worker)}, {@link #validate(Worker)}.
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   183
     *  The {@link Worker#run()} method will called inside the {@link #flush()}
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   184
     *  call. Queues are empties in the abovementioned order.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   186
    public interface Worker {
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   187
        void run();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        String toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   191
    /**
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   192
     * This context contains all the information needed to synthesize new
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   193
     * annotations trees by the completer for repeating annotations.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   194
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   195
    private class AnnotationContext<T extends Attribute.Compound> {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   196
        public final Env<AttrContext> env;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   197
        public final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   198
        public final Map<T, JCDiagnostic.DiagnosticPosition> pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   199
        public final boolean isTypeCompound;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   200
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   201
        public AnnotationContext(Env<AttrContext> env,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   202
                                 Map<Symbol.TypeSymbol, ListBuffer<T>> annotated,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   203
                                 Map<T, JCDiagnostic.DiagnosticPosition> pos,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   204
                                 boolean isTypeCompound) {
13840
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   205
            Assert.checkNonNull(env);
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   206
            Assert.checkNonNull(annotated);
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   207
            Assert.checkNonNull(pos);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   208
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   209
            this.env = env;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   210
            this.annotated = annotated;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   211
            this.pos = pos;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   212
            this.isTypeCompound = isTypeCompound;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   213
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   214
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   215
        public String toString() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   216
            StringBuilder sb = new StringBuilder();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   217
            sb.append("RepeatedContext[");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   218
            for (Map.Entry<Symbol.TypeSymbol, ListBuffer<T>> entry :
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   219
                     annotated.entrySet()) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   220
                sb.append(" ");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   221
                sb.append(entry.getKey());
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   222
                sb.append(" = { ");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   223
                sb.append(entry.getValue());
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   224
                sb.append(" }");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   225
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   226
            sb.append(" ]");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   227
            return sb.toString();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   228
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   229
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   230
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   231
    private static class Placeholder<T extends Attribute.Compound> extends Attribute.Compound {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   232
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   233
        private final Annotate.AnnotationContext<T> ctx;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   234
        private final List<T> placeholderFor;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   235
        private final Symbol on;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   236
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   237
        public Placeholder(Annotate.AnnotationContext<T> ctx,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   238
                           List<T> placeholderFor, Symbol on) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   239
            super(on.type, List.<Pair<Symbol.MethodSymbol, Attribute>>nil(),
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   240
                  placeholderFor.head.position);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   241
            this.ctx = ctx;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   242
            this.placeholderFor = placeholderFor;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   243
            this.on = on;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   244
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   245
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   246
        @Override
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   247
        public String toString() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   248
            return "<placeholder: " + placeholderFor + " on: " + on + ">";
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   249
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   250
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   251
        public List<T> getPlaceholderFor() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   252
            return placeholderFor;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   253
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   254
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   255
        public Annotate.AnnotationContext<T> getRepeatedContext() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   256
            return ctx;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   257
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   258
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   260
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
/* ********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
 * Compute an attribute from its annotation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
 *********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   265
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   266
     * Enter (and attribute) a single regular annotation, returning
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   267
     * its Attribute.  We give these annotations a position in case we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   268
     * end up creating a type annotation from using toTypeCompound.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   269
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   270
     * In some cases, namely on annotations that can never be type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   271
     * annotations (like package annotations), the position can be
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   272
     * null; however, if this annotation is in a place where it might
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   273
     * possibly denote a type annotation, it will have a non-null
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   274
     * position.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   275
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   276
     * @param a Annotation to attribute.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   277
     * @param expected Expected annotation type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   278
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   279
     * @param position The type annotation position this will have if
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   280
     *                 it's converted to a type annotation.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   281
     * @return The Attribute.Compound representing this annotation.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    Attribute.Compound enterAnnotation(JCAnnotation a,
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                                       Type expected,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   285
                                       Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   286
                                       TypeAnnotationPosition position) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   287
        List<Pair<MethodSymbol,Attribute>> buf =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   288
            enterAttributeValues(a, expected, env, position);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   289
        Attribute.Compound ac =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   290
            new Attribute.Compound(a.type, buf, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   291
        a.attribute = ac;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   292
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   293
        return ac;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16342
diff changeset
   294
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16342
diff changeset
   295
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   296
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   297
     * Enter (and attribute) a single type annotation, returning its
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   298
     * Attribute.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   299
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   300
     * Things are a bit complicated, though, because a single source
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   301
     * annotation (JCAnnotation) might give rise to several bytecode
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   302
     * annotations (Attribute.TypeCompound), but we can only associate
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   303
     * a source annotation with one bytecode annotation.  Thus, we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   304
     * have to distinguish between the "primary" (which will be stored
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   305
     * to the JCAnnotation) and "secondary" (which won't) annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   306
     * The primary place this gets used is for anonymous classes.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   307
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   308
     * The annotations we generate for the new instruction are the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   309
     * primary, and the ones we generate for the class are the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   310
     * secondaries.  (Note: this choice is arbitrary, and it does not
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   311
     * appear to cause any problems if these roles are reversed)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   312
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   313
     * @param a The annotation to attribute.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   314
     * @param expected The expected annotation type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   315
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   316
     * @param position The type annotation position to give the type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   317
     *                 annotation.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   318
     * @param secondaryAttr Whether or not this is a secondary (ie
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   319
     *                      will ignore the .attribute field on a).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   320
     * @return The Attribute.TypeCompound representing the annotation.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   321
     */
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16342
diff changeset
   322
    Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   323
                                               Type expected,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   324
                                               Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   325
                                               TypeAnnotationPosition position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   326
                                               boolean secondaryAttr) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   327
        List<Pair<MethodSymbol,Attribute>> buf =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   328
            enterAttributeValues(a, expected, env, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   329
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   330
        // Secondary attr means we do not set the .attribute field of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   331
        // the JCAnnotation, nor do we pay attention to it.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   332
        if (!secondaryAttr || a.attribute == null ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   333
            !(a.attribute instanceof Attribute.TypeCompound)) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   334
            // Create a new TypeCompound
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   335
            Attribute.TypeCompound tc =
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   336
                new Attribute.TypeCompound(a.type, buf, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   337
            a.attribute = tc;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   338
            return tc;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   339
        } else {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   340
            // Use an existing TypeCompound
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   341
            return (Attribute.TypeCompound)a.attribute;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   342
        }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16342
diff changeset
   343
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 16342
diff changeset
   344
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   345
    // Attribute all the annotation's values.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   346
    private List<Pair<MethodSymbol,Attribute>>
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   347
            enterAttributeValues(JCAnnotation a,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   348
                                 Type expected,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   349
                                 Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   350
                                 TypeAnnotationPosition position) {
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   351
        // The annotation might have had its type attributed (but not
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   352
        // checked) by attr.attribAnnotationTypes during MemberEnter,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   353
        // in which case we do not need to do it again.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        Type at = (a.annotationType.type != null ? a.annotationType.type
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                  : attr.attribType(a.annotationType, env));
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        a.type = chk.checkType(a.annotationType.pos(), at, expected);
22439
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   357
        boolean isError = a.type.isErroneous();
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   358
        if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0 && !isError) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            log.error(a.annotationType.pos(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                      "not.annotation.type", a.type.toString());
22439
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   361
            isError = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        List<JCExpression> args = a.args;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
   364
        if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            // special case: elided "value=" assumed
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            args.head = make.at(args.head.pos).
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                Assign(make.Ident(names.value), args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        ListBuffer<Pair<MethodSymbol,Attribute>> buf =
21713
b3fcc9c0fea3 8027375: javac asserts on nested erroneous annotations
jfranck
parents: 21043
diff changeset
   370
            new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            JCExpression t = tl.head;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
   373
            if (!t.hasTag(ASSIGN)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                log.error(t.pos(), "annotation.value.must.be.name.value");
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   375
                enterAttributeValue(t.type = syms.errType, t, env, position);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            JCAssign assign = (JCAssign)t;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
   379
            if (!assign.lhs.hasTag(IDENT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                log.error(t.pos(), "annotation.value.must.be.name.value");
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   381
                enterAttributeValue(t.type = syms.errType, t, env, position);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            JCIdent left = (JCIdent)assign.lhs;
19122
1841f2fa76de 8017216: javac doesn't fill in end position for some errors of type not found
ksrini
parents: 17578
diff changeset
   385
            Symbol method = rs.resolveQualifiedMethod(assign.rhs.pos(),
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   386
                                                          env,
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   387
                                                          a.type,
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   388
                                                          left.name,
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   389
                                                          List.<Type>nil(),
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   390
                                                          null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            left.sym = method;
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            left.type = method.type;
22439
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   393
            if (method.owner != a.type.tsym && !isError)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
                log.error(left.pos(), "no.annotation.member", left.name, a.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            Type result = method.type.getReturnType();
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   396
            Attribute value = enterAttributeValue(result, assign.rhs, env, position);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            if (!method.type.isErroneous())
21713
b3fcc9c0fea3 8027375: javac asserts on nested erroneous annotations
jfranck
parents: 21043
diff changeset
   398
                buf.append(new Pair<>((MethodSymbol)method, value));
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 5847
diff changeset
   399
            t.type = result;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   401
        return buf.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    Attribute enterAttributeValue(Type expected,
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
                                  JCExpression tree,
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
                                  Env<AttrContext> env) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   407
        return enterAttributeValue(expected, tree, env, null);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   408
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   409
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   410
    Attribute enterAttributeValue(Type expected,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   411
                                  JCExpression tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   412
                                  Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   413
                                  TypeAnnotationPosition position) {
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   414
        //first, try completing the attribution value sym - if a completion
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   415
        //error is thrown, we should recover gracefully, and display an
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   416
        //ordinary resolution diagnostic.
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   417
        try {
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   418
            expected.tsym.complete();
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   419
        } catch(CompletionFailure e) {
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   420
            log.error(tree.pos(), "cant.resolve", Kinds.kindName(e.sym), e.sym);
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   421
            expected = syms.errType;
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   422
        }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   423
        if (expected.hasTag(ARRAY)) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   424
            if (!tree.hasTag(NEWARRAY)) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   425
                tree = make.at(tree.pos).
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   426
                    NewArray(null, List.<JCExpression>nil(), List.of(tree));
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   427
            }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   428
            JCNewArray na = (JCNewArray)tree;
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   429
            if (na.elemtype != null) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   430
                log.error(na.elemtype.pos(), "new.not.allowed.in.annotation");
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   431
            }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   432
            ListBuffer<Attribute> buf = new ListBuffer<>();
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   433
            for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   434
                buf.append(enterAttributeValue(types.elemtype(expected),
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   435
                                               l.head, env, position));
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   436
            }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   437
            na.type = expected;
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   438
            return new Attribute.
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   439
                Array(expected, buf.toArray(new Attribute[buf.length()]));
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   440
        }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   441
        if (tree.hasTag(NEWARRAY)) { //error recovery
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   442
            if (!expected.isErroneous())
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   443
                log.error(tree.pos(), "annotation.value.not.allowable.type");
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   444
            JCNewArray na = (JCNewArray)tree;
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   445
            if (na.elemtype != null) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   446
                log.error(na.elemtype.pos(), "new.not.allowed.in.annotation");
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   447
            }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   448
            for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   449
                enterAttributeValue(syms.errType, l.head, env, position);
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   450
            }
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   451
            return new Attribute.Error(syms.errType);
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   452
        }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   453
        if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   454
            if (tree.hasTag(ANNOTATION)) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   455
                return enterAnnotation((JCAnnotation)tree, expected, env, position);
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   456
            } else {
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   457
                log.error(tree.pos(), "annotation.value.must.be.annotation");
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   458
                expected = syms.errType;
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   459
            }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   460
        }
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   461
        if (tree.hasTag(ANNOTATION)) { //error recovery
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   462
            if (!expected.isErroneous())
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   463
                log.error(tree.pos(), "annotation.not.valid.for.type", expected);
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   464
            enterAnnotation((JCAnnotation)tree, syms.errType, env, position);
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   465
            return new Attribute.Error(((JCAnnotation)tree).annotationType.type);
9603
fa337b87574b 6550655: com.sun.tools.javac.code.Symbol$CompletionFailure
mcimadamore
parents: 7681
diff changeset
   466
        }
22439
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   467
        if (expected.isPrimitive() ||
4785d87cd2d6 8029376: Full attribution of unresolvable annotations
jlahoda
parents: 22165
diff changeset
   468
            (types.isSameType(expected, syms.stringType) && !expected.hasTag(TypeTag.ERROR))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
            Type result = attr.attribExpr(tree, env, expected);
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            if (result.isErroneous())
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   471
                return new Attribute.Error(result.getOriginalType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            if (result.constValue() == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                log.error(tree.pos(), "attribute.value.must.be.constant");
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                return new Attribute.Error(expected);
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            result = cfolder.coerce(result, expected);
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
            return new Attribute.Constant(expected, result.constValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        if (expected.tsym == syms.classType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            Type result = attr.attribExpr(tree, env, expected);
19507
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   481
            if (result.isErroneous()) {
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   482
                // Does it look like an unresolved class literal?
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   483
                if (TreeInfo.name(tree) == names._class &&
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   484
                    ((JCFieldAccess) tree).selected.type.isErroneous()) {
19507
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   485
                    Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName();
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   486
                    return new Attribute.UnresolvedClass(expected,
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   487
                            types.createErrorType(n,
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   488
                                    syms.unknownSymbol, syms.classType));
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   489
                } else {
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   490
                    return new Attribute.Error(result.getOriginalType());
19507
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   491
                }
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   492
            }
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   493
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   494
            // Class literals look like field accesses of a field named class
323f001d6be1 8019243: AnnotationTypeMismatchException instead of MirroredTypeException
jfranck
parents: 19122
diff changeset
   495
            // at the tree level
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            if (TreeInfo.name(tree) != names._class) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
                log.error(tree.pos(), "annotation.value.must.be.class.literal");
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   498
                return new Attribute.Error(syms.errType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
            return new Attribute.Class(types,
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                                       (((JCFieldAccess) tree).selected).type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14054
diff changeset
   503
        if (expected.hasTag(CLASS) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            (expected.tsym.flags() & Flags.ENUM) != 0) {
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   505
            Type result = attr.attribExpr(tree, env, expected);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            Symbol sym = TreeInfo.symbol(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
            if (sym == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                TreeInfo.nonstaticSelect(tree) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
                sym.kind != Kinds.VAR ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
                (sym.flags() & Flags.ENUM) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
                log.error(tree.pos(), "enum.annotation.must.be.enum.constant");
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 20599
diff changeset
   512
                return new Attribute.Error(result.getOriginalType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            VarSymbol enumerator = (VarSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            return new Attribute.Enum(expected, enumerator);
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        }
20599
5201f7144a3c 8022765: Compiler crashes with exception on wrong usage of an annotation.
jlahoda
parents: 19507
diff changeset
   517
        //error recovery:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        if (!expected.isErroneous())
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            log.error(tree.pos(), "annotation.value.not.allowable.type");
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        return new Attribute.Error(attr.attribExpr(tree, env, expected));
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
    }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   522
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   523
    /* *********************************
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   524
     * Support for repeating annotations
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   525
     ***********************************/
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   526
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   527
    /* Process repeated annotations. This method returns the
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   528
     * synthesized container annotation or null IFF all repeating
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   529
     * annotation are invalid.  This method reports errors/warnings.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   530
     */
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   531
    private <T extends Attribute.Compound> T processRepeatedAnnotations(
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   532
            List<T> annotations,
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   533
            AnnotationContext<T> ctx,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   534
            Symbol on,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   535
            TypeAnnotationPosition position) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   536
        T firstOccurrence = annotations.head;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   537
        List<Attribute> repeated = List.nil();
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   538
        Type origAnnoType = null;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   539
        Type arrayOfOrigAnnoType = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   540
        Type targetContainerType = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   541
        MethodSymbol containerValueSymbol = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   542
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   543
        Assert.check(!annotations.isEmpty() &&
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   544
                     !annotations.tail.isEmpty()); // i.e. size() > 1
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   545
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   546
        int count = 0;
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   547
        for (List<T> al = annotations; !al.isEmpty(); al = al.tail) {
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   548
            count++;
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   549
            // There must be more than a single anno in the annotation list
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   550
            Assert.check(count > 1 || !al.tail.isEmpty());
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   551
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   552
            T currentAnno = al.head;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   553
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   554
            origAnnoType = currentAnno.type;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   555
            if (arrayOfOrigAnnoType == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   556
                arrayOfOrigAnnoType = types.makeArrayType(origAnnoType);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   557
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   558
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   559
            // Only report errors if this isn't the first occurrence I.E. count > 1
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   560
            boolean reportError = count > 1;
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   561
            Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   562
            if (currentContainerType == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   563
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   564
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   565
            // Assert that the target Container is == for all repeated
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   566
            // annos of the same annotation type, the types should
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   567
            // come from the same Symbol, i.e. be '=='
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   568
            Assert.check(targetContainerType == null || currentContainerType == targetContainerType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   569
            targetContainerType = currentContainerType;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   570
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   571
            containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   572
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   573
            if (containerValueSymbol == null) { // Check of CA type failed
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   574
                // errors are already reported
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   575
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   576
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   577
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   578
            repeated = repeated.prepend(currentAnno);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   579
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   580
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   581
        if (!repeated.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   582
            repeated = repeated.reverse();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   583
            TreeMaker m = make.at(ctx.pos.get(firstOccurrence));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   584
            Pair<MethodSymbol, Attribute> p =
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   585
                    new Pair<MethodSymbol, Attribute>(containerValueSymbol,
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
   586
                               new Attribute.Array(arrayOfOrigAnnoType, repeated));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   587
            if (ctx.isTypeCompound) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   588
                Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), position);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   589
                at.setSynthesized(true);
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   590
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   591
                @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   592
                T x = (T) at;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   593
                return x;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   594
            } else {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   595
                Attribute.Compound c = new Attribute.Compound(targetContainerType,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   596
                                                              List.of(p),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   597
                                                              position);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   598
                JCAnnotation annoTree = m.Annotation(c);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   599
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   600
                if (!chk.annotationApplicable(annoTree, on))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   601
                    log.error(annoTree.pos(), "invalid.repeatable.annotation.incompatible.target", targetContainerType, origAnnoType);
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   602
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   603
                if (!chk.validateAnnotationDeferErrors(annoTree))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   604
                    log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   605
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   606
                c = enterAnnotation(annoTree, targetContainerType, ctx.env, position);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   607
                c.setSynthesized(true);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   608
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   609
                @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   610
                T x = (T) c;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   611
                return x;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   612
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   613
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   614
            return null; // errors should have been reported elsewhere
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   615
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   616
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   617
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   618
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   619
    /** Fetches the actual Type that should be the containing annotation. */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   620
    private Type getContainingType(Attribute.Compound currentAnno,
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   621
            DiagnosticPosition pos,
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   622
            boolean reportError)
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   623
    {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   624
        Type origAnnoType = currentAnno.type;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   625
        TypeSymbol origAnnoDecl = origAnnoType.tsym;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   626
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   627
        // Fetch the Repeatable annotation from the current
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   628
        // annotation's declaration, or null if it has none
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   629
        Attribute.Compound ca = origAnnoDecl.attribute(syms.repeatableType.tsym);
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   630
        if (ca == null) { // has no Repeatable annotation
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   631
            if (reportError)
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   632
                log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   633
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   634
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   635
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   636
        return filterSame(extractContainingType(ca, pos, origAnnoDecl),
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   637
                          origAnnoType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   638
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   639
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   640
    // returns null if t is same as 's', returns 't' otherwise
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   641
    private Type filterSame(Type t, Type s) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   642
        if (t == null || s == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   643
            return t;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   644
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   645
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   646
        return types.isSameType(t, s) ? null : t;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   647
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   648
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   649
    /** Extract the actual Type to be used for a containing annotation. */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   650
    private Type extractContainingType(Attribute.Compound ca,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   651
            DiagnosticPosition pos,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   652
            TypeSymbol annoDecl)
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   653
    {
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   654
        // The next three checks check that the Repeatable annotation
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   655
        // on the declaration of the annotation type that is repeating is
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   656
        // valid.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   657
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   658
        // Repeatable must have at least one element
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   659
        if (ca.values.isEmpty()) {
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   660
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   661
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   662
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   663
        Pair<MethodSymbol,Attribute> p = ca.values.head;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   664
        Name name = p.fst.name;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   665
        if (name != names.value) { // should contain only one element, named "value"
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   666
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   667
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   668
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   669
        if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   670
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   671
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   672
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   673
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   674
        return ((Attribute.Class)p.snd).getValue();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   675
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   676
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   677
    /* Validate that the suggested targetContainerType Type is a valid
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   678
     * container type for repeated instances of originalAnnoType
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   679
     * annotations. Return null and report errors if this is not the
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   680
     * case, return the MethodSymbol of the value element in
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   681
     * targetContainerType if it is suitable (this is needed to
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   682
     * synthesize the container). */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   683
    private MethodSymbol validateContainer(Type targetContainerType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   684
                                           Type originalAnnoType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   685
                                           DiagnosticPosition pos) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   686
        MethodSymbol containerValueSymbol = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   687
        boolean fatalError = false;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   688
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   689
        // Validate that there is a (and only 1) value method
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   690
        Scope scope = targetContainerType.tsym.members();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   691
        int nr_value_elems = 0;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   692
        boolean error = false;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   693
        for(Symbol elm : scope.getSymbolsByName(names.value)) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   694
            nr_value_elems++;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   695
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   696
            if (nr_value_elems == 1 &&
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   697
                elm.kind == Kinds.MTH) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   698
                containerValueSymbol = (MethodSymbol)elm;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   699
            } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   700
                error = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   701
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   702
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   703
        if (error) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   704
            log.error(pos,
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   705
                      "invalid.repeatable.annotation.multiple.values",
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   706
                      targetContainerType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   707
                      nr_value_elems);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   708
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   709
        } else if (nr_value_elems == 0) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   710
            log.error(pos,
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   711
                      "invalid.repeatable.annotation.no.value",
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   712
                      targetContainerType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   713
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   714
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   715
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   716
        // validate that the 'value' element is a method
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   717
        // probably "impossible" to fail this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   718
        if (containerValueSymbol.kind != Kinds.MTH) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   719
            log.error(pos,
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   720
                      "invalid.repeatable.annotation.invalid.value",
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   721
                      targetContainerType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   722
            fatalError = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   723
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   724
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   725
        // validate that the 'value' element has the correct return type
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   726
        // i.e. array of original anno
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   727
        Type valueRetType = containerValueSymbol.type.getReturnType();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   728
        Type expectedType = types.makeArrayType(originalAnnoType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   729
        if (!(types.isArray(valueRetType) &&
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   730
              types.isSameType(expectedType, valueRetType))) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   731
            log.error(pos,
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   732
                      "invalid.repeatable.annotation.value.return",
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   733
                      targetContainerType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   734
                      valueRetType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   735
                      expectedType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   736
            fatalError = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   737
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   738
        if (error) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   739
            fatalError = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   740
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   741
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   742
        // The conditions for a valid containing annotation are made
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   743
        // in Check.validateRepeatedAnnotaton();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   744
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   745
        return fatalError ? null : containerValueSymbol;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   746
    }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   747
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   748
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   749
     * First step of repeating annotations handling: go through a list
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   750
     * of annotations, and gather up all the repeated ones into a map,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   751
     * which we use to build an AnnotationContext.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   752
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   753
     * Because we do this, we need to get all the annotations for a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   754
     * given AST node at once (ie. if we have "@A @B @A int foo;", we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   755
     * have to get "@A @B @A" at the same time).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   756
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   757
     * @param annotations The annotations being attached.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   758
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   759
     * @param sym The symbol to which the annotations will be attached.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   760
     * @param creator The attribute creator used to enter the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   761
     * @param position The position for any type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   762
     * @return The AnnotaionContext for use in the next phase.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   763
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   764
    private <T extends Attribute.Compound> AnnotationContext<T>
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   765
            prepareEnterAnnotations(List<JCAnnotation> annotations,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   766
                                    Env<AttrContext> env,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   767
                                    Symbol sym,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   768
                                    AttributeCreator<T> creator,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   769
                                    TypeAnnotationPosition position) {
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   770
        Map<TypeSymbol, ListBuffer<T>> annotated = new LinkedHashMap<>();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   771
        Map<T, DiagnosticPosition> pos = new HashMap<>();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   772
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   773
        // Go through the annotation list, build up a map from
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   774
        // annotation types to lists of annotations.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   775
        for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   776
            JCAnnotation a = al.head;
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   777
            T c = creator.create(a, syms.annotationType, env, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   778
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   779
            Assert.checkNonNull(c, "Failed to create annotation");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   780
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   781
            if (annotated.containsKey(a.type.tsym)) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   782
                // Make sure we even allow repeating annotations.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   783
                if (!allowRepeatedAnnos) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   784
                    log.error(a.pos(), "repeatable.annotations.not.supported.in.source");
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   785
                    allowRepeatedAnnos = true;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   786
                }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   787
                // Append the annotation to the list for this kind of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   788
                // annotation.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   789
                ListBuffer<T> l = annotated.get(a.type.tsym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   790
                l = l.append(c);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   791
                annotated.put(a.type.tsym, l);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   792
                pos.put(c, a.pos());
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   793
            } else {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   794
                // We are seeing the first annotation of this kind.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   795
                annotated.put(a.type.tsym, ListBuffer.of(c));
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   796
                pos.put(c, a.pos());
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   797
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   798
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   799
            // Note: @Deprecated has no effect on local variables and parameters
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   800
            if (!c.type.isErroneous()
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   801
                && sym.owner.kind != MTH
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   802
                && types.isSameType(c.type, syms.deprecatedType)) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   803
                sym.flags_field |= Flags.DEPRECATED;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   804
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   805
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   806
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   807
        return new AnnotationContext<>(env, annotated, pos,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   808
                                       creator.createsTypeCompound());
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   809
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   810
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   811
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   812
     * Entry-point for repeating annotations handling.  At this point,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   813
     * we should know the type annotation position, and we should have
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   814
     * all the annotations for a given source location.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   815
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   816
     * We first gather up all the repeated annotations and build an
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   817
     * AnnotationContext.  Then create Placeholder's for any repeated
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   818
     * annotations and send them further down the pipeline.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   819
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   820
     * Something to keep in mind here is that even if we are handling
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   821
     * "declaration" annotations, it is still possible that those
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   822
     * might turn into type annotations (consider "@A @B int foo;",
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   823
     * for example).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   824
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   825
     * The pipeline uses a sort of continuation-passing like style,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   826
     * with creator and attacher.  This allows two things.  First, it
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   827
     * allows for a single pipeline for repeating annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   828
     * regardless of what eventually happens to the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   829
     * Second, it allows us to avoid some unsafe casts we would
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   830
     * otherwise have to make.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   831
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   832
     * @param annotations The annotations to handle.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   833
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   834
     * @param sym The symbol to which to attach annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   835
     * @param position The position for type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   836
     * @param creator The creator to use to enter annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   837
     * @param attacher The attacher to use to attach annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   838
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   839
    private <T extends Attribute.Compound>
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   840
            void attachAttributesLater(final List<JCAnnotation> annotations,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   841
                                       final Env<AttrContext> env,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   842
                                       final Symbol sym,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   843
                                       final TypeAnnotationPosition position,
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   844
                                       final AttributeCreator<T> creator,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   845
                                       final AttributeAttacher<T> attacher) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   846
        // First, gather up all the repeated annotations.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   847
        final AnnotationContext<T> ctx =
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   848
            prepareEnterAnnotations(annotations, env, sym, creator, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   849
        final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated =
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   850
            ctx.annotated;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   851
        boolean hasRepeated = false;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   852
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   853
        // Now run through all the annotation types in the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   854
        // AnnotationContext.  If there are any that have more than
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   855
        // one entry, then we set up a Placeholder for them.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   856
        List<T> buf = List.<T>nil();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   857
        for (ListBuffer<T> lb : annotated.values()) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   858
            if (lb.size() == 1) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   859
                buf = buf.prepend(lb.first());
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   860
            } else {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   861
                @SuppressWarnings("unchecked")
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   862
                T res = (T) new Placeholder<>(ctx, lb.toList(), sym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   863
                buf = buf.prepend(res);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   864
                hasRepeated = true;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   865
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   866
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   867
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   868
        final List<T> attrs = buf.reverse();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   869
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   870
        if (!creator.createsTypeCompound()) {
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   871
            // Attach declaration attributes early, so
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   872
            // that @Repeatable and other annotations get attached.
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   873
            // Since the attacher uses setDeclarationAttributes, this
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   874
            // will be overwritten later.
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   875
            //
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   876
            // The root cause of this is that annotations are
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   877
            // themselves defined using annotations.  However, it is
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   878
            // never the case that a type annotation affects the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   879
            // definition of an annotation, so we don't have to do
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   880
            // this.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   881
            //
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   882
            // We really should find a better way to do this.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   883
            @SuppressWarnings("unchecked")
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   884
            List<Attribute.Compound> tempattrs = (List<Attribute.Compound>) attrs;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   885
            sym.setDeclarationAttributes(tempattrs);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   886
        }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   887
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   888
        if (hasRepeated) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   889
            // If we have repeated annotations, then we go to the next
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   890
            // pipeline step, which replaces all the placeholders.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   891
            replacePlaceholdersAndAttach(attrs, ctx, env, sym, attacher);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   892
        } else {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   893
            // If we don't have repeated annotations, then we still
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   894
            // have to run the annotations through the rest of the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   895
            // pipeline.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   896
            //
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   897
            // For type annotations, we might have error-reporting to
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   898
            // do, and the attacher might end up attaching the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   899
            // annotation to the symbol's owner as well.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   900
            //
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   901
            // For regular annotations, we might have a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   902
            // classifyingAttacher, in which case we have to pull the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   903
            // annotations off the symbol, classify them, and then put
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   904
            // them in the right place.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   905
            attachAttributesAfterRepeated(attrs, env, attacher);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   906
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   907
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   908
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   909
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   910
     * Next pipeline step for repeated annotations: replate all the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   911
     * placeholders, and then send the result further down the pipe.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   912
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   913
     * @param attrs The Attributes representing the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   914
     * @param ctx The AnnotationContext being used.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   915
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   916
     * @param sym The symbol to which to attach annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   917
     * @param attacher The attacher to use to attach annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   918
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   919
    private <T extends Attribute.Compound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   920
            void replacePlaceholdersAndAttach(final List<T> attrs,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   921
                                              final AnnotationContext<T> ctx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   922
                                              final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   923
                                              final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   924
                                              final AttributeAttacher<T> attacher) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   925
        // Set up a Worker.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   926
            repeated(new Annotate.Worker() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   927
                    @Override
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   928
                    public String toString() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   929
                        return "repeated annotation pass of: " + sym + " in: " + sym.owner;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   930
                    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   931
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   932
                    @Override
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   933
                    public void run() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   934
                        JavaFileObject oldSource =
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   935
                            log.useSource(env.toplevel.sourcefile);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   936
                        try {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   937
                        // Replace placeholders
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   938
                        final List<T> replaced =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   939
                            replacePlaceholders(attrs, ctx, sym);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   940
                        // Then send the result to the final pipeline stage.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   941
                        attachAttributesAfterRepeated(replaced, env, attacher);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   942
                        } finally {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   943
                            log.useSource(oldSource);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   944
                        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   945
                    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   946
                });
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   947
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   948
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   949
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   950
     * Final pipeline stage.  Simply use the attacher to deal with the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   951
     * annotations however we want to deal with them.  Note that
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   952
     * attachers may do a number of things, like attach annotations to
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   953
     * other symbols (as is the case with some type annotations, which
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   954
     * get attached to their symbol's owner as well), report errors,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   955
     * or even create copies (as is the case with classifyingAttacher)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   956
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   957
     * At this point, we have to be able to guarantee that we don't
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   958
     * see any Placeholders.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   959
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   960
     * @param attrs The Attributes representing the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   961
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   962
     * @param attacher The attacher we use to finish handling the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   963
     * annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   964
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   965
    private <T extends Attribute.Compound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   966
            void attachAttributesAfterRepeated(final List<T> attrs,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   967
                                               final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   968
                                               final AttributeAttacher<T> attacher) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   969
        // Set up a Worker that just calls the attacher.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   970
        afterRepeated(new Worker() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   971
                @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   972
                public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   973
                    return "attach pass for: " + attrs;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   974
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   975
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   976
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   977
                public void run() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   978
                    JavaFileObject oldSource =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   979
                        log.useSource(env.toplevel.sourcefile);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   980
                    try {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   981
                        attacher.attach(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   982
                    } finally {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   983
                        log.useSource(oldSource);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   984
                    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   985
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   986
            });
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   987
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   988
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   989
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   990
     * AttributeAttachers are similar to continuations.  That contains
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   991
     * the behavior of the final stage of the annotation pipeline,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   992
     * when we've creted Attributes (which have a type annotation
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   993
     * position), and we've dealt with repeating annotations.  Once we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   994
     * have done all that, we simply hand off the list of attributes
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   995
     * to the attacher and let it do its work.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   996
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   997
     * If we didn't have the multiple deferred steps, we could
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   998
     * implement this by returning a list of Attributes from a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
   999
     * top-level method representing the entire repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1000
     * pipeline.  Since we have to handle annotations in multiple
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1001
     * steps, we can't do that.  Therefore, in this light, we can
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1002
     * think of an attacher as being essentially a return
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1003
     * continuation.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1004
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1005
     * We also have ways to "build" more complex attachers out of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1006
     * simple ones, such as classifyingAttacher.  This allows us
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1007
     * considerable flexibility in how we deal with annotations at the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1008
     * end of the pipeline (which is necessary, because there are a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1009
     * lot of cases).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1010
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1011
    public interface AttributeAttacher<T extends Attribute.Compound> {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1012
        public void attach(List<T> attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1013
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1014
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1015
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1016
     * An interface for describing error reporting behaviors for
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1017
     * type-only annotations.  Sometimes, we need to report errors if
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1018
     * any annotations wind up being type-only annotations (the best
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1019
     * example being for illegal scoping).  But at the point where we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1020
     * know this, we don't always know if a given annotation will be a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1021
     * type-only annotation, a regular annotation, or both.  So we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1022
     * have to defer the error-reporting until we do know.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1023
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1024
    public interface Reporter<T extends Attribute.Compound> {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1025
        public void report(List<T> attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1026
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1027
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1028
    public enum AnnotationKind { DECLARATION, TYPE, BOTH }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1029
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1030
    public Attribute[] getTargetTypes(Attribute.Compound a) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1031
        Attribute.Compound atTarget =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1032
            a.type.tsym.attribute(syms.annotationTargetType.tsym);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1033
        if (atTarget == null) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1034
            return null;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1035
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1036
        Attribute atValue = atTarget.member(names.value);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1037
        Assert.check(atValue instanceof Attribute.Array);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1038
        return ((Attribute.Array) atValue).values;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1039
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1040
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1041
    public boolean hasTypeUseTarget(Attribute.Compound a,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1042
                                    boolean isTypeParameter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1043
        Attribute[] targets = getTargetTypes(a);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1044
        if (targets != null) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1045
            for (Attribute app : targets) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1046
                Assert.check(app instanceof Attribute.Enum);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1047
                Attribute.Enum e = (Attribute.Enum) app;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1048
                if (e.value.name == names.TYPE_USE ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1049
                    (isTypeParameter && e.value.name == names.TYPE_PARAMETER)) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1050
                    return true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1051
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1052
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1053
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1054
        return false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1055
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1056
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1057
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1058
     * Determine whether an annotation is a declaration annotation,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1059
     * a type annotation, or both.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1060
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1061
    public AnnotationKind annotationKind(Attribute.Compound a, Symbol s) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1062
        Attribute[] targets = getTargetTypes(a);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1063
        if (targets == null) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1064
            return AnnotationKind.DECLARATION;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1065
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1066
        boolean isDecl = false, isType = false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1067
        for (Attribute app : targets) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1068
            Assert.check(app instanceof Attribute.Enum);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1069
            Attribute.Enum e = (Attribute.Enum) app;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1070
            if (e.value.name == names.TYPE) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1071
                if (s.kind == Kinds.TYP) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1072
                    ElementKind skind = s.getKind();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1073
                    // The only symbols we should see here correspond
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1074
                    // to definitions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1075
                    Assert.check(skind == ElementKind.ANNOTATION_TYPE ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1076
                                 skind == ElementKind.INTERFACE ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1077
                                 skind == ElementKind.ENUM ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1078
                                 skind == ElementKind.CLASS);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1079
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1080
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1081
            } else if (e.value.name == names.FIELD) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1082
                if (s.kind == Kinds.VAR &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1083
                        s.owner.kind != Kinds.MTH)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1084
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1085
            } else if (e.value.name == names.METHOD) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1086
                if (s.kind == Kinds.MTH &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1087
                        !s.isConstructor())
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1088
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1089
            } else if (e.value.name == names.PARAMETER) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1090
                if (s.kind == Kinds.VAR &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1091
                        s.owner.kind == Kinds.MTH &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1092
                        (s.flags() & Flags.PARAMETER) != 0)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1093
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1094
            } else if (e.value.name == names.CONSTRUCTOR) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1095
                if (s.kind == Kinds.MTH &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1096
                        s.isConstructor())
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1097
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1098
            } else if (e.value.name == names.LOCAL_VARIABLE) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1099
                if (s.kind == Kinds.VAR &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1100
                        s.owner.kind == Kinds.MTH &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1101
                        (s.flags() & Flags.PARAMETER) == 0)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1102
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1103
            } else if (e.value.name == names.ANNOTATION_TYPE) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1104
                if (s.kind == Kinds.TYP &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1105
                        (s.flags() & Flags.ANNOTATION) != 0)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1106
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1107
            } else if (e.value.name == names.PACKAGE) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1108
                if (s.kind == Kinds.PCK)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1109
                    isDecl = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1110
            } else if (e.value.name == names.TYPE_USE) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1111
                if (s.kind == Kinds.TYP ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1112
                    s.kind == Kinds.VAR ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1113
                    (s.kind == Kinds.MTH && !s.isConstructor() &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1114
                     !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1115
                    (s.kind == Kinds.MTH && s.isConstructor()))
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1116
                    isType = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1117
            } else if (e.value.name == names.TYPE_PARAMETER) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1118
                /* Irrelevant in this case: we will never see symbols
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1119
                 * that are type parameters, as we never attach
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1120
                 * declaration annotations to them. */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1121
                Assert.check(s.getKind() != ElementKind.TYPE_PARAMETER);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1122
            } else {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1123
                Assert.error("annotationKind(): unrecognized Attribute name " + e.value.name +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1124
                        " (" + e.value.name.getClass() + ")");
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1125
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1126
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1127
        if (isDecl && isType) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1128
            return AnnotationKind.BOTH;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1129
        } else if (isType) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1130
            return AnnotationKind.TYPE;
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1131
        } else {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1132
            return AnnotationKind.DECLARATION;
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1133
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1134
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1135
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1136
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1137
     * An attacher that just attaches annotations as declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1138
     * annotations.  This is used in places where we know for a fact
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1139
     * that type annotations cannot occur.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1140
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1141
    private AttributeAttacher<Attribute.Compound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1142
            declAnnotationsAttacher(final Symbol sym) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1143
        return new AttributeAttacher<Attribute.Compound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1144
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1145
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1146
                return "Attacher for strictly declaration annotations, for " +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1147
                    sym;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1148
            }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1149
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1150
            @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1151
            public void attach(List<Attribute.Compound> attrs) {
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1152
                sym.resetAnnotations();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1153
                sym.setDeclarationAttributes(attrs);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1154
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1155
        };
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1156
    }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1157
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1158
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1159
     * An attacher that just attaches annotations as type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1160
     * We use this in places where only type annotations can occur.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1161
     * The most common use for this is any annotation where we have to
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1162
     * "parse" a type (arrays, inner classes, type arguments, bounds,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1163
     * etc.).  We also use this for base types for non-declarations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1164
     * (ie. casts, instanceofs, etc).  A more subtle case is for
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1165
     * anonymous classes and receiver parameters, both of which cannot
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1166
     * have regular annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1167
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1168
    private AttributeAttacher<Attribute.TypeCompound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1169
            typeAnnotationsAttacher(final Symbol sym) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1170
        return new AttributeAttacher<Attribute.TypeCompound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1171
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1172
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1173
                return "Attacher for strictly type annotations, for " + sym;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1174
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1175
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1176
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1177
            public void attach(List<Attribute.TypeCompound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1178
                if (!attrs.isEmpty()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1179
                    attachTypeAnnotations(sym, attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1180
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1181
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1182
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1183
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1184
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1185
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1186
     * Attach type-only annotations using an attacher, and run a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1187
     * reporter.  Either the reporter or the attacher may be null, in
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1188
     * which case we skip that step.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1189
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1190
    private AttributeAttacher<Attribute.TypeCompound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1191
        reportingTypeAnnotationsAttacher(final AttributeAttacher<Attribute.TypeCompound> attacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1192
                                         final Reporter<Attribute.TypeCompound> reporter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1193
        return new AttributeAttacher<Attribute.TypeCompound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1194
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1195
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1196
                return "Error-reporting type annotation, attacher is: " + attacher +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1197
                    "\n reporter is: " + reporter;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1198
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1199
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1200
            @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1201
            public void attach(List<Attribute.TypeCompound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1202
                if (attacher != null)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1203
                    attacher.attach(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1204
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1205
                if (reporter != null)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1206
                    reporter.report(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1207
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1208
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1209
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1210
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1211
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1212
     * Attach type-only annotations to a symbol and also update the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1213
     * .type field on a tree (unless it is a package type).  This is
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1214
     * used to put annotations on to a type as well as a symbol.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1215
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1216
    private AttributeAttacher<Attribute.TypeCompound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1217
        typeUpdatingTypeAnnotationsAttacher(final AttributeAttacher<Attribute.TypeCompound> attacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1218
                                            final JCTree tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1219
        return new AttributeAttacher<Attribute.TypeCompound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1220
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1221
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1222
                return "Type-updating type annotation attacher, attacher is: " + attacher +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1223
                    "\n tree is: " + tree;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1224
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1225
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1226
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1227
            public void attach(List<Attribute.TypeCompound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1228
                if (null != attacher)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1229
                    attacher.attach(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1230
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1231
                if (!attrs.isEmpty() && !tree.type.hasTag(TypeTag.PACKAGE)) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1232
                    tree.type = tree.type.annotatedType(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1233
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1234
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1235
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1236
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1237
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1238
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1239
     * A Reporter for illegal scoping.  We set one of these up in
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1240
     * TypeAnnotate whenever we are in a place that corresponds to a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1241
     * package or static class that cannot be annotated.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1242
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1243
    private void reportIllegalScoping(List<Attribute.TypeCompound> attrs,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1244
                                      int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1245
        switch (attrs.size()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1246
        case 0:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1247
            // Don't issue an error if all type annotations are
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1248
            // also declaration annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1249
            // If the annotations are also declaration annotations, they are
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1250
            // illegal as type annotations but might be legal as declaration annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1251
            // The normal declaration annotation checks make sure that the use is valid.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1252
            break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1253
        case 1:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1254
            log.error(pos, "cant.type.annotate.scoping.1", attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1255
            break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1256
        default:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1257
            log.error(pos, "cant.type.annotate.scoping", attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1258
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1259
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1260
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1261
    private Reporter<Attribute.TypeCompound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1262
            illegalScopingReporter(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1263
        return new Reporter<Attribute.TypeCompound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1264
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1265
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1266
                return "Illegal scoping reporter at position " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1267
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1268
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1269
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1270
            public void report(List<Attribute.TypeCompound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1271
                reportIllegalScoping(attrs, pos);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1272
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1273
        };
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1274
    }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1275
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1276
    // Create the "simple case": just attach type and regular
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1277
    // annotations, no reporting.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1278
    private AttributeAttacher<Attribute.Compound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1279
            classifyingAttacher(final Symbol sym) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1280
        return classifyingAttacher(sym, declAnnotationsAttacher(sym),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1281
                                   typeAnnotationsAttacher(sym),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1282
                                   null);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1283
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1284
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1285
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1286
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1287
     * Build an attacher for handling the case where we have
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1288
     * annotations, but we don't know for sure whether they are
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1289
     * declaration annotations, type annotations, or both.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1290
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1291
     * We do this by taking an attacher for declaration annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1292
     * another one for type annotations, and (possibly) a reporter for
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1293
     * type-only annotations.  We then use the logic from
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1294
     * annotationKind to figure out what kind each annotation is and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1295
     * deal with it accordingly.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1296
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1297
     * Any of the declAttacher, the typeAttacher, or the Reporter can
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1298
     * be null, in which case we skip it.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1299
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1300
     * We have to have the reporter *separate* from the type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1301
     * annotation attacher, because we might be attaching type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1302
     * annotations that are also declaration annotations.  But the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1303
     * semantics of reporters are that they get called for type-only
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1304
     * annotations.  For an example of where this matters, consider
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1305
     * "@A java.lang.Object foo;", where @A can annotate packages and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1306
     * type uses.  We would create the classifyingAttacher with null
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1307
     * for the type attacher and an illegal scoping reporter.  Both
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1308
     * attachers would end up getting called on @A (which, we'd skip
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1309
     * the type attacher, because it's null), the result being that @A
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1310
     * goes on foo as a declaration annotation.  The reporter would
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1311
     * not get called, because there are no type-only annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1312
     * However, if @A can only annotate type uses, then it's a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1313
     * type-only annotation, and we report an illegal scoping error.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1314
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1315
     * Note: there is a case where we want both attachers to be null:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1316
     * speculative attribution.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1317
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1318
     * @param sym The symbol to which to attach annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1319
     * @param declAttacher The attacher to use for declaration (and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1320
     *                     both) annotations, or null.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1321
     * @param typeAttacher The attacher to use for type (and both)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1322
     *                     annotations, or null.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1323
     * @param reporter The reporter to use for type-only annotations, or null.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1324
     * @return The created attacher.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1325
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1326
    private AttributeAttacher<Attribute.Compound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1327
            classifyingAttacher(final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1328
                                final AttributeAttacher<Attribute.Compound> declAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1329
                                final AttributeAttacher<Attribute.TypeCompound> typeAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1330
                                final Reporter<Attribute.TypeCompound> reporter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1331
        return new AttributeAttacher<Attribute.Compound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1332
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1333
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1334
                return "Classifying attacher, attaching to " + sym +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1335
                    "\n declaration annotation attacher is: " + declAttacher +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1336
                    "\n type annotation attacher is: " + typeAttacher +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1337
                    "\n reporter for strictly type annotations is: " + reporter;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1338
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1339
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1340
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1341
            public void attach(List<Attribute.Compound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1342
                // We sort annotations into "buckets" based on what
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1343
                // kind they are.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1344
                ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<>();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1345
                ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<>();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1346
                // We also need to keep track of the type-only
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1347
                // annotations, in case we have a reporting action.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1348
                ListBuffer<Attribute.TypeCompound> onlyTypeAnnos = new ListBuffer<>();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1349
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1350
                for (Attribute.Compound a : attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1351
                    Assert.check(!(a instanceof Placeholder),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1352
                                 "Placeholders found in annotations being attached!");
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1353
                    switch (annotationKind(a, sym)) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1354
                    case DECLARATION:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1355
                        declAnnos.append(a);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1356
                        break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1357
                    case BOTH: {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1358
                        declAnnos.append(a);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1359
                        Attribute.TypeCompound ta = a.toTypeCompound();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1360
                        Assert.checkNonNull(ta.position);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1361
                        typeAnnos.append(ta);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1362
                        break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1363
                    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1364
                    case TYPE: {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1365
                        Attribute.TypeCompound ta = a.toTypeCompound();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1366
                        Assert.checkNonNull(ta.position);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1367
                        typeAnnos.append(ta);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1368
                        // Also keep track which annotations are only type annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1369
                        onlyTypeAnnos.append(ta);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1370
                        break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1371
                    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1372
                    default:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1373
                        throw new AssertionError("Unknown annotation type");
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1374
                    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1375
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1376
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1377
                if (declAttacher != null)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1378
                    declAttacher.attach(declAnnos.toList());
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1379
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1380
                if (typeAttacher != null)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1381
                    typeAttacher.attach(typeAnnos.toList());
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1382
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1383
                if (reporter != null)
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1384
                    reporter.report(onlyTypeAnnos.toList());
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1385
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1386
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1387
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1388
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1389
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1390
     * Actually attach a list of type annotations to a symbol.  For
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1391
     * variables defined in methods, we need to attach to both the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1392
     * variable symbol, as well as the method symbol.  This takes care
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1393
     * of that.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1394
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1395
     * @param sym The symbol to which to attach.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1396
     * @param attrs The annotations to attach.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1397
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1398
    public void attachTypeAnnotations(Symbol sym, List<Attribute.TypeCompound> attrs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1399
        sym.appendUniqueTypeAttributes(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1400
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1401
        // For type annotations on variables in methods, make
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1402
        // sure they are attached to the owner too.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1403
        switch(sym.getKind()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1404
        case PARAMETER:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1405
        case LOCAL_VARIABLE:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1406
        case RESOURCE_VARIABLE:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1407
        case EXCEPTION_PARAMETER:
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1408
            // Make sure all type annotations from the symbol are also
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1409
            // on the owner.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1410
            sym.owner.appendUniqueTypeAttributes(attrs);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1411
            break;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1412
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1413
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1414
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1415
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1416
     * Final task for repeating annotations: go through a list of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1417
     * Attributes and replace all the placeholders with containers.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1418
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1419
     * @param buf The list of Attributes.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1420
     * @param ctx The AnnotationContext.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1421
     * @param sym The symbol to which we are attaching.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1422
     * @return The list of attributes with all placeholders replaced.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1423
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1424
    private <T extends Attribute.Compound> List<T>
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1425
            replacePlaceholders(List<T> buf,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1426
                                Annotate.AnnotationContext<T> ctx,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1427
                                Symbol sym) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1428
        List<T> result = List.nil();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1429
        for (T a : buf) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1430
            if (a instanceof Placeholder) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1431
                @SuppressWarnings("unchecked")
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1432
                    T replacement = replaceOne((Placeholder<T>) a, ctx, sym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1433
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1434
                if (null != replacement) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1435
                    result = result.prepend(replacement);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1436
                }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1437
            } else {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1438
                result = result.prepend(a);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1439
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1440
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1441
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1442
        return result.reverse();
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1443
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1444
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1445
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1446
     * Replace one placeholder with a container.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1447
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1448
    private <T extends Attribute.Compound> T replaceOne(Placeholder<T> placeholder,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1449
                                                        Annotate.AnnotationContext<T> ctx,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1450
                                                        Symbol sym) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1451
        // Process repeated annotations
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1452
        T validRepeated =
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1453
            processRepeatedAnnotations(placeholder.getPlaceholderFor(),
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1454
                                       ctx, sym, placeholder.position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1455
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1456
        if (validRepeated != null) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1457
            // Check that the container isn't manually
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1458
            // present along with repeated instances of
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1459
            // its contained annotation.
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1460
            ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1461
            if (manualContainer != null) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1462
                log.error(ctx.pos.get(manualContainer.first()), "invalid.repeatable.annotation.repeated.and.container.present",
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1463
                        manualContainer.first().type.tsym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1464
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1465
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1466
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1467
        // A null return will delete the Placeholder
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1468
        return validRepeated;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1469
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1470
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1471
/* ********************************************************************
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1472
 * Annotation processing
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1473
 *********************************************************************/
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1474
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1475
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1476
     * Run a list of annotations through the repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1477
     * pipeline, and attach them.  We don't have any diagnostic
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1478
     * position.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1479
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1480
    void annotateLater(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1481
                       final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1482
                       final Symbol s) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1483
        annotateLater(annotations, localEnv, s, null);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1484
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1485
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1486
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1487
     * Run a list of annotations through the repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1488
     * pipeline and attach them.  This is for when we have annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1489
     * that cannot possibly be type annotations (thus, we have no type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1490
     * annotation position).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1491
     */
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1492
    void annotateLater(final List<JCAnnotation> annotations,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1493
                       final Env<AttrContext> localEnv,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1494
                       final Symbol s,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1495
                       final DiagnosticPosition deferPos) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1496
        // Only attach declaration annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1497
        doAnnotateLater(annotations, localEnv, s, deferPos, null,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1498
                        declAnnotationsAttacher(s));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1499
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1500
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1501
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1502
     * Run a list of annotations through the repeating annotation
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1503
     * pipeline, and then classify and attach them.  This is used
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1504
     * whenever we have annotations that might be regular annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1505
     * type annotations, or both.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1506
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1507
    void annotateWithClassifyLater(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1508
                                   final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1509
                                   final Symbol s,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1510
                                   final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1511
                                   final TypeAnnotationPosition tapos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1512
        // Set up just the basic classifying attacher.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1513
        doAnnotateLater(annotations, localEnv, s, deferPos, tapos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1514
                        classifyingAttacher(s));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1515
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1516
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1517
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1518
     * Set up a worker for handling annotations without parsing a type tree.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1519
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1520
    private void doAnnotateLater(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1521
                                 final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1522
                                 final Symbol s,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1523
                                 final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1524
                                 final TypeAnnotationPosition tapos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1525
                                 final AttributeAttacher<Attribute.Compound> attacher) {
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1526
        if (annotations.isEmpty()) {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1527
            return;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1528
        }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1529
        // Mark annotations as incomplete for now.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1530
        //
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1531
        // This should probably get redesigned at some point.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1532
        if (s.kind != PCK) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1533
            s.resetAnnotations();
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1534
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1535
        normal(new Annotate.Worker() {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1536
                @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1537
                public String toString() {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1538
                    return "annotate " + annotations + " onto " + s + " in " + s.owner;
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1539
                }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1540
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1541
                @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1542
                public void run() {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1543
                    annotateNow(annotations, localEnv, s, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1544
                                tapos, attacher);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1545
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1546
            });
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1547
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1548
        validate(annotationValidator(annotations, localEnv, s));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1549
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1550
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1551
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1552
     * Run a list of declaration (meaning they are in a declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1553
     * position) annotations through the repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1554
     * pipeline.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1555
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1556
     * Note that in some cases, these annotations might end up being
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1557
     * type annotations, or both declaration and type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1558
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1559
     * @param annotations The annotations to handle.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1560
     * @param localEnv the environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1561
     * @param s The symbol to which to attach.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1562
     * @param deferPos The diagnostic position to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1563
     * @param position The type annotation position to use if some of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1564
     *                 the annotations end up being type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1565
     * @param attacher The attacher to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1566
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1567
    private void annotateNow(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1568
                             final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1569
                             final Symbol s,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1570
                             final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1571
                             final TypeAnnotationPosition position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1572
                             final AttributeAttacher<Attribute.Compound> attacher) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1573
        if (annotations.isEmpty()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1574
            return;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1575
        }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1576
                    Assert.check(s.kind == PCK || s.annotationsPendingCompletion());
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1577
                    JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1578
        DiagnosticPosition prevLintPos = deferPos != null ?
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1579
            deferredLintHandler.setPos(deferPos) :
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1580
            deferredLintHandler.immediate();
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1581
                    Lint prevLint = deferPos != null ? null : chk.setLint(lint);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1582
                    try {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1583
                        if (s.hasAnnotations() &&
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1584
                            annotations.nonEmpty())
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1585
                            log.error(annotations.head.pos,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1586
                                      "already.annotated",
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1587
                                      kindName(s), s);
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1588
            actualEnterAnnotations(annotations, localEnv, s, position, attacher);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1589
                    } finally {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1590
                        if (prevLint != null)
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1591
                            chk.setLint(prevLint);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1592
                        deferredLintHandler.setPos(prevLintPos);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1593
                        log.useSource(prev);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1594
                    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1595
                }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1596
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1597
    // Set up a validator to enforce some rules on regular annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1598
    private Annotate.Worker annotationValidator(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1599
                                                final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1600
                                                final Symbol s) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1601
        return new Annotate.Worker() { //validate annotations
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1602
            @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1603
            public void run() {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1604
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1605
                try {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1606
                    chk.validateAnnotations(annotations, s);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1607
                } finally {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1608
                    log.useSource(prev);
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1609
                }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1610
            }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1611
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1612
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1613
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1614
    private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1615
                                                boolean isTypeParameter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1616
        // Ensure that no declaration annotations are present.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1617
        // Note that a tree type might be an AnnotatedType with
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1618
        // empty annotations, if only declaration annotations were given.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1619
        // This method will raise an error for such a type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1620
        for (JCAnnotation ai : annotations) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1621
            Assert.checkNonNull(ai.type);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1622
            Assert.checkNonNull(ai.attribute);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1623
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1624
            if (!ai.type.isErroneous() &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1625
                !hasTypeUseTarget(ai.attribute, isTypeParameter)) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1626
                log.error(ai.pos(), "annotation.type.not.applicable");
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1627
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1628
        }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1629
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1630
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1631
    // Set up a validator to enforce some rules on type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1632
    // In addition to those enforced by Check.validateTypeAnnotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1633
    // this enforces that declaration annotations cannot occur on type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1634
    // parameters.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1635
    private Annotate.Worker typeAnnotationValidator(final List<JCAnnotation> annotations,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1636
                                                    final Env<AttrContext> localEnv,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1637
                                                    final boolean isTypeParameter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1638
        return new Annotate.Worker() { //validate annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1639
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1640
            public void run() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1641
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1642
                try {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1643
                    checkForDeclarationAnnotations(annotations, isTypeParameter);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1644
                    chk.validateTypeAnnotations(annotations, isTypeParameter);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1645
                } finally {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1646
                    log.useSource(prev);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1647
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1648
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1649
        };
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1650
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1651
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1652
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1653
     * This is an interface that wraps up the functionality of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1654
     * enterAnnotations and enterTypeAnnotations.  This allows some
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1655
     * code duplication to be removed from the original repeating
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1656
     * annotations pipeline.  It also allows for some unsafe casts to
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1657
     * be eliminated.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1658
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1659
     * Note: when Lambdas can be used in the compiler, we can just use
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1660
     * method refs for enterAnnotations and enterTypeAnnotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1661
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1662
    private interface AttributeCreator<T extends Attribute.Compound> {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1663
        public T create(JCAnnotation a,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1664
                        Type expected,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1665
                        Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1666
                        TypeAnnotationPosition position);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1667
        public abstract boolean createsTypeCompound();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1668
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1669
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1670
    // Note: try to avoid doing anything that makes these any more
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1671
    // than just the equivalent of method refs in a pre-lambda
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1672
    // setting.  That way, they can go away when we are allowed to use
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1673
    // lambda.
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1674
    private final AttributeCreator<Attribute.Compound> enterAnnotationsCreator =
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1675
        new AttributeCreator<Attribute.Compound>() {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1676
        @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1677
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1678
                return "Attribute creator for regular declaration annotations";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1679
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1680
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1681
            @Override
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1682
        public Attribute.Compound create(JCAnnotation a,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1683
                                         Type expected,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1684
                                             Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1685
                                             TypeAnnotationPosition position) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1686
                return enterAnnotation(a, syms.annotationType, env, position);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1687
        }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1688
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1689
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1690
            public boolean createsTypeCompound() { return false; }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1691
    };
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1692
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1693
    private AttributeCreator<Attribute.TypeCompound>
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1694
            enterTypeAnnotationsCreator(final boolean secondaryAttr) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1695
        return new AttributeCreator<Attribute.TypeCompound>() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1696
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1697
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1698
                if (!secondaryAttr) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1699
                    return "Attribute creator for regular type annotations";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1700
                } else {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1701
                    return "Attribute creator for regular type annotations, ignores cached attributes";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1702
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1703
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1704
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1705
        @Override
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1706
        public Attribute.TypeCompound create(JCAnnotation a,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1707
                                             Type expected,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1708
                                                 Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1709
                                                 TypeAnnotationPosition position) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1710
                return enterTypeAnnotation(a, syms.annotationType,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1711
                                           env, position, secondaryAttr);
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1712
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
  1713
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1714
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1715
            public boolean createsTypeCompound() { return true; }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1716
    };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1717
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1718
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1719
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1720
     * Send a list of annotations (which occurred in a declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1721
     * position) into the repeating annotations pipeline.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1722
     */
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1723
    private void actualEnterAnnotations(List<JCAnnotation> annotations,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1724
                                        Env<AttrContext> env,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1725
                                        Symbol s,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1726
                                        TypeAnnotationPosition position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1727
                                        AttributeAttacher<Attribute.Compound> attacher) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1728
        Assert.checkNonNull(s);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1729
        attachAttributesLater(annotations, env, s, position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1730
                              enterAnnotationsCreator, attacher);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1731
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1732
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1733
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1734
     * Send a list of annotations (which occurred in a type-use
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1735
     * position) into the repeating annotations pipeline.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1736
     */
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1737
    private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1738
                                            final Env<AttrContext> env,
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1739
                                            final Symbol s,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1740
                                            final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1741
                                            final boolean secondaryAttr,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1742
                                            final TypeAnnotationPosition position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1743
                                            final AttributeAttacher<Attribute.TypeCompound> attacher) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1744
        Assert.checkNonNull(s);
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1745
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1746
        DiagnosticPosition prevLintPos = null;
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1747
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1748
        if (deferPos != null) {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1749
            prevLintPos = deferredLintHandler.setPos(deferPos);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1750
        }
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1751
        try {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1752
            attachAttributesLater(annotations, env, s, position,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1753
                                  enterTypeAnnotationsCreator(secondaryAttr),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1754
                                  attacher);
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1755
        } finally {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1756
            if (prevLintPos != null)
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1757
                deferredLintHandler.setPos(prevLintPos);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1758
            log.useSource(prev);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1759
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1760
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1761
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1762
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1763
     * Given a type tree, walk down it and handle any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1764
     * find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1765
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1766
     * @param tree The type tree to scan.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1767
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1768
     * @param sym The symbol to which to attach any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1769
     * might find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1770
     * @param deferPos The diagnostic position to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1771
     * @param creator The creator to use for making positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1772
     */
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1773
    public void annotateTypeLater(final JCTree tree,
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1774
                                  final Env<AttrContext> env,
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1775
                                  final Symbol sym,
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1776
                                  final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1777
                                  final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1778
        doAnnotateTypeLater(tree, List.<JCAnnotation>nil(), env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1779
                            sym, deferPos, creator, false, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1780
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1781
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1782
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1783
     * Given a type tree, walk down it and handle any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1784
     * find.  We also have a set of base-type annotations (which
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1785
     * occurred in a declaration position in source), which may either
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1786
     * be declaration annotations or annotations on the base type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1787
     * For an example, in "@A int @B []", we would have the type tree
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1788
     * "int @B []" with base-type annotations "@A".
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1789
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1790
     * @param tree The type tree to scan.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1791
     * @param baseTypeAnnos The base-type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1792
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1793
     * @param sym The symbol to which to attach any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1794
     * might find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1795
     * @param deferPos The diagnostic position to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1796
     * @param creator The creator to use for making positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1797
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1798
    public void annotateTypeLater(final JCTree tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1799
                                  final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1800
                                  final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1801
                                  final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1802
                                  final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1803
                                  final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1804
        doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1805
                            creator, false, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1806
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1807
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1808
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1809
     * Given a type tree, walk down it and handle any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1810
     * find.  We also have a set of base-type annotations (which
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1811
     * occurred in a declaration position in source), which must be
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1812
     * type annotations on the base type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1813
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1814
     * @param tree The type tree to scan.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1815
     * @param baseTypeAnnos The base-type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1816
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1817
     * @param sym The symbol to which to attach any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1818
     * might find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1819
     * @param deferPos The diagnostic position to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1820
     * @param creator The creator to use for making positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1821
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1822
    public void annotateStrictTypeLater(final JCTree tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1823
                                        final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1824
                                        final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1825
                                        final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1826
                                        final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1827
                                        final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1828
        doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1829
                            creator, true, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1830
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1831
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1832
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1833
     * Given a type tree representing an anonymous class' supertype,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1834
     * walk down it and handle any annotations we find.  We also have
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1835
     * a set of base-type annotations (which occurred in a declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1836
     * position in source), which must be type annotations on the base
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1837
     * type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1838
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1839
     * @param tree The type tree to scan.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1840
     * @param baseTypeAnnos The base-type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1841
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1842
     * @param sym The symbol to which to attach any annotations we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1843
     * might find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1844
     * @param deferPos The diagnostic position to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1845
     * @param creator The creator to use for making positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1846
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1847
    public void annotateAnonClassDefLater(final JCTree tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1848
                                          final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1849
                                          final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1850
                                          final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1851
                                          final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1852
                                          final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1853
        doAnnotateTypeLater(tree, baseTypeAnnos, env, sym, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1854
                            creator, true, true);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1855
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1856
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1857
    // The combined worker function for the annotateTypeLater family.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1858
    public void doAnnotateTypeLater(final JCTree tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1859
                                    final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1860
                                    final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1861
                                    final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1862
                                    final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1863
                                    final PositionCreator creator,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1864
                                    final boolean onlyTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1865
                                    final boolean secondaryAttr) {
23134
010b1b0d25fb 8036142: Remove redundant call to annotateTypeLater with null Symbol
emc
parents: 23129
diff changeset
  1866
        Assert.checkNonNull(sym);
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1867
        Assert.checkNonNull(baseTypeAnnos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1868
        Assert.checkNonNull(creator);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1869
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1870
        normal(new Annotate.Worker() {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1871
                @Override
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1872
                public String toString() {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1873
                    return "type annotate " + tree + " onto " + sym + " in " + sym.owner;
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1874
                }
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1875
                @Override
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1876
                public void run() {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1877
                    if (!baseTypeAnnos.isEmpty()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1878
                        sym.resetAnnotations(); // mark Annotations as incomplete for now
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1879
                    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1880
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1881
                    tree.accept(typeAnnotator(baseTypeAnnos, sym, env, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1882
                                              creator, onlyTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1883
                                              secondaryAttr));
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1884
                }
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1885
            });
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1886
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1887
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1888
    /**
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1889
     * A client passed into various visitors that takes a type path as
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1890
     * an argument and performs an action (typically creating a
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1891
     * TypeAnnotationPosition and then creating a {@code Worker} and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1892
     * adding it to a queue.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1893
     */
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1894
    public abstract class PositionCreator {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1895
        public abstract TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1896
                                                      JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1897
                                                      int typeIndex);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1898
    }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1899
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1900
    // For when we don't have a creator.  Throws an exception.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1901
    public final PositionCreator noCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1902
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1903
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1904
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1905
                return "Sentinel null position creator";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1906
        }
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1907
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1908
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1909
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1910
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1911
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1912
                throw new AssertionError("No annotation position creator registered");
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1913
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1914
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1915
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1916
    // For when we are creating annotations that will inevitably
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1917
    // trigger errors.  Creates null.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1918
    public final PositionCreator errorCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1919
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1920
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1921
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1922
                return "Position creator for annotations that represent errors";
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1923
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1924
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1925
        @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1926
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1927
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1928
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1929
                return null;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1930
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1931
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1932
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1933
    // Create class extension positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1934
    public final PositionCreator extendsCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1935
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1936
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1937
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1938
                return "Position creator for extends";
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1939
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1940
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1941
        @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1942
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1943
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1944
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1945
                return TypeAnnotationPosition.classExtends(path, lambda, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1946
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1947
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1948
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1949
    // Create interface implementation positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1950
    public PositionCreator implementsCreator(final int idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1951
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1952
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1953
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1954
                return "Position creator for implements, index " + idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1955
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1956
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1957
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1958
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1959
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1960
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1961
                return TypeAnnotationPosition.classExtends(path, lambda, idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1962
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1963
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1964
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1965
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1966
    // Create method parameter positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1967
    public final PositionCreator paramCreator(final int idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1968
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1969
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1970
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1971
                return "Position creator for parameter " + idx;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1972
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1973
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1974
        @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1975
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1976
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1977
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1978
                return TypeAnnotationPosition.methodParameter(path, lambda, idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1979
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1980
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1981
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1982
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1983
    // Create class type parameter positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1984
    public PositionCreator typeParamCreator(final int idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1985
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1986
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1987
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1988
                return "Position creator for class type parameter " + idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1989
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1990
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1991
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1992
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1993
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1994
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1995
                return TypeAnnotationPosition.typeParameter(path, lambda, idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1996
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1997
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1998
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  1999
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2000
    public PositionCreator typeParamBoundCreator(final JCTypeParameter typaram,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2001
                                                 final int param_idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2002
                                                 final int bound_idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2003
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2004
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2005
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2006
                return "Position creator for class type parameter " + param_idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2007
                    ", bound " + bound_idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2008
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2009
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2010
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2011
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2012
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2013
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2014
                final int real_bound_idx =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2015
                    typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2016
                return TypeAnnotationPosition
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2017
                    .typeParameterBound(path, lambda, param_idx, real_bound_idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2018
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2019
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2020
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2021
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2022
    // Create field positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2023
    public final PositionCreator fieldCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2024
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2025
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2026
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2027
                return "Position creator for field declaration";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2028
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2029
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2030
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2031
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2032
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2033
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2034
                return TypeAnnotationPosition.field(path, lambda, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2035
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2036
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2037
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2038
    // Create local variable positions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2039
    public PositionCreator localVarCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2040
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2041
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2042
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2043
                return "Position creator for local variable declaration at " +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2044
                    pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2045
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2046
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2047
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2048
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2049
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2050
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2051
                return TypeAnnotationPosition.localVariable(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2052
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2053
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2054
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2055
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2056
    // Create resource variable positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2057
    public PositionCreator resourceVarCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2058
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2059
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2060
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2061
                return "Position creator for resource variable declaration at " +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2062
                    pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2063
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2064
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2065
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2066
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2067
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2068
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2069
                return TypeAnnotationPosition.resourceVariable(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2070
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2071
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2072
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2073
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2074
    // Create exception parameter positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2075
    public PositionCreator exceptionParamCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2076
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2077
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2078
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2079
                return "Position creator for exception param declaration at " +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2080
                    pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2081
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2082
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2083
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2084
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2085
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2086
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2087
                return TypeAnnotationPosition.exceptionParameter(path, lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2088
                                                                 typeIndex, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2089
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2090
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2091
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2092
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2093
    // Create constructor reference type argument positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2094
    public PositionCreator constructorRefTypeArgCreator(final int idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2095
                                                        final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2096
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2097
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2098
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2099
                return "Position creator for constructor reference type argument " + idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2100
                    " at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2101
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2102
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2103
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2104
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2105
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2106
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2107
                return TypeAnnotationPosition
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2108
                    .constructorRefTypeArg(path, lambda, idx, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2109
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2110
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2111
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2112
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2113
    public PositionCreator methodInvokeTypeArgCreator(final int idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2114
                                                      final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2115
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2116
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2117
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2118
                return "Position creator for method invoke type argument " + idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2119
                    " at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2120
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2121
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2122
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2123
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2124
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2125
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2126
                return TypeAnnotationPosition.methodInvocationTypeArg(path, lambda, idx, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2127
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2128
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2129
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2130
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2131
    public PositionCreator methodTypeParamCreator(final int idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2132
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2133
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2134
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2135
                return "Position creator for method type parameter " + idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2136
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2137
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2138
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2139
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2140
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2141
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2142
                return TypeAnnotationPosition.methodTypeParameter(path, lambda, idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2143
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2144
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2145
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2146
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2147
    public PositionCreator methodTypeParamBoundCreator(final JCTypeParameter typaram,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2148
                                                       final int param_idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2149
                                                       final int bound_idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2150
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2151
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2152
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2153
                return "Position creator for method type parameter " + param_idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2154
                    " bound " + bound_idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2155
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2156
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2157
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2158
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2159
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2160
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2161
                final int real_bound_idx =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2162
                    typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2163
                return TypeAnnotationPosition
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2164
                    .methodTypeParameterBound(path, lambda, param_idx, real_bound_idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2165
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2166
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2167
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2168
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2169
    public PositionCreator throwCreator(final int idx) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2170
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2171
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2172
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2173
                return "Position creator for throw, type index " + idx;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2174
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2175
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2176
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2177
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2178
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2179
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2180
                return TypeAnnotationPosition.methodThrows(path, lambda, idx, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2181
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2182
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2183
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2184
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2185
    public final PositionCreator returnCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2186
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2187
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2188
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2189
                return "Position creator for method return type";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2190
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2191
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2192
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2193
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2194
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2195
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2196
                return TypeAnnotationPosition.methodReturn(path, lambda, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2197
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2198
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2199
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2200
    public PositionCreator receiverCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2201
        new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2202
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2203
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2204
                return "Position creator for method receiver parameter type";
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2205
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2206
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2207
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2208
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2209
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2210
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2211
                return TypeAnnotationPosition.methodReceiver(path, lambda, -1);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2212
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2213
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2214
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2215
    public PositionCreator methodRefCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2216
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2217
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2218
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2219
                return "Position creator for method reference at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2220
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2221
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2222
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2223
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2224
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2225
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2226
                return TypeAnnotationPosition.methodRef(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2227
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2228
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2229
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2230
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2231
    public PositionCreator methodRefTypeArgCreator(final int idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2232
                                                   final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2233
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2234
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2235
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2236
                return "Position creator for method reference type argument " + idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2237
                    " at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2238
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2239
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2240
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2241
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2242
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2243
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2244
                return TypeAnnotationPosition.methodRefTypeArg(path, lambda, idx, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2245
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2246
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2247
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2248
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2249
    public PositionCreator constructorRefCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2250
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2251
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2252
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2253
                return "Position creator for constructor reference at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2254
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2255
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2256
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2257
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2258
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2259
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2260
                return TypeAnnotationPosition.constructorRef(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2261
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2262
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2263
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2264
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2265
    public PositionCreator constructorInvokeTypeArgCreator(final int idx,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2266
                                                           final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2267
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2268
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2269
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2270
                return "Position creator for constructor invoke type argument " + idx +
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2271
                    " at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2272
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2273
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2274
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2275
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2276
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2277
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2278
                return TypeAnnotationPosition.constructorInvocationTypeArg(path, lambda, idx, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2279
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2280
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2281
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2282
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2283
    public PositionCreator instanceOfCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2284
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2285
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2286
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2287
                return "Position creator for instanceof at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2288
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2289
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2290
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2291
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2292
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2293
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2294
                return TypeAnnotationPosition.instanceOf(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2295
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2296
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2297
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2298
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2299
    public PositionCreator newObjCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2300
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2301
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2302
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2303
                return "Position creator for new at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2304
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2305
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2306
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2307
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2308
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2309
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2310
                return TypeAnnotationPosition.newObj(path, lambda, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2311
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2312
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2313
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2314
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2315
    public PositionCreator castCreator(final int pos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2316
        return new PositionCreator() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2317
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2318
            public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2319
                return "Position creator for cast at " + pos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2320
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2321
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2322
            @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2323
            public TypeAnnotationPosition create(List<TypePathEntry> path,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2324
                                                 JCLambda lambda,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2325
                                                 int typeIndex) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2326
                return TypeAnnotationPosition.typeCast(path, lambda, typeIndex, pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2327
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2328
        };
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2329
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2330
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2331
    public static List<TypePathEntry> makeInners(Type type) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2332
        return addInners(type, List.<TypePathEntry>nil());
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2333
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2334
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2335
    private static List<TypePathEntry> addInners(Type type,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2336
                                                 List<TypePathEntry> typepath) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2337
        Type encl = type.getEnclosingType();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2338
        while (encl != null && encl.getKind() != TypeKind.NONE &&
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2339
               encl.getKind() != TypeKind.ERROR) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2340
            typepath = typepath.append(TypePathEntry.INNER_TYPE);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2341
            encl = encl.getEnclosingType();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2342
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2343
        return typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2344
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2345
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2346
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2347
     * Set up the visitor to scan the type tree and handle any
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2348
     * annotations we find.  If we are in speculative attribution, we
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2349
     * will not actually attach anything, we will just enter the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2350
     * annotations and run them through the pipeline to pick up any
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2351
     * errors that might occur.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2352
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2353
     * @param baseTypeAnnos Annotations on the base type, which need
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2354
     *                      to be classified if onlyTypeAnnos is false.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2355
     * @param sym The symbol to which to attach.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2356
     * @param env The environment.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2357
     * @param creator The position creator to use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2358
     * @param onlyTypeAnnos Whether or not baseTypeAnnos can represent
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2359
     *                      declaration annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2360
     * @param secondaryAttr Whether or not we are creating secondary
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2361
     *                      attributes (see enterTypeAnnotations).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2362
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2363
    public TypeAnnotate typeAnnotator(final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2364
                                      final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2365
                                      final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2366
                                      final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2367
                                      final PositionCreator creator,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2368
                                      final boolean onlyTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2369
                                      final boolean secondaryAttr) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2370
        if (!env.info.isSpeculative) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2371
            return new TypeAnnotate(baseTypeAnnos, sym, env, deferPos, creator,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2372
                                    declAnnotationsAttacher(sym),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2373
                                    typeAnnotationsAttacher(sym),
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2374
                                    onlyTypeAnnos, secondaryAttr);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2375
        } else {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2376
            return new TypeAnnotate(baseTypeAnnos, sym, env, deferPos, creator,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2377
                                    null, null, onlyTypeAnnos, secondaryAttr);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2378
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2379
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2380
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2381
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2382
     * A visitor that scans a type tree and handles an annotations it finds.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2383
     *
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2384
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2385
    private class TypeAnnotate extends TreeScanner {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2386
        // The creator we use to create positions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2387
        protected PositionCreator creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2388
        // The current type path
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2389
        private List<TypePathEntry> typepath = List.nil();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2390
        // The current innermost lambda
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2391
        private JCLambda currentLambda;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2392
        // The current type index, if we are looking at an
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2393
        // intersection type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2394
        private int type_index = 0;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2395
        // Whether or not we are looking at the innermost type.  This
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2396
        // gets used to figure out where to attach base type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2397
        // annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2398
        private boolean innermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2399
        // The attachers and reporter we use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2400
        private AttributeAttacher<Attribute.Compound> declAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2401
        private AttributeAttacher<Attribute.TypeCompound> typeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2402
        private Reporter<Attribute.TypeCompound> reporter;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2403
        // The symbol to which we are attaching.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2404
        private final Symbol sym;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2405
        // The diagnostic position we use.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2406
        private final DiagnosticPosition deferPos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2407
        // The environment
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2408
        private final Env<AttrContext> env;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2409
        private final List<JCAnnotation> baseTypeAnnos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2410
        // Whether or not baseTypeAnnos can be declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2411
        // annotations, or just strictly type annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2412
        private final boolean onlyTypeAnnos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2413
        // Whether or not we are creating secondary attributes (see
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2414
        // enterTypeAnnotations).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2415
        private final boolean secondaryAttr;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2416
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2417
        public TypeAnnotate(final List<JCAnnotation> baseTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2418
                            final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2419
                            final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2420
                            final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2421
                            final PositionCreator creator,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2422
                            final AttributeAttacher<Attribute.Compound> declAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2423
                            final AttributeAttacher<Attribute.TypeCompound> typeAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2424
                            final boolean onlyTypeAnnos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2425
                            final boolean secondaryAttr) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2426
            this.baseTypeAnnos = baseTypeAnnos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2427
            this.sym = sym;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2428
            this.env = env;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2429
            this.deferPos = deferPos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2430
            this.currentLambda = env.getLambda();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2431
            this.creator = creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2432
            this.innermost = true;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2433
            this.declAttacher = declAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2434
            this.typeAttacher = typeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2435
            this.reporter = null;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2436
            this.onlyTypeAnnos = onlyTypeAnnos;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2437
            this.secondaryAttr = secondaryAttr;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2438
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2439
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2440
        // Deal with the base-type annotations.  This should only get
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2441
        // called when we are at the inner-most type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2442
        private void doBaseTypeAnnos() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2443
            if (onlyTypeAnnos) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2444
                // If the base type annotations can only be type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2445
                // annotations, then handle them as such.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2446
                doTypeAnnos(baseTypeAnnos, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2447
            } else if (!baseTypeAnnos.isEmpty()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2448
                // Otherwise, send them into the repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2449
                // pipeline with a classifying attacher we build based
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2450
                // on the current state.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2451
                final TypeAnnotationPosition tapos =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2452
                    creator.create(typepath, currentLambda, type_index);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2453
                annotateNow(baseTypeAnnos, env, sym, deferPos, tapos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2454
                            classifyingAttacher(sym, declAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2455
                                                typeAttacher, reporter));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2456
                // Also set up a validator.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2457
                validate(annotationValidator(baseTypeAnnos, env, sym));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2458
            }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2459
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2460
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2461
        // Deal with type annotations we found while scanning the tree.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2462
        private void doTypeAnnos(List<JCAnnotation> annos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2463
                                 boolean isTypeParameter) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2464
            if (!annos.isEmpty()) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2465
                // Grab the reporter and the type attacher (which,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2466
                // it's ok for either to be null), and combine them
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2467
                // into a reporting attacher.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2468
                final AttributeAttacher<Attribute.TypeCompound> attacher =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2469
                    reportingTypeAnnotationsAttacher(typeAttacher, reporter);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2470
                // Create the position using the current type path and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2471
                // type index.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2472
                final TypeAnnotationPosition tapos =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2473
                    creator.create(typepath, currentLambda, type_index);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2474
                // Send the annotations into the repeating annotations
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2475
                // pipeline, and set up a validator.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2476
                actualEnterTypeAnnotations(annos, env, sym, deferPos, secondaryAttr,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2477
                                           tapos, attacher);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2478
                validate(typeAnnotationValidator(annos, env, isTypeParameter));
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2479
            }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2480
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2481
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2482
        @Override
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2483
        public void visitTypeIdent(final JCPrimitiveTypeTree tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2484
            // This is one place that can represent the base type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2485
            // But we need to make sure we're actually in the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2486
            // innermost type (ie not a type argument or something).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2487
            if (innermost) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2488
                final AttributeAttacher<Attribute.TypeCompound> oldTypeAttacher = typeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2489
                // We want to update the Type to have annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2490
                typeAttacher = typeUpdatingTypeAnnotationsAttacher(oldTypeAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2491
                                                                   tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2492
                // We can't possibly have any INNER_TYPE type path
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2493
                // elements, because these are all primitives.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2494
                doBaseTypeAnnos();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2495
                typeAttacher = oldTypeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2496
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2497
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2498
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2499
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2500
        public void visitIdent(final JCIdent tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2501
            // This is one place that can represent the base type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2502
            // But we need to make sure we're actually in the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2503
            // innermost type (ie not a type argument or something).
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2504
            if (innermost) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2505
                final AttributeAttacher<Attribute.TypeCompound> oldTypeAttacher = typeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2506
                // Set up an attacher that updates the Type, so we get
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2507
                // the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2508
                typeAttacher = typeUpdatingTypeAnnotationsAttacher(oldTypeAttacher,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2509
                                                                   tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2510
                // Add any INNER_TYPE type path elements we might need.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2511
                if (tree.type != null) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2512
                    final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2513
                    typepath = addInners(tree.type, typepath);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2514
                    doBaseTypeAnnos();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2515
                    typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2516
                } else {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2517
                    doBaseTypeAnnos();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2518
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2519
                typeAttacher = oldTypeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2520
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2521
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2522
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2523
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2524
        public void visitAnnotatedType(JCAnnotatedType tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2525
            // This is one place where we run into pure type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2526
            // annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2527
            Assert.checkNonNull(tree.getUnderlyingType().type);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2528
            final boolean oldinnermost = innermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2529
            // Make sure we don't consider ourselves "innermost" when
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2530
            // scanning the annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2531
            innermost = false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2532
            scan(tree.annotations);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2533
            innermost = oldinnermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2534
            scan(tree.underlyingType);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2535
            final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2536
            typepath = addInners(tree.getUnderlyingType().type, typepath);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2537
            doTypeAnnos(tree.annotations, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2538
            typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2539
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2540
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2541
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2542
        public void visitTypeArray(JCArrayTypeTree tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2543
            // This case is simple: just add an ARRAY to the type path.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2544
            final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2545
            typepath = typepath.append(TypePathEntry.ARRAY);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2546
            super.visitTypeArray(tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2547
            typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2548
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2549
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2550
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2551
        public void visitTypeApply(JCTypeApply tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2552
            // Handle type arguments
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2553
            Assert.checkNonNull(tree.getType().type);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2554
            final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2555
            // First, look at the base type.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2556
            scan(tree.clazz);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2557
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2558
            // Add any INNER_TYPE path elements we need first
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2559
            if (tree.getType() != null && tree.getType().type != null) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2560
                typepath = addInners(tree.getType().type, typepath);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2561
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2562
            // Make sure we're not considering ourselves innermost
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2563
            // when looking at type arguments.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2564
            final boolean oldinnermost = innermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2565
            innermost = false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2566
            // For each type argument, add a TYPE_ARGUMENT path
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2567
            // element for the right index.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2568
            int i = 0;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2569
            for (List<JCExpression> l = tree.arguments; l.nonEmpty();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2570
                 l = l.tail, i++) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2571
                final JCExpression arg = l.head;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2572
                final List<TypePathEntry> noargpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2573
                typepath = typepath.append(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, i));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2574
                scan(arg);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2575
                typepath = noargpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2576
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2577
            typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2578
            innermost = oldinnermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2579
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2580
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2581
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2582
        public void visitNewArray(JCNewArray tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2583
            // We can also run into type annotations here, on dimAnnos.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2584
            final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2585
            final PositionCreator oldcreator = creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2586
            creator = newObjCreator(tree.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2587
            doTypeAnnos(tree.annotations, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2588
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2589
            // Go through the dimensions, set up the type path, and
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2590
            // handle any annetations we find.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2591
            for (int i = 0; i < tree.dimAnnotations.size(); i++) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2592
                final List<JCAnnotation> dimAnnos = tree.dimAnnotations.get(i);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2593
                doTypeAnnos(dimAnnos, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2594
                // This is right.  As per the type annotations spec,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2595
                // the first array dimension has no arrays in the type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2596
                // path, the second has one, and so on, and the
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2597
                // element type has n for n dimensions.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2598
                typepath = typepath.append(TypePathEntry.ARRAY);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2599
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2600
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2601
            // The element type is sometimes null, in the case of
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2602
            // array literals.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2603
            scan(tree.elemtype);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2604
            typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2605
            creator = oldcreator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2606
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2607
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2608
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2609
        public void visitWildcard(JCWildcard tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2610
            // Simple: add a WILDCARD type path element and continue.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2611
            final List<TypePathEntry> oldpath = typepath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2612
            typepath = typepath.append(TypePathEntry.WILDCARD);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2613
            super.visitWildcard(tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2614
            typepath = oldpath;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2615
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2616
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2617
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2618
        public void visitTypeParameter(JCTypeParameter tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2619
            // This is another place where we can run into pure type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2620
            // annotations.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2621
            scan(tree.annotations);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2622
            Assert.checkNonNull(tree.type);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2623
            doTypeAnnos(tree.annotations, true);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2624
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2625
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2626
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2627
        public void visitLambda(JCLambda tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2628
            // If we run into a lambda, set the current lambda to it.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2629
            final JCLambda oldLambda = currentLambda;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2630
            currentLambda = tree;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2631
            scan(tree.body);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2632
            scan(tree.params);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2633
            currentLambda = oldLambda;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2634
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2635
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2636
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2637
        public void visitTypeIntersection(JCTypeIntersection tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2638
            final boolean oldinnermost = innermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2639
            // Run through the options, and update the type_index
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2640
            // accordingly.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2641
            for (List<JCExpression> l = tree.bounds; l.nonEmpty();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2642
                 l = l.tail, type_index++) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2643
                scan(l.head);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2644
                // Set innermost to false after the first element
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2645
                innermost = false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2646
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2647
            innermost = oldinnermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2648
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2649
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2650
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2651
        public void visitTypeUnion(JCTypeUnion tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2652
            final boolean oldinnermost = innermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2653
            // Run through the options, and update the type_index
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2654
            // accordingly.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2655
            for (List<JCExpression> l = tree.alternatives; l.nonEmpty();
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2656
                 l = l.tail, type_index++) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2657
                scan(l.head);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2658
                // Set innermost to false after the first element
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2659
                innermost = false;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2660
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2661
            innermost = oldinnermost;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2662
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2663
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2664
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2665
        public void visitSelect(JCFieldAccess tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2666
            // In this case, we need to possibly set up an
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2667
            // illegalScopingReporter, if the selected type cannot be
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2668
            // annotated.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2669
            Symbol sym = tree.sym;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2670
            final AttributeAttacher<Attribute.TypeCompound> oldTypeAttacher = typeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2671
            final Reporter<Attribute.TypeCompound> oldReporter = reporter;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2672
            // If we're selecting from an interface or a static class,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2673
            // set up attachers that will only attach declaration
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2674
            // annotations and will report type annotations as errors.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2675
            Type selectedTy = tree.selected.type;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2676
            if ((sym != null && (sym.isStatic() || sym.isInterface() ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2677
                                selectedTy.hasTag(TypeTag.PACKAGE))) ||
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2678
                tree.name == names._class) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2679
                typeAttacher = null;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2680
                reporter = illegalScopingReporter(tree.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2681
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2682
            super.visitSelect(tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2683
            typeAttacher = oldTypeAttacher;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2684
            reporter = oldReporter;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2685
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2686
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2687
        // These methods stop the visitor from continuing on when it
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2688
        // sees a definition.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2689
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2690
        public void visitVarDef(final JCVariableDecl tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2691
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2692
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2693
        @Override
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2694
        public void visitClassDef(JCClassDecl tree) {
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2695
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2696
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2697
        @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2698
        public void visitNewClass(JCNewClass tree) {
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2699
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2700
            }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2701
        }
24895
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2702
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2703
    // A derived TypeAnnotate visitor that also scans expressions
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2704
    // within Deferred attribution.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2705
    private class TypeAnnotateExpr extends TypeAnnotate {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2706
        // This constructor creates an instance suitable for deferred
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2707
        // attribution.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2708
        public TypeAnnotateExpr(final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2709
                                final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2710
                                final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2711
                                final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2712
            super(List.<JCAnnotation>nil(), sym, env, deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2713
                  creator, null, null, false, false);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2714
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2715
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2716
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2717
        public void visitTypeCast(final JCTypeCast tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2718
            final PositionCreator oldcreator = creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2719
            creator = castCreator(tree.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2720
            super.visitTypeCast(tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2721
            creator = oldcreator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2722
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2723
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2724
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2725
        public void visitTypeTest(JCInstanceOf tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2726
            final PositionCreator oldcreator = creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2727
            creator = instanceOfCreator(tree.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2728
            super.visitTypeTest(tree);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2729
            creator = oldcreator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2730
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2731
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2732
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2733
        public void visitReference(JCMemberReference that) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2734
            final boolean isConstructor = that.getName() == names.init;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2735
            final PositionCreator oldcreator = creator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2736
            creator = isConstructor ? constructorRefCreator(that.pos) :
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2737
                                      methodRefCreator(that.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2738
            scan(that.expr);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2739
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2740
            if (null != that.typeargs) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2741
                int i = 0;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2742
                for (List<JCExpression> l = that.typeargs;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2743
                     l.nonEmpty(); l = l.tail, i++) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2744
                    final Annotate.PositionCreator typeArgCreator =
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2745
                        isConstructor ? constructorRefTypeArgCreator(i, that.pos) :
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2746
                                        methodRefTypeArgCreator(i, that.pos);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2747
                    final JCExpression arg = l.head;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2748
                    scan(that.expr);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2749
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2750
            }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2751
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2752
            creator = oldcreator;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2753
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2754
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2755
        @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2756
        public void visitNewClass(JCNewClass tree) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2757
            // This will be visited by Attr later, so don't do
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2758
            // anything.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2759
        }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2760
    }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2761
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2762
    /**
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2763
     * Set up a visitor to scan an expression and handle any type
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2764
     * annotations it finds, within a deferred attribution context.
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2765
     */
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2766
    public void typeAnnotateExprLater(final JCTree tree,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2767
                                      final Env<AttrContext> env,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2768
                                      final Symbol sym,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2769
                                      final DiagnosticPosition deferPos,
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2770
                                      final PositionCreator creator) {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2771
        Assert.checkNonNull(sym);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2772
        Assert.checkNonNull(creator);
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2773
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2774
        normal(new Annotate.Worker() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2775
                @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2776
                public String toString() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2777
                    return "type annotate " + tree + " onto " + sym + " in " + sym.owner;
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2778
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2779
                @Override
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2780
                public void run() {
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2781
                    tree.accept(new TypeAnnotateExpr(sym, env, deferPos, creator));
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2782
                }
dd091d389fbf 8027262: Determine location for type annotations earlier in compiler pipeline
emc
parents: 23814
diff changeset
  2783
            });
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  2784
    }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
  2785
}