langtools/src/share/classes/com/sun/tools/javac/code/SymbolMetadata.java
author emc
Thu, 03 Apr 2014 20:28:23 -0400
changeset 23814 06ab27895804
parent 22702 1297fbaf34fa
permissions -rw-r--r--
8038263: Refactor annotation handling after actualEnterAnnotations Summary: Move all repeating annotations code into Annotate, rework annotations pipeline into a more completer-like design, eliminate a cast from enterAnnotations/enterTypeAnnotations Reviewed-by: jjg, jfranck
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
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    29
import com.sun.tools.javac.util.Assert;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    30
import com.sun.tools.javac.util.List;
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
/**
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    33
 * Container for all annotations (attributes in javac) on a Symbol.
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
 * This class is explicitly mutable. Its contents will change when attributes
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    36
 * 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
    37
 * List (in javac) is immutable.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    38
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    39
 * An instance of this class can be in one of three states:
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    40
 *
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    41
 * 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
    42
 * annotated (yet). Specifically if the declaration is not annotated this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    43
 * 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
    44
 * NOT_STARTED.
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    45
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    46
 * IN_PROGRESS annotations have been found on the declaration. Will be processed
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    47
 * 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
    48
 * of attributes (and this moves out of the IN_PROGRESS state).
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    49
 *
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    50
 * "unnamed" this SymbolMetadata contains some attributes, possibly the final set.
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    51
 * 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
    52
 * 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
    53
 *
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    54
 * <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
    55
 * 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
    56
 * are subject to change or deletion without notice.</b>
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    57
 */
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    58
public class SymbolMetadata {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    59
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    60
    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
    61
    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
    62
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
     * This field should never be null
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    65
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    66
    private List<Attribute.Compound> attributes = DECL_NOT_STARTED;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    67
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    68
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    69
     * Type attributes for this symbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    70
     * This field should never be null.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    71
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    72
    private List<Attribute.TypeCompound> type_attributes = List.<Attribute.TypeCompound>nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    73
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    74
    /*
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    75
     * Type attributes of initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    76
     * Unused if the current symbol is not a ClassSymbol.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    77
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    78
    private List<Attribute.TypeCompound> init_type_attributes = List.<Attribute.TypeCompound>nil();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    79
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    80
    /*
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    81
     * Type attributes of class initializers in this class.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    82
     * Unused if the current symbol is not a ClassSymbol.
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
    private List<Attribute.TypeCompound> clinit_type_attributes = List.<Attribute.TypeCompound>nil();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    85
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
    86
    /*
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    87
     * The Symbol this SymbolMetadata instance belongs to
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    88
     */
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
    89
    private final Symbol sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    90
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
    91
    public SymbolMetadata(Symbol sym) {
14804
f93a8d60b9a4 8001114: Container annotation is not checked for semantic correctness
jfranck
parents: 14258
diff changeset
    92
        this.sym = sym;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    93
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    94
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    95
    public List<Attribute.Compound> getDeclarationAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    96
        return filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    97
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
    98
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
    99
    public List<Attribute.TypeCompound> getTypeAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   100
        return type_attributes;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   101
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   102
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   103
    public List<Attribute.TypeCompound> getInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   104
        return init_type_attributes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   105
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   106
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   107
    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   108
        return clinit_type_attributes;
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
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   111
    public void setDeclarationAttributes(List<Attribute.Compound> a) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   112
        Assert.check(pendingCompletion() || !isStarted());
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   113
        if (a == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   114
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   115
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   116
        attributes = a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   117
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   118
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   119
    public void setTypeAttributes(List<Attribute.TypeCompound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   120
        if (a == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   121
            throw new NullPointerException();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   122
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   123
        type_attributes = a;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   124
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   125
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   126
    public void setInitTypeAttributes(List<Attribute.TypeCompound> a) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   127
        if (a == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   128
            throw new NullPointerException();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   129
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   130
        init_type_attributes = a;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   131
    }
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
    public void setClassInitTypeAttributes(List<Attribute.TypeCompound> a) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   134
        if (a == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   135
            throw new NullPointerException();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   136
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   137
        clinit_type_attributes = a;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   138
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   139
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   140
    public void setAttributes(SymbolMetadata other) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   141
        if (other == null) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   142
            throw new NullPointerException();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   143
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   144
        setDeclarationAttributes(other.getDeclarationAttributes());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   145
        setTypeAttributes(other.getTypeAttributes());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   146
        setInitTypeAttributes(other.getInitTypeAttributes());
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   147
        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   148
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   149
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   150
    public SymbolMetadata reset() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   151
        attributes = DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   152
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   153
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   154
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   155
    public boolean isEmpty() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   156
        return !isStarted()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   157
                || pendingCompletion()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   158
                || attributes.isEmpty();
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   159
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   160
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   161
    public boolean isTypesEmpty() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   162
        return type_attributes.isEmpty();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   163
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   164
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   165
    public boolean pendingCompletion() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   166
        return attributes == DECL_IN_PROGRESS;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   167
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   168
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   169
    public SymbolMetadata append(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   170
        attributes = filterDeclSentinels(attributes);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   171
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   172
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   173
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   174
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   175
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   176
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   177
            attributes = attributes.appendList(l);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   178
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   179
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   180
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   181
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   182
    public SymbolMetadata appendUniqueTypes(List<Attribute.TypeCompound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   183
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   184
            // no-op
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   185
        } else if (type_attributes.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   186
            type_attributes = l;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   187
        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   188
            // TODO: in case we expect a large number of annotations, this
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   189
            // might be inefficient.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   190
            for (Attribute.TypeCompound tc : l) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   191
                if (!type_attributes.contains(tc))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   192
                    type_attributes = type_attributes.append(tc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   193
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   194
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   195
        return this;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   196
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   197
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   198
    public SymbolMetadata appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   199
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   200
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   201
        } else if (init_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   202
            init_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   203
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   204
            init_type_attributes = init_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   205
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   206
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   207
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   208
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   209
    public SymbolMetadata appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   210
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   211
            // no-op
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   212
        } else if (clinit_type_attributes.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   213
            clinit_type_attributes = l;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   214
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   215
            clinit_type_attributes = clinit_type_attributes.appendList(l);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   216
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   217
        return this;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   218
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   219
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 17578
diff changeset
   220
    public SymbolMetadata prepend(List<Attribute.Compound> l) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   221
        attributes = filterDeclSentinels(attributes);
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
        if (l.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21041
diff changeset
   224
            // no-op
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   225
        } else if (attributes.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   226
            attributes = l;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   227
        } else {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   228
            attributes = attributes.prependList(l);
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   229
        }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   230
        return this;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   231
    }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   232
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   233
    private List<Attribute.Compound> filterDeclSentinels(List<Attribute.Compound> a) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   234
        return (a == DECL_IN_PROGRESS || a == DECL_NOT_STARTED)
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   235
                ? List.<Attribute.Compound>nil()
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   236
                : a;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents:
diff changeset
   237
    }
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
    private boolean isStarted() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15356
diff changeset
   240
        return attributes != DECL_NOT_STARTED;
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
}