1508 1509 private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) { 1510 // primaryException.addSuppressed(catchException); 1511 VarSymbol catchException = 1512 new VarSymbol(0, make.paramName(2), 1513 syms.throwableType, 1514 currentMethodSym); 1515 JCStatement addSuppressionStatement = 1516 make.Exec(makeCall(make.Ident(primaryException), 1517 names.addSuppressed, 1518 List.<JCExpression>of(make.Ident(catchException)))); 1519 1520 // try { resource.close(); } catch (e) { primaryException.addSuppressed(e); } 1521 JCBlock tryBlock = 1522 make.Block(0L, List.<JCStatement>of(makeResourceCloseInvocation(resource))); 1523 JCVariableDecl catchExceptionDecl = make.VarDef(catchException, null); 1524 JCBlock catchBlock = make.Block(0L, List.<JCStatement>of(addSuppressionStatement)); 1525 List<JCCatch> catchClauses = List.<JCCatch>of(make.Catch(catchExceptionDecl, catchBlock)); 1526 JCTry tryTree = make.Try(tryBlock, catchClauses, null); 1527 1528 // if (resource != null) resourceClose; 1529 JCExpression nullCheck = makeBinary(JCTree.NE, 1530 make.Ident(primaryException), 1531 makeNull()); 1532 JCIf closeIfStatement = make.If(nullCheck, 1533 tryTree, 1534 makeResourceCloseInvocation(resource)); 1535 return make.Block(0L, List.<JCStatement>of(closeIfStatement)); 1536 } 1537 1538 private JCStatement makeResourceCloseInvocation(JCExpression resource) { 1539 // create resource.close() method invocation 1540 JCExpression resourceClose = makeCall(resource, names.close, List.<JCExpression>nil()); 1541 return make.Exec(resourceClose); 1542 } 1543 1544 /** Construct a tree that represents the outer instance 1545 * <C.this>. Never pick the current `this'. 1546 * @param pos The source code position to be used for the tree. 1547 * @param c The qualifier class. 1548 */ 1549 JCExpression makeOuterThis(DiagnosticPosition pos, TypeSymbol c) { 1550 List<VarSymbol> ots = outerThisStack; 1551 if (ots.isEmpty()) { 1552 log.error(pos, "no.encl.instance.of.type.in.scope", c); 1553 Assert.error(); 1554 return makeNull(); 1555 } 1556 VarSymbol ot = ots.head; 1557 JCExpression tree = access(make.at(pos).Ident(ot)); 1558 TypeSymbol otc = ot.type.tsym; 1559 while (otc != c) { 1560 do { 1561 ots = ots.tail; | 1508 1509 private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) { 1510 // primaryException.addSuppressed(catchException); 1511 VarSymbol catchException = 1512 new VarSymbol(0, make.paramName(2), 1513 syms.throwableType, 1514 currentMethodSym); 1515 JCStatement addSuppressionStatement = 1516 make.Exec(makeCall(make.Ident(primaryException), 1517 names.addSuppressed, 1518 List.<JCExpression>of(make.Ident(catchException)))); 1519 1520 // try { resource.close(); } catch (e) { primaryException.addSuppressed(e); } 1521 JCBlock tryBlock = 1522 make.Block(0L, List.<JCStatement>of(makeResourceCloseInvocation(resource))); 1523 JCVariableDecl catchExceptionDecl = make.VarDef(catchException, null); 1524 JCBlock catchBlock = make.Block(0L, List.<JCStatement>of(addSuppressionStatement)); 1525 List<JCCatch> catchClauses = List.<JCCatch>of(make.Catch(catchExceptionDecl, catchBlock)); 1526 JCTry tryTree = make.Try(tryBlock, catchClauses, null); 1527 1528 // if (primaryException != null) {try...} else resourceClose; 1529 JCIf closeIfStatement = make.If(makeNonNullCheck(make.Ident(primaryException)), 1530 tryTree, 1531 makeResourceCloseInvocation(resource)); 1532 return make.Block(0L, List.<JCStatement>of(closeIfStatement)); 1533 } 1534 1535 private JCStatement makeResourceCloseInvocation(JCExpression resource) { 1536 // create resource.close() method invocation protected by a null-check 1537 1538 JCExpression resourceClose = makeCall(resource, 1539 names.close, 1540 List.<JCExpression>nil()); 1541 1542 return make.If(makeNonNullCheck(resource), make.Exec(resourceClose), null); 1543 } 1544 1545 private JCExpression makeNonNullCheck(JCExpression expression) { 1546 return makeBinary(JCTree.NE, expression, makeNull()); 1547 } 1548 1549 /** Construct a tree that represents the outer instance 1550 * <C.this>. Never pick the current `this'. 1551 * @param pos The source code position to be used for the tree. 1552 * @param c The qualifier class. 1553 */ 1554 JCExpression makeOuterThis(DiagnosticPosition pos, TypeSymbol c) { 1555 List<VarSymbol> ots = outerThisStack; 1556 if (ots.isEmpty()) { 1557 log.error(pos, "no.encl.instance.of.type.in.scope", c); 1558 Assert.error(); 1559 return makeNull(); 1560 } 1561 VarSymbol ot = ots.head; 1562 JCExpression tree = access(make.at(pos).Ident(ot)); 1563 TypeSymbol otc = ot.type.tsym; 1564 while (otc != c) { 1565 do { 1566 ots = ots.tail; |