From c8995f3cc8278e95fe304888e11786d9538fe2e4 Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Fri, 19 Apr 2024 16:21:33 +0200 Subject: [PATCH] [java-highlighting] IDEA-352187 Support JEP 455: highlighting for instanceof with primitives GitOrigin-RevId: cbd688d0945b03bffb05af85825c610889383fc4 --- .../daemon/impl/analysis/HighlightUtil.java | 15 +- .../analysis/PatternHighlightingModel.java | 17 +- .../messages/JavaPsiBundle.properties | 1 + .../com/intellij/pom/java/JavaFeature.java | 4 + .../InstanceofPrimitivesNotAllowed.java | 81 ++ .../RecordPrimitiveInstanceOfPattern.java | 1137 +++++++++++++++++ ...dPrimitiveInstanceOfPatternNotAllowed.java | 1137 +++++++++++++++++ .../SimplePrimitiveInstanceOf.java | 1068 ++++++++++++++++ .../SimplePrimitiveInstanceOfPattern.java | 1068 ++++++++++++++++ .../daemon/LightPatternsHighlightingTest.java | 10 +- ...ightPrimitivePatternsHighlightingTest.java | 38 + 11 files changed, 4566 insertions(+), 10 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/InstanceofPrimitivesNotAllowed.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPattern.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPatternNotAllowed.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOf.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOfPattern.java create mode 100644 java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPrimitivePatternsHighlightingTest.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 50db617a56b6..69069993ba62 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -206,19 +206,26 @@ public final class HighlightUtil { PsiType checkType = typeElement.getType(); PsiType operandType = operand.getType(); if (operandType == null) return; - if (TypeConversionUtil.isPrimitiveAndNotNull(operandType) - || TypeConversionUtil.isPrimitiveAndNotNull(checkType) - || !TypeConversionUtil.areTypesConvertible(operandType, checkType)) { + boolean operandIsPrimitive = TypeConversionUtil.isPrimitiveAndNotNull(operandType); + boolean checkIsPrimitive = TypeConversionUtil.isPrimitiveAndNotNull(checkType); + boolean convertible = TypeConversionUtil.areTypesConvertible(operandType, checkType); + boolean primitiveInPatternsEnabled = JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(PsiUtil.getLanguageLevel(expression)); + if (((operandIsPrimitive || checkIsPrimitive) && !primitiveInPatternsEnabled) || !convertible) { String message = JavaErrorBundle.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil .formatType(checkType)); HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message); - if (TypeConversionUtil.isPrimitiveAndNotNull(checkType)) { + if (checkIsPrimitive) { IntentionAction action = getFixFactory().createReplacePrimitiveWithBoxedTypeAction(operandType, typeElement); if (action != null) { info.registerFix(action, null, null, null, null); } } + + if (((operandIsPrimitive || checkIsPrimitive) && !primitiveInPatternsEnabled) && convertible) { + registerIncreaseLanguageLevelFixes(expression, JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, info); + } + errorSink.accept(info); return; } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PatternHighlightingModel.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PatternHighlightingModel.java index 65d9f55d2f5f..2b59306c4f81 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PatternHighlightingModel.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PatternHighlightingModel.java @@ -12,6 +12,8 @@ import com.intellij.codeInsight.intention.QuickFixFactory; import com.intellij.modcommand.ModCommandAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.TextRange; +import com.intellij.pom.java.JavaFeature; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.PsiClassType.ClassResolveResult; import com.intellij.psi.util.*; @@ -66,12 +68,16 @@ final class PatternHighlightingModel { PsiType recordComponentType = recordComponents[i].getType(); PsiType substitutedRecordComponentType = substitutor.substitute(recordComponentType); PsiType deconstructionComponentType = JavaPsiPatternUtil.getPatternType(deconstructionComponent); - if (!isApplicable(substitutedRecordComponentType, deconstructionComponentType)) { + if (!isApplicable(substitutedRecordComponentType, deconstructionComponentType, PsiUtil.getLanguageLevel(deconstructionPattern))) { hasMismatchedPattern = true; if (recordComponents.length == deconstructionComponents.length) { HighlightInfo.Builder builder = HighlightUtil.createIncompatibleTypeHighlightInfo(substitutedRecordComponentType, deconstructionComponentType, deconstructionComponent.getTextRange(), 0); + if (isApplicable(substitutedRecordComponentType, deconstructionComponentType, + JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel())) { + HighlightUtil.registerIncreaseLanguageLevelFixes(deconstructionComponent, JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, builder); + } errorSink.accept(builder); reported = true; } @@ -121,8 +127,9 @@ final class PatternHighlightingModel { return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(pattern).descriptionAndTooltip(message); } - private static boolean isApplicable(@NotNull PsiType recordType, @Nullable PsiType patternType) { - if (recordType instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType) { + private static boolean isApplicable(@NotNull PsiType recordType, @Nullable PsiType patternType, @NotNull LanguageLevel languageLevel) { + if ((recordType instanceof PsiPrimitiveType || patternType instanceof PsiPrimitiveType) && + !JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.isSufficient(languageLevel)) { return recordType.equals(patternType); } return patternType != null && TypeConversionUtil.areTypesConvertible(recordType, patternType); @@ -921,8 +928,8 @@ final class PatternHighlightingModel { } static class RecordExhaustivenessResult { - private boolean isExhaustive; - private boolean canBeAdded; + private final boolean isExhaustive; + private final boolean canBeAdded; final Map>> missedBranchesByType = new HashMap<>(); diff --git a/java/java-frontback-psi-api/resources/messages/JavaPsiBundle.properties b/java/java-frontback-psi-api/resources/messages/JavaPsiBundle.properties index b8f6308df613..5db75bd5016c 100644 --- a/java/java-frontback-psi-api/resources/messages/JavaPsiBundle.properties +++ b/java/java-frontback-psi-api/resources/messages/JavaPsiBundle.properties @@ -105,6 +105,7 @@ feature.patterns.in.switch=Patterns in switch feature.javadoc.snippets=@snippet in Javadoc feature.pattern.guard.and.record.patterns=Pattern guards and record patterns feature.record.patterns.in.for.each=Record patterns in for-each loops +feature.primitive.types.in.patterns=Primitive types in patterns, instanceof and switch feature.enum.qualified.name.in.switch=Qualified enum as a constant in switch feature.string.templates=String templates feature.unnamed.vars=Unnamed patterns and variables diff --git a/java/java-frontback-psi-api/src/com/intellij/pom/java/JavaFeature.java b/java/java-frontback-psi-api/src/com/intellij/pom/java/JavaFeature.java index 2a49398650a9..c15008d72061 100644 --- a/java/java-frontback-psi-api/src/com/intellij/pom/java/JavaFeature.java +++ b/java/java-frontback-psi-api/src/com/intellij/pom/java/JavaFeature.java @@ -97,6 +97,10 @@ public enum JavaFeature { */ RECORD_PATTERNS_IN_FOR_EACH(LanguageLevel.JDK_X, "feature.record.patterns.in.for.each", LanguageLevel.JDK_20_PREVIEW), + /** + * Implementation for java 23 + */ + PRIMITIVE_TYPES_IN_PATTERNS(LanguageLevel.JDK_X, "feature.primitive.types.in.patterns"), ; private final @NotNull LanguageLevel myLevel; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/InstanceofPrimitivesNotAllowed.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/InstanceofPrimitivesNotAllowed.java new file mode 100644 index 000000000000..6eb6c0d9cfe7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/InstanceofPrimitivesNotAllowed.java @@ -0,0 +1,81 @@ +package dfa; + +public class InstanceofPrimitivesNotAllowed { + public static void main(String[] args) { + testPrimitiveToPrimitive(); + testPrimitiveToObject(); + testObjectToPrimitive(); + } + + private static void testObjectToPrimitive() { + Integer i = 1; + Object l = 1; + if (i instanceof double) { //error + System.out.println("double"); + } + if (i instanceof int) { //error + System.out.println("int"); + } + if (i instanceof int ii) { //error + System.out.println("int pattern"); + } + if (l instanceof double) { //error + System.out.println("double"); + } + if (l instanceof int) { //error + System.out.println("int"); + } + if (l instanceof int ii) { //error + System.out.println("int pattern"); + } + } + + private static void testPrimitiveToPrimitive() { + int i = 1; + long l = 1; + if (i instanceof double) { //error + System.out.println("double"); + } + if (i instanceof int) { //error + System.out.println("int"); + } + if (i instanceof int ii) { //error + System.out.println("int pattern"); + } + if (l instanceof double) { //error + System.out.println("double"); + } + if (l instanceof int) { //error + System.out.println("int"); + } + if (l instanceof int ii) { //error + System.out.println("int pattern"); + } + } + + private static void testPrimitiveToObject() { + int i = 1; + long l = 1; + if (i instanceof Double) { //error + System.out.println("Double"); + } + if (i instanceof Integer) { //error + System.out.println("Integer"); + } + if (i instanceof Object) { //error + System.out.println("Object"); + } + if (i instanceof Integer ii) { //error + System.out.println("Integer ii"); + } + if (l instanceof Double) { //error + System.out.println("Double"); + } + if (l instanceof Integer) { //error + System.out.println("Integer"); + } + if (l instanceof Object) { //error + System.out.println("Object"); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPattern.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPattern.java new file mode 100644 index 000000000000..1b1333810ba7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPattern.java @@ -0,0 +1,1137 @@ +public class RecordPrimitiveInstanceOfPattern { + + record RecordBool(boolean source) { + } + + record RecordInt(int source) { + } + + record RecordLong(long source) { + } + + record RecordDouble(double source) { + } + + record RecordFloat(float source) { + } + + record RecordByte(byte source) { + } + + record RecordChar(char source) { + } + + record RecordShort(short source) { + } + + record RecordBoolObj(Boolean source) { + } + + record RecordIntObj(Integer source) { + } + + record RecordLongObj(Long source) { + } + + record RecordDoubleObj(Double source) { + } + + record RecordFloatObj(Float source) { + } + + record RecordByteObj(Byte source) { + } + + record RecordCharObj(Character source) { + } + + record RecordShortObj(Short source) { + } + + record RecordNumber(Number source) { + } + + record RecordObject(Object source) { + } + + record RecordRecordInt(RecordInt source) { + } + + public static void main(String[] args) { + testForRecordBool(new RecordBool(true)); + testForRecordInt(new RecordInt(1)); + testForRecordLong(new RecordLong(1L)); + testForRecordDouble(new RecordDouble(2)); + testForRecordFloat(new RecordFloat(1.0f)); + testForRecordByte(new RecordByte((byte) 1)); + testForRecordChar(new RecordChar('1')); + testForRecordShort(new RecordShort((short) 1)); + + testForRecordBoolObject(new RecordBoolObj(true)); + testForRecordIntObject(new RecordIntObj(1)); + testForRecordLongObject(new RecordLongObj(1L)); + testForRecordDoubleObject(new RecordDoubleObj(1.0)); + testForRecordFloatObject(new RecordFloatObj(1.0f)); + testForRecordByteObject(new RecordByteObj((byte) 1)); + testForRecordCharObject(new RecordCharObj('a')); + testForRecordShortObject(new RecordShortObj((short) 1)); + + testForRecordObject(new RecordObject(1)); + testForRecordNumber(new RecordNumber(1)); + + testForRecordRecordInt(new RecordRecordInt(new RecordInt(1))); + } + + private static void testForRecordRecordInt(RecordRecordInt source) { + if (source instanceof RecordRecordInt(RecordInt(boolean target))) { //error + System.out.println(target); + } + if (source instanceof RecordRecordInt(RecordInt(int target))) { + System.out.println(target); + } + } + + private static void testForRecordBool(RecordBool source) { + if (source instanceof RecordBool(boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBool(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordBool(Boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBool(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Object target)) { + System.out.println(target); + } + if (source instanceof RecordBool(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordInt(RecordInt source) { + if (source instanceof RecordInt(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(int target)) { + System.out.println(target); + } + if (source instanceof RecordInt(long target)) { + System.out.println(target); + } + if (source instanceof RecordInt(double target)) { + System.out.println(target); + } + if (source instanceof RecordInt(float target)) { + System.out.println(target); + } + if (source instanceof RecordInt(byte target)) { + System.out.println(target); + } + if (source instanceof RecordInt(char target)) { + System.out.println(target); + } + if (source instanceof RecordInt(short target)) { + System.out.println(target); + } + + if (source instanceof RecordInt(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordInt(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Object target)) { + System.out.println(target); + } + if (source instanceof RecordInt(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordLong(RecordLong source) { + if (source instanceof RecordLong(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(int target)) { + System.out.println(target); + } + if (source instanceof RecordLong(long target)) { + System.out.println(target); + } + if (source instanceof RecordLong(double target)) { + System.out.println(target); + } + if (source instanceof RecordLong(float target)) { + System.out.println(target); + } + if (source instanceof RecordLong(byte target)) { + System.out.println(target); + } + if (source instanceof RecordLong(char target)) { + System.out.println(target); + } + if (source instanceof RecordLong(short target)) { + System.out.println(target); + } + + if (source instanceof RecordLong(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Long target)) { + System.out.println(target); + } + if (source instanceof RecordLong(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Object target)) { + System.out.println(target); + } + if (source instanceof RecordLong(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordDouble(RecordDouble source) { + if (source instanceof RecordDouble(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(int target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(long target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(double target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(float target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(byte target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(char target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(short target)) { + System.out.println(target); + } + + if (source instanceof RecordDouble(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Double target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Object target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordFloat(RecordFloat source) { + if (source instanceof RecordFloat(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(int target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(long target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(double target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(float target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(byte target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(char target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(short target)) { + System.out.println(target); + } + + if (source instanceof RecordFloat(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Float target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Object target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordByte(RecordByte source) { + if (source instanceof RecordByte(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(int target)) { + System.out.println(target); + } + if (source instanceof RecordByte(long target)) { + System.out.println(target); + } + if (source instanceof RecordByte(double target)) { + System.out.println(target); + } + if (source instanceof RecordByte(float target)) { + System.out.println(target); + } + if (source instanceof RecordByte(byte target)) { + System.out.println(target); + } + if (source instanceof RecordByte(char target)) { + System.out.println(target); + } + if (source instanceof RecordByte(short target)) { + System.out.println(target); + } + + if (source instanceof RecordByte(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordByte(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Short _)) { //error + System.out.println(); + } + if (source instanceof RecordByte(Object target)) { + System.out.println(target); + } + if (source instanceof RecordByte(Number _)) { + System.out.println(); + } + } + + private static void testForRecordChar(RecordChar source) { + if (source instanceof RecordChar(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(int target)) { + System.out.println(target); + } + if (source instanceof RecordChar(long target)) { + System.out.println(target); + } + if (source instanceof RecordChar(double target)) { + System.out.println(target); + } + if (source instanceof RecordChar(float target)) { + System.out.println(target); + } + if (source instanceof RecordChar(byte target)) { + System.out.println(target); + } + if (source instanceof RecordChar(char target)) { + System.out.println(target); + } + if (source instanceof RecordChar(short target)) { + System.out.println(target); + } + + if (source instanceof RecordChar(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Character target)) { + System.out.println(target); + } + if (source instanceof RecordChar(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Object target)) { + System.out.println(target); + } + if (source instanceof RecordChar(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordShort(RecordShort source) { + if (source instanceof RecordShort(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(int target)) { + System.out.println(target); + } + if (source instanceof RecordShort(long target)) { + System.out.println(target); + } + if (source instanceof RecordShort(double target)) { + System.out.println(target); + } + if (source instanceof RecordShort(float target)) { + System.out.println(target); + } + if (source instanceof RecordShort(byte target)) { + System.out.println(target); + } + if (source instanceof RecordShort(char target)) { + System.out.println(target); + } + if (source instanceof RecordShort(short target)) { + System.out.println(target); + } + + if (source instanceof RecordShort(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Short target)) { + System.out.println(target); + } + if (source instanceof RecordShort(Object target)) { + System.out.println(target); + } + if (source instanceof RecordShort(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordBoolObject(RecordBoolObj source) { + if (source instanceof RecordBoolObj(boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBoolObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordBoolObj(Boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBoolObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordBoolObj(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordIntObject(RecordIntObj source) { + if (source instanceof RecordIntObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(int target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(long target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordIntObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordLongObject(RecordLongObj source) { + if (source instanceof RecordLongObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(long target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordLongObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Long target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordDoubleObject(RecordDoubleObj source) { + if (source instanceof RecordDoubleObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordDoubleObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordDoubleObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Double target)) { + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordFloatObject(RecordFloatObj source) { + if (source instanceof RecordFloatObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordFloatObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Float target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordByteObject(RecordByteObj source) { + if (source instanceof RecordByteObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(int target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(long target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(byte target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(short target)) { + System.out.println(target); + } + + if (source instanceof RecordByteObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordCharObject(RecordCharObj source) { + if (source instanceof RecordCharObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(int target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(long target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(char target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordCharObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Character target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordShortObject(RecordShortObj source) { + if (source instanceof RecordShortObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(int target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(long target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(double target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(float target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(short target)) { + System.out.println(target); + } + + if (source instanceof RecordShortObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Short target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordObject(RecordObject source) { + if (source instanceof RecordObject(boolean target)) { + System.out.println(target); + } + if (source instanceof RecordObject(int target)) { + System.out.println(target); + } + if (source instanceof RecordObject(long target)) { + System.out.println(target); + } + if (source instanceof RecordObject(double target)) { + System.out.println(target); + } + if (source instanceof RecordObject(float target)) { + System.out.println(target); + } + if (source instanceof RecordObject(byte target)) { + System.out.println(target); + } + if (source instanceof RecordObject(char target)) { + System.out.println(target); + } + if (source instanceof RecordObject(short target)) { + System.out.println(target); + } + + if (source instanceof RecordObject(Boolean target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Long target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Double target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Float target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Character target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Short target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Object target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordNumber(RecordNumber source) { + if (source instanceof RecordNumber(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(int target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(long target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(double target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(float target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(byte target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(short target)) { + System.out.println(target); + } + + if (source instanceof RecordNumber(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Long target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Double target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Float target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(Short target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Object target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Number target)) { + System.out.println(target); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPatternNotAllowed.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPatternNotAllowed.java new file mode 100644 index 000000000000..8a631c28ed88 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/RecordPrimitiveInstanceOfPatternNotAllowed.java @@ -0,0 +1,1137 @@ +public class RecordPrimitiveInstanceOfPatternNotAllowed { + + record RecordBool(boolean source) { + } + + record RecordInt(int source) { + } + + record RecordLong(long source) { + } + + record RecordDouble(double source) { + } + + record RecordFloat(float source) { + } + + record RecordByte(byte source) { + } + + record RecordChar(char source) { + } + + record RecordShort(short source) { + } + + record RecordBoolObj(Boolean source) { + } + + record RecordIntObj(Integer source) { + } + + record RecordLongObj(Long source) { + } + + record RecordDoubleObj(Double source) { + } + + record RecordFloatObj(Float source) { + } + + record RecordByteObj(Byte source) { + } + + record RecordCharObj(Character source) { + } + + record RecordShortObj(Short source) { + } + + record RecordNumber(Number source) { + } + + record RecordObject(Object source) { + } + + record RecordRecordInt(RecordInt source) { + } + + public static void main(String[] args) { + testForRecordBool(new RecordBool(true)); + testForRecordInt(new RecordInt(1)); + testForRecordLong(new RecordLong(1L)); + testForRecordDouble(new RecordDouble(2)); + testForRecordFloat(new RecordFloat(1.0f)); + testForRecordByte(new RecordByte((byte) 1)); + testForRecordChar(new RecordChar('1')); + testForRecordShort(new RecordShort((short) 1)); + + testForRecordBoolObject(new RecordBoolObj(true)); + testForRecordIntObject(new RecordIntObj(1)); + testForRecordLongObject(new RecordLongObj(1L)); + testForRecordDoubleObject(new RecordDoubleObj(1.0)); + testForRecordFloatObject(new RecordFloatObj(1.0f)); + testForRecordByteObject(new RecordByteObj((byte) 1)); + testForRecordCharObject(new RecordCharObj('a')); + testForRecordShortObject(new RecordShortObj((short) 1)); + + testForRecordObject(new RecordObject(1)); + testForRecordNumber(new RecordNumber(1)); + + testForRecordRecordInt(new RecordRecordInt(new RecordInt(1))); + } + + private static void testForRecordRecordInt(RecordRecordInt source) { + if (source instanceof RecordRecordInt(RecordInt(boolean target))) { //error + System.out.println(target); + } + if (source instanceof RecordRecordInt(RecordInt(int target))) { + System.out.println(target); + } + } + + private static void testForRecordBool(RecordBool source) { + if (source instanceof RecordBool(boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBool(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordBool(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordBool(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordInt(RecordInt source) { + if (source instanceof RecordInt(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(int target)) { + System.out.println(target); + } + if (source instanceof RecordInt(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordInt(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordInt(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordLong(RecordLong source) { + if (source instanceof RecordLong(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(long target)) { + System.out.println(target); + } + if (source instanceof RecordLong(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordLong(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordLong(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordDouble(RecordDouble source) { + if (source instanceof RecordDouble(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(double target)) { + System.out.println(target); + } + if (source instanceof RecordDouble(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordDouble(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordDouble(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordFloat(RecordFloat source) { + if (source instanceof RecordFloat(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(float target)) { + System.out.println(target); + } + if (source instanceof RecordFloat(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordFloat(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloat(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordByte(RecordByte source) { + if (source instanceof RecordByte(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(byte target)) { + System.out.println(target); + } + if (source instanceof RecordByte(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordByte(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Short _)) { //error + System.out.println(); + } + if (source instanceof RecordByte(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordByte(Number _)) { //error + System.out.println(); + } + } + + private static void testForRecordChar(RecordChar source) { + if (source instanceof RecordChar(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(char target)) { + System.out.println(target); + } + if (source instanceof RecordChar(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordChar(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordChar(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordShort(RecordShort source) { + if (source instanceof RecordShort(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(short target)) { + System.out.println(target); + } + + if (source instanceof RecordShort(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Object target)) { //error + System.out.println(target); + } + if (source instanceof RecordShort(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordBoolObject(RecordBoolObj source) { + if (source instanceof RecordBoolObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordBoolObj(Boolean target)) { + System.out.println(target); + } + if (source instanceof RecordBoolObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordBoolObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordBoolObj(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordIntObject(RecordIntObj source) { + if (source instanceof RecordIntObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordIntObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordIntObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordIntObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordLongObject(RecordLongObj source) { + if (source instanceof RecordLongObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordLongObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Long target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordLongObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordLongObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordDoubleObject(RecordDoubleObj source) { + if (source instanceof RecordDoubleObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordDoubleObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Double target)) { + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordDoubleObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordFloatObject(RecordFloatObj source) { + if (source instanceof RecordFloatObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordFloatObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Float target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordFloatObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordFloatObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordByteObject(RecordByteObj source) { + if (source instanceof RecordByteObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordByteObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordByteObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordByteObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordCharObject(RecordCharObj source) { + if (source instanceof RecordCharObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordCharObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Character target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(Short target)) { //error + System.out.println(target); + } + if (source instanceof RecordCharObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordCharObj(Number target)) { //error + System.out.println(target); + } + } + + private static void testForRecordShortObject(RecordShortObj source) { + if (source instanceof RecordShortObj(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordShortObj(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Integer target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Long target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Double target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Float target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordShortObj(Short target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(Object target)) { + System.out.println(target); + } + if (source instanceof RecordShortObj(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordObject(RecordObject source) { + if (source instanceof RecordObject(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordObject(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordObject(Boolean target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Long target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Double target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Float target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Character target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Short target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Object target)) { + System.out.println(target); + } + if (source instanceof RecordObject(Number target)) { + System.out.println(target); + } + } + + private static void testForRecordNumber(RecordNumber source) { + if (source instanceof RecordNumber(boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(int target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(long target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(double target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(float target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(byte target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(char target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(short target)) { //error + System.out.println(target); + } + + if (source instanceof RecordNumber(Boolean target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(Integer target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Long target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Double target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Float target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Byte target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Character target)) { //error + System.out.println(target); + } + if (source instanceof RecordNumber(Short target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Object target)) { + System.out.println(target); + } + if (source instanceof RecordNumber(Number target)) { + System.out.println(target); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOf.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOf.java new file mode 100644 index 000000000000..6c2346b4e437 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOf.java @@ -0,0 +1,1068 @@ +public class SimplePrimitiveInstanceOf { + public static void main(String[] args) { + testForBool(true); + testForInt(1); + testForLong(1); + testForDouble(1); + testForFloat(1); + testForByte((byte) 1); + testForChar((char) 1); + testForShort((short) 1); + + testForBoolObject(true); + testForIntObject(1); + testForLongObject(1L); + testForDoubleObject(1d); + testForFloatObject(1f); + testForByteObject((byte) 1); + testForCharObject((char) 1); + testForShortObject((short) 1); + + testForObject(1); + testForNumber(1); + } + + private static void testForBool(boolean source) { + if (source instanceof boolean) { + System.out.println(); + } + if (source instanceof int) { //error + System.out.println(); + } + if (source instanceof long) { //error + System.out.println(); + } + if (source instanceof double) { //error + System.out.println(); + } + if (source instanceof float) { //error + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { //error + System.out.println(); + } + } + + private static void testForInt(int source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForLong(long source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForDouble(double source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForFloat(float source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForByte(byte source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForChar(char source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { //error + System.out.println(); + } + } + + private static void testForShort(short source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForBoolObject(Boolean source) { + if (source instanceof boolean) { + System.out.println(); + } + if (source instanceof int) { //error + System.out.println(); + } + if (source instanceof long) { //error + System.out.println(); + } + if (source instanceof double) { //error + System.out.println(); + } + if (source instanceof float) { //error + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { //error + System.out.println(); + } + } + + private static void testForIntObject(Integer source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForLongObject(Long source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { //error + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForDoubleObject(Double source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { //error + System.out.println(); + } + if (source instanceof long) { //error + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { //error + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForFloatObject(Float source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { //error + System.out.println(); + } + if (source instanceof long) { //error + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForByteObject(Byte source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForCharObject(Character source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { //error + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { + System.out.println(); + } + if (source instanceof Short) { //error + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { //error + System.out.println(); + } + } + + private static void testForShortObject(Short source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { //error + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { //error + System.out.println(); + } + if (source instanceof Long) { //error + System.out.println(); + } + if (source instanceof Double) { //error + System.out.println(); + } + if (source instanceof Float) { //error + System.out.println(); + } + if (source instanceof Byte) { //error + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForObject(Object source) { + if (source instanceof boolean) { + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { + System.out.println(); + } + if (source instanceof Integer) { + System.out.println(); + } + if (source instanceof Long) { + System.out.println(); + } + if (source instanceof Double) { + System.out.println(); + } + if (source instanceof Float) { + System.out.println(); + } + if (source instanceof Byte) { + System.out.println(); + } + if (source instanceof Character) { + System.out.println(); + } + if (source instanceof Short) { + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } + + private static void testForNumber(Number source) { + if (source instanceof boolean) { //error + System.out.println(); + } + if (source instanceof int) { + System.out.println(); + } + if (source instanceof long) { + System.out.println(); + } + if (source instanceof double) { + System.out.println(); + } + if (source instanceof float) { + System.out.println(); + } + if (source instanceof byte) { + System.out.println(); + } + if (source instanceof char) { //error + System.out.println(); + } + if (source instanceof short) { + System.out.println(); + } + + if (source instanceof Boolean) { //error + System.out.println(); + } + if (source instanceof Integer) { + System.out.println(); + } + if (source instanceof Long) { + System.out.println(); + } + if (source instanceof Double) { + System.out.println(); + } + if (source instanceof Float) { + System.out.println(); + } + if (source instanceof Byte) { + System.out.println(); + } + if (source instanceof Character) { //error + System.out.println(); + } + if (source instanceof Short) { + System.out.println(); + } + if (source instanceof Object) { + System.out.println(); + } + if (source instanceof Number) { + System.out.println(); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOfPattern.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOfPattern.java new file mode 100644 index 000000000000..e2e695f3042b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns/SimplePrimitiveInstanceOfPattern.java @@ -0,0 +1,1068 @@ +public class SimplePrimitiveInstanceOfPattern { + public static void main(String[] args) { + testForBool(true); + testForInt(1); + testForLong(1); + testForDouble(1); + testForFloat(1); + testForByte((byte) 1); + testForChar((char) 1); + testForShort((short) 1); + + testForBoolObject(true); + testForIntObject(1); + testForLongObject(1L); + testForDoubleObject(1d); + testForFloatObject(1f); + testForByteObject((byte) 1); + testForCharObject((char) 1); + testForShortObject((short) 1); + + testForObject(1); + testForNumber(1); + } + + private static void testForBool(boolean source) { + if (source instanceof boolean target) { + System.out.println(target); + } + if (source instanceof int target) { //error + System.out.println(target); + } + if (source instanceof long target) { //error + System.out.println(target); + } + if (source instanceof double target) { //error + System.out.println(target); + } + if (source instanceof float target) { //error + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { //error + System.out.println(target); + } + } + + private static void testForInt(int source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForLong(long source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForDouble(double source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForFloat(float source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForByte(byte source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForChar(char source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { //error + System.out.println(target); + } + } + + private static void testForShort(short source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForBoolObject(Boolean source) { + if (source instanceof boolean target) { + System.out.println(target); + } + if (source instanceof int target) { //error + System.out.println(target); + } + if (source instanceof long target) { //error + System.out.println(target); + } + if (source instanceof double target) { //error + System.out.println(target); + } + if (source instanceof float target) { //error + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { //error + System.out.println(target); + } + } + + private static void testForIntObject(Integer source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForLongObject(Long source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { //error + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForDoubleObject(Double source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { //error + System.out.println(target); + } + if (source instanceof long target) { //error + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { //error + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForFloatObject(Float source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { //error + System.out.println(target); + } + if (source instanceof long target) { //error + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForByteObject(Byte source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForCharObject(Character source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { //error + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { + System.out.println(target); + } + if (source instanceof Short target) { //error + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { //error + System.out.println(target); + } + } + + private static void testForShortObject(Short source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { //error + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { //error + System.out.println(target); + } + if (source instanceof Long target) { //error + System.out.println(target); + } + if (source instanceof Double target) { //error + System.out.println(target); + } + if (source instanceof Float target) { //error + System.out.println(target); + } + if (source instanceof Byte target) { //error + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForObject(Object source) { + if (source instanceof boolean target) { + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { + System.out.println(target); + } + if (source instanceof Integer target) { + System.out.println(target); + } + if (source instanceof Long target) { + System.out.println(target); + } + if (source instanceof Double target) { + System.out.println(target); + } + if (source instanceof Float target) { + System.out.println(target); + } + if (source instanceof Byte target) { + System.out.println(target); + } + if (source instanceof Character target) { + System.out.println(target); + } + if (source instanceof Short target) { + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } + + private static void testForNumber(Number source) { + if (source instanceof boolean target) { //error + System.out.println(target); + } + if (source instanceof int target) { + System.out.println(target); + } + if (source instanceof long target) { + System.out.println(target); + } + if (source instanceof double target) { + System.out.println(target); + } + if (source instanceof float target) { + System.out.println(target); + } + if (source instanceof byte target) { + System.out.println(target); + } + if (source instanceof char target) { //error + System.out.println(target); + } + if (source instanceof short target) { + System.out.println(target); + } + + if (source instanceof Boolean target) { //error + System.out.println(target); + } + if (source instanceof Integer target) { + System.out.println(target); + } + if (source instanceof Long target) { + System.out.println(target); + } + if (source instanceof Double target) { + System.out.println(target); + } + if (source instanceof Float target) { + System.out.println(target); + } + if (source instanceof Byte target) { + System.out.println(target); + } + if (source instanceof Character target) { //error + System.out.println(target); + } + if (source instanceof Short target) { + System.out.println(target); + } + if (source instanceof Object target) { + System.out.println(target); + } + if (source instanceof Number target) { + System.out.println(target); + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPatternsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPatternsHighlightingTest.java index 9a8af9478716..171993e4c70b 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPatternsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPatternsHighlightingTest.java @@ -103,7 +103,15 @@ public class LightPatternsHighlightingTest extends LightJavaCodeInsightFixtureTe public void testUnnamedPatternsUnavailable() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_20, this::doTest); - } + } + + public void testInstanceofPrimitivesNotAllowed() { + IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22, this::doTest); + } + + public void testRecordPrimitiveInstanceOfPatternNotAllowed() { + IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22, this::doTest); + } private void doTest() { myFixture.configureByFile(getTestName(false) + ".java"); diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPrimitivePatternsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPrimitivePatternsHighlightingTest.java new file mode 100644 index 000000000000..60c284ab693d --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightPrimitivePatternsHighlightingTest.java @@ -0,0 +1,38 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.java.codeInsight.daemon; + +import com.intellij.JavaTestUtil; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; + +public class LightPrimitivePatternsHighlightingTest extends LightJavaCodeInsightFixtureTestCase { + @Override + protected String getBasePath() { + return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advHighlightingPatterns"; + } + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + //todo change after new Java + return JAVA_X; + } + + public void testRecordPrimitiveInstanceOfPattern() { + doTest(); + } + + public void testSimplePrimitiveInstanceOf() { + doTest(); + } + + public void testSimplePrimitiveInstanceOfPattern() { + doTest(); + } + + private void doTest() { + myFixture.configureByFile(getTestName(false) + ".java"); + myFixture.checkHighlighting(); + } +} \ No newline at end of file