author | mcimadamore |
Thu, 05 Oct 2017 12:19:23 +0100 | |
changeset 47315 | 31f541df4187 |
parent 47216 | 71c04702a3d5 |
child 51563 | de411d537aae |
permissions | -rw-r--r-- |
10 | 1 |
/* |
43865
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
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 | 29 |
import com.sun.tools.javac.util.*; |
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; |
10 | 32 |
|
33 |
/** Contains information specific to the attribute and enter |
|
34 |
* passes, to be used in place of the generic field in environments. |
|
35 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
36 |
* <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
|
37 |
* If you write code that depends on this, you do so at your own risk. |
10 | 38 |
* This code and its internal interfaces are subject to change or |
39 |
* deletion without notice.</b> |
|
40 |
*/ |
|
41 |
public class AttrContext { |
|
42 |
||
43 |
/** The scope of local symbols. |
|
44 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
45 |
WriteableScope scope = null; |
10 | 46 |
|
47 |
/** The number of enclosing `static' modifiers. |
|
48 |
*/ |
|
49 |
int staticLevel = 0; |
|
50 |
||
51 |
/** Is this an environment for a this(...) or super(...) call? |
|
52 |
*/ |
|
53 |
boolean isSelfCall = false; |
|
54 |
||
55 |
/** Are we evaluating the selector of a `super' or type name? |
|
56 |
*/ |
|
57 |
boolean selectSuper = false; |
|
58 |
||
41629 | 59 |
/** Is the current target of lambda expression or method reference serializable or is this a |
60 |
* serializable class? |
|
24219 | 61 |
*/ |
62 |
boolean isSerializable = false; |
|
63 |
||
41629 | 64 |
/** Is this a lambda environment? |
65 |
*/ |
|
66 |
boolean isLambda = false; |
|
67 |
||
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
26532
diff
changeset
|
68 |
/** Is this a speculative attribution environment? |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
26532
diff
changeset
|
69 |
*/ |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
26532
diff
changeset
|
70 |
boolean isSpeculative = false; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
26532
diff
changeset
|
71 |
|
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
72 |
/** |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
73 |
* Is this an attribution environment for an anonymous class instantiated using <> ? |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
74 |
*/ |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
75 |
boolean isAnonymousDiamond = false; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
76 |
|
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
77 |
/** |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
78 |
* 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
|
79 |
*/ |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
80 |
boolean isNewClass = false; |
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
81 |
|
43865
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
82 |
/** Indicate if the type being visited is a service implementation |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
83 |
*/ |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
84 |
boolean visitingServiceImplementation = false; |
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
85 |
|
10 | 86 |
/** Are arguments to current function applications boxed into an array for varargs? |
87 |
*/ |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
88 |
Resolve.MethodResolutionPhase pendingResolutionPhase = null; |
10 | 89 |
|
90 |
/** A record of the lint/SuppressWarnings currently in effect |
|
91 |
*/ |
|
92 |
Lint lint; |
|
93 |
||
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
10
diff
changeset
|
94 |
/** The variable whose initializer is being attributed |
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
10
diff
changeset
|
95 |
* 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
|
96 |
*/ |
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
10
diff
changeset
|
97 |
Symbol enclVar = null; |
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
10
diff
changeset
|
98 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
99 |
/** ResultInfo to be used for attributing 'return' statement expressions |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
100 |
* (set by Attr.visitMethod and Attr.visitLambda) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
101 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
102 |
Attr.ResultInfo returnResult = null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
103 |
|
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14057
diff
changeset
|
104 |
/** 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
|
105 |
*/ |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14057
diff
changeset
|
106 |
Type defaultSuperCallSite = null; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14057
diff
changeset
|
107 |
|
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
29842
diff
changeset
|
108 |
/** 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
|
109 |
* 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
|
110 |
* 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
|
111 |
* contexts (JDK-8145466) |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
29842
diff
changeset
|
112 |
*/ |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
29842
diff
changeset
|
113 |
JCTree preferredTreeForDiagnostics; |
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
29842
diff
changeset
|
114 |
|
10 | 115 |
/** Duplicate this context, replacing scope field and copying all others. |
116 |
*/ |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
117 |
AttrContext dup(WriteableScope scope) { |
10 | 118 |
AttrContext info = new AttrContext(); |
119 |
info.scope = scope; |
|
120 |
info.staticLevel = staticLevel; |
|
121 |
info.isSelfCall = isSelfCall; |
|
122 |
info.selectSuper = selectSuper; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
123 |
info.pendingResolutionPhase = pendingResolutionPhase; |
10 | 124 |
info.lint = lint; |
1045
56f6e84f7825
6676362: Spurious forward reference error with final var + instance variable initializer
mcimadamore
parents:
10
diff
changeset
|
125 |
info.enclVar = enclVar; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
126 |
info.returnResult = returnResult; |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14057
diff
changeset
|
127 |
info.defaultSuperCallSite = defaultSuperCallSite; |
24219 | 128 |
info.isSerializable = isSerializable; |
41629 | 129 |
info.isLambda = isLambda; |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
26532
diff
changeset
|
130 |
info.isSpeculative = isSpeculative; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
28142
diff
changeset
|
131 |
info.isAnonymousDiamond = isAnonymousDiamond; |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
132 |
info.isNewClass = isNewClass; |
34854
d90aa0a83be4
8145466: javac: No line numbers in compilation error
sadayapalam
parents:
29842
diff
changeset
|
133 |
info.preferredTreeForDiagnostics = preferredTreeForDiagnostics; |
43865
532c50fea155
8174243: incorrect error message for nested service provider
vromero
parents:
41629
diff
changeset
|
134 |
info.visitingServiceImplementation = visitingServiceImplementation; |
10 | 135 |
return info; |
136 |
} |
|
137 |
||
138 |
/** Duplicate this context, copying all fields. |
|
139 |
*/ |
|
140 |
AttrContext dup() { |
|
141 |
return dup(scope); |
|
142 |
} |
|
143 |
||
144 |
public Iterable<Symbol> getLocalElements() { |
|
145 |
if (scope == null) |
|
146 |
return List.nil(); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24895
diff
changeset
|
147 |
return scope.getSymbols(); |
10 | 148 |
} |
149 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
150 |
boolean lastResolveVarargs() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
151 |
return pendingResolutionPhase != null && |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
152 |
pendingResolutionPhase.isVarargsRequired(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
153 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13631
diff
changeset
|
154 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14443
diff
changeset
|
155 |
@Override |
10 | 156 |
public String toString() { |
157 |
return "AttrContext[" + scope.toString() + "]"; |
|
158 |
} |
|
159 |
} |