35 import com.sun.tools.javac.tree.*; |
35 import com.sun.tools.javac.tree.*; |
36 import com.sun.tools.javac.util.*; |
36 import com.sun.tools.javac.util.*; |
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
38 |
38 |
39 import com.sun.tools.javac.code.Symbol.*; |
39 import com.sun.tools.javac.code.Symbol.*; |
|
40 import com.sun.tools.javac.comp.Resolve; |
40 import com.sun.tools.javac.tree.JCTree.*; |
41 import com.sun.tools.javac.tree.JCTree.*; |
41 |
42 |
42 import static com.sun.tools.javac.code.Flags.*; |
43 import static com.sun.tools.javac.code.Flags.*; |
43 import static com.sun.tools.javac.code.Kinds.*; |
44 import static com.sun.tools.javac.code.Kinds.*; |
44 import static com.sun.tools.javac.code.TypeTags.*; |
45 import static com.sun.tools.javac.code.TypeTags.*; |
185 private final Log log; |
186 private final Log log; |
186 private final Symtab syms; |
187 private final Symtab syms; |
187 private final Types types; |
188 private final Types types; |
188 private final Check chk; |
189 private final Check chk; |
189 private TreeMaker make; |
190 private TreeMaker make; |
|
191 private final Resolve rs; |
|
192 private Env<AttrContext> attrEnv; |
190 private Lint lint; |
193 private Lint lint; |
191 private final boolean allowRethrowAnalysis; |
194 private final boolean allowRethrowAnalysis; |
192 |
195 |
193 public static Flow instance(Context context) { |
196 public static Flow instance(Context context) { |
194 Flow instance = context.get(flowKey); |
197 Flow instance = context.get(flowKey); |
203 log = Log.instance(context); |
206 log = Log.instance(context); |
204 syms = Symtab.instance(context); |
207 syms = Symtab.instance(context); |
205 types = Types.instance(context); |
208 types = Types.instance(context); |
206 chk = Check.instance(context); |
209 chk = Check.instance(context); |
207 lint = Lint.instance(context); |
210 lint = Lint.instance(context); |
|
211 rs = Resolve.instance(context); |
208 Source source = Source.instance(context); |
212 Source source = Source.instance(context); |
209 allowRethrowAnalysis = source.allowMulticatch(); |
213 allowRethrowAnalysis = source.allowMulticatch(); |
210 } |
214 } |
211 |
215 |
212 /** A flag that indicates whether the last statement could |
216 /** A flag that indicates whether the last statement could |
996 } else { |
1000 } else { |
997 throw new AssertionError(tree); // parser error |
1001 throw new AssertionError(tree); // parser error |
998 } |
1002 } |
999 } |
1003 } |
1000 for (JCTree resource : tree.resources) { |
1004 for (JCTree resource : tree.resources) { |
1001 MethodSymbol topCloseMethod = (MethodSymbol)syms.autoCloseableType.tsym.members().lookup(names.close).sym; |
|
1002 List<Type> closeableSupertypes = resource.type.isCompound() ? |
1005 List<Type> closeableSupertypes = resource.type.isCompound() ? |
1003 types.interfaces(resource.type).prepend(types.supertype(resource.type)) : |
1006 types.interfaces(resource.type).prepend(types.supertype(resource.type)) : |
1004 List.of(resource.type); |
1007 List.of(resource.type); |
1005 for (Type sup : closeableSupertypes) { |
1008 for (Type sup : closeableSupertypes) { |
1006 if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) { |
1009 if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) { |
1007 MethodSymbol closeMethod = types.implementation(topCloseMethod, sup.tsym, types, true); |
1010 Symbol closeMethod = rs.resolveInternalMethod(tree, |
1008 for (Type t : closeMethod.getThrownTypes()) { |
1011 attrEnv, |
1009 markThrown(tree.body, t); |
1012 sup, |
|
1013 names.close, |
|
1014 List.<Type>nil(), |
|
1015 List.<Type>nil()); |
|
1016 if (closeMethod.kind == MTH) { |
|
1017 for (Type t : ((MethodSymbol)closeMethod).getThrownTypes()) { |
|
1018 markThrown(tree.body, t); |
|
1019 } |
1010 } |
1020 } |
1011 } |
1021 } |
1012 } |
1022 } |
1013 } |
1023 } |
1014 scanStat(tree.body); |
1024 scanStat(tree.body); |
1385 * main method |
1395 * main method |
1386 *************************************************************************/ |
1396 *************************************************************************/ |
1387 |
1397 |
1388 /** Perform definite assignment/unassignment analysis on a tree. |
1398 /** Perform definite assignment/unassignment analysis on a tree. |
1389 */ |
1399 */ |
1390 public void analyzeTree(JCTree tree, TreeMaker make) { |
1400 public void analyzeTree(Env<AttrContext> env, TreeMaker make) { |
1391 try { |
1401 try { |
|
1402 attrEnv = env; |
|
1403 JCTree tree = env.tree; |
1392 this.make = make; |
1404 this.make = make; |
1393 inits = new Bits(); |
1405 inits = new Bits(); |
1394 uninits = new Bits(); |
1406 uninits = new Bits(); |
1395 uninitsTry = new Bits(); |
1407 uninitsTry = new Bits(); |
1396 initsWhenTrue = initsWhenFalse = |
1408 initsWhenTrue = initsWhenFalse = |