langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
author emc
Tue, 21 Oct 2014 09:01:51 -0400
changeset 27224 228abfa87080
parent 26781 a786b07c7b91
child 28459 48a68a485760
permissions -rw-r--r--
8054457: Refactor Symbol kinds from small ints to an enum Summary: Replace bitmap logic in symbol.kind and pkind with an enum-based API Reviewed-by: mcimadamore, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
    28
import java.lang.annotation.Annotation;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
    29
import java.lang.annotation.Inherited;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.concurrent.Callable;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    32
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
    36
import com.sun.tools.javac.code.Scope.WriteableScope;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.comp.Attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.jvm.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
    42
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    43
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    44
import com.sun.tools.javac.util.DefinedBy.Api;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    45
import com.sun.tools.javac.util.Name;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import static com.sun.tools.javac.code.Kinds.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    48
import static com.sun.tools.javac.code.Kinds.Kind.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
    49
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    50
import static com.sun.tools.javac.code.TypeTag.CLASS;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    51
import static com.sun.tools.javac.code.TypeTag.FORALL;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    52
import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
/** Root class for Java symbols. It contains subclasses
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  for specific sorts of symbols, such as variables, methods and operators,
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  types, packages. Each subclass is represented as a static inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  inside Symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    59
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    60
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 */
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
    64
public abstract class Symbol extends AnnoConstruct implements Element {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /** The kind of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *  @see Kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     */
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    69
    public Kind kind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /** The flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public long flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /** An accessor method for the flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     *  Flags of class symbols should be accessed through the accessor
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     *  method to make sure that the class symbol is loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public long flags() { return flags_field; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /** The name of this symbol in Utf8 representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public Name name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** The type of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /** The owner of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    public Symbol owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    /** The completer of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    public Completer completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    /** A cache for the type erasure of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    public Type erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   101
    // <editor-fold defaultstate="collapsed" desc="annotations">
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   102
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   103
    /** The attributes of this symbol are contained in this
19928
adce50c2b76c 8022260: Rename javac.code.Annotations to javac.code.SymbolMetadata
jfranck
parents: 19666
diff changeset
   104
     * SymbolMetadata. The SymbolMetadata instance is NOT immutable.
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   105
     */
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   106
    protected SymbolMetadata metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   107
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   108
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   109
    /** An accessor method for the attributes of this symbol.
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   110
     *  Attributes of class symbols should be accessed through the accessor
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   111
     *  method to make sure that the class symbol is loaded.
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   112
     */
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   113
    public List<Attribute.Compound> getRawAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   114
        return (metadata == null)
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   115
                ? List.<Attribute.Compound>nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   116
                : metadata.getDeclarationAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   117
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   118
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   119
    /** An accessor method for the type attributes of this symbol.
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   120
     *  Attributes of class symbols should be accessed through the accessor
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   121
     *  method to make sure that the class symbol is loaded.
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   122
     */
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   123
    public List<Attribute.TypeCompound> getRawTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   124
        return (metadata == null)
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   125
                ? List.<Attribute.TypeCompound>nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   126
                : metadata.getTypeAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   127
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   128
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   129
    /** Fetch a particular annotation from a symbol. */
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   130
    public Attribute.Compound attribute(Symbol anno) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   131
        for (Attribute.Compound a : getRawAttributes()) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   132
            if (a.type.tsym == anno) return a;
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   133
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   134
        return null;
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   135
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   136
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   137
    public boolean annotationsPendingCompletion() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   138
        return metadata == null ? false : metadata.pendingCompletion();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   139
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   140
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   141
    public void appendAttributes(List<Attribute.Compound> l) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   142
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   143
            initedMetadata().append(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   144
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   145
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   146
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   147
    public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   148
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   149
            initedMetadata().appendClassInitTypeAttributes(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   150
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   151
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   152
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   153
    public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   154
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   155
            initedMetadata().appendInitTypeAttributes(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   156
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   157
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   158
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   159
    public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   160
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   161
            initedMetadata().appendUniqueTypes(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   162
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   163
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   164
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   165
    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   166
        return (metadata == null)
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   167
                ? List.<Attribute.TypeCompound>nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   168
                : metadata.getClassInitTypeAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   169
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   170
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   171
    public List<Attribute.TypeCompound> getInitTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   172
        return (metadata == null)
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   173
                ? List.<Attribute.TypeCompound>nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   174
                : metadata.getInitTypeAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   175
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   176
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   177
    public List<Attribute.Compound> getDeclarationAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   178
        return (metadata == null)
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   179
                ? List.<Attribute.Compound>nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   180
                : metadata.getDeclarationAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   181
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   182
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   183
    public boolean hasAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   184
        return (metadata != null && !metadata.isEmpty());
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   185
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   186
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   187
    public boolean hasTypeAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   188
        return (metadata != null && !metadata.isTypesEmpty());
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   189
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   190
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   191
    public void prependAttributes(List<Attribute.Compound> l) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   192
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   193
            initedMetadata().prepend(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   194
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   195
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   196
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   197
    public void resetAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   198
        initedMetadata().reset();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   199
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   200
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   201
    public void setAttributes(Symbol other) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   202
        if (metadata != null || other.metadata != null) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   203
            initedMetadata().setAttributes(other.metadata);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   204
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   205
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   206
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   207
    public void setDeclarationAttributes(List<Attribute.Compound> a) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   208
        if (metadata != null || a.nonEmpty()) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   209
            initedMetadata().setDeclarationAttributes(a);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   210
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   211
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   212
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   213
    public void setTypeAttributes(List<Attribute.TypeCompound> a) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   214
        if (metadata != null || a.nonEmpty()) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   215
            if (metadata == null)
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   216
                metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   217
            metadata.setTypeAttributes(a);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   218
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   219
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   220
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   221
    private SymbolMetadata initedMetadata() {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   222
        if (metadata == null)
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   223
            metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   224
        return metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   225
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   226
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   227
    /** This method is intended for debugging only. */
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   228
    public SymbolMetadata getMetadata() {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   229
        return metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   230
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   231
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   232
    // </editor-fold>
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   233
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /** Construct a symbol with given kind, flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   236
    public Symbol(Kind kind, long flags, Name name, Type type, Symbol owner) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        this.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        this.owner = owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        this.completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        this.erasure_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     *  Legal only for fields and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public Symbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   253
    public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   254
        return v.visitSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   255
    }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   256
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     *  A description of this symbol; overrides Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    /** A Java source description of the location of this symbol; used for
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   265
     *  error reporting.
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   266
     *
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   267
     * @return null if the symbol is a package or a toplevel class defined in
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   268
     * the default package; otherwise, the owner symbol is returned
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   270
    public Symbol location() {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
   271
        if (owner.name == null || (owner.name.isEmpty() &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   272
                                   (owner.flags() & BLOCK) == 0 &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   273
                                   owner.kind != PCK &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   274
                                   owner.kind != TYP)) {
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   275
            return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   277
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   280
    public Symbol location(Type site, Types types) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   281
        if (owner.name == null || owner.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            return location();
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   284
        if (owner.type.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            Type ownertype = types.asOuterSuper(site, owner);
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   286
            if (ownertype != null) return ownertype.tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   288
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   291
    public Symbol baseSymbol() {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   292
        return this;
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   293
    }
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   294
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    /** The symbol's erased type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            erasure_field = types.erasure(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    /** The external type of a symbol. This is the symbol's erased type
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     *  except for constructors of inner classes which get the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     *  instance class added as first argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    public Type externalType(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        Type t = erasure(types);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   309
        if (name == name.table.names.init && owner.hasOuterInstance()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            Type outerThisType = types.erasure(owner.type.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            return new MethodType(t.getParameterTypes().prepend(outerThisType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                                  t.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                                  t.getThrownTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                                  t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   320
    public boolean isDeprecated() {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   321
        return (flags_field & DEPRECATED) != 0;
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   322
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   323
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    public boolean isStatic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            (flags() & STATIC) != 0 ||
20598
aa7b86f98471 8024497: crash returning this-referencing lambda from default method
vromero
parents: 20249
diff changeset
   327
            (owner.flags() & INTERFACE) != 0 && kind != MTH &&
aa7b86f98471 8024497: crash returning this-referencing lambda from default method
vromero
parents: 20249
diff changeset
   328
             name != name.table.names._this;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        return (flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   335
    public boolean isPrivate() {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   336
        return (flags_field & Flags.AccessFlags) == PRIVATE;
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   337
    }
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   338
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   339
    public boolean isEnum() {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   340
        return (flags() & ENUM) != 0;
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   341
    }
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   342
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    /** Is this symbol declared (directly or indirectly) local
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     *  to a method or variable initializer?
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     *  Also includes fields of inner classes which are in
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *  turn local to a method or variable initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    public boolean isLocal() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        return
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   350
            (owner.kind.matches(KindSelector.VAL_MTH) ||
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   351
             (owner.kind == TYP && owner.isLocal()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   354
    /** Has this symbol an empty name? This includes anonymous
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
   355
     *  inner classes.
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   356
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   357
    public boolean isAnonymous() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   358
        return name.isEmpty();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   359
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   360
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    /** Is this symbol a constructor?
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    public boolean isConstructor() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   364
        return name == name.table.names.init;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    /** The fully qualified name of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     *  This is the same as the symbol's name except for class symbols,
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     *  which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    /** The fully qualified name of this symbol after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     *  representation. This is the same as the symbol's name except for
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     *  class symbols, which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
        return getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    /** If this is a class or package, its members, otherwise null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   385
    public WriteableScope members() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    /** A class is an inner class if it it has an enclosing instance class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    public boolean isInner() {
24219
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 23814
diff changeset
   392
        return kind == TYP && type.getEnclosingType().hasTag(CLASS);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    /** An inner class has an outer instance if it is not an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     *  it has an enclosing instance class which might be referenced from the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     *  Nested classes can see instance members of their enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     *  Their constructors carry an additional this$n parameter, inserted
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     *  implicitly by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     *  @see #isInner
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    public boolean hasOuterInstance() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        return
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   405
            type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    /** The closest enclosing class of this symbol's declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    public ClassSymbol enclClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        Symbol c = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        while (c != null &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   413
               (!c.kind.matches(KindSelector.TYP) || !c.type.hasTag(CLASS))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            c = c.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        return (ClassSymbol)c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
    /** The outermost class which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
    public ClassSymbol outermostClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        Symbol prev = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            prev = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        return (ClassSymbol) prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    /** The package which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    public PackageSymbol packge() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        return (PackageSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        throw new AssertionError("isSubClass " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    /** Fully check membership: hierarchy, protection, and hiding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
     *  Does not exclude methods not inherited due to overriding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    public boolean isMemberOf(TypeSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            owner == clazz ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            clazz.isSubClass(owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            isInheritedIn(clazz, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
            !hiddenIn((ClassSymbol)clazz, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    /** Is this symbol the same as or enclosed by the given class? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
    public boolean isEnclosedBy(ClassSymbol clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
            if (sym == clazz) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    private boolean hiddenIn(ClassSymbol clazz, Types types) {
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   466
        Symbol sym = hiddenInInternal(clazz, types);
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   467
        Assert.check(sym != null, "the result of hiddenInInternal() can't be null");
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   468
        /* If we find the current symbol then there is no symbol hiding it
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   469
         */
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   470
        return sym != this;
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   471
    }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   472
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   473
    /** This method looks in the supertypes graph that has the current class as the
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   474
     * initial node, till it finds the current symbol or another symbol that hides it.
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   475
     * If the current class has more than one supertype (extends one class and
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   476
     * implements one or more interfaces) then null can be returned, meaning that
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   477
     * a wrong path in the supertypes graph was selected. Null can only be returned
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   478
     * as a temporary value, as a result of the recursive call.
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   479
     */
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   480
    private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   481
        if (currentClass == owner) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   482
            return this;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   483
        }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   484
        for (Symbol sym : currentClass.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   485
            if (sym.kind == kind &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
                    (kind != MTH ||
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   487
                    (sym.flags() & STATIC) != 0 &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   488
                    types.isSubSignature(sym.type, type))) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   489
                return sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        }
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   492
        Symbol hiddenSym = null;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   493
        for (Type st : types.interfaces(currentClass.type)
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   494
                .prepend(types.supertype(currentClass.type))) {
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   495
            if (st != null && (st.hasTag(CLASS))) {
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   496
                Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types);
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   497
                if (sym == this) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   498
                    return this;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   499
                } else if (sym != null) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   500
                    hiddenSym = sym;
19492
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   501
                }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   502
            }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   503
        }
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   504
        return hiddenSym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    /** Is this symbol inherited into a given class?
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
     *  PRE: If symbol's owner is a interface,
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
     *       it is already assumed that the interface is a superinterface
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
     *       of given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
     *  @param clazz  The class for which we want to establish membership.
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
     *                This must be a subclass of the member's owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    public boolean isInheritedIn(Symbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        default: // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            return this.owner == clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            // we model interfaces as extending Object
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            PackageSymbol thisPackage = this.packge();
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            for (Symbol sup = clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                 sup != null && sup != this.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
                 sup = types.supertype(sup.type).tsym) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   529
                while (sup.type.hasTag(TYPEVAR))
1528
441d4ec466de 6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents: 1357
diff changeset
   530
                    sup = sup.type.getUpperBound().tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
                if (sup.type.isErroneous())
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                    return true; // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                if ((sup.flags() & COMPOUND) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                if (sup.packge() != thisPackage)
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    /** The (variable or method) symbol seen as a member of given
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
     *  class type`site' (this might change the symbol's type).
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
     *  This is used exclusively for producing diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
    public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
    /** Does this method symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
     *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
     *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
     *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
     *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
    public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        if (completer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            Completer c = completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
            completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            c.complete(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    /** True if the symbol represents an entity that exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
    public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   579
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
    public Type asType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   584
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
    public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   589
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
    public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        return ElementKind.OTHER;       // most unkind
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   594
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
    public Set<Modifier> getModifiers() {
16970
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
   596
        return Flags.asModifierSet(flags());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   599
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
    public Name getSimpleName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
    /**
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   605
     * This is the implementation for {@code
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   606
     * javax.lang.model.element.Element.getAnnotationMirrors()}.
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   607
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   608
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   609
    public List<Attribute.Compound> getAnnotationMirrors() {
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   610
        return getRawAttributes();
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   611
    }
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   612
15355
a4757c33cae9 7193719: Support repeating annotations in javax.lang.model
jfranck
parents: 15031
diff changeset
   613
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
    // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   615
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
    public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   620
    public List<TypeVariableSymbol> getTypeParameters() {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19942
diff changeset
   621
        ListBuffer<TypeVariableSymbol> l = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
        for (Type t : type.getTypeArguments()) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   623
            Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   624
            l.append((TypeVariableSymbol)t.tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        return l.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
15564
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   629
    public static class DelegatedSymbol<T extends Symbol> extends Symbol {
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   630
        protected T other;
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   631
        public DelegatedSymbol(T other) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            super(other.kind, other.flags_field, other.name, other.type, other.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            this.other = other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
        public String toString() { return other.toString(); }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   636
        public Symbol location() { return other.location(); }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   637
        public Symbol location(Type site, Types types) { return other.location(site, types); }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
   638
        public Symbol baseSymbol() { return other; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        public Type erasure(Types types) { return other.erasure(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
        public Type externalType(Types types) { return other.externalType(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        public boolean isLocal() { return other.isLocal(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        public boolean isConstructor() { return other.isConstructor(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        public Name getQualifiedName() { return other.getQualifiedName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
        public Name flatName() { return other.flatName(); }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   645
        public WriteableScope members() { return other.members(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
        public boolean isInner() { return other.isInner(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        public boolean hasOuterInstance() { return other.hasOuterInstance(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
        public ClassSymbol enclClass() { return other.enclClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        public ClassSymbol outermostClass() { return other.outermostClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
        public PackageSymbol packge() { return other.packge(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
        public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
        public void complete() throws CompletionFailure { other.complete(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   658
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
            return other.accept(v, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   662
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   663
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   664
            return v.visitSymbol(other, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   665
        }
15564
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   666
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   667
        public T getUnderlyingSymbol() {
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   668
            return other;
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   669
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   672
    /** A base class for Symbols representing types.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
     */
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   674
    public static abstract class TypeSymbol extends Symbol {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   675
        public TypeSymbol(Kind kind, long flags, Name name, Type type, Symbol owner) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   676
            super(kind, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        /** form a fully qualified name from a name and an owner
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        static public Name formFullName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            if (owner == null) return name;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   682
            if ((owner.kind != ERR) &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   683
                (owner.kind.matches(KindSelector.VAL_MTH) ||
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   684
                 (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
                 )) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
            Name prefix = owner.getQualifiedName();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   687
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
            else return prefix.append('.', name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        /** form a fully qualified name from a name and an owner, after
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
         *  converting to flat representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        static public Name formFlatName(Name name, Symbol owner) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   696
            if (owner == null || owner.kind.matches(KindSelector.VAL_MTH) ||
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   697
                (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
                ) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            char sep = owner.kind == TYP ? '$' : '.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            Name prefix = owner.flatName();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   701
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
            else return prefix.append(sep, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
        /**
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 24219
diff changeset
   707
         * A partial ordering between type symbols that refines the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
         * class inheritance graph.
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
         *
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 24219
diff changeset
   710
         * Type variables always precede other kinds of symbols.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        public final boolean precedes(TypeSymbol that, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            if (this == that)
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
                return false;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   715
            if (type.hasTag(that.type.getTag())) {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   716
                if (type.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                    return
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                        types.rank(that.type) < types.rank(this.type) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                        types.rank(that.type) == types.rank(this.type) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                        that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   721
                } else if (type.hasTag(TYPEVAR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
                    return types.isSubtype(this.type, that.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
            }
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   725
            return type.hasTag(TYPEVAR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   728
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
        public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            List<Symbol> list = List.nil();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   731
            if (kind == TYP && type.hasTag(TYPEVAR)) {
6584
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   732
                return list;
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   733
            }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   734
            for (Symbol sym : members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   735
                if (sym != null && (sym.flags() & SYNTHETIC) == 0 && sym.owner == this)
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   736
                    list = list.prepend(sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
            return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   741
        @Override
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   742
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   743
            return v.visitTypeSymbol(this, p);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   744
        }
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   745
    }
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   746
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   747
    /**
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   748
     * Type variables are represented by instances of this class.
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   749
     */
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   750
    public static class TypeVariableSymbol
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   751
            extends TypeSymbol implements TypeParameterElement {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   752
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   753
        public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   754
            super(TYP, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   757
        @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   758
        public ElementKind getKind() {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   759
            return ElementKind.TYPE_PARAMETER;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   762
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   763
        public Symbol getGenericElement() {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   764
            return owner;
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   765
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   766
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   767
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
        public List<Type> getBounds() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            TypeVar t = (TypeVar)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            Type bound = t.getUpperBound();
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
            if (!bound.isCompound())
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
                return List.of(bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
            ClassType ct = (ClassType)bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
            if (!ct.tsym.erasure_field.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
                return ct.interfaces_field.prepend(ct.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                // No superclass was given in bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                // In this case, supertype is Object, erasure is first interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                return ct.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        }
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   782
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   783
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   784
        public List<Attribute.Compound> getAnnotationMirrors() {
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   785
            // Declaration annotations on type variables are stored in type attributes
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   786
            // on the owner of the TypeVariableSymbol
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   787
            List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   788
            int index = owner.getTypeParameters().indexOf(this);
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   789
            List<Attribute.Compound> res = List.nil();
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   790
            for (Attribute.TypeCompound a : candidates) {
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   791
                if (isCurrentSymbolsAnnotation(a, index))
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   792
                    res = res.prepend(a);
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   793
            }
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   794
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   795
            return res.reverse();
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   796
        }
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   797
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   798
        // Helper to getAnnotation[s]
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   799
        @Override
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   800
        public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   801
            String name = annoType.getName();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   802
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   803
            // Declaration annotations on type variables are stored in type attributes
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   804
            // on the owner of the TypeVariableSymbol
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   805
            List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   806
            int index = owner.getTypeParameters().indexOf(this);
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   807
            for (Attribute.TypeCompound anno : candidates)
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   808
                if (isCurrentSymbolsAnnotation(anno, index) &&
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   809
                    name.contentEquals(anno.type.tsym.flatName()))
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   810
                    return anno;
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   811
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   812
            return null;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   813
        }
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   814
            //where:
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   815
            boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) {
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   816
                return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER ||
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   817
                        anno.position.type == TargetType.METHOD_TYPE_PARAMETER) &&
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   818
                       anno.position.parameter_index == index;
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   819
            }
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   820
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   821
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   822
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   823
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   824
            return v.visitTypeParameter(this, p);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   825
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
    /** A class for package symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
    public static class PackageSymbol extends TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
        implements PackageElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   833
        public WriteableScope members_field;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
        public ClassSymbol package_info; // see bug 6443073
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
        public PackageSymbol(Name name, Type type, Symbol owner) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   838
            super(PCK, 0, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
        public PackageSymbol(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            this(name, null, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            this.type = new PackageType(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
            return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   852
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   857
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
        public boolean isUnnamed() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
            return name.isEmpty() && owner != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   862
        public WriteableScope members() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   872
        @Override
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   873
        public List<Attribute.Compound> getRawAttributes() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
            if (completer != null) complete();
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   875
            if (package_info != null && package_info.completer != null) {
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   876
                package_info.complete();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   877
                mergeAttributes();
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   878
            }
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   879
            return super.getRawAttributes();
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   880
        }
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   881
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   882
        private void mergeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   883
            if (metadata == null &&
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   884
                package_info.metadata != null) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   885
                metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   886
                metadata.setAttributes(package_info.metadata);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   887
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
        /** A package "exists" if a type or package that exists has
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
         *  been seen within it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
        public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
            return (flags_field & EXISTS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   897
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
            return ElementKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   902
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
        public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   907
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
            return v.visitPackage(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   911
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   912
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   913
            return v.visitPackageSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   914
        }
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   915
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   916
        /**Resets the Symbol into the state good for next round of annotation processing.*/
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   917
        public void reset() {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   918
            metadata = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   919
        }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
   920
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
    /** A class for class symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
    public static class ClassSymbol extends TypeSymbol implements TypeElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
        /** a scope for all class members; variables, methods and inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
         *  type parameters are not part of this scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
         */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   930
        public WriteableScope members_field;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
        /** the fully qualified name of the class, i.e. pck.outer.inner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
         *  null for anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
        /** the fully qualified name of the class after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
         *  representation, i.e. pck.outer$inner,
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
         *  set externally for local and anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
        public Name flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
        /** the sourcefile where the class came from
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
        public JavaFileObject sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
        /** the classfile from where to load this class
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
         *  this will have extension .class or .java
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        public JavaFileObject classfile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   952
        /** the list of translated local classes (used for generating
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   953
         * InnerClasses attribute)
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   954
         */
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   955
        public List<ClassSymbol> trans_local;
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   956
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
        /** the constant pool of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
        public Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
        public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   962
            super(TYP, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
            this.flatname = formFlatName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
            this.sourcefile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
            this.classfile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
            this.pool = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
        public ClassSymbol(long flags, Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
            this(
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
                flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
                name,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   975
                new ClassType(Type.noType, null, null),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
                owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
            this.type.tsym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
            return className();
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   991
        public WriteableScope members() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   996
        @Override
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   997
        public List<Attribute.Compound> getRawAttributes() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
            if (completer != null) complete();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   999
            return super.getRawAttributes();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1002
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1003
        public List<Attribute.TypeCompound> getRawTypeAttributes() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1004
            if (completer != null) complete();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1005
            return super.getRawTypeAttributes();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1006
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1007
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
        public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
            if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
                erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1011
                                              List.<Type>nil(), this,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1012
                                              type.getMetadata());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
        public String className() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1017
            if (name.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
                    Log.getLocalizedString("anonymous.class", flatname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
                return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1024
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
        public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
            return flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
        public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
            if (this == base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
            } else if ((base.flags() & INTERFACE) != 0) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1037
                for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
                    for (List<Type> is = types.interfaces(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
                         is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
                         is = is.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
                        if (is.head.tsym.isSubClass(base, types)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
            } else {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1043
                for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
                    if (t.tsym == base) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
        public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
                super.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                // quiet error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
                flags_field |= (PUBLIC|STATIC);
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1045
diff changeset
  1057
                this.type = new ErrorType(this, Type.noType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
                throw ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1062
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
        public List<Type> getInterfaces() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
                if (t.interfaces_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
                    t.interfaces_field = List.nil();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1069
                if (t.all_interfaces_field != null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1070
                    return Type.getModelTypes(t.all_interfaces_field);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
                return t.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
                return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1077
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
        public Type getSuperclass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
                if (t.supertype_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
                    t.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
                // An interface has no superclass; its supertype is Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
                return t.isInterface()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
                    ? Type.noType
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1087
                    : t.supertype_field.getModelType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
                return Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1093
        /**
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1094
         * Returns the next class to search for inherited annotations or {@code null}
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1095
         * if the next class can't be found.
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1096
         */
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1097
        private ClassSymbol getSuperClassToSearchForAnnotations() {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1098
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1099
            Type sup = getSuperclass();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1100
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1101
            if (!sup.hasTag(CLASS) || sup.isErroneous())
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1102
                return null;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1103
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1104
            return (ClassSymbol) sup.tsym;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1105
        }
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1106
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1107
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1108
        @Override
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1109
        protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1110
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1111
            ClassSymbol sup = getSuperClassToSearchForAnnotations();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1112
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1113
            return sup == null ? super.getInheritedAnnotations(annoType)
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1114
                               : sup.getAnnotationsByType(annoType);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1115
        }
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1116
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1117
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1118
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
            if ((flags & ANNOTATION) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
                return ElementKind.ANNOTATION_TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
            else if ((flags & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                return ElementKind.INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
            else if ((flags & ENUM) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                return ElementKind.ENUM;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
                return ElementKind.CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1131
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
20610
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1132
        public Set<Modifier> getModifiers() {
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1133
            long flags = flags();
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1134
            return Flags.asModifierSet(flags & ~DEFAULT);
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1135
        }
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1136
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1137
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
        public NestingKind getNestingKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
            if (owner.kind == PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
                return NestingKind.TOP_LEVEL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
            else if (name.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                return NestingKind.ANONYMOUS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            else if (owner.kind == MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                return NestingKind.LOCAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                return NestingKind.MEMBER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1150
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1151
        @Override
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1152
        protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1153
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1154
            Attribute.Compound attrib = super.getAttribute(annoType);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1155
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1156
            boolean inherited = annoType.isAnnotationPresent(Inherited.class);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1157
            if (attrib != null || !inherited)
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1158
                return attrib;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1159
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1160
            // Search supertypes
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1161
            ClassSymbol superType = getSuperClassToSearchForAnnotations();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1162
            return superType == null ? null
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1163
                                     : superType.getAttribute(annoType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1166
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1167
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1168
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1169
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
            return v.visitType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1173
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1174
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1175
            return v.visitClassSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1176
        }
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1177
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1178
        /**Resets the Symbol into the state good for next round of annotation processing.*/
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1179
        public void reset() {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1180
            kind = TYP;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1181
            erasure_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1182
            members_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1183
            flags_field = 0;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1184
            if (type instanceof ClassType) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1185
                ClassType t = (ClassType)type;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1186
                t.setEnclosingType(Type.noType);
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1187
                t.rank_field = -1;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1188
                t.typarams_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1189
                t.allparams_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1190
                t.supertype_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1191
                t.interfaces_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1192
                t.all_interfaces_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1193
            }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1194
            metadata = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1195
        }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1196
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
    /** A class for variable symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
    public static class VarSymbol extends Symbol implements VariableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
        /** The variable's declaration position.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
        public int pos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
        /** The variable's address. Used for different purposes during
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
         *  flow analysis, translation and code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
         *  Flow analysis:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
         *    If this is a blank final or local variable, its sequence number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
         *  Translation:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
         *    If this is a private field, its access number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
         *  Code generation:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
         *    If this is a local variable, its logical slot number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
        public int adr = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
        /** Construct a variable symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
        public VarSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
            super(VAR, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
        public VarSymbol clone(Symbol newOwner) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1228
            VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1229
                @Override
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1230
                public Symbol baseSymbol() {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1231
                    return VarSymbol.this;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1232
                }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1233
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
            v.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
            v.adr = adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            v.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
//          System.out.println("clone " + v + " in " + newOwner);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
            return v;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
            return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1249
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
            if ((flags & PARAMETER) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
                if (isExceptionParameter())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
                    return ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
                    return ElementKind.PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
            } else if ((flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
                return ElementKind.ENUM_CONSTANT;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
            } else if (owner.kind == TYP || owner.kind == ERR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
                return ElementKind.FIELD;
6718
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
  1261
            } else if (isResourceVariable()) {
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
  1262
                return ElementKind.RESOURCE_VARIABLE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
                return ElementKind.LOCAL_VARIABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1268
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
            return v.visitVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1273
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
        public Object getConstantValue() { // Mirror API
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
            return Constants.decode(getConstValue(), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
        public void setLazyConstValue(final Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
                                      final Attr attr,
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19928
diff changeset
  1280
                                      final JCVariableDecl variable)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
            setData(new Callable<Object>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
                public Object call() {
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19928
diff changeset
  1284
                    return attr.attribLazyConstantValue(env, variable, type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
            });
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
         * The variable's constant value, if this is a constant.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
         * Before the constant value is evaluated, it points to an
19666
01a225608c25 8010310: [javadoc] Error processing sources with -private
jjg
parents: 19657
diff changeset
  1292
         * initializer environment.  If this is not a constant, it can
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
         * be used for other stuff.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
        private Object data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
        public boolean isExceptionParameter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
            return data == ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1301
        public boolean isResourceVariable() {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1302
            return data == ElementKind.RESOURCE_VARIABLE;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1303
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1304
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        public Object getConstValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            // TODO: Consider if getConstValue and getConstantValue can be collapsed
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1307
            if (data == ElementKind.EXCEPTION_PARAMETER ||
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1308
                data == ElementKind.RESOURCE_VARIABLE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
            } else if (data instanceof Callable<?>) {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1311
                // In this case, this is a final variable, with an as
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
                // yet unevaluated initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
                Callable<?> eval = (Callable<?>)data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
                data = null; // to make sure we don't evaluate this twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
                    data = eval.call();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
                } catch (Exception ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
                    throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
            return data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
        public void setData(Object data) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1325
            Assert.check(!(data instanceof Env<?>), this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
            this.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1328
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1329
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1330
            return v.visitVarSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1331
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
    /** A class for method symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
    public static class MethodSymbol extends Symbol implements ExecutableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
        /** The code of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
        public Code code = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1341
        /** The extra (synthetic/mandated) parameters of the method. */
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1342
        public List<VarSymbol> extraParams = List.nil();
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1343
19657
48226ff07b84 8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents: 19492
diff changeset
  1344
        /** The captured local variables in an anonymous class */
48226ff07b84 8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents: 19492
diff changeset
  1345
        public List<VarSymbol> capturedLocals = List.nil();
48226ff07b84 8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents: 19492
diff changeset
  1346
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
        /** The parameters of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
        public List<VarSymbol> params = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
        /** The names of the parameters */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
        public List<Name> savedParameterNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
        /** For an attribute field accessor, its default value if any.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
         *  The value is null if none appeared in the method
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
         *  declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
        public Attribute defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
        /** Construct a method symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
        public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
            super(MTH, flags, name, type, owner);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1363
            if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
        public MethodSymbol clone(Symbol newOwner) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1369
            MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1370
                @Override
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1371
                public Symbol baseSymbol() {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1372
                    return MethodSymbol.this;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1373
                }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1374
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
            m.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
            return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1379
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16970
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1380
        public Set<Modifier> getModifiers() {
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1381
            long flags = flags();
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1382
            return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags);
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1383
        }
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1384
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
            if ((flags() & BLOCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
                return owner.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
            } else {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1391
                String s = (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
                    ? owner.name.toString()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
                    : name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
                if (type != null) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1395
                    if (type.hasTag(FORALL))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
                        s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
                    s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
                return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1403
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1404
            return false;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1405
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1406
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
        /** find a symbol that this (proxy method) symbol implements.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
         *  @param    c       The class whose members are searched for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
         *                    implementations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
        public Symbol implemented(TypeSymbol c, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
            Symbol impl = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
            for (List<Type> is = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
                 impl == null && is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
                 is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
                TypeSymbol i = is.head.tsym;
7628
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1417
                impl = implementedIn(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1418
                if (impl == null)
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1419
                    impl = implemented(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1420
            }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1421
            return impl;
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1422
        }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1423
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1424
        public Symbol implementedIn(TypeSymbol c, Types types) {
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1425
            Symbol impl = null;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1426
            for (Symbol sym : c.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1427
                if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
7628
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1428
                    // FIXME: I suspect the following requires a
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1429
                    // subst() for a parametric return type.
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1430
                    types.isSameType(type.getReturnType(),
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1431
                                     types.memberType(owner.type, sym).getReturnType())) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1432
                    impl = sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
            return impl;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
        /** Will the erasure of this method be considered by the VM to
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
         *  override the erasure of the other when seen from class `origin'?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
        public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
                types.asSuper(owner.type, other.owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
                types.isSameType(erasure(types), other.erasure(types)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
                (flags() & ABSTRACT) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
                other.isOverridableIn(origin) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
                this.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
                types.isSameType(erasure(types), other.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
        /** The implementation of this (abstract) symbol in class origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
         *  from the VM's point of view, null if method does not have an
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
         *  implementation in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
         *  @param origin   The class of which the implementation is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
        public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
            for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1468
                for (Symbol sym : c.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1469
                    if (sym.kind == MTH &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1470
                        ((MethodSymbol)sym).binaryOverrides(this, origin, types))
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1471
                        return (MethodSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
        /** Does this symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
  1478
         *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
         *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
         *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
         *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
         *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
        public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1491
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
                types.asSuper(owner.type, other.owner) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
                Type mt = types.memberType(owner.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
                Type ot = types.memberType(owner.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
                if (types.isSubSignature(mt, ot)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
                    if (!checkResult)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
                    if (types.returnTypeSubstitutable(mt, ot))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
            if ((flags() & ABSTRACT) != 0 ||
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1507
                    ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1508
                    !other.isOverridableIn(origin) ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1509
                    !this.isMemberOf(origin, types))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
            // assert types.asSuper(origin.type, other.owner) != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
            Type mt = types.memberType(origin.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
            Type ot = types.memberType(origin.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
                types.isSubSignature(mt, ot) &&
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1517
                (!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
        private boolean isOverridableIn(TypeSymbol origin) {
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8625
diff changeset
  1521
            // JLS 8.4.6.1
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
            switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
            case Flags.PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
            case Flags.PUBLIC:
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1526
                return !this.owner.isInterface() ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1527
                        (flags_field & STATIC) == 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
            case Flags.PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
                return (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
            case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
                // for package private: can only override in the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
                // package
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
                    this.packge() == origin.packge() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
                    (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1541
        @Override
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1542
        public boolean isInheritedIn(Symbol clazz, Types types) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1543
            switch ((int)(flags_field & Flags.AccessFlags)) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1544
                case PUBLIC:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1545
                    return !this.owner.isInterface() ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1546
                            clazz == owner ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1547
                            (flags_field & STATIC) == 0;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1548
                default:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1549
                    return super.isInheritedIn(clazz, types);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1550
            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1551
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1552
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
        /** The implementation of this (abstract) symbol in class origin;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
         *  null if none exists. Synthetic methods are not considered
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
         *  as possible implementations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
6591
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1558
            return implementation(origin, types, checkResult, implementation_filter);
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1559
        }
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1560
        // where
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 15720
diff changeset
  1561
            public static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
6591
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1562
                public boolean accepts(Symbol s) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
  1563
                    return s.kind == MTH &&
6591
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1564
                            (s.flags() & SYNTHETIC) == 0;
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1565
                }
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1566
            };
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1567
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1568
        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
8242
3873b4aaf4a8 7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents: 8225
diff changeset
  1569
            MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
3539
3c265cb6f4e0 6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents: 3149
diff changeset
  1570
            if (res != null)
3c265cb6f4e0 6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents: 3149
diff changeset
  1571
                return res;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
            // if origin is derived from a raw type, we might have missed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1573
            // an implementation because we do not know enough about instantiations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1574
            // in this case continue with the supertype as origin.
12083
c9d98f7e59e8 7148556: Implementing a generic interface causes a public clone() to become inaccessible
mcimadamore
parents: 10627
diff changeset
  1575
            if (types.isDerivedRaw(origin.type) && !origin.isInterface())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1576
                return implementation(types.supertype(origin.type).tsym, types, checkResult);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1577
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1578
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1579
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
06bc494ca11e Initial load
duke
parents:
diff changeset
  1581
        public List<VarSymbol> params() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
            owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
            if (params == null) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1584
                // If ClassReader.saveParameterNames has been set true, then
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1585
                // savedParameterNames will be set to a list of names that
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1586
                // matches the types in type.getParameterTypes().  If any names
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1587
                // were not found in the class file, those names in the list will
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1588
                // be set to the empty name.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1589
                // If ClassReader.saveParameterNames has been set false, then
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1590
                // savedParameterNames will be null.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1591
                List<Name> paramNames = savedParameterNames;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
                savedParameterNames = null;
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1593
                // discard the provided names if the list of names is the wrong size.
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
  1594
                if (paramNames == null || paramNames.size() != type.getParameterTypes().size()) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1595
                    paramNames = List.nil();
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
  1596
                }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21480
diff changeset
  1597
                ListBuffer<VarSymbol> buf = new ListBuffer<>();
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1598
                List<Name> remaining = paramNames;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1599
                // assert: remaining and paramNames are both empty or both
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1600
                // have same cardinality as type.getParameterTypes()
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1601
                int i = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
                for (Type t : type.getParameterTypes()) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1603
                    Name paramName;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1604
                    if (remaining.isEmpty()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1605
                        // no names for any parameters available
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1606
                        paramName = createArgName(i, paramNames);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1607
                    } else {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1608
                        paramName = remaining.head;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1609
                        remaining = remaining.tail;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1610
                        if (paramName.isEmpty()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1611
                            // no name for this specific parameter
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1612
                            paramName = createArgName(i, paramNames);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1613
                        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1614
                    }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1615
                    buf.append(new VarSymbol(PARAMETER, paramName, t, this));
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1616
                    i++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
                params = buf.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
            return params;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1623
        // Create a name for the argument at position 'index' that is not in
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1624
        // the exclude list. In normal use, either no names will have been
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1625
        // provided, in which case the exclude list is empty, or all the names
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1626
        // will have been provided, in which case this method will not be called.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1627
        private Name createArgName(int index, List<Name> exclude) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1628
            String prefix = "arg";
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1629
            while (true) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1630
                Name argName = name.table.fromString(prefix + index);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1631
                if (!exclude.contains(argName))
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1632
                    return argName;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1633
                prefix += "$";
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1634
            }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1635
        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1636
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
            return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1641
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
        public ElementKind getKind() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1643
            if (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1644
                return ElementKind.CONSTRUCTOR;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1645
            else if (name == name.table.names.clinit)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
                return ElementKind.STATIC_INIT;
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1647
            else if ((flags() & BLOCK) != 0)
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1648
                return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
                return ElementKind.METHOD;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1653
        public boolean isStaticOrInstanceInit() {
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1654
            return getKind() == ElementKind.STATIC_INIT ||
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1655
                    getKind() == ElementKind.INSTANCE_INIT;
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1656
        }
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1657
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1658
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
        public Attribute getDefaultValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
            return defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1663
        @DefinedBy(Api.LANGUAGE_MODEL)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1664
        public List<VarSymbol> getParameters() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
            return params();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1668
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
        public boolean isVarArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
            return (flags() & VARARGS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1673
        @DefinedBy(Api.LANGUAGE_MODEL)
14956
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1674
        public boolean isDefault() {
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1675
            return (flags() & DEFAULT) != 0;
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1676
        }
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1677
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1678
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1683
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1684
            return v.visitMethodSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1685
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1686
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1687
        @DefinedBy(Api.LANGUAGE_MODEL)
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1688
        public Type getReceiverType() {
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1689
            return asType().getReceiverType();
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1690
        }
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1691
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1692
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
        public Type getReturnType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
            return asType().getReturnType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1697
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
        public List<Type> getThrownTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
            return asType().getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1703
    /** A class for invokedynamic method calls.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1704
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1705
    public static class DynamicMethodSymbol extends MethodSymbol {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1706
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1707
        public Object[] staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1708
        public Symbol bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1709
        public int bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1710
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1711
        public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1712
            super(0, name, type, owner);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1713
            this.bsm = bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1714
            this.bsmKind = bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1715
            this.staticArgs = staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1716
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1717
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1718
        @Override
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1719
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1720
            return true;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1721
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1722
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1723
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
    /** A class for predefined operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
    public static class OperatorSymbol extends MethodSymbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
        public int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
06bc494ca11e Initial load
duke
parents:
diff changeset
  1730
        public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
            super(PUBLIC | STATIC, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1734
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1735
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1736
            return v.visitOperatorSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1737
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
    /** Symbol completer interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
    public static interface Completer {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
        void complete(Symbol sym) throws CompletionFailure;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
    public static class CompletionFailure extends RuntimeException {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
        public Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1750
        /** A diagnostic object describing the failure
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1751
         */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1752
        public JCDiagnostic diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1753
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
        /** A localized string describing the failure.
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1755
         * @deprecated Use {@code getDetail()} or {@code getMessage()}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
         */
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1757
        @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
        public String errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
        public CompletionFailure(Symbol sym, String errmsg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
            this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
            this.errmsg = errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
//          this.printStackTrace();//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1766
        public CompletionFailure(Symbol sym, JCDiagnostic diag) {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1767
            this.sym = sym;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1768
            this.diag = diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1769
//          this.printStackTrace();//DEBUG
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1770
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1771
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1772
        public JCDiagnostic getDiagnostic() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1773
            return diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1774
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1775
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1776
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
        public String getMessage() {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1778
            if (diag != null)
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1779
                return diag.getMessage(null);
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1780
            else
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1781
                return errmsg;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1782
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1783
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1784
        public Object getDetailValue() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1785
            return (diag != null ? diag : errmsg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
        public CompletionFailure initCause(Throwable cause) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
            super.initCause(cause);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
    }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1795
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1796
    /**
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1797
     * A visitor for symbols.  A visitor is used to implement operations
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1798
     * (or relations) on symbols.  Most common operations on types are
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1799
     * binary relations and this interface is designed for binary
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1800
     * relations, that is, operations on the form
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1801
     * Symbol&nbsp;&times;&nbsp;P&nbsp;&rarr;&nbsp;R.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1802
     * <!-- In plain text: Type x P -> R -->
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1803
     *
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1804
     * @param <R> the return type of the operation implemented by this
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1805
     * visitor; use Void if no return type is needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1806
     * @param <P> the type of the second argument (the first being the
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1807
     * symbol itself) of the operation implemented by this visitor; use
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1808
     * Void if a second argument is not needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1809
     */
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1810
    public interface Visitor<R,P> {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1811
        R visitClassSymbol(ClassSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1812
        R visitMethodSymbol(MethodSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1813
        R visitPackageSymbol(PackageSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1814
        R visitOperatorSymbol(OperatorSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1815
        R visitVarSymbol(VarSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1816
        R visitTypeSymbol(TypeSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1817
        R visitSymbol(Symbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1818
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
}