src/share/classes/com/sun/tools/javac/code/Type.java

changeset 1898
a204cf7aab7e
parent 1891
42b3c5e92461
child 1905
f65a807714ba
equal deleted inserted replaced
1897:866c87c01285 1898:a204cf7aab7e
1450 /** equality constraints */ 1450 /** equality constraints */
1451 EQ; 1451 EQ;
1452 } 1452 }
1453 1453
1454 /** inference variable bounds */ 1454 /** inference variable bounds */
1455 private Map<InferenceBound, List<Type>> bounds; 1455 protected Map<InferenceBound, List<Type>> bounds;
1456 1456
1457 /** inference variable's inferred type (set from Infer.java) */ 1457 /** inference variable's inferred type (set from Infer.java) */
1458 public Type inst = null; 1458 public Type inst = null;
1459 1459
1460 /** number of declared (upper) bounds */ 1460 /** number of declared (upper) bounds */
1518 public void setBounds(InferenceBound ib, List<Type> newBounds) { 1518 public void setBounds(InferenceBound ib, List<Type> newBounds) {
1519 bounds.put(ib, newBounds); 1519 bounds.put(ib, newBounds);
1520 } 1520 }
1521 1521
1522 /** add a bound of a given kind - this might trigger listener notification */ 1522 /** add a bound of a given kind - this might trigger listener notification */
1523 public void addBound(InferenceBound ib, Type bound, Types types) { 1523 public final void addBound(InferenceBound ib, Type bound, Types types) {
1524 addBound(ib, bound, types, false);
1525 }
1526
1527 protected void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
1524 Type bound2 = boundMap.apply(bound); 1528 Type bound2 = boundMap.apply(bound);
1525 List<Type> prevBounds = bounds.get(ib); 1529 List<Type> prevBounds = bounds.get(ib);
1526 for (Type b : prevBounds) { 1530 for (Type b : prevBounds) {
1527 //check for redundancy - use strict version of isSameType on tvars 1531 //check for redundancy - use strict version of isSameType on tvars
1528 //(as the standard version will lead to false positives w.r.t. clones ivars) 1532 //(as the standard version will lead to false positives w.r.t. clones ivars)
1573 } 1577 }
1574 //step 2 - replace bounds 1578 //step 2 - replace bounds
1575 bounds.put(ib, newBounds.toList()); 1579 bounds.put(ib, newBounds.toList());
1576 //step 3 - for each dependency, add new replaced bound 1580 //step 3 - for each dependency, add new replaced bound
1577 for (Type dep : deps) { 1581 for (Type dep : deps) {
1578 addBound(ib, types.subst(dep, from, to), types); 1582 addBound(ib, types.subst(dep, from, to), types, true);
1579 } 1583 }
1580 } 1584 }
1581 } finally { 1585 } finally {
1582 listener = prevListener; 1586 listener = prevListener;
1583 if (!boundsChanged.isEmpty()) { 1587 if (!boundsChanged.isEmpty()) {
1588 1592
1589 private void notifyChange(EnumSet<InferenceBound> ibs) { 1593 private void notifyChange(EnumSet<InferenceBound> ibs) {
1590 if (listener != null) { 1594 if (listener != null) {
1591 listener.varChanged(this, ibs); 1595 listener.varChanged(this, ibs);
1592 } 1596 }
1597 }
1598
1599 public boolean isCaptured() {
1600 return false;
1601 }
1602 }
1603
1604 /**
1605 * This class is used to represent synthetic captured inference variables
1606 * that can be generated during nested generic method calls. The only difference
1607 * between these inference variables and ordinary ones is that captured inference
1608 * variables cannot get new bounds through incorporation.
1609 */
1610 public static class CapturedUndetVar extends UndetVar {
1611
1612 public CapturedUndetVar(CapturedType origin, Types types) {
1613 super(origin, types);
1614 if (!origin.lower.hasTag(BOT)) {
1615 bounds.put(InferenceBound.LOWER, List.of(origin.lower));
1616 }
1617 }
1618
1619 @Override
1620 public void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
1621 if (update) {
1622 //only change bounds if request comes from substBounds
1623 super.addBound(ib, bound, types, update);
1624 }
1625 }
1626
1627 @Override
1628 public boolean isCaptured() {
1629 return true;
1593 } 1630 }
1594 } 1631 }
1595 1632
1596 /** Represents NONE. 1633 /** Represents NONE.
1597 */ 1634 */

mercurial