langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Annotate.java
author jjg
Tue, 07 Apr 2015 11:04:29 -0700
changeset 29842 826ac2519523
parent 27224 228abfa87080
child 29960 d20c04ed8ffe
permissions -rw-r--r--
8031744: Annotations on many Language Model elements are not returned Reviewed-by: jfranck, mcimadamore, emc, jlahoda, jjg Contributed-by: joel.franck@oracle.com, maurizio.cimadamore@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
     2
 * Copyright (c) 2003, 2015, 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
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    28
import com.sun.tools.javac.code.*;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    29
import com.sun.tools.javac.code.Attribute.Compound;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    30
import com.sun.tools.javac.code.Attribute.TypeCompound;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    31
import com.sun.tools.javac.code.Scope.WriteableScope;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    32
import com.sun.tools.javac.code.Symbol.*;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    33
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    34
import com.sun.tools.javac.tree.JCTree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    35
import com.sun.tools.javac.tree.JCTree.*;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    36
import com.sun.tools.javac.tree.TreeInfo;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    37
import com.sun.tools.javac.tree.TreeMaker;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    38
import com.sun.tools.javac.tree.TreeScanner;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    39
import com.sun.tools.javac.util.*;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    40
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    41
import com.sun.tools.javac.util.List;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    42
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    43
import javax.tools.JavaFileObject;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    44
import java.util.*;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    45
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    46
import static com.sun.tools.javac.code.Flags.SYNTHETIC;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    47
import static com.sun.tools.javac.code.Kinds.Kind.MTH;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    48
import static com.sun.tools.javac.code.Kinds.Kind.VAR;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    49
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14054
diff changeset
    50
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
    51
import static com.sun.tools.javac.code.TypeTag.CLASS;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    52
import static com.sun.tools.javac.tree.JCTree.Tag.ANNOTATION;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    53
import static com.sun.tools.javac.tree.JCTree.Tag.ASSIGN;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    54
import static com.sun.tools.javac.tree.JCTree.Tag.IDENT;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    55
import static com.sun.tools.javac.tree.JCTree.Tag.NEWARRAY;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9603
diff changeset
    56
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    57
/** Enter annotations onto symbols and types (and trees).
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    58
 *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    59
 *  This is also a pseudo stage in the compiler taking care of scheduling when annotations are
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    60
 *  entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    62
 *  <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
    63
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
public class Annotate {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21713
diff changeset
    68
    protected static final Context.Key<Annotate> annotateKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    public static Annotate instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        Annotate instance = context.get(annotateKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            instance = new Annotate(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    77
    private final Attr attr;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    78
    private final Check chk;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    79
    private final ConstFold cfolder;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    80
    private final DeferredLintHandler deferredLintHandler;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    81
    private final Enter enter;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    82
    private final Lint lint;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    83
    private final Log log;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    84
    private final Names names;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    85
    private final Resolve resolve;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    86
    private final TreeMaker make;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    87
    private final Symtab syms;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    88
    private final TypeEnvs typeEnvs;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    89
    private final Types types;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
    90
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    91
    private final Attribute theUnfinishedDefaultValue;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    92
    private final boolean allowRepeatedAnnos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    protected Annotate(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        context.put(annotateKey, this);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    96
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        attr = Attr.instance(context);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    98
        chk = Check.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
    99
        cfolder = ConstFold.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   100
        deferredLintHandler = DeferredLintHandler.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   101
        enter = Enter.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        log = Log.instance(context);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   103
        lint = Lint.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   104
        make = TreeMaker.instance(context);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   105
        names = Names.instance(context);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   106
        resolve = Resolve.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   107
        syms = Symtab.instance(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   108
        typeEnvs = TypeEnvs.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        types = Types.instance(context);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   110
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   111
        theUnfinishedDefaultValue =  new Attribute.Error(syms.errType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   112
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   113
        Source source = Source.instance(context);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   114
        allowRepeatedAnnos = source.allowRepeatedAnnotations();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   117
    /** Semaphore to delay annotation processing */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   118
    private int blockCount = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   120
    /** Called when annotations processing needs to be postponed. */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   121
    public void blockAnnotations() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   122
        blockCount++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   125
    /** Called when annotation processing can be resumed. */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   126
    public void unblockAnnotations() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   127
        blockCount--;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   128
        if (blockCount == 0)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   129
            flush();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
21043
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   132
    /** Variant which allows for a delayed flush of annotations.
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   133
     * Needed by ClassReader */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   134
    public void unblockAnnotationsNoFlush() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   135
        blockCount--;
21043
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   136
    }
3b000be15694 8026286: Improper locking of annotation queues causes assertion failures.
emc
parents: 21041
diff changeset
   137
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   138
    /** are we blocking annotation processing? */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   139
    public boolean annotationsBlocked() {return blockCount > 0; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   140
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   141
    public List<TypeCompound> fromAnnotations(List<JCAnnotation> annotations) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   142
        if (annotations.isEmpty()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   143
            return List.nil();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   144
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   145
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   146
        ListBuffer<TypeCompound> buf = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   147
        for (JCAnnotation anno : annotations) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   148
            Assert.checkNonNull(anno.attribute);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   149
            buf.append((TypeCompound) anno.attribute);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   150
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   151
        return buf.toList();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   152
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   153
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   154
    /** Annotate (used for everything else) */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   155
    public void normal(Runnable r) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   156
        q.append(r);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   157
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   158
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   159
    /** Validate, triggers after 'normal' */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   160
    public void validate(Runnable a) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   161
        validateQ.append(a);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   162
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   163
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   164
    /** Flush all annotation queues */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public void flush() {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   166
        if (annotationsBlocked()) return;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   167
        if (isFlushing()) return;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   168
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   169
        startFlushing();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        try {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   171
            while (q.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   172
                q.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   173
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   174
            while (typesQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   175
                typesQ.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   176
            }
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   177
            while (afterTypesQ.nonEmpty()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   178
                afterTypesQ.next().run();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   179
            }
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   180
            while (validateQ.nonEmpty()) {
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 21018
diff changeset
   181
                validateQ.next().run();
21018
95d225149128 8014016: javac is too late detecting invalid annotation usage
jlahoda
parents: 21015
diff changeset
   182
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        } finally {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   184
            doneFlushing();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   185
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   186
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   187
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   188
    private ListBuffer<Runnable> q = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   189
    private ListBuffer<Runnable> validateQ = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   190
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   191
    private int flushCount = 0;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   192
    private boolean isFlushing() { return flushCount > 0; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   193
    private void startFlushing() { flushCount++; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   194
    private void doneFlushing() { flushCount--; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   195
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   196
    ListBuffer<Runnable> typesQ = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   197
    ListBuffer<Runnable> afterTypesQ = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   198
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   199
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   200
    public void typeAnnotation(Runnable a) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   201
        typesQ.append(a);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   202
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   203
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   204
    public void afterTypes(Runnable a) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   205
        afterTypesQ.append(a);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   206
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   207
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   208
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   209
     * Queue annotations for later attribution and entering. This is probably the method you are looking for.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   210
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   211
     * @param annotations the list of JCAnnotations to attribute and enter
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   212
     * @param localEnv    the enclosing env
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   213
     * @param s           ths Symbol on which to enter the annotations
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   214
     * @param deferPos    report errors here
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   215
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   216
    public void annotateLater(List<JCAnnotation> annotations, Env<AttrContext> localEnv,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   217
            Symbol s, DiagnosticPosition deferPos)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   218
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   219
        if (annotations.isEmpty()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   220
            return;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   221
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   222
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   223
        s.resetAnnotations(); // mark Annotations as incomplete for now
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   224
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   225
        normal(new Runnable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   226
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   227
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   228
                return "Annotate " + annotations + " onto " + s + " in " + s.owner;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   229
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   230
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   231
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   232
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   233
                Assert.check(s.annotationsPendingCompletion());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   234
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   235
                DiagnosticPosition prevLintPos =
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   236
                        deferPos != null
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   237
                                ? deferredLintHandler.setPos(deferPos)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   238
                                : deferredLintHandler.immediate();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   239
                Lint prevLint = deferPos != null ? null : chk.setLint(lint);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   240
                try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   241
                    if (s.hasAnnotations() && annotations.nonEmpty())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   242
                        log.error(annotations.head.pos, "already.annotated", Kinds.kindName(s), s);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   243
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   244
                    Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   245
                    annotateNow(s, annotations, localEnv, false);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   246
                } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   247
                    if (prevLint != null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   248
                        chk.setLint(prevLint);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   249
                    deferredLintHandler.setPos(prevLintPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   250
                    log.useSource(prev);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   251
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   252
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   253
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   254
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   255
        validate(new Runnable() { //validate annotations
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   256
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   257
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   258
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   259
                try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   260
                    chk.validateAnnotations(annotations, s);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   261
                } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   262
                    log.useSource(prev);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   263
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   264
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   265
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   266
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   267
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   268
                return "validate annotations: " + annotations + " on " + s;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   269
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   270
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   271
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   272
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   273
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   274
    /** Queue processing of an attribute default value. */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   275
    public void annotateDefaultValueLater(JCExpression defaultValue, Env<AttrContext> localEnv,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   276
            MethodSymbol m, DiagnosticPosition deferPos)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   277
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   278
        normal(new Runnable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   279
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   280
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   281
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   282
                DiagnosticPosition prevLintPos = deferredLintHandler.setPos(deferPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   283
                try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   284
                    enterDefaultValue(defaultValue, localEnv, m);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   285
                } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   286
                    deferredLintHandler.setPos(prevLintPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   287
                    log.useSource(prev);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   288
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   289
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   290
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   291
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   292
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   293
                return "Annotate " + m.owner + "." +
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   294
                        m + " default " + defaultValue;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   295
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   296
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   297
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   298
        validate(new Runnable() { //validate annotations
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   299
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   300
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   301
                JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   302
                try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   303
                    // if default value is an annotation, check it is a well-formed
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   304
                    // annotation value (e.g. no duplicate values, no missing values, etc.)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   305
                    chk.validateAnnotationTree(defaultValue);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   306
                } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   307
                    log.useSource(prev);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   308
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   309
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   310
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   311
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   312
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   313
                return "Validate default value " + m.owner + "." + m + " default " + defaultValue;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   314
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   315
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   316
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   317
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   318
    /** Enter a default value for an annotation element. */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   319
    private void enterDefaultValue(JCExpression defaultValue,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   320
            Env<AttrContext> localEnv, MethodSymbol m) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   321
        m.defaultValue = attributeAnnotationValue(m.type.getReturnType(), defaultValue, localEnv);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   322
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   323
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   324
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   325
     * Gather up annotations into a map from type symbols to lists of Compound attributes,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   326
     * then continue on with repeating annotations processing.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   327
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   328
    private <T extends Attribute.Compound> void annotateNow(Symbol toAnnotate,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   329
            List<JCAnnotation> withAnnotations, Env<AttrContext> env, boolean typeAnnotations)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   330
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   331
        Map<TypeSymbol, ListBuffer<T>> annotated = new LinkedHashMap<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   332
        Map<T, DiagnosticPosition> pos = new HashMap<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   333
        boolean allowRepeatedAnnos = this.allowRepeatedAnnos;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   334
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   335
        for (List<JCAnnotation> al = withAnnotations; !al.isEmpty(); al = al.tail) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   336
            JCAnnotation a = al.head;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   337
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   338
            T c;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   339
            if (typeAnnotations) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   340
                @SuppressWarnings("unchecked")
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   341
                T tmp = (T)attributeTypeAnnotation(a, syms.annotationType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   342
                c = tmp;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   343
            } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   344
                @SuppressWarnings("unchecked")
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   345
                T tmp = (T)attributeAnnotation(a, syms.annotationType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   346
                c = tmp;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   347
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   348
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   349
            Assert.checkNonNull(c, "Failed to create annotation");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   350
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   351
            if (annotated.containsKey(a.type.tsym)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   352
                if (!allowRepeatedAnnos) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   353
                    log.error(a.pos(), "repeatable.annotations.not.supported.in.source");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   354
                    allowRepeatedAnnos = true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   355
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   356
                ListBuffer<T> l = annotated.get(a.type.tsym);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   357
                l = l.append(c);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   358
                annotated.put(a.type.tsym, l);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   359
                pos.put(c, a.pos());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   360
            } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   361
                annotated.put(a.type.tsym, ListBuffer.of(c));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   362
                pos.put(c, a.pos());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   363
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   364
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   365
            // Note: @Deprecated has no effect on local variables and parameters
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   366
            if (!c.type.isErroneous()
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   367
                    && toAnnotate.owner.kind != MTH
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   368
                    && types.isSameType(c.type, syms.deprecatedType)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   369
                toAnnotate.flags_field |= Flags.DEPRECATED;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   370
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   371
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   372
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   373
        List<T> buf = List.nil();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   374
        for (ListBuffer<T> lb : annotated.values()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   375
            if (lb.size() == 1) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   376
                buf = buf.prepend(lb.first());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   377
            } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   378
                AnnotationContext<T> ctx = new AnnotationContext<>(env, annotated, pos, typeAnnotations);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   379
                T res = makeContainerAnnotation(lb.toList(), ctx, toAnnotate);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   380
                if (res != null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   381
                    buf = buf.prepend(res);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   382
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   383
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   384
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   385
        if (typeAnnotations) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   386
            @SuppressWarnings("unchecked")
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   387
            List<TypeCompound> attrs = (List<TypeCompound>)buf.reverse();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   388
            toAnnotate.appendUniqueTypeAttributes(attrs);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   389
        } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   390
            @SuppressWarnings("unchecked")
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   391
            List<Attribute.Compound> attrs =  (List<Attribute.Compound>)buf.reverse();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   392
            toAnnotate.resetAnnotations();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   393
            toAnnotate.setDeclarationAttributes(attrs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   397
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   398
     * Attribute and store a semantic representation of the annotation tree {@code tree} into the
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   399
     * tree.attribute field.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   400
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   401
     * @param tree the tree representing an annotation
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   402
     * @param expectedAnnotationType the expected (super)type of the annotation
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   403
     * @param env the current env in where the annotation instance is found
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   405
    public Attribute.Compound attributeAnnotation(JCAnnotation tree, Type expectedAnnotationType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   406
                                                  Env<AttrContext> env)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   407
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   408
        // The attribute might have been entered if it is Target or Repetable
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   409
        // Because TreeCopier does not copy type, redo this if type is null
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   410
        if (tree.attribute != null && tree.type != null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   411
            return tree.attribute;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   412
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   413
        List<Pair<MethodSymbol, Attribute>> elems = attributeAnnotationValues(tree, expectedAnnotationType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   414
        Attribute.Compound ac = new Attribute.Compound(tree.type, elems);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   415
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   416
        return tree.attribute = ac;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   417
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   418
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   419
    /** Attribute and store a semantic representation of the type annotation tree {@code tree} into
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   420
     * the tree.attribute field.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   421
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   422
     * @param a the tree representing an annotation
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   423
     * @param expectedAnnotationType the expected (super)type of the annotation
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   424
     * @param env the the current env in where the annotation instance is found
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   425
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   426
    public Attribute.TypeCompound attributeTypeAnnotation(JCAnnotation a, Type expectedAnnotationType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   427
                                                          Env<AttrContext> env)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   428
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   429
        // The attribute might have been entered if it is Target or Repetable
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   430
        // Because TreeCopier does not copy type, redo this if type is null
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   431
        if (a.attribute == null || a.type == null || !(a.attribute instanceof Attribute.TypeCompound)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   432
            // Create a new TypeCompound
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   433
            List<Pair<MethodSymbol,Attribute>> elems =
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   434
                    attributeAnnotationValues(a, expectedAnnotationType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   435
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   436
            Attribute.TypeCompound tc =
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   437
                    new Attribute.TypeCompound(a.type, elems, TypeAnnotationPosition.unknown);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   438
            a.attribute = tc;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   439
            return tc;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   440
        } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   441
            // Use an existing TypeCompound
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   442
            return (Attribute.TypeCompound)a.attribute;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   443
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   446
    /**
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   447
     *  Attribute annotation elements creating a list of pairs of the Symbol representing that
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   448
     *  element and the value of that element as an Attribute. */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   449
    private List<Pair<MethodSymbol, Attribute>> attributeAnnotationValues(JCAnnotation a,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   450
            Type expected, Env<AttrContext> env)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   451
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   452
        // The annotation might have had its type attributed (but not
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   453
        // checked) by attr.attribAnnotationTypes during MemberEnter,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   454
        // in which case we do not need to do it again.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   455
        Type at = (a.annotationType.type != null ?
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   456
                a.annotationType.type : attr.attribType(a.annotationType, env));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   457
        a.type = chk.checkType(a.annotationType.pos(), at, expected);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   458
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   459
        boolean isError = a.type.isErroneous();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   460
        if (!a.type.tsym.isAnnotationType() && !isError) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   461
            log.error(a.annotationType.pos(),
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   462
                    "not.annotation.type", a.type.toString());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   463
            isError = true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   464
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   465
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   466
        // List of name=value pairs (or implicit "value=" if size 1)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   467
        List<JCExpression> args = a.args;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   468
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   469
        boolean elidedValue = false;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   470
        // special case: elided "value=" assumed
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   471
        if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   472
            args.head = make.at(args.head.pos).
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   473
                    Assign(make.Ident(names.value), args.head);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   474
            elidedValue = true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   475
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   476
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   477
        ListBuffer<Pair<MethodSymbol,Attribute>> buf = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   478
        for (List<JCExpression> tl = args; tl.nonEmpty(); tl = tl.tail) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   479
            Pair<MethodSymbol, Attribute> p = attributeAnnotationNameValuePair(tl.head, a.type, isError, env, elidedValue);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   480
            if (p != null && !p.fst.type.isErroneous())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   481
                buf.append(p);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   482
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   483
        return buf.toList();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   484
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   485
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   486
    // where
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   487
    private Pair<MethodSymbol, Attribute> attributeAnnotationNameValuePair(JCExpression nameValuePair,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   488
            Type thisAnnotationType, boolean badAnnotation, Env<AttrContext> env, boolean elidedValue)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   489
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   490
        if (!nameValuePair.hasTag(ASSIGN)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   491
            log.error(nameValuePair.pos(), "annotation.value.must.be.name.value");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   492
            attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   493
            return null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   494
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   495
        JCAssign assign = (JCAssign)nameValuePair;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   496
        if (!assign.lhs.hasTag(IDENT)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   497
            log.error(nameValuePair.pos(), "annotation.value.must.be.name.value");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   498
            attributeAnnotationValue(nameValuePair.type = syms.errType, nameValuePair, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   499
            return null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   500
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   501
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   502
        // Resolve element to MethodSym
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   503
        JCIdent left = (JCIdent)assign.lhs;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   504
        Symbol method = resolve.resolveQualifiedMethod(elidedValue ? assign.rhs.pos() : left.pos(),
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   505
                env, thisAnnotationType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   506
                left.name, List.<Type>nil(), null);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   507
        left.sym = method;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   508
        left.type = method.type;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   509
        if (method.owner != thisAnnotationType.tsym && !badAnnotation)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   510
            log.error(left.pos(), "no.annotation.member", left.name, thisAnnotationType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   511
        Type resultType = method.type.getReturnType();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   512
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   513
        // Compute value part
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   514
        Attribute value = attributeAnnotationValue(resultType, assign.rhs, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   515
        nameValuePair.type = resultType;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   516
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   517
        return method.type.isErroneous() ? null : new Pair<>((MethodSymbol)method, value);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   518
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   519
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   520
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   521
    /** Attribute an annotation element value */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   522
    private Attribute attributeAnnotationValue(Type expectedElementType, JCExpression tree,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   523
            Env<AttrContext> env)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   524
    {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   525
        //first, try completing the symbol for the annotation value - if acompletion
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   526
        //error is thrown, we should recover gracefully, and display an
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   527
        //ordinary resolution diagnostic.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   528
        try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   529
            expectedElementType.tsym.complete();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   530
        } catch(CompletionFailure e) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   531
            log.error(tree.pos(), "cant.resolve", Kinds.kindName(e.sym), e.sym);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   532
            expectedElementType = syms.errType;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   533
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   534
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   535
        if (expectedElementType.hasTag(ARRAY)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   536
            return getAnnotationArrayValue(expectedElementType, tree, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   537
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   538
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   539
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   540
        //error recovery
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   541
        if (tree.hasTag(NEWARRAY)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   542
            if (!expectedElementType.isErroneous())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   543
                log.error(tree.pos(), "annotation.value.not.allowable.type");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   544
            JCNewArray na = (JCNewArray)tree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   545
            if (na.elemtype != null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   546
                log.error(na.elemtype.pos(), "new.not.allowed.in.annotation");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   547
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   548
            for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   549
                attributeAnnotationValue(syms.errType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   550
                        l.head,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   551
                        env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   552
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   553
            return new Attribute.Error(syms.errType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   554
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   555
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   556
        if (expectedElementType.tsym.isAnnotationType()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   557
            if (tree.hasTag(ANNOTATION)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   558
                return attributeAnnotation((JCAnnotation)tree, expectedElementType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   559
            } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   560
                log.error(tree.pos(), "annotation.value.must.be.annotation");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   561
                expectedElementType = syms.errType;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   562
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   563
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   564
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   565
        //error recovery
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   566
        if (tree.hasTag(ANNOTATION)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   567
            if (!expectedElementType.isErroneous())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   568
                log.error(tree.pos(), "annotation.not.valid.for.type", expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   569
            attributeAnnotation((JCAnnotation)tree, syms.errType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   570
            return new Attribute.Error(((JCAnnotation)tree).annotationType.type);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   571
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   572
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   573
        if (expectedElementType.isPrimitive() ||
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   574
                (types.isSameType(expectedElementType, syms.stringType) && !expectedElementType.hasTag(TypeTag.ERROR))) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   575
            return getAnnotationPrimitiveValue(expectedElementType, tree, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   576
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   577
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   578
        if (expectedElementType.tsym == syms.classType.tsym) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   579
            return getAnnotationClassValue(expectedElementType, tree, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   580
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   581
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   582
        if (expectedElementType.hasTag(CLASS) &&
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   583
                (expectedElementType.tsym.flags() & Flags.ENUM) != 0) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   584
            return getAnnotationEnumValue(expectedElementType, tree, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   585
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   586
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   587
        //error recovery:
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   588
        if (!expectedElementType.isErroneous())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   589
            log.error(tree.pos(), "annotation.value.not.allowable.type");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   590
        return new Attribute.Error(attr.attribExpr(tree, env, expectedElementType));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   591
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   592
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   593
    private Attribute getAnnotationEnumValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   594
        Type result = attr.attribExpr(tree, env, expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   595
        Symbol sym = TreeInfo.symbol(tree);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   596
        if (sym == null ||
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   597
                TreeInfo.nonstaticSelect(tree) ||
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   598
                sym.kind != VAR ||
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   599
                (sym.flags() & Flags.ENUM) == 0) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   600
            log.error(tree.pos(), "enum.annotation.must.be.enum.constant");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   601
            return new Attribute.Error(result.getOriginalType());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   602
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   603
        VarSymbol enumerator = (VarSymbol) sym;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   604
        return new Attribute.Enum(expectedElementType, enumerator);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   605
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   606
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   607
    private Attribute getAnnotationClassValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   608
        Type result = attr.attribExpr(tree, env, expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   609
        if (result.isErroneous()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   610
            // Does it look like an unresolved class literal?
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   611
            if (TreeInfo.name(tree) == names._class &&
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   612
                    ((JCFieldAccess) tree).selected.type.isErroneous()) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   613
                Name n = (((JCFieldAccess) tree).selected).type.tsym.flatName();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   614
                return new Attribute.UnresolvedClass(expectedElementType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   615
                        types.createErrorType(n,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   616
                                syms.unknownSymbol, syms.classType));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   617
            } else {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   618
                return new Attribute.Error(result.getOriginalType());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   619
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   620
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   621
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   622
        // Class literals look like field accesses of a field named class
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   623
        // at the tree level
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   624
        if (TreeInfo.name(tree) != names._class) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   625
            log.error(tree.pos(), "annotation.value.must.be.class.literal");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   626
            return new Attribute.Error(syms.errType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   627
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   628
        return new Attribute.Class(types,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   629
                (((JCFieldAccess) tree).selected).type);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   630
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   631
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   632
    private Attribute getAnnotationPrimitiveValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   633
        Type result = attr.attribExpr(tree, env, expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   634
        if (result.isErroneous())
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   635
            return new Attribute.Error(result.getOriginalType());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   636
        if (result.constValue() == null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   637
            log.error(tree.pos(), "attribute.value.must.be.constant");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   638
            return new Attribute.Error(expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   639
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   640
        result = cfolder.coerce(result, expectedElementType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   641
        return new Attribute.Constant(expectedElementType, result.constValue());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   642
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   643
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   644
    private Attribute getAnnotationArrayValue(Type expectedElementType, JCExpression tree, Env<AttrContext> env) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   645
        // Special case, implicit array
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   646
        if (!tree.hasTag(NEWARRAY)) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   647
            tree = make.at(tree.pos).
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   648
                    NewArray(null, List.<JCExpression>nil(), List.of(tree));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   649
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   650
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   651
        JCNewArray na = (JCNewArray)tree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   652
        if (na.elemtype != null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   653
            log.error(na.elemtype.pos(), "new.not.allowed.in.annotation");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   654
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   655
        ListBuffer<Attribute> buf = new ListBuffer<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   656
        for (List<JCExpression> l = na.elems; l.nonEmpty(); l=l.tail) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   657
            buf.append(attributeAnnotationValue(types.elemtype(expectedElementType),
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   658
                    l.head,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   659
                    env));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   660
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   661
        na.type = expectedElementType;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   662
        return new Attribute.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   663
                Array(expectedElementType, buf.toArray(new Attribute[buf.length()]));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   664
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   665
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   666
    /* *********************************
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   667
     * Support for repeating annotations
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   668
     ***********************************/
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   669
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   670
    /**
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   671
     * This context contains all the information needed to synthesize new
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   672
     * annotations trees for repeating annotations.
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   673
     */
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   674
    private class AnnotationContext<T extends Attribute.Compound> {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   675
        public final Env<AttrContext> env;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   676
        public final Map<Symbol.TypeSymbol, ListBuffer<T>> annotated;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   677
        public final Map<T, JCDiagnostic.DiagnosticPosition> pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   678
        public final boolean isTypeCompound;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   679
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   680
        public AnnotationContext(Env<AttrContext> env,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   681
                                 Map<Symbol.TypeSymbol, ListBuffer<T>> annotated,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   682
                                 Map<T, JCDiagnostic.DiagnosticPosition> pos,
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   683
                                 boolean isTypeCompound) {
13840
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   684
            Assert.checkNonNull(env);
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   685
            Assert.checkNonNull(annotated);
a365c561f4de 7196774: javac cannot be built with JDK 6 after 7151010
jjg
parents: 13689
diff changeset
   686
            Assert.checkNonNull(pos);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   687
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   688
            this.env = env;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   689
            this.annotated = annotated;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   690
            this.pos = pos;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   691
            this.isTypeCompound = isTypeCompound;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   692
        }
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   693
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   694
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   695
    /* Process repeated annotations. This method returns the
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   696
     * synthesized container annotation or null IFF all repeating
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   697
     * annotation are invalid.  This method reports errors/warnings.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   698
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   699
    private <T extends Attribute.Compound> T processRepeatedAnnotations(List<T> annotations,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   700
            AnnotationContext<T> ctx, Symbol on)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   701
    {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   702
        T firstOccurrence = annotations.head;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   703
        List<Attribute> repeated = List.nil();
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   704
        Type origAnnoType = null;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   705
        Type arrayOfOrigAnnoType = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   706
        Type targetContainerType = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   707
        MethodSymbol containerValueSymbol = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   708
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   709
        Assert.check(!annotations.isEmpty() && !annotations.tail.isEmpty()); // i.e. size() > 1
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   710
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   711
        int count = 0;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   712
        for (List<T> al = annotations; !al.isEmpty(); al = al.tail) {
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   713
            count++;
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   714
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   715
            // 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
   716
            Assert.check(count > 1 || !al.tail.isEmpty());
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   717
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   718
            T currentAnno = al.head;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   719
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   720
            origAnnoType = currentAnno.type;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   721
            if (arrayOfOrigAnnoType == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   722
                arrayOfOrigAnnoType = types.makeArrayType(origAnnoType);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   723
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   724
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   725
            // 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
   726
            boolean reportError = count > 1;
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   727
            Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno), reportError);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   728
            if (currentContainerType == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   729
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   730
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   731
            // Assert that the target Container is == for all repeated
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   732
            // annos of the same annotation type, the types should
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   733
            // come from the same Symbol, i.e. be '=='
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   734
            Assert.check(targetContainerType == null || currentContainerType == targetContainerType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   735
            targetContainerType = currentContainerType;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   736
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   737
            containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   738
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   739
            if (containerValueSymbol == null) { // Check of CA type failed
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   740
                // errors are already reported
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   741
                continue;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   742
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   743
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   744
            repeated = repeated.prepend(currentAnno);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   745
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   746
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   747
        if (!repeated.isEmpty() && targetContainerType == null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   748
            log.error(ctx.pos.get(annotations.head), "duplicate.annotation.invalid.repeated", origAnnoType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   749
            return null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   750
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   751
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   752
        if (!repeated.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   753
            repeated = repeated.reverse();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   754
            TreeMaker m = make.at(ctx.pos.get(firstOccurrence));
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   755
            Pair<MethodSymbol, Attribute> p =
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   756
                    new Pair<MethodSymbol, Attribute>(containerValueSymbol,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   757
                            new Attribute.Array(arrayOfOrigAnnoType, repeated));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   758
            if (ctx.isTypeCompound) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   759
                /* TODO: the following code would be cleaner:
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   760
                Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p),
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   761
                        ((Attribute.TypeCompound)annotations.head).position);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   762
                JCTypeAnnotation annoTree = m.TypeAnnotation(at);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   763
                at = attributeTypeAnnotation(annoTree, targetContainerType, ctx.env);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   764
                */
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   765
                // However, we directly construct the TypeCompound to keep the
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   766
                // direct relation to the contained TypeCompounds.
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   767
                Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p),
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   768
                        ((Attribute.TypeCompound)annotations.head).position);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   769
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   770
                // TODO: annotation applicability checks from below?
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   771
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   772
                at.setSynthesized(true);
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   773
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   774
                @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   775
                T x = (T) at;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   776
                return x;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   777
            } else {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   778
                Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   779
                JCAnnotation annoTree = m.Annotation(c);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   780
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   781
                if (!chk.annotationApplicable(annoTree, on))
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   782
                    log.error(annoTree.pos(), "invalid.repeatable.annotation.incompatible.target",
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   783
                            targetContainerType, origAnnoType);
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14359
diff changeset
   784
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   785
                if (!chk.validateAnnotationDeferErrors(annoTree))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   786
                    log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   787
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   788
                c = attributeAnnotation(annoTree, targetContainerType, ctx.env);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   789
                c.setSynthesized(true);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   790
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   791
                @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   792
                T x = (T) c;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   793
                return x;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   794
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   795
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   796
            return null; // errors should have been reported elsewhere
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   797
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   798
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   799
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   800
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   801
     * Fetches the actual Type that should be the containing annotation.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   802
     */
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   803
    private Type getContainingType(Attribute.Compound currentAnno,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   804
                                   DiagnosticPosition pos,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   805
                                   boolean reportError)
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   806
    {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   807
        Type origAnnoType = currentAnno.type;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   808
        TypeSymbol origAnnoDecl = origAnnoType.tsym;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   809
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   810
        // Fetch the Repeatable annotation from the current
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   811
        // annotation's declaration, or null if it has none
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   812
        Attribute.Compound ca = origAnnoDecl.getAnnotationTypeMetadata().getRepeatable();
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   813
        if (ca == null) { // has no Repeatable annotation
16342
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   814
            if (reportError)
28d6ae9ed67c 7196531: Duplicate error messages on repeating annotations
jfranck
parents: 15385
diff changeset
   815
                log.error(pos, "duplicate.annotation.missing.container", origAnnoType, syms.repeatableType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   816
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   817
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   818
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   819
        return filterSame(extractContainingType(ca, pos, origAnnoDecl),
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   820
                origAnnoType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   821
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   822
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   823
    // returns null if t is same as 's', returns 't' otherwise
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   824
    private Type filterSame(Type t, Type s) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   825
        if (t == null || s == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   826
            return t;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   827
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   828
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   829
        return types.isSameType(t, s) ? null : t;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   830
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   831
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   832
    /** Extract the actual Type to be used for a containing annotation. */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   833
    private Type extractContainingType(Attribute.Compound ca,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   834
                                       DiagnosticPosition pos,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   835
                                       TypeSymbol annoDecl)
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   836
    {
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   837
        // The next three checks check that the Repeatable annotation
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   838
        // on the declaration of the annotation type that is repeating is
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   839
        // valid.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   840
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   841
        // Repeatable must have at least one element
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   842
        if (ca.values.isEmpty()) {
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14961
diff changeset
   843
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   844
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   845
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   846
        Pair<MethodSymbol,Attribute> p = ca.values.head;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   847
        Name name = p.fst.name;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   848
        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
   849
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   850
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   851
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   852
        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
   853
            log.error(pos, "invalid.repeatable.annotation", annoDecl);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   854
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   855
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   856
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   857
        return ((Attribute.Class)p.snd).getValue();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   858
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   859
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   860
    /* Validate that the suggested targetContainerType Type is a valid
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   861
     * container type for repeated instances of originalAnnoType
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   862
     * annotations. Return null and report errors if this is not the
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   863
     * case, return the MethodSymbol of the value element in
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   864
     * targetContainerType if it is suitable (this is needed to
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   865
     * synthesize the container). */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   866
    private MethodSymbol validateContainer(Type targetContainerType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   867
                                           Type originalAnnoType,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   868
                                           DiagnosticPosition pos) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   869
        MethodSymbol containerValueSymbol = null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   870
        boolean fatalError = false;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   871
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   872
        // Validate that there is a (and only 1) value method
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   873
        Scope scope = targetContainerType.tsym.members();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   874
        int nr_value_elems = 0;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   875
        boolean error = false;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   876
        for(Symbol elm : scope.getSymbolsByName(names.value)) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   877
            nr_value_elems++;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   878
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   879
            if (nr_value_elems == 1 &&
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   880
                    elm.kind == MTH) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   881
                containerValueSymbol = (MethodSymbol)elm;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   882
            } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   883
                error = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   884
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   885
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   886
        if (error) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   887
            log.error(pos,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   888
                    "invalid.repeatable.annotation.multiple.values",
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   889
                    targetContainerType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   890
                    nr_value_elems);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   891
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   892
        } else if (nr_value_elems == 0) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   893
            log.error(pos,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   894
                    "invalid.repeatable.annotation.no.value",
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   895
                    targetContainerType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   896
            return null;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   897
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   898
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   899
        // validate that the 'value' element is a method
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   900
        // probably "impossible" to fail this
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 27121
diff changeset
   901
        if (containerValueSymbol.kind != MTH) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   902
            log.error(pos,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   903
                    "invalid.repeatable.annotation.invalid.value",
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   904
                    targetContainerType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   905
            fatalError = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   906
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   907
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   908
        // validate that the 'value' element has the correct return type
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   909
        // i.e. array of original anno
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   910
        Type valueRetType = containerValueSymbol.type.getReturnType();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   911
        Type expectedType = types.makeArrayType(originalAnnoType);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   912
        if (!(types.isArray(valueRetType) &&
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   913
                types.isSameType(expectedType, valueRetType))) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   914
            log.error(pos,
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   915
                    "invalid.repeatable.annotation.value.return",
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   916
                    targetContainerType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   917
                    valueRetType,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   918
                    expectedType);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   919
            fatalError = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   920
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   921
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   922
        return fatalError ? null : containerValueSymbol;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
   923
    }
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   924
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   925
    private <T extends Attribute.Compound> T makeContainerAnnotation(List<T> toBeReplaced,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   926
            AnnotationContext<T> ctx, Symbol sym)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   927
    {
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   928
        // Process repeated annotations
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   929
        T validRepeated =
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   930
                processRepeatedAnnotations(toBeReplaced, ctx, sym);
23814
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
        if (validRepeated != null) {
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   933
            // Check that the container isn't manually
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   934
            // present along with repeated instances of
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   935
            // its contained annotation.
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   936
            ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   937
            if (manualContainer != null) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   938
                log.error(ctx.pos.get(manualContainer.first()),
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   939
                        "invalid.repeatable.annotation.repeated.and.container.present",
23814
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   940
                        manualContainer.first().type.tsym);
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   941
            }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   942
        }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   943
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   944
        // A null return will delete the Placeholder
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   945
        return validRepeated;
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   946
    }
06ab27895804 8038263: Refactor annotation handling after actualEnterAnnotations
emc
parents: 23397
diff changeset
   947
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   948
    /********************
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   949
     * Type annotations *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   950
     ********************/
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   951
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   952
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   953
     * Attribute the list of annotations and enter them onto s.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   954
     */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   955
    public void enterTypeAnnotations(List<JCAnnotation> annotations, Env<AttrContext> env,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   956
            Symbol s, DiagnosticPosition deferPos)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   957
    {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
   958
        Assert.checkNonNull(s, "Symbol argument to actualEnterTypeAnnotations is nul/");
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   959
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   960
        DiagnosticPosition prevLintPos = null;
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   961
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   962
        if (deferPos != null) {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   963
            prevLintPos = deferredLintHandler.setPos(deferPos);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   964
        }
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   965
        try {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   966
            annotateNow(s, annotations, env, true);
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   967
        } finally {
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   968
            if (prevLintPos != null)
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   969
                deferredLintHandler.setPos(prevLintPos);
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
   970
            log.useSource(prev);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   971
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   972
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
   973
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   974
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   975
     * Enqueue tree for scanning of type annotations, attaching to the Symbol sym.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   976
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   977
    public void queueScanTreeAndTypeAnnotate(JCTree tree, Env<AttrContext> env, Symbol sym,
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   978
            DiagnosticPosition deferPos)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   979
    {
23134
010b1b0d25fb 8036142: Remove redundant call to annotateTypeLater with null Symbol
emc
parents: 23129
diff changeset
   980
        Assert.checkNonNull(sym);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   981
        normal(new Runnable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   982
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   983
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   984
                return "type annotate " + tree + " onto " + sym + " in " + sym.owner;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   985
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   986
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   987
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   988
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   989
                tree.accept(new TypeAnnotate(env, sym, deferPos));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   990
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   991
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   992
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   993
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   994
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   995
     * Apply the annotations to the particular type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   996
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   997
    public void annotateTypeSecondStage(JCTree tree, List<JCAnnotation> annotations, Type storeAt) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   998
        typeAnnotation(new Runnable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
   999
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1000
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1001
                return "Type annotate 2:nd stage " + annotations + " onto " + tree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1002
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1003
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1004
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1005
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1006
                List<Attribute.TypeCompound> compounds = fromAnnotations(annotations);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1007
                Assert.check(annotations.size() == compounds.size());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1008
                storeAt.getMetadataOfKind(Kind.ANNOTATIONS).combine(new TypeMetadata.Annotations(compounds));
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1009
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1010
        });
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1011
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1012
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1013
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1014
     * Apply the annotations to the particular type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1015
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1016
    public void annotateTypeParameterSecondStage(JCTree tree, List<JCAnnotation> annotations) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1017
        typeAnnotation(new Runnable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1018
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1019
            public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1020
                return "Type annotate 2:nd stage " + annotations + " onto " + tree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1021
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1022
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1023
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1024
            public void run() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1025
                List<Attribute.TypeCompound> compounds = fromAnnotations(annotations);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1026
                Assert.check(annotations.size() == compounds.size());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1027
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1028
        });
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1029
    }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1030
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1031
    /**
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1032
     * We need to use a TreeScanner, because it is not enough to visit the top-level
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1033
     * annotations. We also need to visit type arguments, etc.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1034
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1035
    private class TypeAnnotate extends TreeScanner {
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1036
        private final Env<AttrContext> env;
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1037
        private final Symbol sym;
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1038
        private DiagnosticPosition deferPos;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1039
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1040
        public TypeAnnotate(Env<AttrContext> env, Symbol sym, DiagnosticPosition deferPos) {
23129
6d3b2e246dac 8035766: Execute TypeAnnotate visitor at queue flush time
emc
parents: 23126
diff changeset
  1041
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1042
            this.env = env;
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1043
            this.sym = sym;
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1044
            this.deferPos = deferPos;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1045
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1046
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1047
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1048
        public void visitAnnotatedType(JCAnnotatedType tree) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1049
            enterTypeAnnotations(tree.annotations, env, sym, deferPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1050
            scan(tree.underlyingType);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1051
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1052
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1053
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1054
        public void visitTypeParameter(JCTypeParameter tree) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1055
            enterTypeAnnotations(tree.annotations, env, sym, deferPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1056
            scan(tree.bounds);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1057
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1058
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1059
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1060
        public void visitNewArray(JCNewArray tree) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1061
            enterTypeAnnotations(tree.annotations, env, sym, deferPos);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1062
            for (List<JCAnnotation> dimAnnos : tree.dimAnnotations)
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1063
                enterTypeAnnotations(dimAnnos, env, sym, deferPos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1064
            scan(tree.elemtype);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1065
            scan(tree.elems);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1066
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1067
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1068
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1069
        public void visitMethodDef(JCMethodDecl tree) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1070
            scan(tree.mods);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1071
            scan(tree.restype);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1072
            scan(tree.typarams);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1073
            scan(tree.recvparam);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1074
            scan(tree.params);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1075
            scan(tree.thrown);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1076
            scan(tree.defaultValue);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1077
            // Do not annotate the body, just the signature.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1078
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1079
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1080
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1081
        public void visitVarDef(JCVariableDecl tree) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1082
            DiagnosticPosition prevPos = deferPos;
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1083
            deferPos = tree.pos();
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1084
            try {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 27121
diff changeset
  1085
                if (sym != null && sym.kind == VAR) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1086
                    // Don't visit a parameter once when the sym is the method
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1087
                    // and once when the sym is the parameter.
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1088
                    scan(tree.mods);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1089
                    scan(tree.vartype);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1090
                }
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1091
                scan(tree.init);
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1092
            } finally {
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1093
                deferPos = prevPos;
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1094
            }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1095
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1096
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1097
        @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1098
        public void visitClassDef(JCClassDecl tree) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1099
            // We can only hit a classdef if it is declared within
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1100
            // a method. Ignore it - the class will be visited
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1101
            // separately later.
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1102
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1103
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1104
        @Override
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1105
        public void visitNewClass(JCNewClass tree) {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1106
            if (tree.def == null) {
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1107
                // For an anonymous class instantiation the class
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1108
                // will be visited separately.
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26266
diff changeset
  1109
                super.visitNewClass(tree);
23126
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1110
            }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1111
        }
1994a0d3b8de 8035758: Move annotation codepaths from MemberEnter.java to Annotate.java
emc
parents: 22702
diff changeset
  1112
    }
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1113
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1114
    /*********************
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1115
     * Completer support *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1116
     *********************/
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1117
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1118
    private AnnotationTypeCompleter theSourceCompleter = new AnnotationTypeCompleter() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1119
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1120
        public void complete(ClassSymbol sym) throws CompletionFailure {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1121
            Env<AttrContext> context = typeEnvs.get(sym);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1122
            Annotate.this.attributeAnnotationType(context);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1123
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1124
    };
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1125
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1126
    /* Last stage completer to enter just enough annotations to have a prototype annotation type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1127
     * This currently means entering @Target and @Repetable.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1128
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1129
    public AnnotationTypeCompleter annotationTypeSourceCompleter() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1130
        return theSourceCompleter;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1131
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1132
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1133
    private void attributeAnnotationType(Env<AttrContext> env) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1134
        Assert.check(((JCClassDecl)env.tree).sym.isAnnotationType(),
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1135
                "Trying to annotation type complete a non-annotation type");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1136
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1137
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1138
        try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1139
            JCClassDecl tree = (JCClassDecl)env.tree;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1140
            AnnotationTypeVisitor v = new AnnotationTypeVisitor(attr, chk, syms, typeEnvs);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1141
            v.scanAnnotationType(tree);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1142
            tree.sym.getAnnotationTypeMetadata().setRepeatable(v.repeatable);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1143
            tree.sym.getAnnotationTypeMetadata().setTarget(v.target);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1144
        } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1145
            log.useSource(prev);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1146
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1147
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1148
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1149
    public Attribute unfinishedDefaultValue() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1150
        return theUnfinishedDefaultValue;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1151
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1152
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1153
    public static interface AnnotationTypeCompleter {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1154
        void complete(ClassSymbol sym) throws CompletionFailure;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1155
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1156
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1157
    /** Visitor to determine a prototype annotation type for a class declaring an annotation type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1158
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1159
     *  <p><b>This is NOT part of any supported API.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1160
     *  If you write code that depends on this, you do so at your own risk.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1161
     *  This code and its internal interfaces are subject to change or
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1162
     *  deletion without notice.</b>
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1163
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1164
    public class AnnotationTypeVisitor extends TreeScanner {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1165
        private Env<AttrContext> env;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1166
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1167
        private final Attr attr;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1168
        private final Check check;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1169
        private final Symtab tab;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1170
        private final TypeEnvs typeEnvs;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1171
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1172
        private Compound target;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1173
        private Compound repeatable;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1174
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1175
        public AnnotationTypeVisitor(Attr attr, Check check, Symtab tab, TypeEnvs typeEnvs) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1176
            this.attr = attr;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1177
            this.check = check;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1178
            this.tab = tab;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1179
            this.typeEnvs = typeEnvs;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1180
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1181
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1182
        public Compound getRepeatable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1183
            return repeatable;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1184
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1185
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1186
        public Compound getTarget() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1187
            return target;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1188
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1189
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1190
        public void scanAnnotationType(JCClassDecl decl) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1191
            visitClassDef(decl);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1192
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1193
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1194
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1195
        public void visitClassDef(JCClassDecl tree) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1196
            Env<AttrContext> prevEnv = env;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1197
            env = typeEnvs.get(tree.sym);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1198
            try {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1199
                scan(tree.mods); // look for repeatable and target
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1200
                // don't descend into body
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1201
            } finally {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1202
                env = prevEnv;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1203
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1204
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1205
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1206
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1207
        public void visitAnnotation(JCAnnotation tree) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1208
            Type t = tree.annotationType.type;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1209
            if (t == null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1210
                t = attr.attribType(tree.annotationType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1211
                tree.annotationType.type = t = check.checkType(tree.annotationType.pos(), t, tab.annotationType);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1212
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1213
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1214
            if (t == tab.annotationTargetType) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1215
                target = Annotate.this.attributeAnnotation(tree, tab.annotationTargetType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1216
            } else if (t == tab.repeatableType) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1217
                repeatable = Annotate.this.attributeAnnotation(tree, tab.repeatableType, env);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1218
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1219
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1220
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1221
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1222
    /** Represents the semantics of an Annotation Type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1223
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1224
     *  <p><b>This is NOT part of any supported API.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1225
     *  If you write code that depends on this, you do so at your own risk.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1226
     *  This code and its internal interfaces are subject to change or
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1227
     *  deletion without notice.</b>
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1228
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1229
    public static class AnnotationTypeMetadata {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1230
        final ClassSymbol metaDataFor;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1231
        private Compound target;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1232
        private Compound repeatable;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1233
        private AnnotationTypeCompleter annotationTypeCompleter;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1234
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1235
        public AnnotationTypeMetadata(ClassSymbol metaDataFor, AnnotationTypeCompleter annotationTypeCompleter) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1236
            this.metaDataFor = metaDataFor;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1237
            this.annotationTypeCompleter = annotationTypeCompleter;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1238
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1239
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1240
        private void init() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1241
            // Make sure metaDataFor is member entered
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1242
            while (metaDataFor.completer != null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1243
                metaDataFor.complete();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1244
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1245
            if (annotationTypeCompleter != null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1246
                AnnotationTypeCompleter c = annotationTypeCompleter;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1247
                annotationTypeCompleter = null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1248
                c.complete(metaDataFor);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1249
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1250
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1251
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1252
        public void complete() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1253
            init();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1254
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1255
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1256
        public Compound getRepeatable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1257
            init();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1258
            return repeatable;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1259
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1260
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1261
        public void setRepeatable(Compound repeatable) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1262
            Assert.checkNull(this.repeatable);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1263
            this.repeatable = repeatable;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1264
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1265
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1266
        public Compound getTarget() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1267
            init();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1268
            return target;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1269
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1270
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1271
        public void setTarget(Compound target) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1272
            Assert.checkNull(this.target);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1273
                this.target = target;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1274
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1275
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1276
        public Set<MethodSymbol> getAnnotationElements() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1277
            init();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1278
            Set<MethodSymbol> members = new LinkedHashSet<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1279
            WriteableScope s = metaDataFor.members();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1280
            Iterable<Symbol> ss = s.getSymbols(NON_RECURSIVE);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1281
            for (Symbol sym : ss)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1282
                if (sym.kind == MTH &&
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1283
                        sym.name != sym.name.table.names.clinit &&
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1284
                        (sym.flags() & SYNTHETIC) == 0)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1285
                    members.add((MethodSymbol)sym);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1286
            return members;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1287
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1288
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1289
        public Set<MethodSymbol> getAnnotationElementsWithDefault() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1290
            init();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1291
            Set<MethodSymbol> members = getAnnotationElements();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1292
            Set<MethodSymbol> res = new LinkedHashSet<>();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1293
            for (MethodSymbol m : members)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1294
                if (m.defaultValue != null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1295
                    res.add(m);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1296
            return res;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1297
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1298
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1299
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1300
        public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1301
            return "Annotation type for: " + metaDataFor;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1302
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1303
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1304
        public boolean isMetadataForAnnotationType() { return true; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1305
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1306
        public static AnnotationTypeMetadata notAnAnnotationType() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1307
            return NOT_AN_ANNOTATION_TYPE;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1308
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1309
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1310
        private static final AnnotationTypeMetadata NOT_AN_ANNOTATION_TYPE =
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1311
                new AnnotationTypeMetadata(null, null) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1312
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1313
                    public void complete() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1314
                    } // do nothing
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1315
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1316
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1317
                    public String toString() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1318
                        return "Not an annotation type";
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1319
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1320
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1321
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1322
                    public Set<MethodSymbol> getAnnotationElements() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1323
                        return new LinkedHashSet<>(0);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1324
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1325
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1326
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1327
                    public Set<MethodSymbol> getAnnotationElementsWithDefault() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1328
                        return new LinkedHashSet<>(0);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1329
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1330
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1331
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1332
                    public boolean isMetadataForAnnotationType() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1333
                        return false;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1334
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1335
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1336
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1337
                    public Compound getTarget() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1338
                        return null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1339
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1340
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1341
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1342
                    public Compound getRepeatable() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1343
                        return null;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1344
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1345
                };
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 27224
diff changeset
  1346
    }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 10950
diff changeset
  1347
}