mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
captured wildcard: convert to primitive (IDEA-151408)
This commit is contained in:
@@ -408,10 +408,16 @@ public class TypeConversionUtil {
|
||||
}
|
||||
|
||||
public static boolean isPrimitiveAndNotNull(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isPrimitiveAndNotNull(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
return type instanceof PsiPrimitiveType && !isNullType(type);
|
||||
}
|
||||
|
||||
public static boolean isEnumType(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isEnumType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClass psiClass = ((PsiClassType)type).resolve();
|
||||
return psiClass != null && psiClass.isEnum();
|
||||
@@ -427,14 +433,23 @@ public class TypeConversionUtil {
|
||||
return isFloatType(type) || isDoubleType(type);
|
||||
}
|
||||
public static boolean isDoubleType(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isDoubleType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
return PsiType.DOUBLE.equals(type) || PsiType.DOUBLE.equals(PsiPrimitiveType.getUnboxedType(type));
|
||||
}
|
||||
|
||||
public static boolean isFloatType(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isFloatType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
return PsiType.FLOAT.equals(type) || PsiType.FLOAT.equals(PsiPrimitiveType.getUnboxedType(type));
|
||||
}
|
||||
|
||||
public static boolean isLongType(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isLongType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
return PsiType.LONG.equals(type) || PsiType.LONG.equals(PsiPrimitiveType.getUnboxedType(type));
|
||||
}
|
||||
|
||||
@@ -443,6 +458,9 @@ public class TypeConversionUtil {
|
||||
}
|
||||
|
||||
public static boolean isBooleanType(@Nullable PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isBooleanType(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
return PsiType.BOOLEAN.equals(type) || PsiType.BOOLEAN.equals(PsiPrimitiveType.getUnboxedType(type));
|
||||
}
|
||||
|
||||
@@ -460,6 +478,9 @@ public class TypeConversionUtil {
|
||||
* Integer.MAX_VALUE for others
|
||||
*/
|
||||
public static int getTypeRank(@NotNull PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
type = ((PsiCapturedWildcardType)type).getUpperBound();
|
||||
}
|
||||
PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(type);
|
||||
if (unboxedType != null) {
|
||||
type = unboxedType;
|
||||
@@ -586,6 +607,9 @@ public class TypeConversionUtil {
|
||||
}
|
||||
|
||||
public static boolean isPrimitiveAndNotNullOrWrapper(PsiType type) {
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
return isPrimitiveAndNotNullOrWrapper(((PsiCapturedWildcardType)type).getUpperBound());
|
||||
}
|
||||
if (type instanceof PsiClassType) {
|
||||
return PsiPrimitiveType.getUnboxedType(type) != null;
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
class Test {
|
||||
private void test(AtomicReference<? extends Boolean> atomic) {
|
||||
boolean val = !atomic.get();
|
||||
boolean val1 = atomic.get() && atomic.get();
|
||||
assert atomic.get();
|
||||
}
|
||||
}
|
||||
+4
@@ -962,4 +962,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testForeachOverCapturedWildcardWithCollectionUpperBound() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCapturedWildcardWithPrimitiveTypesChecks() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user