langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 21041 99f5e5e97425
child 22702 1297fbaf34fa
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     1
/*
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14804
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     4
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    10
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    15
 * accompanied this code).
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    16
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    20
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    23
 * questions.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    24
 */
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    25
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    26
package com.sun.tools.javac.code;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    27
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    28
import java.util.Map;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13689
diff changeset
    29
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    30
import javax.tools.JavaFileObject;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    31
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    32
import com.sun.tools.javac.comp.Annotate;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    33
import com.sun.tools.javac.comp.AttrContext;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    34
import com.sun.tools.javac.comp.Env;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13689
diff changeset
    35
import com.sun.tools.javac.util.*;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    36
import com.sun.tools.javac.util.Assert;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    37
import com.sun.tools.javac.util.List;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    38
import com.sun.tools.javac.util.Log;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    39
import com.sun.tools.javac.util.Pair;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    40
import static com.sun.tools.javac.code.Kinds.PCK;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    41
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    42
/**
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    43
 * Container for all annotations (attributes in javac) on a Symbol.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    44
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    45
 * This class is explicitly mutable. Its contents will change when attributes
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    46
 * are annotated onto the Symbol. However this class depends on the facts that
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    47
 * List (in javac) is immutable.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    48
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    49
 * An instance of this class can be in one of three states:
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    50
 *
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    51
 * NOT_STARTED indicates that the Symbol this instance belongs to has not been
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    52
 * annotated (yet). Specifically if the declaration is not annotated this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    53
 * instance will never move past NOT_STARTED. You can never go back to
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    54
 * NOT_STARTED.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    55
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    56
 * IN_PROGRESS annotations have been found on the declaration. Will be processed
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    57
 * later. You can reset to IN_PROGRESS. While IN_PROGRESS you can set the list
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    58
 * of attributes (and this moves out of the IN_PROGRESS state).
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    59
 *
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    60
 * "unnamed" this SymbolMetadata contains some attributes, possibly the final set.
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    61
 * While in this state you can only prepend or append to the attributes not set
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    62
 * it directly. You can also move back to the IN_PROGRESS state using reset().
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    63
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    64
 * <p><b>This is NOT part of any supported API. If you write code that depends
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    65
 * on this, you do so at your own risk. This code and its internal interfaces
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    66
 * are subject to change or deletion without notice.</b>
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    67
 */
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    68
public class SymbolMetadata {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    69
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    70
    private static final List<Attribute.Compound> DECL_NOT_STARTED = List.of(null);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    71
    private static final List<Attribute.Compound> DECL_IN_PROGRESS = List.of(null);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    72
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    73
    /*
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    74
     * This field should never be null
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    75
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    76
    private List<Attribute.Compound> attributes = DECL_NOT_STARTED;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    77
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    78
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    79
     * Type attributes for this symbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    80
     * This field should never be null.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    81
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    82
    private List<Attribute.TypeCompound> type_attributes = List.<Attribute.TypeCompound>nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    83
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    84
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    85
     * Type attributes of initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    86
     * Unused if the current symbol is not a ClassSymbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    87
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    88
    private List<Attribute.TypeCompound> init_type_attributes = List.<Attribute.TypeCompound>nil();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    89
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    90
    /*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    91
     * Type attributes of class initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    92
     * Unused if the current symbol is not a ClassSymbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    93
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    94
    private List<Attribute.TypeCompound> clinit_type_attributes = List.<Attribute.TypeCompound>nil();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    95
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    96
    /*
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    97
     * The Symbol this SymbolMetadata instance belongs to
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    98
     */
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
    99
    private final Symbol sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   100
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   101
    public SymbolMetadata(Symbol sym) {
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
   102
        this.sym = sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   103
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   104
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   105
    public List<Attribute.Compound> getDeclarationAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   106
        return filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   107
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   108
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   109
    public List<Attribute.TypeCompound> getTypeAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   110
        return type_attributes;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   111
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   112
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   113
    public List<Attribute.TypeCompound> getInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   114
        return init_type_attributes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   115
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   116
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   117
    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   118
        return clinit_type_attributes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   119
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   120
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   121
    public void setDeclarationAttributes(List<Attribute.Compound> a) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   122
        Assert.check(pendingCompletion() || !isStarted());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   123
        if (a == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   124
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   125
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   126
        attributes = a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   127
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   128
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   129
    public void setTypeAttributes(List<Attribute.TypeCompound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   130
        if (a == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   131
            throw new NullPointerException();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   132
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   133
        type_attributes = a;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   134
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   135
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   136
    public void setInitTypeAttributes(List<Attribute.TypeCompound> a) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   137
        if (a == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   138
            throw new NullPointerException();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   139
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   140
        init_type_attributes = a;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   141
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   142
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   143
    public void setClassInitTypeAttributes(List<Attribute.TypeCompound> a) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   144
        if (a == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   145
            throw new NullPointerException();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   146
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   147
        clinit_type_attributes = a;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   148
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   149
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   150
    public void setAttributes(SymbolMetadata other) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   151
        if (other == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   152
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   153
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   154
        setDeclarationAttributes(other.getDeclarationAttributes());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   155
        setTypeAttributes(other.getTypeAttributes());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   156
        setInitTypeAttributes(other.getInitTypeAttributes());
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   157
        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   158
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   159
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   160
    public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   161
        Assert.check(pendingCompletion() || (!isStarted() && sym.kind == PCK));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   162
        this.setDeclarationAttributes(getAttributesForCompletion(ctx));
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   163
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   164
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   165
    public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   166
        this.appendUniqueTypes(getAttributesForCompletion(ctx));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   167
    }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   168
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   169
    private <T extends Attribute.Compound> List<T> getAttributesForCompletion(
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   170
            final Annotate.AnnotateRepeatedContext<T> ctx) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   171
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   172
        Map<Symbol.TypeSymbol, ListBuffer<T>> annotated = ctx.annotated;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   173
        boolean atLeastOneRepeated = false;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   174
        List<T> buf = List.<T>nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   175
        for (ListBuffer<T> lb : annotated.values()) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   176
            if (lb.size() == 1) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   177
                buf = buf.prepend(lb.first());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   178
            } else { // repeated
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   179
                // This will break when other subtypes of Attributs.Compound
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   180
                // are introduced, because PlaceHolder is a subtype of TypeCompound.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   181
                T res;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   182
                @SuppressWarnings("unchecked")
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   183
                T ph = (T) new Placeholder<>(ctx, lb.toList(), sym);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   184
                res = ph;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   185
                buf = buf.prepend(res);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   186
                atLeastOneRepeated = true;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   187
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   188
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   189
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   190
        if (atLeastOneRepeated) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   191
            // The Symbol s is now annotated with a combination of
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   192
            // finished non-repeating annotations and placeholders for
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   193
            // repeating annotations.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   194
            //
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   195
            // We need to do this in two passes because when creating
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   196
            // a container for a repeating annotation we must
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14804
diff changeset
   197
            // guarantee that the @Repeatable on the
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   198
            // contained annotation is fully annotated
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   199
            //
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   200
            // The way we force this order is to do all repeating
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   201
            // annotations in a pass after all non-repeating are
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14804
diff changeset
   202
            // finished. This will work because @Repeatable
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   203
            // is non-repeating and therefore will be annotated in the
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   204
            // fist pass.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   205
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   206
            // Queue a pass that will replace Attribute.Placeholders
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   207
            // with Attribute.Compound (made from synthesized containers).
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 19928
diff changeset
   208
            ctx.annotateRepeated(new Annotate.Worker() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   209
                @Override
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   210
                public String toString() {
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
   211
                    return "repeated annotation pass of: " + sym + " in: " + sym.owner;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   212
                }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   213
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   214
                @Override
21040
3e32f68d2151 8026510: The name of com.sun.tools.javac.comp.Annotate.Annotator is confusing
jlahoda
parents: 19928
diff changeset
   215
                public void run() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   216
                    complete(ctx);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   217
                }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   218
            });
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   219
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   220
        // Add non-repeating attributes
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   221
        return buf.reverse();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   222
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   223
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   224
    public SymbolMetadata reset() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   225
        attributes = DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   226
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   227
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   228
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   229
    public boolean isEmpty() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   230
        return !isStarted()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   231
                || pendingCompletion()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   232
                || attributes.isEmpty();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   233
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   234
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   235
    public boolean isTypesEmpty() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   236
        return type_attributes.isEmpty();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   237
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   238
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   239
    public boolean pendingCompletion() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   240
        return attributes == DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   241
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   242
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   243
    public SymbolMetadata append(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   244
        attributes = filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   245
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   246
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   247
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   248
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   249
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   250
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   251
            attributes = attributes.appendList(l);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   252
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   253
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   254
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   255
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   256
    public SymbolMetadata appendUniqueTypes(List<Attribute.TypeCompound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   257
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   258
            // no-op
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   259
        } else if (type_attributes.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   260
            type_attributes = l;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   261
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   262
            // TODO: in case we expect a large number of annotations, this
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   263
            // might be inefficient.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   264
            for (Attribute.TypeCompound tc : l) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   265
                if (!type_attributes.contains(tc))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   266
                    type_attributes = type_attributes.append(tc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   267
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   268
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   269
        return this;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   270
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   271
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   272
    public SymbolMetadata appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   273
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   274
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   275
        } else if (init_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   276
            init_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   277
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   278
            init_type_attributes = init_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   279
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   280
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   281
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   282
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   283
    public SymbolMetadata appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   284
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   285
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   286
        } else if (clinit_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   287
            clinit_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   288
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   289
            clinit_type_attributes = clinit_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   290
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   291
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   292
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   293
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   294
    public SymbolMetadata prepend(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   295
        attributes = filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   296
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   297
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   298
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   299
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   300
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   301
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   302
            attributes = attributes.prependList(l);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   303
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   304
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   305
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   306
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   307
    private List<Attribute.Compound> filterDeclSentinels(List<Attribute.Compound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   308
        return (a == DECL_IN_PROGRESS || a == DECL_NOT_STARTED)
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   309
                ? List.<Attribute.Compound>nil()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   310
                : a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   311
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   312
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   313
    private boolean isStarted() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   314
        return attributes != DECL_NOT_STARTED;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   315
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   316
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   317
    private List<Attribute.Compound> getPlaceholders() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   318
        List<Attribute.Compound> res = List.<Attribute.Compound>nil();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   319
        for (Attribute.Compound a : filterDeclSentinels(attributes)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   320
            if (a instanceof Placeholder) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   321
                res = res.prepend(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   322
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   323
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   324
        return res.reverse();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   325
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   326
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   327
    private List<Attribute.TypeCompound> getTypePlaceholders() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   328
        List<Attribute.TypeCompound> res = List.<Attribute.TypeCompound>nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   329
        for (Attribute.TypeCompound a : type_attributes) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   330
            if (a instanceof Placeholder) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   331
                res = res.prepend(a);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   332
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   333
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   334
        return res.reverse();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   335
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   336
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   337
    /*
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   338
     * Replace Placeholders for repeating annotations with their containers
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   339
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   340
    private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   341
        Log log = ctx.log;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   342
        Env<AttrContext> env = ctx.env;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   343
        JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   344
        try {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   345
            // TODO: can we reduce duplication in the following branches?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   346
            if (ctx.isTypeCompound) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   347
                Assert.check(!isTypesEmpty());
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   348
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   349
                if (isTypesEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   350
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   351
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   352
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   353
                List<Attribute.TypeCompound> result = List.nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   354
                for (Attribute.TypeCompound a : getTypeAttributes()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   355
                    if (a instanceof Placeholder) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   356
                        @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   357
                        Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   358
                        Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   359
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   360
                        if (null != replacement) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   361
                            result = result.prepend(replacement);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   362
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   363
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   364
                        result = result.prepend(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   365
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   366
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   367
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   368
                type_attributes = result.reverse();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   369
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   370
                Assert.check(SymbolMetadata.this.getTypePlaceholders().isEmpty());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   371
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   372
                Assert.check(!pendingCompletion());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   373
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   374
                if (isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   375
                    return;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   376
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   377
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   378
                List<Attribute.Compound> result = List.nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   379
                for (Attribute.Compound a : getDeclarationAttributes()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   380
                    if (a instanceof Placeholder) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   381
                        @SuppressWarnings("unchecked")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   382
                        Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   383
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   384
                        if (null != replacement) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   385
                            result = result.prepend(replacement);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   386
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   387
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   388
                        result = result.prepend(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   389
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   390
                }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   391
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   392
                attributes = result.reverse();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   393
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   394
                Assert.check(SymbolMetadata.this.getPlaceholders().isEmpty());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   395
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   396
        } finally {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   397
            log.useSource(oldSource);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   398
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   399
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   400
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   401
    private <T extends Attribute.Compound> T replaceOne(Placeholder<T> placeholder, Annotate.AnnotateRepeatedContext<T> ctx) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   402
        Log log = ctx.log;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   403
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   404
        // Process repeated annotations
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   405
        T validRepeated = ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor(), sym);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   406
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   407
        if (validRepeated != null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   408
            // Check that the container isn't manually
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   409
            // present along with repeated instances of
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   410
            // its contained annotation.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   411
            ListBuffer<T> manualContainer = ctx.annotated.get(validRepeated.type.tsym);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   412
            if (manualContainer != null) {
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14804
diff changeset
   413
                log.error(ctx.pos.get(manualContainer.first()), "invalid.repeatable.annotation.repeated.and.container.present",
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   414
                        manualContainer.first().type.tsym);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   415
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   416
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   417
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   418
        // A null return will delete the Placeholder
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   419
        return validRepeated;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   420
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   421
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   422
    private static class Placeholder<T extends Attribute.Compound> extends Attribute.TypeCompound {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   423
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   424
        private final Annotate.AnnotateRepeatedContext<T> ctx;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   425
        private final List<T> placeholderFor;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   426
        private final Symbol on;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   427
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   428
        public Placeholder(Annotate.AnnotateRepeatedContext<T> ctx, List<T> placeholderFor, Symbol on) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   429
            super(on.type, List.<Pair<Symbol.MethodSymbol, Attribute>>nil(),
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   430
                    ctx.isTypeCompound ?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   431
                            ((Attribute.TypeCompound)placeholderFor.head).position :
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21040
diff changeset
   432
                                new TypeAnnotationPosition());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   433
            this.ctx = ctx;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   434
            this.placeholderFor = placeholderFor;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   435
            this.on = on;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   436
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   437
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   438
        @Override
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   439
        public String toString() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   440
            return "<placeholder: " + placeholderFor + " on: " + on + ">";
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   441
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   442
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   443
        public List<T> getPlaceholderFor() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   444
            return placeholderFor;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   445
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   446
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   447
        public Annotate.AnnotateRepeatedContext<T> getRepeatedContext() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   448
            return ctx;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   449
        }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   450
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   451
}