mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
[java-tests] Mock JDK 21 (downloaded from the repository); remove in-place mocks where possible
Part of IDEA-334171 Store MockJDK in artifact repository, rather than in Git GitOrigin-RevId: 9c6214e3ead47cc164d20813f5a2b37136607213
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2204b08d1c
commit
77d1d0ab2e
@@ -1,6 +1,6 @@
|
||||
public class FooMap<K,V extends K> implements YourMapInterface<K, V> {
|
||||
void foo() {
|
||||
class Zoooooooo {}
|
||||
Zoo<caret>
|
||||
Zooo<caret>
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
enum TestEnum { TEXT1, TEXT2 }
|
||||
enum TestEnum { MYVAL1, MYVAL2 }
|
||||
public @interface TestAnnotation { TestEnum value(); }
|
||||
|
||||
@TestAnnotation(Tex<caret>)
|
||||
@TestAnnotation(MYVAL<caret>)
|
||||
@@ -1,4 +1,4 @@
|
||||
enum TestEnum { TEXT1, TEXT2 }
|
||||
enum TestEnum { MYVAL1, MYVAL2 }
|
||||
public @interface TestAnnotation { TestEnum value(); }
|
||||
|
||||
@TestAnnotation(TestEnum.TEXT1<caret>)
|
||||
@TestAnnotation(TestEnum.MYVAL1<caret>)
|
||||
@@ -1,17 +1,4 @@
|
||||
// "Fix all 'Redundant embedded expression in string template' problems in file" "true"
|
||||
package java.lang;
|
||||
import java.util.*;
|
||||
public interface StringTemplate {
|
||||
List<String> fragments();
|
||||
List<Object> values();
|
||||
native static StringTemplate of(String string);
|
||||
Processor<String, RuntimeException> STR;
|
||||
Processor<StringTemplate, RuntimeException> RAW;
|
||||
interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(STR."hello|null|world");
|
||||
|
||||
@@ -1,17 +1,4 @@
|
||||
// "Fix all 'Redundant embedded expression in string template' problems in file" "true"
|
||||
package java.lang;
|
||||
import java.util.*;
|
||||
public interface StringTemplate {
|
||||
List<String> fragments();
|
||||
List<Object> values();
|
||||
native static StringTemplate of(String string);
|
||||
Processor<String, RuntimeException> STR;
|
||||
Processor<StringTemplate, RuntimeException> RAW;
|
||||
interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(STR."hello|\{ }|world");
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// "Replace 'YYYY' with 'yyyy'" "true"
|
||||
package java.text;
|
||||
|
||||
class SimpleDateFormat{public SimpleDateFormat(String pattern) {}}
|
||||
import java.text.*;
|
||||
|
||||
class X {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// "Replace 'YYYY' with 'yyyy'" "true"
|
||||
package java.text;
|
||||
|
||||
class SimpleDateFormat{public SimpleDateFormat(String pattern) {}}
|
||||
import java.text.*;
|
||||
|
||||
class X {
|
||||
SimpleDateFormat format = new SimpleDateFormat("YY<caret>YY/MM/dd");
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// "Fix all 'SequencedCollection method can be used' problems in file" "true"
|
||||
package java.util;
|
||||
import java.util.*;
|
||||
|
||||
interface SequencedCollection<E> extends Collection<E> {
|
||||
}
|
||||
interface Foo extends SequencedCollection<String> {}
|
||||
|
||||
public class Test {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// "Fix all 'SequencedCollection method can be used' problems in file" "true"
|
||||
package java.util;
|
||||
import java.util.*;
|
||||
|
||||
interface SequencedCollection<E> extends Collection<E> {
|
||||
}
|
||||
interface Foo extends SequencedCollection<String> {}
|
||||
|
||||
public class Test {
|
||||
|
||||
@@ -7,8 +7,8 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
private void newMethod(String s, String s1) {
|
||||
private void newMethod(String s, String x) {
|
||||
System.out.println(s);
|
||||
System.out.println(s1);
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,3 @@
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
public interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}
|
||||
class Main {
|
||||
|
||||
class FailureException extends Exception {}
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
public interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}
|
||||
class Main {
|
||||
|
||||
class FailureException extends Exception {}
|
||||
|
||||
@@ -4,110 +4,19 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.RedundantCompareToJavaTimeInspection;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class RedundantCompareToJavaTimeInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
public void testCompareTo() {
|
||||
myFixture.addClass("""
|
||||
package java.time.chrono;
|
||||
interface ChronoLocalDateTime<T>{}
|
||||
interface ChronoLocalDate{}
|
||||
""");
|
||||
//ignore because we mock these classes
|
||||
//noinspection MethodOverloadsMethodOfSuperclass
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.chrono.*;class LocalDate implements ChronoLocalDate, Comparable<ChronoLocalDate>{
|
||||
public static LocalDate now() {
|
||||
return new LocalDate();
|
||||
}
|
||||
@Override
|
||||
public int compareTo(ChronoLocalDate o) {
|
||||
return 0;
|
||||
}
|
||||
public boolean isAfter(LocalDate localDate) {
|
||||
return true;
|
||||
}
|
||||
public boolean isBefore(LocalDate localDate) {
|
||||
return true;
|
||||
}
|
||||
public boolean isEqual(LocalDate localDate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class LocalDateTime implements ChronoLocalDateTime<LocalDateTime>, Comparable<ChronoLocalDateTime>{
|
||||
public static LocalDateTime now() {
|
||||
return new LocalDateTime();
|
||||
}
|
||||
@Override
|
||||
public int compareTo(ChronoLocalDateTime<?> o) {
|
||||
return 0;
|
||||
}
|
||||
public boolean isAfter(LocalDateTime localDateTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isBefore(LocalDateTime localDateTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isEqual(LocalDateTime localDateTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class LocalTime implements Comparable<LocalTime>{
|
||||
public static LocalTime now() {
|
||||
return new LocalTime();
|
||||
}
|
||||
@Override
|
||||
public int compareTo(LocalTime o) {
|
||||
return 0;
|
||||
}
|
||||
public boolean isAfter(LocalTime localTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isBefore(LocalTime localTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class OffsetTime implements Comparable<OffsetTime> {
|
||||
public static OffsetTime now() {
|
||||
return new OffsetTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(OffsetTime o) {
|
||||
return 0;
|
||||
}
|
||||
public boolean isAfter(OffsetTime offsetTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isBefore(OffsetTime offsetTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isEqual(OffsetTime offsetTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class OffsetDateTime implements Comparable<OffsetDateTime>{
|
||||
public static OffsetDateTime now() {
|
||||
return new OffsetDateTime();
|
||||
}
|
||||
@Override
|
||||
public int compareTo(OffsetDateTime o) {
|
||||
return 0;
|
||||
}
|
||||
public boolean isAfter(OffsetDateTime offsetDateTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isBefore(OffsetDateTime offsetDateTime) {
|
||||
return true;
|
||||
}
|
||||
public boolean isEqual(OffsetDateTime offsetDateTime) {
|
||||
return true;
|
||||
}
|
||||
}""");
|
||||
final LocalInspectionTool inspection = new RedundantCompareToJavaTimeInspection();
|
||||
myFixture.enableInspections(inspection);
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ public class RedundantStringOperationInspectionTest extends LightJavaInspectionT
|
||||
}
|
||||
|
||||
protected void doTest21() {
|
||||
addStringTemplateClass();
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21_PREVIEW, this::doTest);
|
||||
}
|
||||
|
||||
@@ -49,20 +48,6 @@ public class RedundantStringOperationInspectionTest extends LightJavaInspectionT
|
||||
checkQuickFixAll();
|
||||
}
|
||||
|
||||
private void addStringTemplateClass() {
|
||||
myFixture.addClass("""
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}""");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/inspection/redundantStringOperation/";
|
||||
|
||||
@@ -314,7 +314,7 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testInsideSwitchCaseWithEnumConstant() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "compareTo", "equals");
|
||||
myFixture.assertPreferredCompletionItems(0, "compareTo", "describeConstable", "equals");
|
||||
}
|
||||
|
||||
public void testMethodInAnnotation() {
|
||||
@@ -512,13 +512,15 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testLocalClassTwice() {
|
||||
configure();
|
||||
assertOrderedEquals(myFixture.getLookupElementStrings(), "Zoooz", "Zooooo", "ZipOutputStream");
|
||||
assertOrderedEquals(myFixture.getLookupElementStrings(),
|
||||
"Zoooz", "Zooooo", "ZoneId", "ZoneRulesException", "ZoneRulesProvider", "ZipOutputStream");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testLocalTopLevelConflict() {
|
||||
configure();
|
||||
assertOrderedEquals(myFixture.getLookupElementStrings(), "Zoooz", "Zooooo", "ZipOutputStream");
|
||||
assertOrderedEquals(myFixture.getLookupElementStrings(),
|
||||
"Zoooz", "Zooooo", "ZoneId", "ZoneRulesException", "ZoneRulesProvider", "ZipOutputStream");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
@@ -1944,8 +1946,10 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.Full
|
||||
public void testShowNonImportedVarInitializers() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(1, "Field", "FIELD1", "FIELD2", "FIELD3", "FIELD4");
|
||||
var fieldItems = myFixture.getLookup().getItems().subList(1, 5);
|
||||
// Format.Field, DateFormat.Field, NumberFormat.Field, etc. classes are suggested first
|
||||
myFixture.assertPreferredCompletionItems(5,
|
||||
"Field", "Field", "Field", "Field", "Field", "FIELD1", "FIELD2", "FIELD3", "FIELD4");
|
||||
var fieldItems = myFixture.getLookup().getItems().subList(5, 9);
|
||||
assertEquals(Arrays.asList("( \"x\") in E", "(\"y\") {...} in E", null, " ( = 42) in E"),
|
||||
ContainerUtil.map(fieldItems, item -> renderElement(item).getTailText()));
|
||||
assertTrue(renderElement(fieldItems.get(3)).getTailFragments().get(0).isItalic());
|
||||
@@ -2455,12 +2459,14 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
public void testNoFinalLibraryClassesInExtends() {
|
||||
myFixture.configureByText("X.java", "class StriFoo{}final class StriBar{}class X extends Stri<caret>");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(myFixture.getLookupElementStrings(), List.of(
|
||||
List<String> expected = List.of(
|
||||
"StriFoo", // non-final project class
|
||||
"StringIndexOutOfBoundsException", "StringTokenizer", "StringConcatException", "StringReader", "StringWriter",
|
||||
// non-final library classes
|
||||
"StringBufferInputStream", // deprecated library class
|
||||
"StriBar")); // final project class (red)
|
||||
"StriBar", // final project class (red)
|
||||
"StringTemplate"); // interface (red)
|
||||
assertEquals(expected, myFixture.getLookupElementStrings());
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
|
||||
@@ -25,8 +25,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
record Point(int x, int y);
|
||||
class X {
|
||||
@@ -47,8 +47,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x1, int y2)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x1, int y2)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
record Point(int x, int y);
|
||||
class X {
|
||||
@@ -69,8 +69,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
import com.example.Point;
|
||||
|
||||
@@ -115,8 +115,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
import com.example.Y;
|
||||
|
||||
@@ -139,8 +139,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
record Point(int x, int y);
|
||||
class X {
|
||||
@@ -166,7 +166,7 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
myFixture.completeBasic();
|
||||
// Options contributed by TypoTolerantMatcher; these classes contain nested public classes,
|
||||
// so we allow them, as they may potentially contain string constants
|
||||
assertEquals(List.of("ForkJoinPool", "ThreadPoolExecutor"), myFixture.getLookupElementStrings());
|
||||
assertEquals(List.of("Policy", "ForkJoinPool", "ThreadPoolExecutor"), myFixture.getLookupElementStrings());
|
||||
}
|
||||
|
||||
@NeedsIndex.Full
|
||||
@@ -181,8 +181,8 @@ public class NormalPatternsCompletionTest extends NormalCompletionTestCase {
|
||||
}
|
||||
}""");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(List.of("Point", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(1);
|
||||
assertEquals(List.of("Point", "PolicyQualifierInfo", "Point(int x, int y)", "NullPointerException"), myFixture.getLookupElementStrings());
|
||||
selectItem(2);
|
||||
myFixture.checkResult("""
|
||||
import com.example.Point;
|
||||
|
||||
|
||||
@@ -21,24 +21,6 @@ public class LightStringTemplatesHighlightingTest extends LightJavaCodeInsightFi
|
||||
public void testStringTemplates() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
myFixture.addClass("""
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
Processor<StringTemplate, RuntimeException> RAW = st -> st;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
public interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.util;
|
||||
public final class FormatProcessor implements Processor<String, RuntimeException> {
|
||||
private FormatProcessor(Locale locale) {}
|
||||
public static final FormatProcessor FMT = new FormatProcessor(Locale.ROOT);
|
||||
}""");
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
|
||||
@@ -69,20 +69,11 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
||||
public void testSkipSwitchExpressionWithThrow() { doTest(); }
|
||||
|
||||
public void testStringTemplates() {
|
||||
myFixture.addClass("""
|
||||
package java.lang;
|
||||
import java.util.*;
|
||||
public interface StringTemplate {
|
||||
List<String> fragments();
|
||||
List<Object> values();
|
||||
native static StringTemplate of(String string);
|
||||
Processor<String, RuntimeException> STR;
|
||||
Processor<StringTemplate, RuntimeException> RAW;
|
||||
interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}""");
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testChronoRange() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
@@ -92,46 +92,6 @@ public class DataFlowRangeAnalysisTest extends DataFlowInspectionTestCase {
|
||||
public void testStringIndexOfRelation() { doTest(); }
|
||||
public void testIncompleteLoop() { doTest(); }
|
||||
public void testTwoFlagsMixed() { doTest(); }
|
||||
public void testChronoRange() {
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
public interface TemporalField{}""");
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
import java.time.temporal.TemporalField;
|
||||
public enum ChronoField implements TemporalField{
|
||||
INSTANT_SECONDS, OFFSET_SECONDS, MINUTE_OF_HOUR, ERA, EPOCH_DAY
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
public interface OffsetTime{
|
||||
int get(TemporalField field);
|
||||
long getLong(TemporalField field);
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
public interface LocalDateTime{
|
||||
int get(TemporalField field);
|
||||
long getLong(TemporalField field);
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
public interface LocalDate{
|
||||
int get(TemporalField field);
|
||||
long getLong(TemporalField field);
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
public interface LocalTime{
|
||||
int get(TemporalField field);
|
||||
long getLong(TemporalField field);
|
||||
}""");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testJmhParamRange() {
|
||||
myFixture.addClass("package org.openjdk.jmh.annotations;public @interface Param {String[] value();}");
|
||||
|
||||
@@ -25,7 +25,7 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,28 +185,7 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
|
||||
|
||||
public void testCharacterMethods() { checkHighlighting(); }
|
||||
|
||||
@SuppressWarnings("MethodOverloadsMethodOfSuperclass")
|
||||
public void testDateTimeComparing() {
|
||||
myFixture.addClass("""
|
||||
package java.time.chrono;
|
||||
public interface ChronoLocalDateTime<T> { }""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
public final class LocalTime {
|
||||
public static LocalTime now() { return new LocalTime(); }
|
||||
public boolean isBefore(LocalTime localTime) { return false; }
|
||||
public boolean isAfter(LocalTime localTime) { return false; }
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.chrono.ChronoLocalDateTime;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
public final class LocalDateTime implements ChronoLocalDateTime<LocalDate> {
|
||||
public static LocalDateTime now() { return new LocalDateTime(); }
|
||||
public boolean isBefore(ChronoLocalDateTime<LocalDate> localDateTime2) { return false; }
|
||||
public boolean isAfter(ChronoLocalDateTime<LocalDate> localDateTime2) { return false; }
|
||||
}""");
|
||||
checkHighlighting();
|
||||
}
|
||||
|
||||
|
||||
@@ -295,20 +295,4 @@ public class StringTemplateMigrationInspectionTest extends LightJavaCodeInsightF
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return LightJavaCodeInsightFixtureTestCase.JAVA_21;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.addClass("""
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}""");
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,11 @@ import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.PackageEntry;
|
||||
import com.intellij.psi.codeStyle.PackageEntryTable;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleSettingsModifier;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.ServiceContainerUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.concurrency.AppExecutorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -45,6 +46,11 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
return BASE_PATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -82,18 +88,6 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
doTest();
|
||||
}
|
||||
public void testStringTemplates() {
|
||||
IdeaTestUtil.setModuleLanguageLevel(getModule(), LanguageLevel.JDK_21_PREVIEW);
|
||||
myFixture.addClass("""
|
||||
package java.lang;
|
||||
public interface StringTemplate {
|
||||
Processor<String, RuntimeException> STR = null;
|
||||
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
|
||||
@FunctionalInterface
|
||||
public interface Processor<R, E extends Throwable> {
|
||||
R process(StringTemplate stringTemplate) throws E;
|
||||
}
|
||||
}""");
|
||||
doTest();
|
||||
}
|
||||
public void testNewImportListIsEmptyAndCommentPreserved() { doTest(); }
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.registry.RegistryValue;
|
||||
@@ -24,6 +25,7 @@ import com.intellij.refactoring.extractMethod.ExtractMethodHandler;
|
||||
import com.intellij.refactoring.extractMethod.ExtractMethodProcessor;
|
||||
import com.intellij.refactoring.extractMethod.PrepareFailedException;
|
||||
import com.intellij.refactoring.util.duplicates.Match;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -37,6 +39,11 @@ public class ExtractMethodTest extends LightJavaCodeInsightTestCase {
|
||||
@NonNls private static final String BASE_PATH = "/refactoring/extractMethod/";
|
||||
private boolean myCatchOnNewLine = true;
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk21();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
@@ -15,14 +15,10 @@ public class IncorrectDateTimeFormatInspectionTest extends LightJavaCodeInsightF
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
//mock
|
||||
//noinspection InstantiationOfUtilityClass
|
||||
myFixture.addClass("package java.time.format;public class DateTimeFormatter{" +
|
||||
"public static DateTimeFormatter ofPattern(String pattern) {return new DateTimeFormatter();}}");
|
||||
myFixture.enableInspections(new IncorrectDateTimeFormatInspection());
|
||||
myFixture.testHighlighting(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@@ -15,16 +15,10 @@ public class IncorrectMessageFormatInspectionTest extends LightJavaCodeInsightFi
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"NonFinalUtilityClass", "UtilityClassWithPublicConstructor"})
|
||||
private void doTest() {
|
||||
myFixture.addClass("""
|
||||
package java.text;
|
||||
public class MessageFormat{
|
||||
public MessageFormat(String pattern) {}
|
||||
public static String format(String pattern, Object ... arguments) {return null;}}""");
|
||||
myFixture.enableInspections(new IncorrectMessageFormatInspection());
|
||||
myFixture.testHighlighting(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@@ -15,11 +15,10 @@ public class SuspiciousDateFormatInspectionTest extends LightJavaCodeInsightFixt
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.addClass("package java.text;public class SimpleDateFormat{public SimpleDateFormat(String pattern) {}}");
|
||||
myFixture.enableInspections(new SuspiciousDateFormatInspection());
|
||||
myFixture.testHighlighting(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UnsupportedChronoFieldUnitCallTest extends LightJavaInspectionTestCase {
|
||||
@@ -59,37 +61,8 @@ public class UnsupportedChronoFieldUnitCallTest extends LightJavaInspectionTestC
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[]{
|
||||
"""
|
||||
package java.time.temporal;
|
||||
public interface TemporalUnit{}""",
|
||||
"""
|
||||
package java.time.temporal;
|
||||
public public enum ChronoUnit implements TemporalUnit{HOURS, DAYS}""",
|
||||
"""
|
||||
package java.time.temporal;
|
||||
public interface TemporalField{}""",
|
||||
"""
|
||||
package java.time.temporal;
|
||||
public enum ChronoField implements TemporalField{SECOND_OF_DAY, MONTH_OF_YEAR}""",
|
||||
"""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
public final class LocalTime {
|
||||
public int get(TemporalField field) { return 0; }
|
||||
public LocalTime minus(long amountToAdd, TemporalUnit unit) { return null; }
|
||||
}""",
|
||||
"""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
public final class LocalDate {
|
||||
public int get(TemporalField field) { return 0; }
|
||||
public LocalDate minus(long amountToAdd, TemporalUnit unit) { return null; }
|
||||
}"""
|
||||
};
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.siyeh.ig.fixes.bugs;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import com.siyeh.ig.bugs.SuspiciousDateFormatInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_21;
|
||||
|
||||
public class SuspiciousDateFormatFixTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected LocalInspectionTool @NotNull [] configureLocalInspectionTools() {
|
||||
@@ -19,6 +22,11 @@ public class SuspiciousDateFormatFixTest extends LightQuickFixParameterizedTestC
|
||||
return "/com/siyeh/igfixes/bugs/suspicious_date_format";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
package com.siyeh.ig.internationalization;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
@@ -14,26 +16,8 @@ public class SimpleDateFormatWithoutLocaleInspectionTest extends LightJavaInspec
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[] {
|
||||
"package java.text;" +
|
||||
"import java.util.Locale;" +
|
||||
"public class SimpleDateFormat {" +
|
||||
" public SimpleDateFormat(String pattern) {}" +
|
||||
" public SimpleDateFormat(String pattern, Locale locale) {}" +
|
||||
"}",
|
||||
|
||||
"package java.time.format;" +
|
||||
"import java.util.Locale;" +
|
||||
"public final class DateTimeFormatter {" +
|
||||
" public static DateTimeFormatter ofPattern(String pattern) {" +
|
||||
" return null;" +
|
||||
" }" +
|
||||
" public static DateTimeFormatter ofPattern(String pattern, Locale locale) {" +
|
||||
" return null;" +
|
||||
" }" +
|
||||
"}"
|
||||
};
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
public void testSimpleDateFormatWithoutLocale() { doTest(); }
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package com.siyeh.ig.maturity;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
@@ -28,13 +30,8 @@ public class UseOfObsoleteDateTimeApiInspectionTest extends LightJavaInspectionT
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[] {
|
||||
"package java.util;" +
|
||||
"public class TimeZone {}",
|
||||
"package java.time;" +
|
||||
"public class Instant {}"
|
||||
};
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,32 +19,6 @@ public class RedundantExplicitChronoFieldInspectionTest extends LightJavaCodeIns
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new RedundantExplicitChronoFieldInspection());
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
public interface TemporalUnit{}""");
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
public public enum ChronoUnit implements TemporalUnit{NANOS, YEARS, DECADES, FOREVER}""");
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
public interface TemporalField{}""");
|
||||
myFixture.addClass("""
|
||||
package java.time.temporal;
|
||||
public enum ChronoField implements TemporalField{NANO_OF_SECOND, NANO_OF_DAY, YEAR, INSTANT_SECONDS}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalField;
|
||||
public final class OffsetDateTime {
|
||||
public int get(TemporalField field) { return 0; }
|
||||
public int getNano() { return 0; }
|
||||
public int getYear() { return 0; }
|
||||
}""");
|
||||
myFixture.addClass("""
|
||||
package java.time;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
public final class OffsetTime {
|
||||
public OffsetTime plus(long amountToAdd, TemporalUnit unit) { return new OffsetTime(); }
|
||||
}""");
|
||||
}
|
||||
|
||||
public void testPreview() {
|
||||
@@ -58,7 +32,7 @@ public class RedundantExplicitChronoFieldInspectionTest extends LightJavaCodeIns
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
private void doTest(@Nullable String quickFixName) {
|
||||
|
||||
@@ -2,31 +2,15 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class AccessToNonThreadSafeStaticFieldFromInstanceInspectionTest extends LightJavaInspectionTestCase {
|
||||
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[]{
|
||||
"package java.text;" +
|
||||
"import java.util.Date;" +
|
||||
"public abstract class DateFormat {" +
|
||||
" public String format(Date d) {}" +
|
||||
" public static DateFormat getDateInstance() {" +
|
||||
" return null;" +
|
||||
" }" +
|
||||
"}",
|
||||
"package java.text;" +
|
||||
"public class SimpleDateFormat extends DateFormat {" +
|
||||
" public SimpleDateFormat(String s) {}" +
|
||||
"}"
|
||||
};
|
||||
}
|
||||
|
||||
public void testSimple() {
|
||||
doTest("import java.util.Date;" +
|
||||
"import java.text.DateFormat;" +
|
||||
@@ -63,6 +47,11 @@ public class AccessToNonThreadSafeStaticFieldFromInstanceInspectionTest extends
|
||||
"}");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool getInspection() {
|
||||
return new AccessToNonThreadSafeStaticFieldFromInstanceInspection();
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.jarRepository.JarRepositoryManager;
|
||||
import com.intellij.jarRepository.RemoteRepositoryDescription;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.LanguageLevelUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.projectRoots.*;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.projectRoots.impl.MockSdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -22,11 +26,13 @@ import com.intellij.util.lang.JavaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -67,15 +73,40 @@ public final class IdeaTestUtil {
|
||||
}
|
||||
|
||||
public static @NotNull Sdk getMockJdk(@NotNull JavaVersion version) {
|
||||
int mockJdk = version.feature >= 11 ? 11 :
|
||||
int mockJdk = version.feature >= 21 ? 21 :
|
||||
version.feature >= 11 ? 11 :
|
||||
version.feature >= 9 ? 9 :
|
||||
version.feature >= 7 ? version.feature :
|
||||
version.feature >= 5 ? 7 :
|
||||
4;
|
||||
if (mockJdk > 11) {
|
||||
return createMockJdkFromRepository("java " + version, mockJdk);
|
||||
}
|
||||
String path = getPathForJdkNamed(MOCK_JDK_DIR_NAME_PREFIX + (mockJdk < 11 ? "1." : "") + mockJdk).getPath();
|
||||
return createMockJdk("java " + version, path);
|
||||
}
|
||||
|
||||
private static Sdk createMockJdkFromRepository(String name, int version) {
|
||||
List<RemoteRepositoryDescription> repos = MavenDependencyUtil.getRemoteRepositoryDescriptions();
|
||||
String coordinates = "org.jetbrains.mockjdk:mockjdk-base-java:" + version + ".0";
|
||||
RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(coordinates, false);
|
||||
Collection<OrderRoot> roots =
|
||||
JarRepositoryManager.loadDependenciesModal(ProjectManager.getInstance().getDefaultProject(), libraryProperties, false, false, null,
|
||||
repos);
|
||||
if (roots.isEmpty()) {
|
||||
throw new IllegalStateException("MockJDK artifact not found: " + coordinates);
|
||||
}
|
||||
if (roots.size() != 1) {
|
||||
throw new IllegalStateException("Unexpected number of roots: " + coordinates + ": " + roots);
|
||||
}
|
||||
VirtualFile file = roots.iterator().next().getFile();
|
||||
String canonicalPath = file.getCanonicalPath();
|
||||
if (canonicalPath == null) {
|
||||
throw new IllegalStateException("No canonical path found for " + file);
|
||||
}
|
||||
return createMockJdk(name, canonicalPath);
|
||||
}
|
||||
|
||||
public static @NotNull Sdk createMockJdk(@NotNull String name, @NotNull String path) {
|
||||
JavaSdk javaSdk = JavaSdk.getInstance();
|
||||
if (javaSdk == null) {
|
||||
@@ -108,10 +139,17 @@ public final class IdeaTestUtil {
|
||||
}
|
||||
};
|
||||
|
||||
File[] jars = new File(path, "jre/lib").listFiles(f -> f.getName().endsWith(".jar"));
|
||||
if (jars != null) {
|
||||
for (File jar : jars) {
|
||||
sdkModificator.addRoot("jar://"+PathUtil.toSystemIndependentName(jar.getPath())+"!/", OrderRootType.CLASSES);
|
||||
String sdkPath;
|
||||
if (path.endsWith(".jar!/")) {
|
||||
sdkPath = PathUtil.getParentPath(path);
|
||||
sdkModificator.addRoot("jar://"+path, OrderRootType.CLASSES);
|
||||
} else {
|
||||
sdkPath = PathUtil.toSystemIndependentName(path);
|
||||
File[] jars = new File(path, "jre/lib").listFiles(f -> f.getName().endsWith(".jar"));
|
||||
if (jars != null) {
|
||||
for (File jar : jars) {
|
||||
sdkModificator.addRoot("jar://"+PathUtil.toSystemIndependentName(jar.getPath())+"!/", OrderRootType.CLASSES);
|
||||
}
|
||||
}
|
||||
}
|
||||
// only Mock JDKs 1.4/1.7 have src.zip
|
||||
@@ -123,7 +161,7 @@ public final class IdeaTestUtil {
|
||||
|
||||
JavaSdkImpl.attachJdkAnnotations(sdkModificator);
|
||||
|
||||
return new MockSdk(name, PathUtil.toSystemIndependentName(path), name, roots, () -> JavaSdk.getInstance());
|
||||
return new MockSdk(name, sdkPath, name, roots, () -> JavaSdk.getInstance());
|
||||
}
|
||||
|
||||
// it's JDK 1.4, not 14
|
||||
@@ -159,6 +197,10 @@ public final class IdeaTestUtil {
|
||||
return getMockJdk(JavaVersion.compose(11));
|
||||
}
|
||||
|
||||
public static @NotNull Sdk getMockJdk21() {
|
||||
return getMockJdk(JavaVersion.compose(21));
|
||||
}
|
||||
|
||||
public static @NotNull File getMockJdk14Path() {
|
||||
return getPathForJdkNamed(MOCK_JDK_DIR_NAME_PREFIX + "1.4");
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public final class MavenDependencyUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<RemoteRepositoryDescription> getRemoteRepositoryDescriptions() {
|
||||
public static List<RemoteRepositoryDescription> getRemoteRepositoryDescriptions() {
|
||||
return ContainerUtil.map(IntelliJProjectConfiguration.getRemoteRepositoryDescriptions(), repository ->
|
||||
new RemoteRepositoryDescription(repository.getId(), repository.getName(), repository.getUrl()));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
package com.intellij.spellchecker.inspection;
|
||||
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaSpellcheckerInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
@@ -11,13 +13,8 @@ public class JavaSpellcheckerInspectionTest extends LightJavaCodeInsightFixtureT
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.addClass("package org.jetbrains.annotations;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"@Retention(RetentionPolicy.CLASS)" +
|
||||
"@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE, ElementType.PACKAGE})" +
|
||||
"public @interface NonNls {}");
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
public void testCorrectJava() { doTest(); }
|
||||
@@ -44,29 +41,7 @@ public class JavaSpellcheckerInspectionTest extends LightJavaCodeInsightFixtureT
|
||||
public void testNonNlsLocalVariableAndComment() { doTest(); }
|
||||
public void testFieldComment() { doTest(); }
|
||||
public void testDoNotCheckDerivedNames() { doTest(); }
|
||||
public void testSkipDateTime() {
|
||||
myFixture.addClass("""
|
||||
package java.text;
|
||||
public class SimpleDateFormat{
|
||||
public SimpleDateFormat(String pattern){}
|
||||
public void applyPattern(String pattern){}
|
||||
public void applyLocalizedPattern(String pattern){}
|
||||
}
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package java.time.format;
|
||||
public class DateTimeFormatter{
|
||||
public static DateTimeFormatter ofPattern(String pattern){return null;}
|
||||
}
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package java.time.format;
|
||||
public class DateTimeFormatterBuilder{
|
||||
public DateTimeFormatterBuilder appendPattern(String pattern){return this;}
|
||||
}
|
||||
""");
|
||||
doTest();
|
||||
}
|
||||
public void testSkipDateTime() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
myFixture.enableInspections(SpellcheckerInspectionTestCase.getInspectionTools());
|
||||
|
||||
Reference in New Issue
Block a user