src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
author jlahoda
Fri, 09 Mar 2018 09:42:10 +0100
changeset 49197 cc2673fa8c20
parent 48945 6e6c777a37a2
child 54339 f69a2f675f19
permissions -rw-r--r--
8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure. Summary: Catching CompletionFailures that would be thrown to API clients, and re-completing the symbols again when javac itself needs it. Reviewed-by: cushon, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48945
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
     2
 * Copyright (c) 1999, 2018, 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;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    30
import java.util.Collections;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
    31
import java.util.EnumSet;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    32
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import java.util.concurrent.Callable;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    35
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    36
import javax.lang.model.element.Element;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    37
import javax.lang.model.element.ElementKind;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    38
import javax.lang.model.element.ElementVisitor;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    39
import javax.lang.model.element.ExecutableElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    40
import javax.lang.model.element.Modifier;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    41
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    42
import javax.lang.model.element.NestingKind;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    43
import javax.lang.model.element.PackageElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    44
import javax.lang.model.element.TypeElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    45
import javax.lang.model.element.TypeParameterElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    46
import javax.lang.model.element.VariableElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    47
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    50
import com.sun.tools.javac.code.Kinds.Kind;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
    51
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.javac.comp.Attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.javac.jvm.*;
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    57
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
    58
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    59
import com.sun.tools.javac.tree.JCTree.Tag;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    60
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    61
import com.sun.tools.javac.util.DefinedBy.Api;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14062
diff changeset
    62
import com.sun.tools.javac.util.Name;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
    63
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
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
    66
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
    67
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
    68
import com.sun.tools.javac.code.Scope.WriteableScope;
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    69
import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    70
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
    71
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
    72
import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    73
import static com.sun.tools.javac.jvm.ByteCodes.iadd;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    74
import static com.sun.tools.javac.jvm.ByteCodes.ishll;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    75
import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    76
import static com.sun.tools.javac.jvm.ByteCodes.lxor;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
    77
import static com.sun.tools.javac.jvm.ByteCodes.string_add;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
/** Root class for Java symbols. It contains subclasses
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *  for specific sorts of symbols, such as variables, methods and operators,
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *  types, packages. Each subclass is represented as a static inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *  inside Symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    84
 *  <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
    85
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 */
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
    89
public abstract class Symbol extends AnnoConstruct implements Element {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** The kind of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     *  @see Kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    94
    public Kind kind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /** The flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public long flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** An accessor method for the flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     *  Flags of class symbols should be accessed through the accessor
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     *  method to make sure that the class symbol is loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    public long flags() { return flags_field; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /** The name of this symbol in Utf8 representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    public Name name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /** The type of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /** The owner of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public Symbol owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    /** The completer of this symbol.
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   119
     * This should never equal null (NULL_COMPLETER should be used instead).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    public Completer completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /** A cache for the type erasure of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public Type erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   127
    // <editor-fold defaultstate="collapsed" desc="annotations">
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
    /** 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
   130
     * 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
   131
     */
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   132
    protected SymbolMetadata metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   133
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   134
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   135
    /** 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
   136
     *  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
   137
     *  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
   138
     */
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   139
    public List<Attribute.Compound> getRawAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   140
        return (metadata == null)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   141
                ? List.nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   142
                : metadata.getDeclarationAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   143
    }
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
    /** 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
   146
     *  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
   147
     *  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
   148
     */
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   149
    public List<Attribute.TypeCompound> getRawTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   150
        return (metadata == null)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   151
                ? List.nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   152
                : metadata.getTypeAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   153
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   154
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   155
    /** 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
   156
    public Attribute.Compound attribute(Symbol anno) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   157
        for (Attribute.Compound a : getRawAttributes()) {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   158
            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
   159
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   160
        return null;
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   161
    }
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
    public boolean annotationsPendingCompletion() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   164
        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
   165
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   166
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   167
    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
   168
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   169
            initedMetadata().append(l);
18010
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
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   172
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   173
    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
   174
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   175
            initedMetadata().appendClassInitTypeAttributes(l);
18010
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
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   178
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   179
    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
   180
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   181
            initedMetadata().appendInitTypeAttributes(l);
18010
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
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   184
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   185
    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
   186
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   187
            initedMetadata().appendUniqueTypes(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   188
        }
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 List<Attribute.TypeCompound> getClassInitTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   192
        return (metadata == null)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   193
                ? List.nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   194
                : metadata.getClassInitTypeAttributes();
18010
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 List<Attribute.TypeCompound> getInitTypeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   198
        return (metadata == null)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   199
                ? List.nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   200
                : metadata.getInitTypeAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   201
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   202
33712
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   203
    public void setInitTypeAttributes(List<Attribute.TypeCompound> l) {
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   204
        initedMetadata().setInitTypeAttributes(l);
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   205
    }
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   206
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   207
    public void setClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   208
        initedMetadata().setClassInitTypeAttributes(l);
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   209
    }
fd1ce6d7ac63 8136419: Type annotations in initializers and lambda bodies not written to class file
sadayapalam
parents: 33367
diff changeset
   210
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   211
    public List<Attribute.Compound> getDeclarationAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   212
        return (metadata == null)
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
   213
                ? List.nil()
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   214
                : metadata.getDeclarationAttributes();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   215
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   216
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   217
    public boolean hasAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   218
        return (metadata != null && !metadata.isEmpty());
18010
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
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   221
    public boolean hasTypeAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   222
        return (metadata != null && !metadata.isTypesEmpty());
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   223
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   224
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   225
    public boolean isCompleted() {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   226
        return completer.isTerminal();
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   227
    }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   228
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   229
    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
   230
        if (l.nonEmpty()) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   231
            initedMetadata().prepend(l);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   232
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   233
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   234
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   235
    public void resetAnnotations() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   236
        initedMetadata().reset();
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   237
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   238
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   239
    public void setAttributes(Symbol other) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   240
        if (metadata != null || other.metadata != null) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   241
            initedMetadata().setAttributes(other.metadata);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   242
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   243
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   244
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   245
    public void setDeclarationAttributes(List<Attribute.Compound> a) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   246
        if (metadata != null || a.nonEmpty()) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   247
            initedMetadata().setDeclarationAttributes(a);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   248
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   249
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   250
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   251
    public void setTypeAttributes(List<Attribute.TypeCompound> a) {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   252
        if (metadata != null || a.nonEmpty()) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   253
            if (metadata == null)
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   254
                metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   255
            metadata.setTypeAttributes(a);
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   256
        }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   257
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   258
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   259
    private SymbolMetadata initedMetadata() {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   260
        if (metadata == null)
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   261
            metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   262
        return metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   263
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   264
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   265
    /** This method is intended for debugging only. */
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   266
    public SymbolMetadata getMetadata() {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
   267
        return metadata;
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   268
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   269
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   270
    // </editor-fold>
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   271
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    /** Construct a symbol with given kind, flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     */
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   274
    public Symbol(Kind kind, long flags, Name name, Type type, Symbol owner) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        this.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        this.owner = owner;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   279
        this.completer = Completer.NULL_COMPLETER;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        this.erasure_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     *  Legal only for fields and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    public Symbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   291
    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
   292
        return v.visitSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   293
    }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   294
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     *  A description of this symbol; overrides Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    /** 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
   303
     *  error reporting.
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   304
     *
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   305
     * @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
   306
     * the default package; otherwise, the owner symbol is returned
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     */
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   308
    public Symbol location() {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
   309
        if (owner.name == null || (owner.name.isEmpty() &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   310
                                   (owner.flags() & BLOCK) == 0 &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   311
                                   owner.kind != PCK &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   312
                                   owner.kind != TYP)) {
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   313
            return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   315
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   318
    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
   319
        if (owner.name == null || owner.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            return location();
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   322
        if (owner.type.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            Type ownertype = types.asOuterSuper(site, owner);
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   324
            if (ownertype != null) return ownertype.tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   326
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   329
    public Symbol baseSymbol() {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   330
        return this;
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   331
    }
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   332
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    /** The symbol's erased type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            erasure_field = types.erasure(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    /** The external type of a symbol. This is the symbol's erased type
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     *  except for constructors of inner classes which get the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     *  instance class added as first argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    public Type externalType(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        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
   347
        if (name == name.table.names.init && owner.hasOuterInstance()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            Type outerThisType = types.erasure(owner.type.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            return new MethodType(t.getParameterTypes().prepend(outerThisType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                                  t.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                                  t.getThrownTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                                  t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   358
    public boolean isDeprecated() {
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   359
        return (flags_field & DEPRECATED) != 0;
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   360
    }
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17278
diff changeset
   361
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   362
    public boolean hasDeprecatedAnnotation() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   363
        return (flags_field & DEPRECATED_ANNOTATION) != 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   364
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   365
41637
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41516
diff changeset
   366
    public boolean isDeprecatedForRemoval() {
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41516
diff changeset
   367
        return (flags_field & DEPRECATED_REMOVAL) != 0;
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41516
diff changeset
   368
    }
7b24b4c32ee6 8145471: javac changes for enhanced deprecation
jjg
parents: 41516
diff changeset
   369
40772
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   370
    public boolean isDeprecatableViaAnnotation() {
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   371
        switch (getKind()) {
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   372
            case LOCAL_VARIABLE:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   373
            case PACKAGE:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   374
            case PARAMETER:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   375
            case RESOURCE_VARIABLE:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   376
            case EXCEPTION_PARAMETER:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   377
                return false;
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   378
            default:
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   379
                return true;
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   380
        }
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   381
    }
de87954b8f20 8164073: Javac should unconditionally warn if deprecated javadoc tag is used without @Deprecated annotation
sadayapalam
parents: 39920
diff changeset
   382
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    public boolean isStatic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            (flags() & STATIC) != 0 ||
20598
aa7b86f98471 8024497: crash returning this-referencing lambda from default method
vromero
parents: 20249
diff changeset
   386
            (owner.flags() & INTERFACE) != 0 && kind != MTH &&
aa7b86f98471 8024497: crash returning this-referencing lambda from default method
vromero
parents: 20249
diff changeset
   387
             name != name.table.names._this;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        return (flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   394
    public boolean isPrivate() {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   395
        return (flags_field & Flags.AccessFlags) == PRIVATE;
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   396
    }
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   397
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   398
    public boolean isEnum() {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   399
        return (flags() & ENUM) != 0;
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   400
    }
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
   401
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    /** Is this symbol declared (directly or indirectly) local
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     *  to a method or variable initializer?
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     *  Also includes fields of inner classes which are in
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     *  turn local to a method or variable initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public boolean isLocal() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        return
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   409
            (owner.kind.matches(KindSelector.VAL_MTH) ||
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   410
             (owner.kind == TYP && owner.isLocal()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   413
    /** Has this symbol an empty name? This includes anonymous
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
   414
     *  inner classes.
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   415
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   416
    public boolean isAnonymous() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   417
        return name.isEmpty();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   418
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   419
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    /** Is this symbol a constructor?
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    public boolean isConstructor() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   423
        return name == name.table.names.init;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    /** The fully qualified name of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     *  This is the same as the symbol's name except for class symbols,
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
     *  which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
    public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    /** The fully qualified name of this symbol after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
     *  representation. This is the same as the symbol's name except for
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
     *  class symbols, which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        return getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    /** If this is a class or package, its members, otherwise null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   444
    public WriteableScope members() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    /** A class is an inner class if it it has an enclosing instance class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    public boolean isInner() {
24219
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 23814
diff changeset
   451
        return kind == TYP && type.getEnclosingType().hasTag(CLASS);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    /** An inner class has an outer instance if it is not an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
     *  it has an enclosing instance class which might be referenced from the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
     *  Nested classes can see instance members of their enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
     *  Their constructors carry an additional this$n parameter, inserted
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
     *  implicitly by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     *  @see #isInner
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public boolean hasOuterInstance() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        return
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   464
            type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
    /** The closest enclosing class of this symbol's declaration.
34561
79c436257611 8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents: 33712
diff changeset
   468
     *  Warning: this (misnamed) method returns the receiver itself
79c436257611 8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents: 33712
diff changeset
   469
     *  when the receiver is a class (as opposed to its enclosing
79c436257611 8144673: Suspect message regarding suitable enclosing instance not being in scope
sadayapalam
parents: 33712
diff changeset
   470
     *  class as one may be misled to believe.)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    public ClassSymbol enclClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        Symbol c = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        while (c != null &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   475
               (!c.kind.matches(KindSelector.TYP) || !c.type.hasTag(CLASS))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            c = c.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        return (ClassSymbol)c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    /** The outermost class which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
    public ClassSymbol outermostClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        Symbol prev = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            prev = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        return (ClassSymbol) prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    /** The package which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    public PackageSymbol packge() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        return (PackageSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
    /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        throw new AssertionError("isSubClass " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    /** Fully check membership: hierarchy, protection, and hiding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
     *  Does not exclude methods not inherited due to overriding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
    public boolean isMemberOf(TypeSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            owner == clazz ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            clazz.isSubClass(owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            isInheritedIn(clazz, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            !hiddenIn((ClassSymbol)clazz, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
    /** Is this symbol the same as or enclosed by the given class? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
    public boolean isEnclosedBy(ClassSymbol clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            if (sym == clazz) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
    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
   528
        Symbol sym = hiddenInInternal(clazz, types);
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   529
        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
   530
        /* 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
   531
         */
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   532
        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
   533
    }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   534
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   535
    /** 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
   536
     * 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
   537
     * 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
   538
     * 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
   539
     * 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
   540
     * as a temporary value, as a result of the recursive call.
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   541
     */
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   542
    private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   543
        if (currentClass == owner) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   544
            return this;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   545
        }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   546
        for (Symbol sym : currentClass.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   547
            if (sym.kind == kind &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                    (kind != MTH ||
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   549
                    (sym.flags() & STATIC) != 0 &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   550
                    types.isSubSignature(sym.type, type))) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   551
                return sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        }
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   554
        Symbol hiddenSym = null;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   555
        for (Type st : types.interfaces(currentClass.type)
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   556
                .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
   557
            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
   558
                Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types);
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   559
                if (sym == this) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   560
                    return this;
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   561
                } else if (sym != null) {
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   562
                    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
   563
                }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   564
            }
767d7330011f 6537020: JCK tests: a compile-time error should be given in case of ambiguously imported fields (types, methods)
mcimadamore
parents: 19126
diff changeset
   565
        }
23396
06e3726c6b3f 8034924: Incorrect inheritance of inaccessible static method
vromero
parents: 22163
diff changeset
   566
        return hiddenSym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
48945
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   569
    /** Is this symbol accessible in a given class?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
     *  PRE: If symbol's owner is a interface,
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     *       it is already assumed that the interface is a superinterface
48945
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   572
     *       the given class.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     *  @param clazz  The class for which we want to establish membership.
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     *                This must be a subclass of the member's owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     */
48945
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   576
    public final boolean isAccessibleIn(Symbol clazz, Types types) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        default: // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            return this.owner == clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            // we model interfaces as extending Object
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
            PackageSymbol thisPackage = this.packge();
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            for (Symbol sup = clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
                 sup != null && sup != this.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
                 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
   591
                while (sup.type.hasTag(TYPEVAR))
1528
441d4ec466de 6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents: 1357
diff changeset
   592
                    sup = sup.type.getUpperBound().tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
                if (sup.type.isErroneous())
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                    return true; // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                if ((sup.flags() & COMPOUND) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                if (sup.packge() != thisPackage)
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
48945
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   604
    /** Is this symbol inherited into a given class?
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   605
     *  PRE: If symbol's owner is a interface,
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   606
     *       it is already assumed that the interface is a superinterface
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   607
     *       of the given class.
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   608
     *  @param clazz  The class for which we want to establish membership.
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   609
     *                This must be a subclass of the member's owner.
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   610
     */
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   611
    public boolean isInheritedIn(Symbol clazz, Types types) {
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   612
        return isAccessibleIn(clazz, types);
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   613
    }
6e6c777a37a2 8186688: javax.lang.model.util.Elements.hides does not work correctly with interfaces
jjg
parents: 48683
diff changeset
   614
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    /** The (variable or method) symbol seen as a member of given
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
     *  class type`site' (this might change the symbol's type).
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
     *  This is used exclusively for producing diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
    public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
    /** Does this method symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
     *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
     *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
     *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
     *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
     *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
    public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
    /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    public void complete() throws CompletionFailure {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   639
        if (completer != Completer.NULL_COMPLETER) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            Completer c = completer;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
   641
            completer = Completer.NULL_COMPLETER;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
            c.complete(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   646
    public void apiComplete() throws CompletionFailure {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   647
        try {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   648
            complete();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   649
        } catch (CompletionFailure cf) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   650
            cf.dcfh.handleAPICompletionFailure(cf);
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   651
        }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   652
    }
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   653
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
    /** True if the symbol represents an entity that exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
    public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   660
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
    public Type asType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   665
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
    public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
        return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   670
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
    public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        return ElementKind.OTHER;       // most unkind
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   675
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
    public Set<Modifier> getModifiers() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   677
        apiComplete();
16970
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
   678
        return Flags.asModifierSet(flags());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   681
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
    public Name getSimpleName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
    /**
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   687
     * This is the implementation for {@code
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   688
     * javax.lang.model.element.Element.getAnnotationMirrors()}.
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   689
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   690
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   691
    public List<Attribute.Compound> getAnnotationMirrors() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   692
        apiComplete();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   693
        return getRawAttributes();
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   694
    }
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
   695
15355
a4757c33cae9 7193719: Support repeating annotations in javax.lang.model
jfranck
parents: 15031
diff changeset
   696
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
    // 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
   698
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
    public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   703
    public List<TypeVariableSymbol> getTypeParameters() {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19942
diff changeset
   704
        ListBuffer<TypeVariableSymbol> l = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        for (Type t : type.getTypeArguments()) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   706
            Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   707
            l.append((TypeVariableSymbol)t.tsym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        return l.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
15564
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   712
    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
   713
        protected T other;
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   714
        public DelegatedSymbol(T other) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            super(other.kind, other.flags_field, other.name, other.type, other.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            this.other = other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
        public String toString() { return other.toString(); }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   719
        public Symbol location() { return other.location(); }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   720
        public Symbol location(Type site, Types types) { return other.location(site, types); }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
   721
        public Symbol baseSymbol() { return other; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
        public Type erasure(Types types) { return other.erasure(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        public Type externalType(Types types) { return other.externalType(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        public boolean isLocal() { return other.isLocal(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
        public boolean isConstructor() { return other.isConstructor(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        public Name getQualifiedName() { return other.getQualifiedName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
        public Name flatName() { return other.flatName(); }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   728
        public WriteableScope members() { return other.members(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
        public boolean isInner() { return other.isInner(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        public boolean hasOuterInstance() { return other.hasOuterInstance(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        public ClassSymbol enclClass() { return other.enclClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        public ClassSymbol outermostClass() { return other.outermostClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
        public PackageSymbol packge() { return other.packge(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
        public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
        public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
        public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
        public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        public void complete() throws CompletionFailure { other.complete(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   741
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
            return other.accept(v, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   745
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   746
        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
   747
            return v.visitSymbol(other, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   748
        }
15564
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   749
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   750
        public T getUnderlyingSymbol() {
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   751
            return other;
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   752
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   755
    /** A base class for Symbols representing types.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
     */
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   757
    public static abstract class TypeSymbol extends Symbol {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   758
        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
   759
            super(kind, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
        /** form a fully qualified name from a name and an owner
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        static public Name formFullName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
            if (owner == null) return name;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   765
            if ((owner.kind != ERR) &&
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   766
                (owner.kind.matches(KindSelector.VAL_MTH) ||
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   767
                 (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                 )) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            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
   770
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
            else return prefix.append('.', name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
        /** form a fully qualified name from a name and an owner, after
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
         *  converting to flat representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
        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
   779
            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
   780
                (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                ) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
            char sep = owner.kind == TYP ? '$' : '.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
            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
   784
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            else return prefix.append(sep, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        /**
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 24219
diff changeset
   790
         * A partial ordering between type symbols that refines the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
         * class inheritance graph.
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
         *
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 24219
diff changeset
   793
         * Type variables always precede other kinds of symbols.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        public final boolean precedes(TypeSymbol that, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
            if (this == that)
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
                return false;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   798
            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
   799
                if (type.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                    return
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                        types.rank(that.type) < types.rank(this.type) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                        types.rank(that.type) == types.rank(this.type) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
                        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
   804
                } else if (type.hasTag(TYPEVAR)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                    return types.isSubtype(this.type, that.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            }
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18389
diff changeset
   808
            return type.hasTag(TYPEVAR);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   811
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            List<Symbol> list = List.nil();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   814
            if (kind == TYP && type.hasTag(TYPEVAR)) {
6584
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   815
                return list;
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   816
            }
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   817
            apiComplete();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
   818
            for (Symbol sym : members().getSymbols(NON_RECURSIVE)) {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   819
                sym.apiComplete();
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   820
                if ((sym.flags() & SYNTHETIC) == 0 && sym.owner == this && sym.kind != ERR) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
   821
                    list = list.prepend(sym);
37001
594b4565d8a4 8151191: javac error when running javadoc on some inner classes
vromero
parents: 36526
diff changeset
   822
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   827
        public AnnotationTypeMetadata getAnnotationTypeMetadata() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   828
            Assert.error("Only on ClassSymbol");
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   829
            return null; //unreachable
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   830
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   831
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   832
        public boolean isAnnotationType() { return false; }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
   833
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   834
        @Override
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   835
        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
   836
            return v.visitTypeSymbol(this, p);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   837
        }
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   838
    }
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   839
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   840
    /**
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   841
     * Type variables are represented by instances of this class.
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   842
     */
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   843
    public static class TypeVariableSymbol
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   844
            extends TypeSymbol implements TypeParameterElement {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   845
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   846
        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
   847
            super(TYP, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   850
        @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   851
        public ElementKind getKind() {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   852
            return ElementKind.TYPE_PARAMETER;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   855
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   856
        public Symbol getGenericElement() {
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   857
            return owner;
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   858
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   859
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   860
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
        public List<Type> getBounds() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
            TypeVar t = (TypeVar)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            Type bound = t.getUpperBound();
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
            if (!bound.isCompound())
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
                return List.of(bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
            ClassType ct = (ClassType)bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
            if (!ct.tsym.erasure_field.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
                return ct.interfaces_field.prepend(ct.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
                // No superclass was given in bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
                // In this case, supertype is Object, erasure is first interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
                return ct.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
        }
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   875
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   876
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   877
        public List<Attribute.Compound> getAnnotationMirrors() {
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   878
            // 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
   879
            // on the owner of the TypeVariableSymbol
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   880
            List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   881
            int index = owner.getTypeParameters().indexOf(this);
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   882
            List<Attribute.Compound> res = List.nil();
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   883
            for (Attribute.TypeCompound a : candidates) {
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   884
                if (isCurrentSymbolsAnnotation(a, index))
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   885
                    res = res.prepend(a);
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   886
            }
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   887
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   888
            return res.reverse();
17278
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   889
        }
a48ec76f26e9 8011027: Type parameter annotations not passed through to javax.lang.model
jfranck
parents: 16970
diff changeset
   890
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   891
        // Helper to getAnnotation[s]
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   892
        @Override
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   893
        public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   894
            String name = annoType.getName();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   895
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   896
            // Declaration annotations on type variables are stored in type attributes
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   897
            // on the owner of the TypeVariableSymbol
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   898
            List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes();
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   899
            int index = owner.getTypeParameters().indexOf(this);
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   900
            for (Attribute.TypeCompound anno : candidates)
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   901
                if (isCurrentSymbolsAnnotation(anno, index) &&
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   902
                    name.contentEquals(anno.type.tsym.flatName()))
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   903
                    return anno;
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   904
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   905
            return null;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   906
        }
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   907
            //where:
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   908
            boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) {
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   909
                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
   910
                        anno.position.type == TargetType.METHOD_TYPE_PARAMETER) &&
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   911
                        anno.position.parameter_index == index;
25009
55c823e853f2 8046916: Type parameter annotations don't work with multiple type parameters
jlahoda
parents: 24396
diff changeset
   912
            }
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   913
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
   914
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   915
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   916
        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
   917
            return v.visitTypeParameter(this, p);
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
   918
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   920
    /** A class for module symbols.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   921
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   922
    public static class ModuleSymbol extends TypeSymbol
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   923
            implements ModuleElement {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   924
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   925
        public Name version;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   926
        public JavaFileManager.Location sourceLocation;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   927
        public JavaFileManager.Location classLocation;
43772
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43376
diff changeset
   928
        public JavaFileManager.Location patchLocation;
4e5350b7be75 8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents: 43376
diff changeset
   929
        public JavaFileManager.Location patchOutputLocation;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   930
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   931
        /** All directives, in natural order. */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   932
        public List<com.sun.tools.javac.code.Directive> directives;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   933
        public List<com.sun.tools.javac.code.Directive.RequiresDirective> requires;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   934
        public List<com.sun.tools.javac.code.Directive.ExportsDirective> exports;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   935
        public List<com.sun.tools.javac.code.Directive.OpensDirective> opens;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   936
        public List<com.sun.tools.javac.code.Directive.ProvidesDirective> provides;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   937
        public List<com.sun.tools.javac.code.Directive.UsesDirective> uses;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   938
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   939
        public ClassSymbol module_info;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   940
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   941
        public PackageSymbol unnamedPackage;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   942
        public Map<Name, PackageSymbol> visiblePackages;
43138
680d378b9d64 8169197: Improve error reporting for compiling against unexported package
jlahoda
parents: 42828
diff changeset
   943
        public Set<ModuleSymbol> readModules;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   944
        public List<Symbol> enclosedPackages = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   945
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   946
        public Completer usesProvidesCompleter = Completer.NULL_COMPLETER;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   947
        public final Set<ModuleFlags> flags = EnumSet.noneOf(ModuleFlags.class);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
   948
        public final Set<ModuleResolutionFlags> resolutionFlags = EnumSet.noneOf(ModuleResolutionFlags.class);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   949
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   950
        /**
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   951
         * Create a ModuleSymbol with an associated module-info ClassSymbol.
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   952
         */
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   953
        public static ModuleSymbol create(Name name, Name module_info) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   954
            ModuleSymbol msym = new ModuleSymbol(name, null);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   955
            ClassSymbol info = new ClassSymbol(Flags.MODULE, module_info, msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   956
            info.fullname = formFullName(module_info, msym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   957
            info.flatname = info.fullname;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   958
            info.members_field = WriteableScope.create(info);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   959
            msym.module_info = info;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   960
            return msym;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   961
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   962
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   963
        public ModuleSymbol(Name name, Symbol owner) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   964
            super(MDL, 0, name, null, owner);
41254
08f8dbf7741e 8152911: javac assertion error when compiling overlay sources
jlahoda
parents: 40774
diff changeset
   965
            Assert.checkNonNull(name);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   966
            this.type = new ModuleType(this);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   967
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   968
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   969
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
45687
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 43772
diff changeset
   970
        public Name getSimpleName() {
45752
32eb45c44fc8 8183148: cleanup ModuleSymbol.getSimpleName
vromero
parents: 45744
diff changeset
   971
            return Convert.shortName(name);
45687
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 43772
diff changeset
   972
        }
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 43772
diff changeset
   973
07463ccee73b 8163989: Clarify ModuleElement spec
darcy
parents: 43772
diff changeset
   974
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
43376
f165c71d9e03 8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents: 43270
diff changeset
   975
        public boolean isOpen() {
f165c71d9e03 8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents: 43270
diff changeset
   976
            return flags.contains(ModuleFlags.OPEN);
f165c71d9e03 8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents: 43270
diff changeset
   977
        }
f165c71d9e03 8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents: 43270
diff changeset
   978
f165c71d9e03 8172810: ModuleElement should declare and provide appropriate modifiers
jjg
parents: 43270
diff changeset
   979
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   980
        public boolean isUnnamed() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   981
            return name.isEmpty() && owner == null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   982
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   983
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   984
        @Override
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   985
        public boolean isDeprecated() {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   986
            return hasDeprecatedAnnotation();
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   987
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
   988
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   989
        public boolean isNoModule() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   990
            return false;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   991
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   992
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   993
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   994
        public ElementKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   995
            return ElementKind.MODULE;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   996
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   997
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   998
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
   999
        public java.util.List<Directive> getDirectives() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1000
            apiComplete();
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1001
            completeUsesProvides();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1002
            return Collections.unmodifiableList(directives);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1003
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1004
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1005
        public void completeUsesProvides() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1006
            if (usesProvidesCompleter != Completer.NULL_COMPLETER) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1007
                Completer c = usesProvidesCompleter;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1008
                usesProvidesCompleter = Completer.NULL_COMPLETER;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1009
                c.complete(this);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1010
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1011
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1012
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1013
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1014
        public ClassSymbol outermostClass() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1015
            return null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1016
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1017
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1018
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1019
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1020
            // TODO: the following strings should be localized
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1021
            // Do this with custom anon subtypes in Symtab
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1022
            String n = (name == null) ? "<unknown>"
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1023
                    : (name.isEmpty()) ? "<unnamed>"
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1024
                    : String.valueOf(name);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1025
            return n;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1026
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1027
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37001
diff changeset
  1028
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1029
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1030
            return v.visitModule(this, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1031
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1032
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37001
diff changeset
  1033
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1034
        public List<Symbol> getEnclosedElements() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1035
            List<Symbol> list = List.nil();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1036
            for (Symbol sym : enclosedPackages) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1037
                if (sym.members().anyMatch(m -> m.kind == TYP))
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1038
                    list = list.prepend(sym);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1039
            }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1040
            return list;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1041
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1042
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1043
        public void reset() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1044
            this.directives = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1045
            this.requires = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1046
            this.exports = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1047
            this.provides = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1048
            this.uses = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1049
            this.visiblePackages = null;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1050
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1051
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1052
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1054
    public enum ModuleFlags {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1055
        OPEN(0x0020),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1056
        SYNTHETIC(0x1000),
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1057
        MANDATED(0x8000);
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1058
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1059
        public static int value(Set<ModuleFlags> s) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1060
            int v = 0;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1061
            for (ModuleFlags f: s)
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1062
                v |= f.value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1063
            return v;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1064
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1065
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1066
        private ModuleFlags(int value) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1067
            this.value = value;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1068
        }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1069
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1070
        public final int value;
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1071
    }
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1072
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1073
    public enum ModuleResolutionFlags {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1074
        DO_NOT_RESOLVE_BY_DEFAULT(0x0001),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1075
        WARN_DEPRECATED(0x0002),
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1076
        WARN_DEPRECATED_REMOVAL(0x0004),
43270
de9a02e20567 8171177: Compiler should issue a warning for incubating modules that are resolved
jlahoda
parents: 43265
diff changeset
  1077
        WARN_INCUBATING(0x0008);
42822
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1078
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1079
        public static int value(Set<ModuleResolutionFlags> s) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1080
            int v = 0;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1081
            for (ModuleResolutionFlags f: s)
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1082
                v |= f.value;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1083
            return v;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1084
        }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1085
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1086
        private ModuleResolutionFlags(int value) {
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1087
            this.value = value;
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1088
        }
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1089
a84956e7ee4d 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42407
diff changeset
  1090
        public final int value;
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1091
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41932
diff changeset
  1092
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
    /** A class for package symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
    public static class PackageSymbol extends TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
        implements PackageElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1098
        public WriteableScope members_field;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
        public ClassSymbol package_info; // see bug 6443073
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1101
        public ModuleSymbol modle;
43265
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 43138
diff changeset
  1102
        // the file containing the documentation comments for the package
4ec472ee5135 8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents: 43138
diff changeset
  1103
        public JavaFileObject sourcefile;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
        public PackageSymbol(Name name, Type type, Symbol owner) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16557
diff changeset
  1106
            super(PCK, 0, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
        public PackageSymbol(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
            this(name, null, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
            this.type = new PackageType(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
            return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1120
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1125
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
        public boolean isUnnamed() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
            return name.isEmpty() && owner != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1130
        public WriteableScope members() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1131
            complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        public long flags() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1136
            complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1140
        @Override
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1141
        public List<Attribute.Compound> getRawAttributes() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1142
            complete();
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1143
            if (package_info != null) {
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
  1144
                package_info.complete();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1145
                mergeAttributes();
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
  1146
            }
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1147
            return super.getRawAttributes();
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1148
        }
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1149
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1150
        private void mergeAttributes() {
21480
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
  1151
            if (metadata == null &&
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
  1152
                package_info.metadata != null) {
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
  1153
                metadata = new SymbolMetadata(this);
9d08c2d0fafd 8025109: Better encapsulation for AnnotatedType
jjg
parents: 21007
diff changeset
  1154
                metadata.setAttributes(package_info.metadata);
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
  1155
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
        /** A package "exists" if a type or package that exists has
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
         *  been seen within it.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
        public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
            return (flags_field & EXISTS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1165
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
            return ElementKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1170
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
        public Symbol getEnclosingElement() {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 34561
diff changeset
  1172
            return modle != null && !modle.isNoModule() ? modle : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1175
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            return v.visitPackage(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1179
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1180
        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
  1181
            return v.visitPackageSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1182
        }
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1183
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1184
        /**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
  1185
        public void reset() {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1186
            metadata = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1187
        }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1188
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
    /** A class for class symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
    public static class ClassSymbol extends TypeSymbol implements TypeElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
        /** a scope for all class members; variables, methods and inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
         *  type parameters are not part of this scope
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
         */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1198
        public WriteableScope members_field;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        /** the fully qualified name of the class, i.e. pck.outer.inner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
         *  null for anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
        /** the fully qualified name of the class after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
         *  representation, i.e. pck.outer$inner,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
         *  set externally for local and anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
        public Name flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
        /** the sourcefile where the class came from
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
        public JavaFileObject sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
        /** the classfile from where to load this class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
         *  this will have extension .class or .java
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
        public JavaFileObject classfile;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
  1220
        /** the list of translated local classes (used for generating
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
  1221
         * InnerClasses attribute)
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
  1222
         */
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
  1223
        public List<ClassSymbol> trans_local;
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
  1224
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
        /** the constant pool of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
        public Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1229
        /** the annotation metadata attached to this class */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1230
        private AnnotationTypeMetadata annotationTypeMetadata;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1231
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
        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
  1233
            super(TYP, flags, name, type, owner);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            this.flatname = formFlatName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
            this.sourcefile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
            this.classfile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
            this.pool = null;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1240
            this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        public ClassSymbol(long flags, Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
            this(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
                flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
                name,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1247
                new ClassType(Type.noType, null, null),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
                owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
            this.type.tsym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
            return className();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
        public long flags() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1259
            complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1263
        public WriteableScope members() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1264
            complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1268
        @Override
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1269
        public List<Attribute.Compound> getRawAttributes() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1270
            complete();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14956
diff changeset
  1271
            return super.getRawAttributes();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1274
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1275
        public List<Attribute.TypeCompound> getRawTypeAttributes() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  1276
            complete();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1277
            return super.getRawTypeAttributes();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1278
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1279
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
        public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
            if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
                erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
  1283
                                              List.nil(), this,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1284
                                              type.getMetadata());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
            return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        public String className() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1289
            if (name.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
                    Log.getLocalizedString("anonymous.class", flatname);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
                return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1296
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
        public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
            return flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            if (this == base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            } 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
  1309
                for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
                    for (List<Type> is = types.interfaces(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
                         is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
                         is = is.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
                        if (is.head.tsym.isSubClass(base, types)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
            } else {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1315
                for (Type t = type; t.hasTag(CLASS); t = types.supertype(t))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
                    if (t.tsym == base) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
        /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
        public void complete() throws CompletionFailure {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1324
            Completer origCompleter = completer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
                super.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
            } catch (CompletionFailure ex) {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1328
                ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
                // quiet error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
                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
  1331
                this.type = new ErrorType(this, Type.noType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
                throw ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1336
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
        public List<Type> getInterfaces() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1338
            apiComplete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
                if (t.interfaces_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
                    t.interfaces_field = List.nil();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1343
                if (t.all_interfaces_field != null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1344
                    return Type.getModelTypes(t.all_interfaces_field);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
                return t.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
                return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1351
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
        public Type getSuperclass() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1353
            apiComplete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
                if (t.supertype_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
                    t.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
                // An interface has no superclass; its supertype is Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
                return t.isInterface()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
                    ? Type.noType
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
  1361
                    : t.supertype_field.getModelType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
                return Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1367
        /**
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1368
         * Returns the next class to search for inherited annotations or {@code null}
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1369
         * if the next class can't be found.
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1370
         */
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1371
        private ClassSymbol getSuperClassToSearchForAnnotations() {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1372
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1373
            Type sup = getSuperclass();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1374
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1375
            if (!sup.hasTag(CLASS) || sup.isErroneous())
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1376
                return null;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1377
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1378
            return (ClassSymbol) sup.tsym;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1379
        }
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1380
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1381
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1382
        @Override
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1383
        protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1384
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1385
            ClassSymbol sup = getSuperClassToSearchForAnnotations();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1386
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1387
            return sup == null ? super.getInheritedAnnotations(annoType)
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1388
                               : sup.getAnnotationsByType(annoType);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1389
        }
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1390
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1391
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1392
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
        public ElementKind getKind() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1394
            apiComplete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
            if ((flags & ANNOTATION) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
                return ElementKind.ANNOTATION_TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
            else if ((flags & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
                return ElementKind.INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
            else if ((flags & ENUM) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
                return ElementKind.ENUM;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
                return ElementKind.CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1406
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
20610
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1407
        public Set<Modifier> getModifiers() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1408
            apiComplete();
20610
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1409
            long flags = flags();
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1410
            return Flags.asModifierSet(flags & ~DEFAULT);
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1411
        }
81a202481805 8025118: Annotation processing api returns default modifier for interface without default methods
jlahoda
parents: 20598
diff changeset
  1412
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1413
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
        public NestingKind getNestingKind() {
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  1415
            apiComplete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
            if (owner.kind == PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
                return NestingKind.TOP_LEVEL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
            else if (name.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
                return NestingKind.ANONYMOUS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
            else if (owner.kind == MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
                return NestingKind.LOCAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
                return NestingKind.MEMBER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1426
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1427
        @Override
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1428
        protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1429
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1430
            Attribute.Compound attrib = super.getAttribute(annoType);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1431
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1432
            boolean inherited = annoType.isAnnotationPresent(Inherited.class);
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1433
            if (attrib != null || !inherited)
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1434
                return attrib;
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1435
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1436
            // Search supertypes
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1437
            ClassSymbol superType = getSuperClassToSearchForAnnotations();
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1438
            return superType == null ? null
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1439
                                     : superType.getAttribute(annoType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1442
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1443
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20610
diff changeset
  1444
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1445
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
            return v.visitType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1449
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1450
        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
  1451
            return v.visitClassSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1452
        }
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1453
28459
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1454
        public void markAbstractIfNeeded(Types types) {
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1455
            if (types.enter.getEnv(this) != null &&
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1456
                (flags() & ENUM) != 0 && types.supertype(type).tsym == types.syms.enumSym &&
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1457
                (flags() & (FINAL | ABSTRACT)) == 0) {
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1458
                if (types.firstUnimplementedAbstract(this) != null)
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1459
                    // add the ABSTRACT flag to an enum
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1460
                    flags_field |= ABSTRACT;
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1461
            }
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1462
        }
48a68a485760 8068517: Compiler may generate wrong InnerClasses attribute for static enum reference
jlahoda
parents: 27224
diff changeset
  1463
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1464
        /**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
  1465
        public void reset() {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1466
            kind = TYP;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1467
            erasure_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1468
            members_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1469
            flags_field = 0;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1470
            if (type instanceof ClassType) {
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1471
                ClassType t = (ClassType)type;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1472
                t.setEnclosingType(Type.noType);
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1473
                t.rank_field = -1;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1474
                t.typarams_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1475
                t.allparams_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1476
                t.supertype_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1477
                t.interfaces_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1478
                t.all_interfaces_field = null;
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1479
            }
39372
a42db8c180c3 8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents: 37848
diff changeset
  1480
            clearAnnotationMetadata();
a42db8c180c3 8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents: 37848
diff changeset
  1481
        }
a42db8c180c3 8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents: 37848
diff changeset
  1482
a42db8c180c3 8132446: AsssertionError in ClassSymbol.setAnnotationType
sadayapalam
parents: 37848
diff changeset
  1483
        public void clearAnnotationMetadata() {
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1484
            metadata = null;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1485
            annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1486
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1487
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1488
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1489
        public AnnotationTypeMetadata getAnnotationTypeMetadata() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1490
            return annotationTypeMetadata;
23810
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1491
        }
b92eb80925f0 8038455: Use single Context for all rounds of annotation processing
jlahoda
parents: 23396
diff changeset
  1492
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1493
        @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1494
        public boolean isAnnotationType() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1495
            return (flags_field & Flags.ANNOTATION) != 0;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1496
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1497
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1498
        public void setAnnotationTypeMetadata(AnnotationTypeMetadata a) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1499
            Assert.checkNonNull(a);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1500
            Assert.check(!annotationTypeMetadata.isMetadataForAnnotationType());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1501
            this.annotationTypeMetadata = a;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1502
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
    /** A class for variable symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
    public static class VarSymbol extends Symbol implements VariableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
        /** The variable's declaration position.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
        public int pos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
        /** The variable's address. Used for different purposes during
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
         *  flow analysis, translation and code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
         *  Flow analysis:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
         *    If this is a blank final or local variable, its sequence number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
         *  Translation:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
         *    If this is a private field, its access number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
         *  Code generation:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
         *    If this is a local variable, its logical slot number.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
        public int adr = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
        /** Construct a variable symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
        public VarSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
            super(VAR, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
        public VarSymbol clone(Symbol newOwner) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1534
            VarSymbol v = new VarSymbol(flags_field, name, type, newOwner) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1535
                @Override
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1536
                public Symbol baseSymbol() {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1537
                    return VarSymbol.this;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1538
                }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1539
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
            v.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
            v.adr = adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
            v.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
//          System.out.println("clone " + v + " in " + newOwner);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
            return v;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
            return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
            return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1555
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
            if ((flags & PARAMETER) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
                if (isExceptionParameter())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
                    return ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1561
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
                    return ElementKind.PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
            } else if ((flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
                return ElementKind.ENUM_CONSTANT;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
            } else if (owner.kind == TYP || owner.kind == ERR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
                return ElementKind.FIELD;
6718
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
  1567
            } else if (isResourceVariable()) {
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
  1568
                return ElementKind.RESOURCE_VARIABLE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
                return ElementKind.LOCAL_VARIABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1573
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1574
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1575
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1576
            return v.visitVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1577
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1578
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1579
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
        public Object getConstantValue() { // Mirror API
06bc494ca11e Initial load
duke
parents:
diff changeset
  1581
            return Constants.decode(getConstValue(), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
06bc494ca11e Initial load
duke
parents:
diff changeset
  1584
        public void setLazyConstValue(final Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1585
                                      final Attr attr,
19942
e9dae0e41075 8021112: Spurious unchecked warning reported by javac
jlahoda
parents: 19928
diff changeset
  1586
                                      final JCVariableDecl variable)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1587
        {
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42822
diff changeset
  1588
            setData((Callable<Object>)() -> attr.attribLazyConstantValue(env, variable, type));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1589
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1590
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
         * The variable's constant value, if this is a constant.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
         * Before the constant value is evaluated, it points to an
19666
01a225608c25 8010310: [javadoc] Error processing sources with -private
jjg
parents: 19657
diff changeset
  1594
         * initializer environment.  If this is not a constant, it can
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
         * be used for other stuff.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1596
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1597
        private Object data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1598
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
        public boolean isExceptionParameter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1600
            return data == ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1601
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1603
        public boolean isResourceVariable() {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1604
            return data == ElementKind.RESOURCE_VARIABLE;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1605
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1606
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
        public Object getConstValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
            // 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
  1609
            if (data == ElementKind.EXCEPTION_PARAMETER ||
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1610
                data == ElementKind.RESOURCE_VARIABLE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
            } else if (data instanceof Callable<?>) {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1613
                // In this case, this is a final variable, with an as
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
                // yet unevaluated initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
                Callable<?> eval = (Callable<?>)data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
                data = null; // to make sure we don't evaluate this twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
                    data = eval.call();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
                } catch (Exception ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
                    throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
            return data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
        public void setData(Object data) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1627
            Assert.check(!(data instanceof Env<?>), this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
            this.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1630
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1631
        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
  1632
            return v.visitVarSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1633
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
    /** A class for method symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
    public static class MethodSymbol extends Symbol implements ExecutableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
        /** The code of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
        public Code code = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1643
        /** The extra (synthetic/mandated) parameters of the method. */
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1644
        public List<VarSymbol> extraParams = List.nil();
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15719
diff changeset
  1645
19657
48226ff07b84 8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents: 19492
diff changeset
  1646
        /** 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
  1647
        public List<VarSymbol> capturedLocals = List.nil();
48226ff07b84 8020745: Suspicious MethodParameters attribute generated for local classes capturing local variables
emc
parents: 19492
diff changeset
  1648
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
        /** The parameters of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1650
        public List<VarSymbol> params = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28459
diff changeset
  1652
        /** For an annotation type element, its default value if any.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
         *  The value is null if none appeared in the method
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
         *  declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
        public Attribute defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
        /** Construct a method symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
        public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            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
  1662
            if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
        public MethodSymbol clone(Symbol newOwner) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1668
            MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1669
                @Override
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1670
                public Symbol baseSymbol() {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1671
                    return MethodSymbol.this;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1672
                }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14051
diff changeset
  1673
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
            m.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
            return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1678
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
16970
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1679
        public Set<Modifier> getModifiers() {
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1680
            long flags = flags();
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1681
            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
  1682
        }
0967fa88590b 8011383: Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods
mcimadamore
parents: 16967
diff changeset
  1683
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
            if ((flags() & BLOCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
                return owner.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
            } else {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1690
                String s = (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
                    ? owner.name.toString()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
                    : name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
                if (type != null) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1694
                    if (type.hasTag(FORALL))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
                        s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
                    s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
                return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1702
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1703
            return false;
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
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
        /** find a symbol that this (proxy method) symbol implements.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
         *  @param    c       The class whose members are searched for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
         *                    implementations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
        public Symbol implemented(TypeSymbol c, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
            Symbol impl = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
            for (List<Type> is = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
                 impl == null && is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
                 is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
                TypeSymbol i = is.head.tsym;
7628
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1716
                impl = implementedIn(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1717
                if (impl == null)
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1718
                    impl = implemented(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1719
            }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1720
            return impl;
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1721
        }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1722
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1723
        public Symbol implementedIn(TypeSymbol c, Types types) {
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1724
            Symbol impl = null;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1725
            for (Symbol sym : c.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1726
                if (this.overrides(sym, (TypeSymbol)owner, types, true) &&
7628
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1727
                    // FIXME: I suspect the following requires a
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1728
                    // subst() for a parametric return type.
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1729
                    types.isSameType(type.getReturnType(),
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1730
                                     types.memberType(owner.type, sym).getReturnType())) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1731
                    impl = sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
            return impl;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
        /** Will the erasure of this method be considered by the VM to
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
         *  override the erasure of the other when seen from class `origin'?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
        public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
                types.asSuper(owner.type, other.owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1749
                types.isSameType(erasure(types), other.erasure(types)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1750
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1751
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
                (flags() & ABSTRACT) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
                other.isOverridableIn(origin) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
                this.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1757
                types.isSameType(erasure(types), other.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
        /** The implementation of this (abstract) symbol in class origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
         *  from the VM's point of view, null if method does not have an
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
         *  implementation in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
         *  @param origin   The class of which the implementation is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
        public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
            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
  1767
                for (Symbol sym : c.members().getSymbolsByName(name)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1768
                    if (sym.kind == MTH &&
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1769
                        ((MethodSymbol)sym).binaryOverrides(this, origin, types))
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25009
diff changeset
  1770
                        return (MethodSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1773
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
        /** Does this symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
  1777
         *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
  1778
         *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
         *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
         *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
         *
33367
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1783
         *  A quirk in the works is that if the receiver is a method symbol for
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1784
         *  an inherited abstract method we answer false summarily all else being
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1785
         *  immaterial. Abstract "own" methods (i.e `this' is a direct member of
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1786
         *  origin) don't get rejected as summarily and are put to test against the
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1787
         *  suitable criteria.
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1788
         *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
         *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
        public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
33367
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1792
            return overrides(_other, origin, types, checkResult, true);
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1793
        }
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1794
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1795
        /** Does this symbol override `other' symbol, when both are seen as
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1796
         *  members of class `origin'?  It is assumed that _other is a member
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1797
         *  of origin.
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1798
         *
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1799
         *  Caveat: If `this' is an abstract inherited member of origin, it is
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1800
         *  deemed to override `other' only when `requireConcreteIfInherited'
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1801
         *  is false.
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1802
         *
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1803
         *  It is assumed that both symbols have the same name.  The static
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1804
         *  modifier is ignored for this test.
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1805
         *
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1806
         *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1807
         */
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1808
        public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1809
                                            boolean requireConcreteIfInherited) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1810
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1811
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1817
                types.asSuper(owner.type, other.owner) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1818
                Type mt = types.memberType(owner.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
                Type ot = types.memberType(owner.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
                if (types.isSubSignature(mt, ot)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
                    if (!checkResult)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
                    if (types.returnTypeSubstitutable(mt, ot))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
            // check for an inherited implementation
33367
546ffcb790a5 8074803: Name clash
sadayapalam
parents: 33364
diff changeset
  1829
            if (((flags() & ABSTRACT) != 0 && requireConcreteIfInherited) ||
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1830
                    ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) ||
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1831
                    !other.isOverridableIn(origin) ||
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1832
                    !this.isMemberOf(origin, types))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
            // assert types.asSuper(origin.type, other.owner) != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
            Type mt = types.memberType(origin.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1837
            Type ot = types.memberType(origin.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
                types.isSubSignature(mt, ot) &&
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14443
diff changeset
  1840
                (!checkResult || types.resultSubtype(mt, ot, types.noWarnings));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
        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
  1844
            // JLS 8.4.6.1
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
            switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
            case Flags.PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1847
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
            case Flags.PUBLIC:
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1849
                return !this.owner.isInterface() ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1850
                        (flags_field & STATIC) == 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
            case Flags.PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
                return (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
            case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
                // for package private: can only override in the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
                // package
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
                    this.packge() == origin.packge() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
                    (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1864
        @Override
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1865
        public boolean isInheritedIn(Symbol clazz, Types types) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1866
            switch ((int)(flags_field & Flags.AccessFlags)) {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1867
                case PUBLIC:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1868
                    return !this.owner.isInterface() ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1869
                            clazz == owner ||
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1870
                            (flags_field & STATIC) == 0;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1871
                default:
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1872
                    return super.isInheritedIn(clazz, types);
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1873
            }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1874
        }
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15355
diff changeset
  1875
33364
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 30066
diff changeset
  1876
        public boolean isLambdaMethod() {
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 30066
diff changeset
  1877
            return (flags() & LAMBDA_METHOD) == LAMBDA_METHOD;
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 30066
diff changeset
  1878
        }
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 30066
diff changeset
  1879
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1880
        /** The implementation of this (abstract) symbol in class origin;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
         *  null if none exists. Synthetic methods are not considered
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
         *  as possible implementations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
        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
  1885
            return implementation(origin, types, checkResult, implementation_filter);
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1886
        }
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1887
        // where
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42822
diff changeset
  1888
            public static final Filter<Symbol> implementation_filter = s ->
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42822
diff changeset
  1889
                    s.kind == MTH && (s.flags() & SYNTHETIC) == 0;
6591
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1890
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1891
        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
  1892
            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
  1893
            if (res != null)
3c265cb6f4e0 6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents: 3149
diff changeset
  1894
                return res;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
            // if origin is derived from a raw type, we might have missed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1896
            // an implementation because we do not know enough about instantiations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1897
            // 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
  1898
            if (types.isDerivedRaw(origin.type) && !origin.isInterface())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1899
                return implementation(types.supertype(origin.type).tsym, types, checkResult);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1900
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1901
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1902
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1903
06bc494ca11e Initial load
duke
parents:
diff changeset
  1904
        public List<VarSymbol> params() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1905
            owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1906
            if (params == null) {
48344
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1907
                ListBuffer<VarSymbol> newParams = new ListBuffer<>();
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1908
                int i = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1909
                for (Type t : type.getParameterTypes()) {
48344
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1910
                    Name paramName = name.table.fromString("arg" + i);
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1911
                    VarSymbol param = new VarSymbol(PARAMETER, paramName, t, this);
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1912
                    newParams.append(param);
48683
b2f2bdba0472 8194268: Incorrect parameter names for synthetic methods
cushon
parents: 48344
diff changeset
  1913
                    i++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1914
                }
48344
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1915
                params = newParams.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1916
            }
48344
89f6aa26fd6c 8007720: Names are not loaded correctly for method parameters if the parameters have annotations
cushon
parents: 47216
diff changeset
  1917
            Assert.checkNonNull(params);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1918
            return params;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1919
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1920
06bc494ca11e Initial load
duke
parents:
diff changeset
  1921
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1922
            return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1923
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1924
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1925
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1926
        public ElementKind getKind() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1927
            if (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1928
                return ElementKind.CONSTRUCTOR;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1929
            else if (name == name.table.names.clinit)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1930
                return ElementKind.STATIC_INIT;
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1931
            else if ((flags() & BLOCK) != 0)
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1932
                return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1933
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1934
                return ElementKind.METHOD;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1935
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1936
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1937
        public boolean isStaticOrInstanceInit() {
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1938
            return getKind() == ElementKind.STATIC_INIT ||
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1939
                    getKind() == ElementKind.INSTANCE_INIT;
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1940
        }
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1941
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1942
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1943
        public Attribute getDefaultValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1944
            return defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1945
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1946
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1947
        @DefinedBy(Api.LANGUAGE_MODEL)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
  1948
        public List<VarSymbol> getParameters() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1949
            return params();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1950
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1951
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1952
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1953
        public boolean isVarArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1954
            return (flags() & VARARGS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1955
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1956
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1957
        @DefinedBy(Api.LANGUAGE_MODEL)
14956
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1958
        public boolean isDefault() {
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1959
            return (flags() & DEFAULT) != 0;
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1960
        }
185bd7c693d8 8005046: Provide checking for a default method in javax.lang.model
darcy
parents: 14547
diff changeset
  1961
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1962
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1963
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1964
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1965
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1966
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1967
        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
  1968
            return v.visitMethodSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1969
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1970
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1971
        @DefinedBy(Api.LANGUAGE_MODEL)
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1972
        public Type getReceiverType() {
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1973
            return asType().getReceiverType();
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1974
        }
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16333
diff changeset
  1975
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1976
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1977
        public Type getReturnType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1978
            return asType().getReturnType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1979
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1980
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1981
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1982
        public List<Type> getThrownTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1983
            return asType().getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1984
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1985
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1986
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1987
    /** A class for invokedynamic method calls.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1988
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1989
    public static class DynamicMethodSymbol extends MethodSymbol {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1990
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1991
        public Object[] staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1992
        public Symbol bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1993
        public int bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1994
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1995
        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
  1996
            super(0, name, type, owner);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1997
            this.bsm = bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1998
            this.bsmKind = bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1999
            this.staticArgs = staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2000
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2001
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2002
        @Override
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2003
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2004
            return true;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2005
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2006
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  2007
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2008
    /** A class for predefined operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2009
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2010
    public static class OperatorSymbol extends MethodSymbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2011
06bc494ca11e Initial load
duke
parents:
diff changeset
  2012
        public int opcode;
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2013
        private int accessCode = Integer.MIN_VALUE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2014
06bc494ca11e Initial load
duke
parents:
diff changeset
  2015
        public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2016
            super(PUBLIC | STATIC, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2017
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2018
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2019
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2020
        @Override
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2021
        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
  2022
            return v.visitOperatorSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2023
        }
39920
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2024
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2025
        public int getAccessCode(Tag tag) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2026
            if (accessCode != Integer.MIN_VALUE && !tag.isIncOrDecUnaryOp()) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2027
                return accessCode;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2028
            }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2029
            accessCode = AccessCode.from(tag, opcode);
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2030
            return accessCode;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2031
        }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2032
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2033
        /** Access codes for dereferencing, assignment,
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2034
         *  and pre/post increment/decrement.
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2035
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2036
         *  All access codes for accesses to the current class are even.
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2037
         *  If a member of the superclass should be accessed instead (because
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2038
         *  access was via a qualified super), add one to the corresponding code
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2039
         *  for the current class, making the number odd.
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2040
         *  This numbering scheme is used by the backend to decide whether
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2041
         *  to issue an invokevirtual or invokespecial call.
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2042
         *
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2043
         *  @see Gen#visitSelect(JCFieldAccess tree)
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2044
         */
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2045
        public enum AccessCode {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2046
            UNKNOWN(-1, Tag.NO_TAG),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2047
            DEREF(0, Tag.NO_TAG),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2048
            ASSIGN(2, Tag.ASSIGN),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2049
            PREINC(4, Tag.PREINC),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2050
            PREDEC(6, Tag.PREDEC),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2051
            POSTINC(8, Tag.POSTINC),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2052
            POSTDEC(10, Tag.POSTDEC),
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2053
            FIRSTASGOP(12, Tag.NO_TAG);
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2054
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2055
            public final int code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2056
            public final Tag tag;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2057
            public static final int numberOfAccessCodes = (lushrl - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code + 2;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2058
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2059
            AccessCode(int code, Tag tag) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2060
                this.code = code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2061
                this.tag = tag;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2062
            }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2063
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2064
            static public AccessCode getFromCode(int code) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2065
                for (AccessCode aCodes : AccessCode.values()) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2066
                    if (aCodes.code == code) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2067
                        return aCodes;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2068
                    }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2069
                }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2070
                return UNKNOWN;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2071
            }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2072
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2073
            static int from(Tag tag, int opcode) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2074
                /** Map bytecode of binary operation to access code of corresponding
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2075
                *  assignment operation. This is always an even number.
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2076
                */
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2077
                switch (tag) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2078
                    case PREINC:
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2079
                        return AccessCode.PREINC.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2080
                    case PREDEC:
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2081
                        return AccessCode.PREDEC.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2082
                    case POSTINC:
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2083
                        return AccessCode.POSTINC.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2084
                    case POSTDEC:
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2085
                        return AccessCode.POSTDEC.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2086
                }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2087
                if (iadd <= opcode && opcode <= lxor) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2088
                    return (opcode - iadd) * 2 + FIRSTASGOP.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2089
                } else if (opcode == string_add) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2090
                    return (lxor + 1 - iadd) * 2 + FIRSTASGOP.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2091
                } else if (ishll <= opcode && opcode <= lushrl) {
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2092
                    return (opcode - ishll + lxor + 2 - iadd) * 2 + FIRSTASGOP.code;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2093
                }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2094
                return -1;
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2095
            }
4923274643f2 8161708: javac, consider a different way to handle access code for operators
vromero
parents: 39372
diff changeset
  2096
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2097
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2098
06bc494ca11e Initial load
duke
parents:
diff changeset
  2099
    /** Symbol completer interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2101
    public static interface Completer {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2102
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2103
        /** Dummy completer to be used when the symbol has been completed or
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2104
         * does not need completion.
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2105
         */
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2106
        public final static Completer NULL_COMPLETER = new Completer() {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2107
            public void complete(Symbol sym) { }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2108
            public boolean isTerminal() { return true; }
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2109
        };
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2110
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2111
        void complete(Symbol sym) throws CompletionFailure;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2112
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2113
        /** Returns true if this completer is <em>terminal</em>. A terminal
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2114
         * completer is used as a place holder when the symbol is completed.
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2115
         * Calling complete on a terminal completer will not affect the symbol.
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2116
         *
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2117
         * The dummy NULL_COMPLETER and the GraphDependencies completer are
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2118
         * examples of terminal completers.
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2119
         *
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2120
         * @return true iff this completer is terminal
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2121
         */
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2122
        default boolean isTerminal() {
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2123
            return false;
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 29842
diff changeset
  2124
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2126
06bc494ca11e Initial load
duke
parents:
diff changeset
  2127
    public static class CompletionFailure extends RuntimeException {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2128
        private static final long serialVersionUID = 0;
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  2129
        public final DeferredCompletionFailureHandler dcfh;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2130
        public Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2131
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2132
        /** A diagnostic object describing the failure
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2133
         */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2134
        public JCDiagnostic diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2135
49197
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  2136
        public CompletionFailure(Symbol sym, JCDiagnostic diag, DeferredCompletionFailureHandler dcfh) {
cc2673fa8c20 8187950: javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
jlahoda
parents: 48945
diff changeset
  2137
            this.dcfh = dcfh;
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2138
            this.sym = sym;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2139
            this.diag = diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2140
//          this.printStackTrace();//DEBUG
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2141
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2142
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2143
        public JCDiagnostic getDiagnostic() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2144
            return diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2145
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2146
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2147
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2148
        public String getMessage() {
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 43772
diff changeset
  2149
            return diag.getMessage(null);
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2150
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  2151
45504
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 43772
diff changeset
  2152
        public JCDiagnostic getDetailValue() {
ea7475564d07 8170326: Inconsistencies between code, compiler.properties and comments
jlahoda
parents: 43772
diff changeset
  2153
            return diag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2154
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
06bc494ca11e Initial load
duke
parents:
diff changeset
  2156
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2157
        public CompletionFailure initCause(Throwable cause) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2158
            super.initCause(cause);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2159
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2160
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2161
06bc494ca11e Initial load
duke
parents:
diff changeset
  2162
    }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2163
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2164
    /**
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2165
     * A visitor for symbols.  A visitor is used to implement operations
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2166
     * (or relations) on symbols.  Most common operations on types are
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2167
     * binary relations and this interface is designed for binary
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2168
     * relations, that is, operations on the form
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2169
     * Symbol&nbsp;&times;&nbsp;P&nbsp;&rarr;&nbsp;R.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2170
     * <!-- In plain text: Type x P -> R -->
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2171
     *
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2172
     * @param <R> the return type of the operation implemented by this
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2173
     * visitor; use Void if no return type is needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2174
     * @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
  2175
     * symbol itself) of the operation implemented by this visitor; use
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2176
     * Void if a second argument is not needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2177
     */
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2178
    public interface Visitor<R,P> {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2179
        R visitClassSymbol(ClassSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2180
        R visitMethodSymbol(MethodSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2181
        R visitPackageSymbol(PackageSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2182
        R visitOperatorSymbol(OperatorSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2183
        R visitVarSymbol(VarSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2184
        R visitTypeSymbol(TypeSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2185
        R visitSymbol(Symbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  2186
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
}