mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 10:15:53 +00:00
improvements type inference of type intersections (affects ValLambda.java, ValWeirdTypes.java tests)
This commit is contained in:
1 parent
69e6932b81
commit
f0343886a3
7 files changed
+39
-10
No files matched your search
@@ -893,7 +893,12 @@ public class EclipseHandlerUtil {
|
||||
WildcardBinding wildcard = (WildcardBinding) binding;
|
||||
if (wildcard.boundKind == Wildcard.EXTENDS) {
|
||||
if (!allowCompound) {
|
||||
return makeType(wildcard.bound, pos, false);
|
||||
TypeBinding bound = wildcard.bound;
|
||||
boolean isObject = bound.id == TypeIds.T_JavaLangObject;
|
||||
TypeBinding[] otherBounds = wildcard.otherBounds;
|
||||
if (isObject && otherBounds != null && otherBounds.length > 0) {
|
||||
return makeType(otherBounds[0], pos, false);
|
||||
} else return makeType(bound, pos, false);
|
||||
} else {
|
||||
Wildcard out = new Wildcard(Wildcard.EXTENDS);
|
||||
setGeneratedBy(out, pos);
|
||||
|
||||
@@ -336,7 +336,7 @@ public class JavacResolution {
|
||||
if (type instanceof ClassType) {
|
||||
List<Type> ifaces = ((ClassType) type).interfaces_field;
|
||||
Type supertype = ((ClassType) type).supertype_field;
|
||||
if (ifaces != null && ifaces.length() == 1) {
|
||||
if (isObject(supertype) && ifaces != null && ifaces.length() > 0) {
|
||||
return typeToJCTree(ifaces.get(0), ast, allowCompound, allowVoid);
|
||||
}
|
||||
if (supertype != null) return typeToJCTree(supertype, ast, allowCompound, allowVoid);
|
||||
@@ -402,6 +402,10 @@ public class JavacResolution {
|
||||
return genericsToJCTreeNodes(generics, ast, replacement);
|
||||
}
|
||||
|
||||
private static boolean isObject(Type supertype) {
|
||||
return supertype.tsym.toString().equals("java.lang.Object");
|
||||
}
|
||||
|
||||
private static JCExpression genericsToJCTreeNodes(List<Type> generics, JavacAST ast, JCExpression rawTypeNode) throws TypeNotConvertibleException {
|
||||
if (generics != null && !generics.isEmpty()) {
|
||||
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
|
||||
|
||||
@@ -5,9 +5,9 @@ class ValLambda {
|
||||
};
|
||||
}
|
||||
public void easyIntersectionLambda() {
|
||||
final java.lang.Object foo = (Runnable & java.io.Serializable) () -> {
|
||||
final java.lang.Runnable foo = (Runnable & java.io.Serializable) () -> {
|
||||
};
|
||||
final java.lang.Object bar = (java.io.Serializable & Runnable) () -> {
|
||||
final java.io.Serializable bar = (java.io.Serializable & Runnable) () -> {
|
||||
};
|
||||
}
|
||||
public void easyLubLambda() {
|
||||
|
||||
@@ -56,8 +56,14 @@ public class ValWeirdTypes<Z> {
|
||||
final int singleInt = copy[0];
|
||||
}
|
||||
public void arraysAsList() {
|
||||
final java.util.List<java.lang.Class<? extends java.lang.Object>> x = Arrays.asList(String.class, BigDecimal.class);
|
||||
for (final java.lang.Class<?> y : x) {
|
||||
final java.util.List<java.lang.Class<? extends java.io.Serializable>> x = Arrays.asList(String.class, BigDecimal.class);
|
||||
for (final java.lang.Class<? extends java.io.Serializable> y : x) {
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("all")
|
||||
public void arraysAsList2() {
|
||||
final java.util.List<java.lang.Class<? extends java.lang.Comparable>> x = Arrays.asList(String.class, BigDecimal.class, Comparable.class);
|
||||
for (final java.lang.Class<? extends java.lang.Comparable> y : x) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ class ValLambda {
|
||||
};
|
||||
}
|
||||
public void easyIntersectionLambda() {
|
||||
final @lombok.val java.lang.Object foo = (Runnable & java.io.Serializable) () -> {
|
||||
final @lombok.val java.lang.Runnable foo = (Runnable & java.io.Serializable) () -> {
|
||||
};
|
||||
final @lombok.val java.lang.Object bar = (java.io.Serializable & Runnable) () -> {
|
||||
final @lombok.val java.io.Serializable bar = (java.io.Serializable & Runnable) () -> {
|
||||
};
|
||||
}
|
||||
public void easyLubLambda() {
|
||||
|
||||
@@ -63,8 +63,14 @@ public class ValWeirdTypes<Z> {
|
||||
final @val int singleInt = copy[0];
|
||||
}
|
||||
public void arraysAsList() {
|
||||
final @val java.util.List<java.lang.Class<? extends java.lang.Object>> x = Arrays.asList(String.class, BigDecimal.class);
|
||||
for (final @val java.lang.Class<? extends java.lang.Object> y : x)
|
||||
final @val java.util.List<java.lang.Class<? extends java.io.Serializable>> x = Arrays.asList(String.class, BigDecimal.class);
|
||||
for (final @val java.lang.Class<? extends java.io.Serializable> y : x)
|
||||
{
|
||||
}
|
||||
}
|
||||
public @SuppressWarnings("all") void arraysAsList2() {
|
||||
final @val java.util.List<java.lang.Class<? extends java.lang.Comparable>> x = Arrays.asList(String.class, BigDecimal.class, Comparable.class);
|
||||
for (final @val java.lang.Class<? extends java.lang.Comparable> y : x)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +72,12 @@ public class ValWeirdTypes<Z> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public void arraysAsList2() {
|
||||
val x = Arrays.asList(String.class, BigDecimal.class, Comparable.class);
|
||||
for (val y : x) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user