src/share/classes/com/sun/tools/javac/comp/Attr.java

changeset 731
fadc6d3e63f4
parent 724
7755f47542a0
child 735
f2048d9c666e
equal deleted inserted replaced
730:20659c8c917d 731:fadc6d3e63f4
119 allowAnonOuterThis = source.allowAnonOuterThis(); 119 allowAnonOuterThis = source.allowAnonOuterThis();
120 allowStringsInSwitch = source.allowStringsInSwitch(); 120 allowStringsInSwitch = source.allowStringsInSwitch();
121 sourceName = source.name; 121 sourceName = source.name;
122 relax = (options.isSet("-retrofit") || 122 relax = (options.isSet("-retrofit") ||
123 options.isSet("-relax")); 123 options.isSet("-relax"));
124 findDiamonds = options.get("findDiamond") != null &&
125 source.allowDiamond();
124 useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); 126 useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
125 enableSunApiLintControl = options.isSet("enableSunApiLintControl"); 127 enableSunApiLintControl = options.isSet("enableSunApiLintControl");
126 } 128 }
127 129
128 /** Switch: relax some constraints for retrofit mode. 130 /** Switch: relax some constraints for retrofit mode.
151 153
152 /** Switch: allow references to surrounding object from anonymous 154 /** Switch: allow references to surrounding object from anonymous
153 * objects during constructor call? 155 * objects during constructor call?
154 */ 156 */
155 boolean allowAnonOuterThis; 157 boolean allowAnonOuterThis;
158
159 /** Switch: generates a warning if diamond can be safely applied
160 * to a given new expression
161 */
162 boolean findDiamonds;
163
164 /**
165 * Internally enables/disables diamond finder feature
166 */
167 static final boolean allowDiamondFinder = true;
156 168
157 /** 169 /**
158 * Switch: warn about use of variable before declaration? 170 * Switch: warn about use of variable before declaration?
159 * RFE: 6425594 171 * RFE: 6425594
160 */ 172 */
1570 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); 1582 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
1571 1583
1572 if (TreeInfo.isDiamond(tree)) { 1584 if (TreeInfo.isDiamond(tree)) {
1573 clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes); 1585 clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes);
1574 clazz.type = clazztype; 1586 clazz.type = clazztype;
1587 } else if (allowDiamondFinder &&
1588 clazztype.getTypeArguments().nonEmpty() &&
1589 findDiamonds) {
1590 Type inferred = attribDiamond(localEnv,
1591 tree,
1592 clazztype,
1593 mapping,
1594 argtypes,
1595 typeargtypes);
1596 if (!inferred.isErroneous() &&
1597 inferred.tag == CLASS &&
1598 types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings) &&
1599 chk.checkDiamond((ClassType)inferred).isEmpty()) {
1600 String key = types.isSameType(clazztype, inferred) ?
1601 "diamond.redundant.args" :
1602 "diamond.redundant.args.1";
1603 log.warning(tree.clazz.pos(), key, clazztype, inferred);
1604 }
1575 } 1605 }
1576 1606
1577 // If we have made no mistakes in the class type... 1607 // If we have made no mistakes in the class type...
1578 if (clazztype.tag == CLASS) { 1608 if (clazztype.tag == CLASS) {
1579 // Enums may not be instantiated except implicitly 1609 // Enums may not be instantiated except implicitly

mercurial