IDEA-133514 (Malformed format string inspection doesn't seem to understand Java 8's java.time classes)

This commit is contained in:
Bas Leijdekkers
2015-08-27 11:43:31 +02:00
parent 6ee3957e68
commit e1146c697b
3 changed files with 51 additions and 1 deletions
@@ -260,7 +260,8 @@ class FormatDecode {
return PsiType.LONG.equals(type) ||
CommonClassNames.JAVA_LANG_LONG.equals(text) ||
InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_DATE) ||
InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_CALENDAR);
InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_CALENDAR) ||
InheritanceUtil.isInheritor(type, "java.time.temporal.TemporalAccessor");
}
}
@@ -89,5 +89,6 @@ public class MalformedFormatString {
void goodStrings() {
String.format("%-B", true); // left justify flag
String.format("%,d", 34567890);
System.out.printf("%tF %n", java.time.ZonedDateTime.now()); // java.time.temporal.TemporalAccessor, new in Java 8
}
}
@@ -18,4 +18,52 @@ public class MalformedFormatStringInspectionTest extends LightInspectionTestCase
inspection.methodNames.add("d");
return inspection;
}
@Override
protected String[] getEnvironmentClasses() {
return new String[] {
"package java.time.temporal;\n" +
"public interface TemporalAccessor {\n" +
" boolean isSupported(TemporalField field);\n" +
" default ValueRange range(TemporalField field) {\n" +
" return null;\n" +
" }\n" +
" default int get(TemporalField field) {\n" +
" return 0;\n" +
" }\n" +
" long getLong(TemporalField field);\n" +
" default <R> R query(TemporalQuery<R> query) {\n" +
" return null;\n" +
" }\n" +
"}",
"package java.time.temporal;\n" +
"public interface Temporal extends TemporalAccessor {\n" +
" boolean isSupported(TemporalUnit unit);\n" +
" default Temporal with(TemporalAdjuster adjuster) {\n" +
" return null;\n" +
" }\n" +
" Temporal with(TemporalField field, long newValue);\n" +
" default Temporal plus(TemporalAmount amount) {\n" +
" return null;\n" +
" }\n" +
" Temporal plus(long amountToAdd, TemporalUnit unit);\n" +
" default Temporal minus(TemporalAmount amount) {\n" +
" return null;\n" +
" }\n" +
" default Temporal minus(long amountToSubtract, TemporalUnit unit) {\n" +
" return null;\n" +
" }\n" +
" long until(Temporal endExclusive, TemporalUnit unit);\n" +
"}",
"package java.time;\n" +
"import java.time.temporal.Temporal;\n" +
"public abstract class ZonedDateTime implements Temporal {\n" +
" public static ZonedDateTime now() {\n" +
" return null;\n" +
" }\n" +
"}"
};
}
}