mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
[java] IDEA-354964 Migrate standard descriptors like JAVA_21 to TYPE_USE annotations
- extract tests, which require old annotations - return old name to method to add annotations GitOrigin-RevId: c559cea10f942f72d5a19176d3ee808d46ad5dd2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
02a2f7bc86
commit
092062f856
@@ -93,9 +93,7 @@ class Contracts {
|
||||
private void testNotArraySize() {
|
||||
String[] things = retrieveThings();
|
||||
assertThat(things, not(is(arrayWithSize(2))));
|
||||
assertThat(things[0], is(equalTo("...")));
|
||||
things = null;
|
||||
assertThat(<warning descr="Array access 'things[0]' will produce 'NullPointerException'">things[0]</warning>, is(equalTo("...")));
|
||||
assertThat(<warning descr="Array access 'things[0]' may produce 'NullPointerException'">things[0]</warning>, is(equalTo("...")));
|
||||
}
|
||||
|
||||
void testBoxed(Contracts c) {
|
||||
|
||||
@@ -33,54 +33,11 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
|
||||
}
|
||||
|
||||
|
||||
private void checkHighlighting() {
|
||||
myFixture.enableInspections(new DataFlowInspection(), new ConstantValueInspection());
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testAssertThat() {
|
||||
myFixture.addClass("""
|
||||
package org.hamcrest; public class CoreMatchers { public static <T> Matcher<T> notNullValue() {}
|
||||
public static <T> Matcher<T> nullValue() {}
|
||||
public static <T> Matcher<T> not(Matcher<T> matcher) {}
|
||||
public static <T> Matcher<T> is(Matcher<T> matcher) {}
|
||||
public static <T> Matcher<T> is(T operand) {}
|
||||
public static <T> Matcher<T> equalTo(T operand) {}
|
||||
public static <E> Matcher<E[]> arrayWithSize(int size) {}\s
|
||||
}""");
|
||||
myFixture.addClass("package org.hamcrest; public interface Matcher<T> {}");
|
||||
myFixture.addClass("""
|
||||
package org.junit; public class Assert { public static <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher) {}
|
||||
public static <T> void assertThat(String msg, T actual, org.hamcrest.Matcher<? super T> matcher) {}
|
||||
}""");
|
||||
|
||||
myFixture.addClass("""
|
||||
package org.assertj.core.api; public class Assertions { public static <T> AbstractAssert<?, T> assertThat(Object actual) {}
|
||||
public static <T> AbstractAssert<?, T> assertThat(java.util.concurrent.atomic.AtomicBoolean actual) {}
|
||||
public static <T> AbstractAssert<?, T> assertThat(boolean actual) {}
|
||||
}""");
|
||||
myFixture.addClass("package org.assertj.core.api; public class AbstractAssert<S extends AbstractAssert<S, A>, A> {" +
|
||||
"public S isNotNull() {}" +
|
||||
"public S describedAs(String s) {}" +
|
||||
"public S isTrue() {}" +
|
||||
"public S isNotEmpty() {}" +
|
||||
"public S isEmpty() {}" +
|
||||
"public S isPresent() {}" +
|
||||
"public S isNotBlank() {}" +
|
||||
"public S isEqualTo(Object expected) {}" +
|
||||
"public S map(java.util.function.Function<String, Object> mapper) {}" +
|
||||
"public S hasSize(int size) {}" +
|
||||
"public S hasSizeBetween(int min, int max) {}" +
|
||||
"public S hasSizeGreaterThan(int size) {}" +
|
||||
"public S hasSizeGreaterThanOrEqualTo(int size) {}" +
|
||||
"public S hasSizeLessThan(int size) {}" +
|
||||
"public S hasSizeLessThanOrEqualTo(int size) {}" +
|
||||
"}");
|
||||
|
||||
checkHighlighting();
|
||||
}
|
||||
|
||||
public void testAssumeThat() {
|
||||
myFixture.addClass("package org.hamcrest; public class CoreMatchers { " +
|
||||
"public static <T> Matcher<T> notNullValue() {}\n" +
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.dataFlow.ConstantValueInspection;
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HardcodedContractsWithoutTypeUseAnnotationTest extends DataFlowInspectionTestCase {
|
||||
|
||||
private static final ProjectDescriptor JDK_21_WITH_NOT_TYPE_USE_ANNOTATION = new ProjectDescriptor(LanguageLevel.JDK_21) {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
addJetBrainsAnnotations(model);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
//it is necessary for some tests
|
||||
return JDK_21_WITH_NOT_TYPE_USE_ANNOTATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
|
||||
}
|
||||
|
||||
|
||||
private void checkHighlighting() {
|
||||
myFixture.enableInspections(new DataFlowInspection(), new ConstantValueInspection());
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testAssertThat() {
|
||||
myFixture.addClass("""
|
||||
package org.hamcrest; public class CoreMatchers { public static <T> Matcher<T> notNullValue() {}
|
||||
public static <T> Matcher<T> nullValue() {}
|
||||
public static <T> Matcher<T> not(Matcher<T> matcher) {}
|
||||
public static <T> Matcher<T> is(Matcher<T> matcher) {}
|
||||
public static <T> Matcher<T> is(T operand) {}
|
||||
public static <T> Matcher<T> equalTo(T operand) {}
|
||||
public static <E> Matcher<E[]> arrayWithSize(int size) {}\s
|
||||
}""");
|
||||
myFixture.addClass("package org.hamcrest; public interface Matcher<T> {}");
|
||||
myFixture.addClass("""
|
||||
package org.junit; public class Assert { public static <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher) {}
|
||||
public static <T> void assertThat(String msg, T actual, org.hamcrest.Matcher<? super T> matcher) {}
|
||||
}""");
|
||||
|
||||
myFixture.addClass("""
|
||||
package org.assertj.core.api; public class Assertions { public static <T> AbstractAssert<?, T> assertThat(Object actual) {}
|
||||
public static <T> AbstractAssert<?, T> assertThat(java.util.concurrent.atomic.AtomicBoolean actual) {}
|
||||
public static <T> AbstractAssert<?, T> assertThat(boolean actual) {}
|
||||
}""");
|
||||
myFixture.addClass("package org.assertj.core.api; public class AbstractAssert<S extends AbstractAssert<S, A>, A> {" +
|
||||
"public S isNotNull() {}" +
|
||||
"public S describedAs(String s) {}" +
|
||||
"public S isTrue() {}" +
|
||||
"public S isNotEmpty() {}" +
|
||||
"public S isEmpty() {}" +
|
||||
"public S isPresent() {}" +
|
||||
"public S isNotBlank() {}" +
|
||||
"public S isEqualTo(Object expected) {}" +
|
||||
"public S map(java.util.function.Function<String, Object> mapper) {}" +
|
||||
"public S hasSize(int size) {}" +
|
||||
"public S hasSizeBetween(int min, int max) {}" +
|
||||
"public S hasSizeGreaterThan(int size) {}" +
|
||||
"public S hasSizeGreaterThanOrEqualTo(int size) {}" +
|
||||
"public S hasSizeLessThan(int size) {}" +
|
||||
"public S hasSizeLessThanOrEqualTo(int size) {}" +
|
||||
"}");
|
||||
|
||||
checkHighlighting();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,7 @@ public class PointlessBooleanExpressionFixTest extends IGQuickFixesTestCase {
|
||||
myFixture.enableInspections(inspection);
|
||||
myRelativePath = "pointlessboolean";
|
||||
myDefaultHint = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
public void testNegation() { doTest(); }
|
||||
|
||||
@@ -16,7 +16,7 @@ public class CreateNullBranchFixTest extends IGQuickFixesTestCase {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myRelativePath = "dataflow/create_null_branch";
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@ public class IfCanBePatternSwitchFixTest extends IGQuickFixesTestCase {
|
||||
myFixture.enableInspections(inspection);
|
||||
myRelativePath = "migration/if_can_be_switch";
|
||||
myDefaultHint = CommonQuickFixBundle.message("fix.replace.x.with.y", PsiKeyword.IF, PsiKeyword.SWITCH);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@ public class IfCanBePrimitivePatternSwitchFixTest extends IGQuickFixesTestCase {
|
||||
myFixture.enableInspections(inspection);
|
||||
myRelativePath = "migration/if_can_be_switch";
|
||||
myDefaultHint = CommonQuickFixBundle.message("fix.replace.x.with.y", PsiKeyword.IF, PsiKeyword.SWITCH);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ public class LambdaCanBeReplacedWithAnonymousFixTest extends IGQuickFixesTestCas
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new LambdaCanBeReplacedWithAnonymousInspection());
|
||||
myDefaultHint = InspectionGadgetsBundle.message("lambda.can.be.replaced.with.anonymous.quickfix");
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsWithTypeUse);
|
||||
}
|
||||
|
||||
public void testSimpleRunnable() {
|
||||
|
||||
@@ -98,7 +98,7 @@ public abstract class LightJavaCodeInsightTestCase extends LightPlatformCodeInsi
|
||||
@Override
|
||||
protected void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
|
||||
}
|
||||
else {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
|
||||
@@ -73,11 +73,11 @@ public class DefaultLightProjectDescriptor extends LightProjectDescriptor {
|
||||
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES);
|
||||
}
|
||||
|
||||
public DefaultLightProjectDescriptor withJetBrainsAnnotationsJava8AndHigher() {
|
||||
public DefaultLightProjectDescriptor withJetBrainsAnnotationsWithTypeUse() {
|
||||
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
|
||||
}
|
||||
|
||||
public static void addJetBrainsAnnotationsJava8AndHigher(ModifiableRootModel model) {
|
||||
public static void addJetBrainsAnnotationsWithTypeUse(ModifiableRootModel model) {
|
||||
MavenDependencyUtil.addFromMaven(model, JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
addJetBrainsAnnotationsWithTypeUse(model);
|
||||
}
|
||||
else {
|
||||
addJetBrainsAnnotations(model);
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class LombokTestUtil {
|
||||
public static final DefaultLightProjectDescriptor LOMBOK_DESCRIPTOR = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
|
||||
MavenDependencyUtil.addFromMaven(model, LOMBOK_MAVEN_COORDINATES, true, DependencyScope.PROVIDED);
|
||||
MavenDependencyUtil.addFromMaven(model, JACKSON_MAVEN_COORDINATES);
|
||||
MavenDependencyUtil.addFromMaven(model, "com.google.guava:guava:27.0.1-jre");
|
||||
@@ -37,7 +37,7 @@ public final class LombokTestUtil {
|
||||
public static final DefaultLightProjectDescriptor WITHOUT_LOMBOK_DESCRIPTOR = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
|
||||
MavenDependencyUtil.addFromMaven(model, JACKSON_MAVEN_COORDINATES);
|
||||
MavenDependencyUtil.addFromMaven(model, "com.google.guava:guava:27.0.1-jre");
|
||||
MavenDependencyUtil.addFromMaven(model, "org.slf4j:slf4j-api:1.7.30");
|
||||
|
||||
Reference in New Issue
Block a user