src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrContext.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57963 ed7eb20871c5
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
55306
ea43db53de91 8223305: Compiler support for Switch Expressions
jlahoda
parents: 51563
diff changeset
     2
 * Copyright (c) 1999, 2019, 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: 1264
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: 1264
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: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
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.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
34854
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
    28
import com.sun.tools.javac.tree.JCTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
    31
import com.sun.tools.javac.code.Scope.WriteableScope;
57963
ed7eb20871c5 8230105: -XDfind=diamond crashes
jlahoda
parents: 55306
diff changeset
    32
import com.sun.tools.javac.comp.DeferredAttr.AttributionMode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/** Contains information specific to the attribute and enter
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *  passes, to be used in place of the generic field in environments.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    37
 *  <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
    38
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
public class AttrContext {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    /** The scope of local symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
    46
    WriteableScope scope = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /** The number of enclosing `static' modifiers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    int staticLevel = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /** Is this an environment for a this(...) or super(...) call?
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    boolean isSelfCall = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    /** Are we evaluating the selector of a `super' or type name?
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    boolean selectSuper = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
41629
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    60
    /** Is the current target of lambda expression or method reference serializable or is this a
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    61
     *  serializable class?
24219
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 14541
diff changeset
    62
     */
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 14541
diff changeset
    63
    boolean isSerializable = false;
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 14541
diff changeset
    64
41629
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    65
    /** Is this a lambda environment?
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    66
     */
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    67
    boolean isLambda = false;
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
    68
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 26532
diff changeset
    69
    /** Is this a speculative attribution environment?
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 26532
diff changeset
    70
     */
57963
ed7eb20871c5 8230105: -XDfind=diamond crashes
jlahoda
parents: 55306
diff changeset
    71
    AttributionMode attributionMode = AttributionMode.FULL;
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 26532
diff changeset
    72
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
    73
    /**
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
    74
     *  Is this an attribution environment for an anonymous class instantiated using <> ?
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
    75
     */
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
    76
    boolean isAnonymousDiamond = false;
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
    77
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
    78
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
    79
     *  Is this an attribution environment for an instance creation expression?
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
    80
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
    81
    boolean isNewClass = false;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
    82
43865
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 41629
diff changeset
    83
    /** Indicate if the type being visited is a service implementation
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 41629
diff changeset
    84
     */
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 41629
diff changeset
    85
    boolean visitingServiceImplementation = false;
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 41629
diff changeset
    86
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    /** Are arguments to current function applications boxed into an array for varargs?
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
    89
    Resolve.MethodResolutionPhase pendingResolutionPhase = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /** A record of the lint/SuppressWarnings currently in effect
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    Lint lint;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
1045
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
    95
    /** The variable whose initializer is being attributed
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
    96
     * useful for detecting self-references in variable initializers
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
    97
     */
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
    98
    Symbol enclVar = null;
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
    99
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   100
    /** ResultInfo to be used for attributing 'return' statement expressions
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   101
     * (set by Attr.visitMethod and Attr.visitLambda)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   102
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   103
    Attr.ResultInfo returnResult = null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   104
55306
ea43db53de91 8223305: Compiler support for Switch Expressions
jlahoda
parents: 51563
diff changeset
   105
    /** ResultInfo to be used for attributing 'yield' statement expressions
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   106
     * (set by Attr.visitSwitchExpression)
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   107
     */
55306
ea43db53de91 8223305: Compiler support for Switch Expressions
jlahoda
parents: 51563
diff changeset
   108
    Attr.ResultInfo yieldResult = null;
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   109
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14057
diff changeset
   110
    /** Symbol corresponding to the site of a qualified default super call
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14057
diff changeset
   111
     */
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14057
diff changeset
   112
    Type defaultSuperCallSite = null;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14057
diff changeset
   113
34854
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   114
    /** Tree that when non null, is to be preferentially used in diagnostics.
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   115
     *  Usually Env<AttrContext>.tree is the tree to be referred to in messages,
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   116
     *  but this may not be true during the window a method is looked up in enclosing
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   117
     *  contexts (JDK-8145466)
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   118
     */
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   119
    JCTree preferredTreeForDiagnostics;
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   120
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /** Duplicate this context, replacing scope field and copying all others.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   123
    AttrContext dup(WriteableScope scope) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        AttrContext info = new AttrContext();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        info.scope = scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        info.staticLevel = staticLevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        info.isSelfCall = isSelfCall;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        info.selectSuper = selectSuper;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   129
        info.pendingResolutionPhase = pendingResolutionPhase;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        info.lint = lint;
1045
56f6e84f7825 6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents: 10
diff changeset
   131
        info.enclVar = enclVar;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   132
        info.returnResult = returnResult;
55306
ea43db53de91 8223305: Compiler support for Switch Expressions
jlahoda
parents: 51563
diff changeset
   133
        info.yieldResult = yieldResult;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14057
diff changeset
   134
        info.defaultSuperCallSite = defaultSuperCallSite;
24219
e7dc661cafae 8029102: Enhance compiler warnings for Lambda
vromero
parents: 14541
diff changeset
   135
        info.isSerializable = isSerializable;
41629
9d203cde7d84 8026721: Enhance Lambda serialization
vromero
parents: 34854
diff changeset
   136
        info.isLambda = isLambda;
57963
ed7eb20871c5 8230105: -XDfind=diamond crashes
jlahoda
parents: 55306
diff changeset
   137
        info.attributionMode = attributionMode;
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 28142
diff changeset
   138
        info.isAnonymousDiamond = isAnonymousDiamond;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29776
diff changeset
   139
        info.isNewClass = isNewClass;
34854
d90aa0a83be4 8145466: javac: No line numbers in compilation error
sadayapalam
parents: 29842
diff changeset
   140
        info.preferredTreeForDiagnostics = preferredTreeForDiagnostics;
43865
532c50fea155 8174243: incorrect error message for nested service provider
vromero
parents: 41629
diff changeset
   141
        info.visitingServiceImplementation = visitingServiceImplementation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        return info;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /** Duplicate this context, copying all fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    AttrContext dup() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        return dup(scope);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    public Iterable<Symbol> getLocalElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        if (scope == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
            return List.nil();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24895
diff changeset
   154
        return scope.getSymbols();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   157
    boolean lastResolveVarargs() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   158
        return pendingResolutionPhase != null &&
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   159
                pendingResolutionPhase.isVarargsRequired();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   160
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13631
diff changeset
   161
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14443
diff changeset
   162
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        return "AttrContext[" + scope.toString() + "]";
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
}