src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeMetadata.java
author ronsh
Fri, 29 Mar 2019 07:38:34 -0700
changeset 54339 f69a2f675f19
parent 47216 71c04702a3d5
permissions -rw-r--r--
8221118: Avoid eagerly creating JCDiagnostic for CompletionFailures Reviewed-by: jjg, mcimadamore, forax
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     1
/*
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 29842
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 29842
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     4
 *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    10
 *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    15
 * accompanied this code).
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    16
 *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    20
 *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    23
 * questions.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    24
 */
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    25
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    26
package com.sun.tools.javac.code;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    27
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    28
import com.sun.tools.javac.util.Assert;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    29
import com.sun.tools.javac.util.List;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    30
import java.util.EnumMap;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    31
import java.util.HashSet;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    32
import java.util.Set;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    33
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    34
/**
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    35
 * TypeMetadata is essentially an immutable {@code EnumMap<Entry.Kind, <? extends Entry>>}
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    36
 *
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    37
 * A metadata class represented by a subtype of Entry can express a property on a Type instance.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    38
 * Thers should be at most one instance of an Entry per Entry.Kind on any given Type instance.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    39
 *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    40
 * Metadata classes of a specific kind are responsible for how they combine themselvs.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    41
 *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    42
 * @implNote {@code Entry:combine} need not be commutative.
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    43
 */
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    44
public class TypeMetadata {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    45
    public static final TypeMetadata EMPTY = new TypeMetadata();
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    46
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    47
    private final EnumMap<Entry.Kind, Entry> contents;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    48
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    49
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    50
     * Create a new empty TypeMetadata map.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    51
     */
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    52
    private TypeMetadata() {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    53
        contents = new EnumMap<>(Entry.Kind.class);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    54
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    55
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    56
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    57
     * Create a new TypeMetadata map containing the Entry {@code elem}.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    58
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    59
     * @param elem the sole contents of this map
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    60
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    61
    public TypeMetadata(Entry elem) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    62
        this();
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    63
        Assert.checkNonNull(elem);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    64
        contents.put(elem.kind(), elem);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    65
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    66
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    67
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    68
     * Creates a copy of TypeMetadata {@code other} with a shallow copy the other's metadata contents.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    69
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    70
     * @param other the TypeMetadata to copy contents from.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    71
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    72
    public TypeMetadata(TypeMetadata other) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    73
        Assert.checkNonNull(other);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    74
        contents = other.contents.clone();
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    75
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    76
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    77
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    78
     * Return a copy of this TypeMetadata with the metadata entry for {@code elem.kind()} combined
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    79
     * with {@code elem}.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    80
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    81
     * @param elem the new value
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    82
     * @return a new TypeMetadata updated with {@code Entry elem}
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    83
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    84
    public TypeMetadata combine(Entry elem) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    85
        Assert.checkNonNull(elem);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    86
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    87
        TypeMetadata out = new TypeMetadata(this);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    88
        Entry.Kind key = elem.kind();
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    89
        if (contents.containsKey(key)) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    90
            out.add(key, this.contents.get(key).combine(elem));
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    91
        } else {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    92
            out.add(key, elem);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    93
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    94
        return out;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    95
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
    96
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    97
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    98
     * Return a copy of this TypeMetadata with the metadata entry for all kinds from {@code other}
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
    99
     * combined with the same kind from this.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   100
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   101
     * @param other the TypeMetadata to combine with this
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   102
     * @return a new TypeMetadata updated with all entries from {@code other}
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   103
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   104
    public TypeMetadata combineAll(TypeMetadata other) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   105
        Assert.checkNonNull(other);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   106
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   107
        TypeMetadata out = new TypeMetadata();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   108
        Set<Entry.Kind> keys = new HashSet<>(contents.keySet());
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   109
        keys.addAll(other.contents.keySet());
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   110
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   111
        for(Entry.Kind key : keys) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   112
            if (contents.containsKey(key)) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   113
                if (other.contents.containsKey(key)) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   114
                    out.add(key, contents.get(key).combine(other.contents.get(key)));
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   115
                } else {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   116
                    out.add(key, contents.get(key));
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   117
                }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   118
            } else if (other.contents.containsKey(key)) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   119
                out.add(key, other.contents.get(key));
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   120
            }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   121
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   122
        return out;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   123
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   124
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   125
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   126
     * Return a TypeMetadata with the metadata entry for {@code kind} removed.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   127
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   128
     * This may be the same instance or a new TypeMetadata.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   129
     *
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   130
     * @param kind the {@code Kind} to remove metadata for
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   131
     * @return a new TypeMetadata without {@code Kind kind}
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   132
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   133
    public TypeMetadata without(Entry.Kind kind) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   134
        if (this == EMPTY || contents.get(kind) == null)
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   135
            return this;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   136
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   137
        TypeMetadata out = new TypeMetadata(this);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   138
        out.contents.remove(kind);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   139
        return out.contents.isEmpty() ? EMPTY : out;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   140
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   141
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   142
    public Entry get(Entry.Kind kind) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   143
        return contents.get(kind);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   144
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   145
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   146
    private void add(Entry.Kind kind, Entry elem) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   147
        contents.put(kind, elem);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   148
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   149
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   150
    public interface Entry {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   151
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   152
        public enum Kind {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   153
            ANNOTATIONS
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   154
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   155
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   156
        /**
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   157
         * Get the kind of metadata this object represents
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   158
         */
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   159
        public Kind kind();
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   160
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   161
        /**
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   162
         * Combine this type metadata with another metadata of the
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   163
         * same kind.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   164
         *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   165
         * @param other The metadata with which to combine this one.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   166
         * @return The combined metadata.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   167
         */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   168
        public Entry combine(Entry other);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   169
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   170
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   171
    /**
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   172
     * A type metadata object holding type annotations.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   173
     */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   174
    public static class Annotations implements Entry {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   175
        private List<Attribute.TypeCompound> annos;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   176
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   177
        public static final List<Attribute.TypeCompound> TO_BE_SET = List.nil();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   178
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   179
        public Annotations(List<Attribute.TypeCompound> annos) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   180
            this.annos = annos;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   181
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   182
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   183
        /**
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   184
         * Get the type annotations contained in this metadata.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   185
         *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   186
         * @return The annotations.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   187
         */
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   188
        public List<Attribute.TypeCompound> getAnnotations() {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   189
            return annos;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   190
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   191
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   192
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   193
        public Annotations combine(Entry other) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   194
            Assert.check(annos == TO_BE_SET);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   195
            annos = ((Annotations)other).annos;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   196
            return this;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   197
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   198
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   199
        @Override
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   200
        public Kind kind() { return Kind.ANNOTATIONS; }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   201
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   202
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 26781
diff changeset
   203
        public String toString() { return "ANNOTATIONS [ " + annos + " ]"; }
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   204
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
diff changeset
   205
}