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
GitOrigin-RevId: d13187d41d214bd2ccadecb4cadc925f7d787d60
This commit is contained in:
committed by
intellij-monorepo-bot
parent
950fc76efd
commit
638393e895
@@ -153,6 +153,10 @@ public final class JavaReferenceAdjuster implements ReferenceAdjuster {
|
||||
if (modifierList != null) {
|
||||
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
|
||||
if (AnnotationTargetUtil.findAnnotationTarget(annotation, PsiAnnotation.TargetType.TYPE_USE) != null) {
|
||||
if (modifierList.getParent() instanceof PsiMethod &&
|
||||
AnnotationTargetUtil.findAnnotationTarget(annotation, PsiAnnotation.TargetType.METHOD) != null) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class MissortedModifiers {
|
||||
|
||||
//@Type(type = "org.joda.time.contrib.hibernate.PersistentYearMonthDay")
|
||||
//@Column(name = "current_month")
|
||||
<warning descr="Missorted modifiers 'final public @Nullable @NotNull'">final</warning>
|
||||
<warning descr="Missorted modifiers 'final public'">final</warning>
|
||||
public
|
||||
@Nullable
|
||||
// commment
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.refactoring.listeners.RefactoringEventListener
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.ui.ChooserInterceptor
|
||||
import com.intellij.ui.UiInterceptors
|
||||
import com.intellij.util.ui.UIUtil
|
||||
@@ -590,10 +589,6 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
|
||||
} while (isVariableSwitched)
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||
return ExtractMethodNewTest.SimpleLightProjectDescriptorWithAnnotations(moduleTypeId, projectJDK)
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
val settings = JavaRefactoringSettings.getInstance()
|
||||
|
||||
@@ -8,11 +8,7 @@ import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.registry.RegistryValue;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -31,8 +27,6 @@ import com.intellij.refactoring.extractMethod.newImpl.MethodExtractor;
|
||||
import com.intellij.refactoring.util.duplicates.Match;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -1930,21 +1924,4 @@ public class ExtractMethodNewTest extends LightJavaCodeInsightTestCase {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return new SimpleLightProjectDescriptorWithAnnotations(getModuleTypeId(), getProjectJDK());
|
||||
}
|
||||
|
||||
static class SimpleLightProjectDescriptorWithAnnotations extends SimpleLightProjectDescriptor{
|
||||
|
||||
protected SimpleLightProjectDescriptorWithAnnotations(@NotNull String moduleTypeId, @Nullable Sdk sdk) {
|
||||
super(moduleTypeId, sdk);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsWithTypeUse(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -616,7 +616,7 @@ class JavaSuggestedRefactoringTest : BaseSuggestedRefactoringTest() {
|
||||
'('
|
||||
LineBreak('', true)
|
||||
Group (added):
|
||||
'@Nls @NotNull @NonStandard("X")'
|
||||
'@NotNull @Nls @NonStandard("X")'
|
||||
' '
|
||||
'String'
|
||||
' '
|
||||
@@ -642,7 +642,7 @@ class JavaSuggestedRefactoringTest : BaseSuggestedRefactoringTest() {
|
||||
|
||||
class C implements I {
|
||||
@Override
|
||||
public void foo(@Nls @NotNull @NonStandard("X") String s) {
|
||||
public void foo(@NotNull @Nls @NonStandard("X") String s) {
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
|
||||
@@ -5,26 +5,12 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.RedundantSuppressInspection;
|
||||
import com.intellij.java.JavaBundle;
|
||||
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.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.pom.java.LanguageLevel.JDK_21_PREVIEW;
|
||||
|
||||
public class ExtractMethodRecommenderInspectionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
private static final ProjectDescriptor JDK_21_PREVIEW_WITH_ANNOTATIONS = new ProjectDescriptor(JDK_21_PREVIEW) {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
addJetBrainsAnnotationsWithTypeUse(model);
|
||||
}
|
||||
};
|
||||
|
||||
public void testExtractMethodRecommender() {
|
||||
ExtractMethodRecommenderInspection inspection = new ExtractMethodRecommenderInspection();
|
||||
inspection.minLength = 10;
|
||||
@@ -90,7 +76,7 @@ public class ExtractMethodRecommenderInspectionTest extends LightJavaCodeInsight
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JDK_21_PREVIEW_WITH_ANNOTATIONS;
|
||||
return JAVA_21;
|
||||
}
|
||||
|
||||
@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::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
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::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
@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::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
@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::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
@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::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
}
|
||||
|
||||
public void testSimpleRunnable() {
|
||||
|
||||
@@ -2,14 +2,34 @@
|
||||
package com.siyeh.ig.migration;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
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 com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MethodCanBeVariableArityMethodInspectionTest extends LightJavaInspectionTestCase {
|
||||
|
||||
private static final ProjectDescriptor JAVA_HIGHEST_WITH_OLD_ANNOTATIONS = new ProjectDescriptor(LanguageLevel.HIGHEST) {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
addJetBrainsAnnotations(model);
|
||||
}
|
||||
};
|
||||
|
||||
public void testMethodCanBeVariableArity() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_HIGHEST_WITH_OLD_ANNOTATIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
final MethodCanBeVariableArityMethodInspection inspection = new MethodCanBeVariableArityMethodInspection();
|
||||
|
||||
@@ -93,10 +93,18 @@ public abstract class LightJavaCodeInsightTestCase extends LightPlatformCodeInsi
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
LanguageLevel languageLevel = getLanguageLevel();
|
||||
return new SimpleLightProjectDescriptor(getModuleTypeId(), getProjectJDK()) {
|
||||
@Override
|
||||
protected void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
//DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
}
|
||||
else {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.
|
||||
*/
|
||||
// Copyright 2000-2024 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.fixtures;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -87,7 +73,11 @@ public class DefaultLightProjectDescriptor extends LightProjectDescriptor {
|
||||
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES);
|
||||
}
|
||||
|
||||
public static void addJetBrainsAnnotationsWithTypeUse(ModifiableRootModel model) {
|
||||
public DefaultLightProjectDescriptor withJetBrainsAnnotationsJava8AndHigher() {
|
||||
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
|
||||
}
|
||||
|
||||
public static void addJetBrainsAnnotationsJava8AndHigher(ModifiableRootModel model) {
|
||||
MavenDependencyUtil.addFromMaven(model, JETBRAINS_ANNOTATIONS_COORDINATES_JAVA_8);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,12 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
addJetBrainsAnnotations(model);
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
addJetBrainsAnnotationsJava8AndHigher(model);
|
||||
}
|
||||
else {
|
||||
addJetBrainsAnnotations(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase;
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil;
|
||||
import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil;
|
||||
import org.jetbrains.kotlin.idea.test.TestMetadataUtil;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractJavaAgainstKotlinCheckerTest extends KotlinDaemonA
|
||||
protected Module createMainModule() throws IOException {
|
||||
Module module = super.createMainModule();
|
||||
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotationsJava8AndHigher);
|
||||
|
||||
String configFileText = getConfigFileText();
|
||||
if (configFileText == null) {
|
||||
|
||||
@@ -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.addJetBrainsAnnotations(model);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(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.addJetBrainsAnnotations(model);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotationsJava8AndHigher(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