langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/SymbolMetadata.java
author mcimadamore
Fri, 16 Dec 2016 15:27:47 +0000
changeset 42828 cce89649f958
parent 39600 83ea7c12c164
permissions -rw-r--r--
8171371: Remove redundant type-arguments from generic method calls Reviewed-by: jjg, rfield, mchung
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
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13689
diff changeset
    28
39600
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
    29
import com.sun.tools.javac.code.Attribute.TypeCompound;
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
    30
import com.sun.tools.javac.code.Kinds.Kind;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    31
import com.sun.tools.javac.util.Assert;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    32
import com.sun.tools.javac.util.List;
39600
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
    33
import com.sun.tools.javac.util.ListBuffer;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    34
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    35
/**
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    36
 * Container for all annotations (attributes in javac) on a Symbol.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    37
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    38
 * This class is explicitly mutable. Its contents will change when attributes
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    39
 * 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
    40
 * List (in javac) is immutable.
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
 * An instance of this class can be in one of three states:
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    43
 *
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    44
 * 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
    45
 * annotated (yet). Specifically if the declaration is not annotated this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    46
 * 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
    47
 * NOT_STARTED.
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
 * IN_PROGRESS annotations have been found on the declaration. Will be processed
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    50
 * 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
    51
 * of attributes (and this moves out of the IN_PROGRESS state).
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    52
 *
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    53
 * "unnamed" this SymbolMetadata contains some attributes, possibly the final set.
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    54
 * 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
    55
 * 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
    56
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    57
 * <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
    58
 * 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
    59
 * are subject to change or deletion without notice.</b>
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    60
 */
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    61
public class SymbolMetadata {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    62
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    63
    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
    64
    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
    65
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    66
    /*
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    67
     * This field should never be null
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    68
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    69
    private List<Attribute.Compound> attributes = DECL_NOT_STARTED;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    70
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    71
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    72
     * Type attributes for this symbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    73
     * This field should never be null.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    74
     */
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 39600
diff changeset
    75
    private List<Attribute.TypeCompound> type_attributes = List.nil();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    76
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    77
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    78
     * Type attributes of initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    79
     * Unused if the current symbol is not a ClassSymbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    80
     */
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 39600
diff changeset
    81
    private List<Attribute.TypeCompound> init_type_attributes = List.nil();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    82
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    83
    /*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    84
     * Type attributes of class initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    85
     * Unused if the current symbol is not a ClassSymbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    86
     */
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 39600
diff changeset
    87
    private List<Attribute.TypeCompound> clinit_type_attributes = List.nil();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    88
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    89
    /*
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    90
     * The Symbol this SymbolMetadata instance belongs to
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    91
     */
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
    92
    private final Symbol sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    93
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    94
    public SymbolMetadata(Symbol sym) {
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
    95
        this.sym = sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    96
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    97
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    98
    public List<Attribute.Compound> getDeclarationAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    99
        return filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   100
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   101
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   102
    public List<Attribute.TypeCompound> getTypeAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   103
        return type_attributes;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   104
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   105
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   106
    public List<Attribute.TypeCompound> getInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   107
        return init_type_attributes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   108
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   109
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   110
    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   111
        return clinit_type_attributes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   112
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   113
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   114
    public void setDeclarationAttributes(List<Attribute.Compound> a) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   115
        Assert.check(pendingCompletion() || !isStarted());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   116
        if (a == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   117
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   118
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   119
        attributes = a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   120
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   121
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   122
    public void setTypeAttributes(List<Attribute.TypeCompound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   123
        if (a == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   124
            throw new NullPointerException();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   125
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   126
        type_attributes = a;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   127
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   128
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   129
    public void setInitTypeAttributes(List<Attribute.TypeCompound> a) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   130
        if (a == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   131
            throw new NullPointerException();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   132
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   133
        init_type_attributes = a;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   134
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   135
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   136
    public void setClassInitTypeAttributes(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
        clinit_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
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   143
    public void setAttributes(SymbolMetadata other) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   144
        if (other == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   145
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   146
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   147
        setDeclarationAttributes(other.getDeclarationAttributes());
39600
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   148
        if ((sym.flags() & Flags.BRIDGE) != 0) {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   149
            Assert.check(other.sym.kind == Kind.MTH);
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   150
            ListBuffer<TypeCompound> typeAttributes = new ListBuffer<>();
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   151
            for (TypeCompound tc : other.getTypeAttributes()) {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   152
                // Carry over only contractual type annotations: i.e nothing interior to method body.
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   153
                if (!tc.position.type.isLocal())
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   154
                    typeAttributes.append(tc);
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   155
            }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   156
            setTypeAttributes(typeAttributes.toList());
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   157
        } else {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   158
            setTypeAttributes(other.getTypeAttributes());
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   159
        }
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   160
        if (sym.kind == Kind.TYP) {
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   161
            setInitTypeAttributes(other.getInitTypeAttributes());
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   162
            setClassInitTypeAttributes(other.getClassInitTypeAttributes());
83ea7c12c164 8160928: javac incorrectly copies over interior type annotations to bridge method
sadayapalam
parents: 25874
diff changeset
   163
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   164
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   165
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   166
    public SymbolMetadata reset() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   167
        attributes = DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   168
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   169
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   170
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   171
    public boolean isEmpty() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   172
        return !isStarted()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   173
                || pendingCompletion()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   174
                || attributes.isEmpty();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   175
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   176
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   177
    public boolean isTypesEmpty() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   178
        return type_attributes.isEmpty();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   179
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   180
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   181
    public boolean pendingCompletion() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   182
        return attributes == DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   183
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   184
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   185
    public SymbolMetadata append(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   186
        attributes = filterDeclSentinels(attributes);
13689
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
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   189
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   190
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   191
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   192
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   193
            attributes = attributes.appendList(l);
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
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   196
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   197
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   198
    public SymbolMetadata appendUniqueTypes(List<Attribute.TypeCompound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   199
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   200
            // no-op
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   201
        } else if (type_attributes.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   202
            type_attributes = l;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   203
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   204
            // TODO: in case we expect a large number of annotations, this
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   205
            // might be inefficient.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   206
            for (Attribute.TypeCompound tc : l) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   207
                if (!type_attributes.contains(tc))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   208
                    type_attributes = type_attributes.append(tc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   209
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   210
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   211
        return this;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   212
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   213
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   214
    public SymbolMetadata appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   215
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   216
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   217
        } else if (init_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   218
            init_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   219
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   220
            init_type_attributes = init_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   221
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   222
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   223
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   224
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   225
    public SymbolMetadata appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   226
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   227
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   228
        } else if (clinit_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   229
            clinit_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   230
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   231
            clinit_type_attributes = clinit_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   232
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   233
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   234
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   235
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   236
    public SymbolMetadata prepend(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   237
        attributes = filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   238
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   239
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   240
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   241
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   242
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   243
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   244
            attributes = attributes.prependList(l);
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
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   247
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   248
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   249
    private List<Attribute.Compound> filterDeclSentinels(List<Attribute.Compound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   250
        return (a == DECL_IN_PROGRESS || a == DECL_NOT_STARTED)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 39600
diff changeset
   251
                ? List.nil()
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   252
                : a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   253
    }
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
    private boolean isStarted() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   256
        return attributes != DECL_NOT_STARTED;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   257
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   258
}