mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 15:52:01 +07:00
[java-tests] IDEA-333831 Separate mock JDK and JetBrains annotations for testing
Also: avoid manual mocking of Java 10 classes in StreamCollector10Inlining test, use mockJDK11 instead Also: rewrite SliceTestCase and its inheritors to LightJavaCodeInsightFixtureTestCase, as annotations.jar is not included into project created by DaemonAnalyzerTestCase Also: 'mutates' attribute of @Contract annotation is resolvable now, as we can use newer jetbrains-annotations library. Also: documentation tests now don't generate links to JetBrains annotations, which corresponds to the actual behavior in production GitOrigin-RevId: e460826893c1277cb2b78b18aae9d5aca97d8333
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ccd91ed6be
commit
aa6829d7c1
@@ -1,2 +1,2 @@
|
||||
@T<caret>
|
||||
@Tt<caret>
|
||||
@interface Foo { }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://java.util.List"><code><span style="color:#000000;">java.util.List</span><span style=""><</span><span style="color:#20999d;">E</span><span style="">></span></code></a></div><div class='definition'><pre><span style="color:#808000;">@</span><a href="psi_element://org.jetbrains.annotations.Contract"><code><span style="color:#808000;">Contract</span></code></a><span style="">(</span><span style="">pure</span><span style=""> = </span><span style="color:#000080;font-weight:bold;">true</span><span style="">)</span><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://java.util.List"><code><span style="color:#000000;">java.util.List</span><span style=""><</span><span style="color:#20999d;">E</span><span style="">></span></code></a></div><div class='definition'><pre><span style="color:#808000;">@</span><span style="color:#808000;">Contract</span><span style="">(</span><span style="">pure</span><span style=""> = </span><span style="color:#000080;font-weight:bold;">true</span><span style="">)</span><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<span style="color:#000080;font-weight:bold;">public abstract</span> <span style="color:#000080;font-weight:bold;">boolean</span> <span style="color:#000000;">contains</span><span style="">(</span><br> <a href="psi_element://java.lang.Object"><code><span style="color:#000000;">Object</span></code></a> <span style="color:#000000;">o</span><br><span style="">)</span></pre></div><div class='content'>
|
||||
Returns <tt>true</tt> if this list contains the specified element.
|
||||
More formally, returns <tt>true</tt> if and only if this list contains
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<html><head><base href="placeholder"></head><body><div class="bottom"><icon src="AllIcons.Nodes.Class"> <a href="psi_element://java.lang.Class"><code><span style="color:#000000;">java.lang.Class</span><span style=""><</span><span style="color:#20999d;">T</span><span style="">></span></code></a></div><div class='definition'><pre><span style="color:#ff0000">@<span style="color:#808000;">CallerSensitive</span></span>
|
||||
<span style="color:#808000;">@</span><a href="psi_element://org.jetbrains.annotations.NotNull"><code><span style="color:#808000;">NotNull</span></code></a><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<span style="color:#808000;">@</span><a href="psi_element://org.jetbrains.annotations.Contract"><code><span style="color:#808000;">Contract</span></code></a><span style="">(</span><span style="">pure</span><span style=""> = </span><span style="color:#000080;font-weight:bold;">true</span><span style="">)</span><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<span style="color:#808000;">@</span><span style="color:#808000;">NotNull</span><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<span style="color:#808000;">@</span><span style="color:#808000;">Contract</span><span style="">(</span><span style="">pure</span><span style=""> = </span><span style="color:#000080;font-weight:bold;">true</span><span style="">)</span><a href="external.annotations"><icon src="AllIcons.Ide.External_link_arrow"></a>
|
||||
<span style="color:#000080;font-weight:bold;">public</span> <a href="psi_element://java.lang.reflect.Constructor"><code><span style="color:#000000;">java.lang.reflect.Constructor</span></code></a><span style=""><</span><span style="">?</span><span style="">></span><span style="">[]</span> <span style="color:#000000;">getDeclaredConstructors</span><span style="">(</span><span style="">)</span>
|
||||
<span style="color:#000080;font-weight:bold;">throws</span> <a href="psi_element://java.lang.SecurityException"><code><span style="color:#000000;">SecurityException</span></code></a></pre></div><table class='sections'><p><tr><td valign='top' class='section'><p>Throws:</td><td valign='top'><p><a href="psi_element://java.lang.SecurityException"><code><span style="color:#0000ff;">SecurityException</span></code></a></td></table><div class="bottom-no-content"><icon src="AllIcons.Nodes.PpLibFolder"/> < java 10 ></div>
|
||||
@@ -0,0 +1,20 @@
|
||||
<root>
|
||||
<item name='org.jetbrains.annotations.ApiStatus ApiStatus()'>
|
||||
<annotation name='org.jetbrains.annotations.Contract'>
|
||||
<val name="value" val=""->fail""/>
|
||||
<val name="pure" val="true"/>
|
||||
</annotation>
|
||||
</item>
|
||||
<item name='org.jetbrains.annotations.Async Async()'>
|
||||
<annotation name='org.jetbrains.annotations.Contract'>
|
||||
<val name="value" val=""->fail""/>
|
||||
<val name="pure" val="true"/>
|
||||
</annotation>
|
||||
</item>
|
||||
<item name='org.jetbrains.annotations.Debug Debug()'>
|
||||
<annotation name='org.jetbrains.annotations.Contract'>
|
||||
<val name="value" val=""->fail""/>
|
||||
<val name="pure" val="true"/>
|
||||
</annotation>
|
||||
</item>
|
||||
</root>
|
||||
@@ -12,12 +12,12 @@ public class MutabilityBasics {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Contract(<error descr="Cannot resolve method 'mutates'">mutates</error> = "param")
|
||||
@Contract(mutates = "param")
|
||||
static <T extends Comparable<T>> void sort(List<T> collection) {
|
||||
Collections.sort(collection);
|
||||
}
|
||||
|
||||
@Contract(<error descr="Cannot resolve method 'mutates'">mutates</error> = "param1")
|
||||
@Contract(mutates = "param1")
|
||||
static <T extends Comparable<T>> void addAll(Collection<T> collection, List<T> other) {
|
||||
sort(<warning descr="Immutable object is passed where mutable is expected">other</warning>);
|
||||
collection.addAll(other);
|
||||
@@ -33,7 +33,7 @@ public class MutabilityBasics {
|
||||
interface Point {
|
||||
int get();
|
||||
|
||||
@Contract(<error descr="Cannot resolve method 'mutates'">mutates</error> = "this")
|
||||
@Contract(mutates = "this")
|
||||
void set(int x);
|
||||
|
||||
@Contract(pure = true)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package <error descr="Package 'stream' exists in another module: java.base">java.util.stream</error>;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -7,14 +5,6 @@ import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
// Mock
|
||||
class Collectors {
|
||||
public static native <T> Collector<T, ?, List<T>> toList();
|
||||
public static native <T> Collector<T, ?, List<T>> toUnmodifiableList();
|
||||
public static native <T> Collector<T, ?, Set<T>> toUnmodifiableSet();
|
||||
public static native <T, K, U> Collector<T, ?, Map<K,U>> toUnmodifiableMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper);
|
||||
}
|
||||
|
||||
public class StreamCollector10Inlining {
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -9,6 +9,7 @@ PsiJavaFileStub [org.jetbrains.annotations]
|
||||
PsiRefListStub[IMPLEMENTS_LIST:]
|
||||
PsiMethodStub[annotation value:java.lang.String default=""]
|
||||
PsiModifierListStub[mask=1025]
|
||||
PsiAnnotationStub[@org.jetbrains.annotations.NonNls]
|
||||
PsiTypeParameterListStub
|
||||
PsiParameterListStub
|
||||
PsiRefListStub[THROWS_LIST:]
|
||||
|
||||
@@ -77,6 +77,7 @@ public class AddAnnotationFixTest extends UsefulTestCase {
|
||||
javaCodeStyleSettings.USE_EXTERNAL_ANNOTATIONS = false;
|
||||
}
|
||||
});
|
||||
ModuleRootModificationUtil.updateModel(myFixture.getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ExternalAnnotationsTest extends UsefulTestCase {
|
||||
myFixture.setUp();
|
||||
Module myModule = builder.getFixture().getModule();
|
||||
ModuleRootModificationUtil.updateModel(myModule, model -> {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
String contentUrl = VfsUtilCore.pathToUrl(myFixture.getTempDirPath());
|
||||
model.addContentEntry(contentUrl).addSourceFolder(contentUrl + "/src", false);
|
||||
final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class);
|
||||
|
||||
@@ -45,6 +45,7 @@ public class NullableNotNullManagerTest extends LightJavaCodeInsightFixtureTestC
|
||||
super.configureModule(module, model, contentEntry);
|
||||
VirtualFile file =
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(JavaTestUtil.getJavaTestDataPath() + "/nullableAnnotations/");
|
||||
addJetBrainsAnnotations(model);
|
||||
MavenDependencyUtil.addFromMaven(model, "com.google.code.findbugs:jsr305:3.0.2");
|
||||
// Library order is important
|
||||
PsiTestUtil.newLibrary("lib_2.0").classesRoot(file.findChild("lib_2.0")).addTo(model);
|
||||
|
||||
@@ -404,8 +404,8 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testPreferApplicableAnnotations() {
|
||||
myFixture.addClass(
|
||||
"\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Target;\n\n@Target(ElementType.ANNOTATION_TYPE)\n@interface TMetaAnno {}\n\n@Target(ElementType.LOCAL_VARIABLE)\n@interface TLocalAnno {}");
|
||||
checkPreferredItems(0, "TMetaAnno", "Target", "TabLayoutPolicy", "TabPlacement");
|
||||
"\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Target;\n\n@Target(ElementType.ANNOTATION_TYPE)\n@interface TtMetaAnno {}\n\n@Target(ElementType.LOCAL_VARIABLE)\n@interface TtLocalAnno {}");
|
||||
checkPreferredItems(0, "TtMetaAnno", "TtLocalAnno");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
|
||||
@@ -1659,8 +1659,8 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
|
||||
public void testImplementViaOverrideCompletion() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "Override/Implement methods...", "public void run");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "OverrideOnly", "Override/Implement methods...", "MustBeInvokedByOverriders", "public void run");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(4));
|
||||
myFixture.type('\n');
|
||||
checkResult();
|
||||
}
|
||||
@@ -1668,8 +1668,8 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
|
||||
public void testSuggestToOverrideMethodsWhenTypingOverrideAnnotation() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(1));
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "OverrideOnly", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
myFixture.type('\n');
|
||||
NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
|
||||
checkResult();
|
||||
@@ -1678,8 +1678,8 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
|
||||
public void testSuggestToOverrideMethodsWhenTypingOverrideAnnotationBeforeMethod() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(1));
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "OverrideOnly", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
myFixture.type('\n');
|
||||
NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
|
||||
checkResult();
|
||||
@@ -1688,8 +1688,8 @@ public class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
@NeedsIndex.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
|
||||
public void testSuggestToOverrideMethodsInMulticaretMode() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(1));
|
||||
myFixture.assertPreferredCompletionItems(0, "Override", "OverrideOnly", "Override/Implement methods...");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
myFixture.type('\n');
|
||||
NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
|
||||
checkResult();
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.DumbModeTestUtils;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -55,6 +56,15 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
return IdeaTestUtil.getMockJdk(JavaVersion.compose(myJdkVersion));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpModule() {
|
||||
super.setUpModule();
|
||||
if (!getTestName(false).equals("HideNonDocumentedFlowAnnotations")) {
|
||||
ModuleRootModificationUtil.updateModel(
|
||||
myModule, model -> DefaultLightProjectDescriptor.addJetBrainsAnnotations(model));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LanguageLevel getProjectLanguageLevel() {
|
||||
return LanguageLevel.HIGHEST;
|
||||
@@ -236,7 +246,7 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testHideNonDocumentedFlowAnnotations() {
|
||||
Sdk sdk = removeAnnotationsJar(PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk17()));
|
||||
Sdk sdk = PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk17());
|
||||
WriteAction.runAndWait(() -> ProjectJdkTable.getInstance().addJdk(sdk, getTestRootDisposable()));
|
||||
ModuleRootModificationUtil.setModuleSdk(myModule, sdk);
|
||||
|
||||
@@ -251,15 +261,6 @@ public class JavaDocInfoGeneratorTest extends JavaCodeInsightTestCase {
|
||||
assertFalse(doc, doc.contains("Flow"));
|
||||
}
|
||||
|
||||
private static Sdk removeAnnotationsJar(Sdk sdk) {
|
||||
SdkModificator modificator = sdk.getSdkModificator();
|
||||
VirtualFile annotationsJar = ContainerUtil.find(modificator.getRoots(OrderRootType.CLASSES), r -> r.getName().contains("annotations"));
|
||||
modificator.setName(modificator.getName() + "-" + annotationsJar.getPath());
|
||||
modificator.removeRoot(annotationsJar, OrderRootType.CLASSES);
|
||||
modificator.commitChanges();
|
||||
return sdk;
|
||||
}
|
||||
|
||||
public void testMatchingParameterNameFromParent() {
|
||||
configureByFile();
|
||||
PsiClass psiClass = ((PsiJavaFile)myFile).getClasses()[1];
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 2000-2018 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.java.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
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.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DataFlowInspection10Test extends DataFlowInspectionTestCase {
|
||||
private static final DefaultLightProjectDescriptor PROJECT_DESCRIPTOR = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk(LanguageLevel.JDK_10.toJavaVersion()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_10);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return PROJECT_DESCRIPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
|
||||
}
|
||||
|
||||
public void testStreamCollector10Inlining() { doTest(); }
|
||||
|
||||
public void testAvoidWarningAtNotInferredType() { doTest();}
|
||||
|
||||
public void testSameArguments() { doTest(); }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2000-2018 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.java.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DataFlowInspection11Test extends DataFlowInspectionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_11_ANNOTATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/inspection/dataFlow/fixture/";
|
||||
}
|
||||
|
||||
public void testStreamCollector10Inlining() { doTest(); }
|
||||
|
||||
public void testAvoidWarningAtNotInferredType() { doTest();}
|
||||
|
||||
public void testSameArguments() { doTest(); }
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import org.junit.platform.suite.api.Suite;
|
||||
DataFlowInspectionTest.class,
|
||||
DataFlowInspection8Test.class,
|
||||
DataFlowInspection9Test.class,
|
||||
DataFlowInspection10Test.class,
|
||||
DataFlowInspection11Test.class,
|
||||
DataFlowInspection16Test.class,
|
||||
DataFlowInspection20Test.class,
|
||||
DataFlowInspection21Test.class,
|
||||
|
||||
@@ -55,6 +55,7 @@ public class BytecodeAnalysisIntegrationTest extends LightJavaCodeInsightFixture
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
|
||||
addJetBrainsAnnotations(model);
|
||||
MavenDependencyUtil.addFromMaven(model, "org.apache.velocity:velocity:1.7");
|
||||
MavenDependencyUtil.addFromMaven(model, "commons-collections:commons-collections:3.2.1");
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class BytecodeAnalysisResultsHighlightingTest extends DataFlowInspectionT
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
PsiTestUtil.addProjectLibrary(model, "velocity", IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("Velocity"));
|
||||
PsiTestUtil.addProjectLibrary(model, "commons-lang", IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("commons-lang3"));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.java.psi;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.IoTestUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -11,11 +12,11 @@ import com.intellij.psi.impl.compiled.ClsFileImpl;
|
||||
import com.intellij.psi.stubs.PsiFileStub;
|
||||
import com.intellij.psi.stubs.StubBase;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ClsStubBuilderTest extends LightIdeaTestCase {
|
||||
public class ClsStubBuilderTest extends LightJavaCodeInsightTestCase {
|
||||
public void testUtilList() { doClassTest("java.util.List"); }
|
||||
public void testNullable() { doClassTest("org.jetbrains.annotations.Nullable"); }
|
||||
public void testUtilCollections() { doClassTest("java.util.Collections"); }
|
||||
@@ -69,6 +70,11 @@ public class ClsStubBuilderTest extends LightIdeaTestCase {
|
||||
doTest(clsFile, getTestName(false) + ".txt");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk17();
|
||||
}
|
||||
|
||||
private static void doTest(VirtualFile clsFile, String resultFileName) {
|
||||
try {
|
||||
PsiFileStub<?> stub = ClsFileImpl.buildFileStub(clsFile, clsFile.contentsToByteArray());
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.ide.scratch.ScratchRootType;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -21,6 +22,7 @@ import com.intellij.refactoring.RefactoringSettings;
|
||||
import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -28,6 +30,12 @@ import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||
|
||||
public class SafeDeleteTest extends MultiFileTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
@@ -18,14 +18,12 @@ package com.intellij.java.slicer;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.execution.filters.ExceptionAnalysisProvider;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.slicer.*;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,8 +34,8 @@ import java.util.Map;
|
||||
|
||||
public class SliceBackwardTest extends SliceTestCase {
|
||||
@Override
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk11());
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_17_ANNOTATED;
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
@@ -49,18 +47,18 @@ public class SliceBackwardTest extends SliceTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LanguageLevel getProjectLanguageLevel() {
|
||||
return LanguageLevel.JDK_16;
|
||||
protected String getBasePath() {
|
||||
return "/java/java-tests/testData/codeInsight/slice/backward/";
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String filter, @NotNull String @NotNull... stack) throws Exception {
|
||||
configureByFile("/codeInsight/slice/backward/"+getTestName(false)+".java");
|
||||
myFixture.configureByFile(getTestName(false)+".java");
|
||||
Map<String, RangeMarker> sliceUsageName2Offset = SliceTestUtil.extractSliceOffsetsFromDocument(getEditor().getDocument());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
PsiElement element = SliceHandler.create(true).getExpressionAtCaret(getEditor(), getFile());
|
||||
assertNotNull(element);
|
||||
SliceTestUtil.Node tree = SliceTestUtil.buildTree(element, sliceUsageName2Offset);
|
||||
Collection<HighlightInfo> errors = highlightErrors();
|
||||
Collection<HighlightInfo> errors = myFixture.doHighlighting(HighlightSeverity.ERROR);
|
||||
assertEmpty(errors);
|
||||
SliceAnalysisParams params = new SliceAnalysisParams();
|
||||
params.scope = new AnalysisScope(getProject());
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.java.slicer;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -26,14 +27,19 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class SliceForwardTest extends SliceTestCase {
|
||||
private void dotest() throws Exception {
|
||||
configureByFile("/codeInsight/slice/forward/"+getTestName(false)+".java");
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/java/java-tests/testData/codeInsight/slice/forward/";
|
||||
}
|
||||
|
||||
private void dotest() {
|
||||
myFixture.configureByFile(getTestName(false)+".java");
|
||||
Map<String, RangeMarker> sliceUsageName2Offset = SliceTestUtil.extractSliceOffsetsFromDocument(getEditor().getDocument());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
PsiElement element = SliceHandler.create(false).getExpressionAtCaret(getEditor(), getFile());
|
||||
assertNotNull(element);
|
||||
SliceTestUtil.Node tree = SliceTestUtil.buildTree(element, sliceUsageName2Offset);
|
||||
Collection<HighlightInfo> errors = highlightErrors();
|
||||
Collection<HighlightInfo> errors = myFixture.doHighlighting(HighlightSeverity.ERROR);
|
||||
assertEmpty(errors);
|
||||
SliceAnalysisParams params = new SliceAnalysisParams();
|
||||
params.scope = new AnalysisScope(getProject());
|
||||
@@ -42,14 +48,14 @@ public class SliceForwardTest extends SliceTestCase {
|
||||
SliceTestUtil.checkUsages(usage, tree);
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception { dotest();}
|
||||
public void testInterMethod() throws Exception { dotest();}
|
||||
public void testParameters() throws Exception { dotest();}
|
||||
public void testRequireNonNull() throws Exception { dotest();}
|
||||
public void testAppend() throws Exception { dotest();}
|
||||
public void testOverloadedMember() throws Exception { dotest();}
|
||||
public void testOverloadedMember2() throws Exception { dotest();}
|
||||
public void testOverloadedMember3() throws Exception { dotest();}
|
||||
public void testOneInterfaceTwoImplementations() throws Exception { dotest();}
|
||||
public void testOneInterfaceTwoImplementations2() throws Exception { dotest();}
|
||||
public void testSimple() { dotest();}
|
||||
public void testInterMethod() { dotest();}
|
||||
public void testParameters() { dotest();}
|
||||
public void testRequireNonNull() { dotest();}
|
||||
public void testAppend() { dotest();}
|
||||
public void testOverloadedMember() { dotest();}
|
||||
public void testOverloadedMember2() { dotest();}
|
||||
public void testOverloadedMember3() { dotest();}
|
||||
public void testOneInterfaceTwoImplementations() { dotest();}
|
||||
public void testOneInterfaceTwoImplementations2() { dotest();}
|
||||
}
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package com.intellij.java.slicer;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class SliceTestCase extends DaemonAnalyzerTestCase {
|
||||
public abstract class SliceTestCase extends LightJavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk17());
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_7_ANNOTATED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.intellij.java.slicer;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -19,12 +21,17 @@ import org.jetbrains.annotations.NonNls;
|
||||
import java.util.*;
|
||||
|
||||
public class SliceTreeTest extends SliceTestCase {
|
||||
private SliceTreeStructure configureTree(@NonNls String name) throws Exception {
|
||||
configureByFile("/codeInsight/slice/backward/"+ name +".java");
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/java/java-tests/testData/codeInsight/slice/backward/";
|
||||
}
|
||||
|
||||
private SliceTreeStructure configureTree(@NonNls String name) {
|
||||
myFixture.configureByFile(name + ".java");
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
PsiElement element = SliceHandler.create(true).getExpressionAtCaret(getEditor(), getFile());
|
||||
assertNotNull(element);
|
||||
Collection<HighlightInfo> errors = highlightErrors();
|
||||
Collection<HighlightInfo> errors = myFixture.doHighlighting(HighlightSeverity.ERROR);
|
||||
assertEmpty(errors);
|
||||
|
||||
SliceAnalysisParams params = new SliceAnalysisParams();
|
||||
@@ -34,7 +41,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
SliceUsage usage = LanguageSlicing.getProvider(element).createRootUsage(element, params);
|
||||
|
||||
|
||||
ToolWindowHeadlessManagerImpl.MockToolWindow toolWindow = new ToolWindowHeadlessManagerImpl.MockToolWindow(myProject);
|
||||
ToolWindowHeadlessManagerImpl.MockToolWindow toolWindow = new ToolWindowHeadlessManagerImpl.MockToolWindow(getProject());
|
||||
SlicePanel panel = new SlicePanel(getProject(), true, new SliceRootNode(getProject(), new DuplicateMap(), usage), false, toolWindow) {
|
||||
@Override
|
||||
public boolean isAutoScroll() {
|
||||
@@ -68,7 +75,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testTypingDoesNotInterfereWithDuplicates() throws Exception {
|
||||
public void testTypingDoesNotInterfereWithDuplicates() {
|
||||
SliceTreeStructure treeStructure = configureTree("DupSlice");
|
||||
SliceNode root = treeStructure.getRootElement();
|
||||
List<SliceNode> nodes = new ArrayList<>();
|
||||
@@ -83,7 +90,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
type(" xx");
|
||||
myFixture.type(" xx");
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
backspace();
|
||||
backspace();
|
||||
@@ -109,7 +116,11 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertTrue(hasDups.isEmpty());
|
||||
}
|
||||
|
||||
public void testLeafExpressionsAreEmptyInCaseOfInfinitelyExpandingTreeWithDuplicateNodes() throws Exception {
|
||||
private void backspace() {
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
|
||||
}
|
||||
|
||||
public void testLeafExpressionsAreEmptyInCaseOfInfinitelyExpandingTreeWithDuplicateNodes() {
|
||||
SliceTreeStructure treeStructure = configureTree("Tuple");
|
||||
SliceNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -118,7 +129,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertEmpty(leaves);
|
||||
}
|
||||
|
||||
public void testLeafExpressionsSimple() throws Exception {
|
||||
public void testLeafExpressionsSimple() {
|
||||
SliceTreeStructure treeStructure = configureTree("DupSlice");
|
||||
SliceNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -129,7 +140,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertEquals(1111111111, ((PsiLiteral)element).getValue());
|
||||
}
|
||||
|
||||
public void testLeafExpressionsMoreComplex() throws Exception {
|
||||
public void testLeafExpressionsMoreComplex() {
|
||||
SliceTreeStructure treeStructure = configureTree("Duplicate");
|
||||
SliceNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -147,7 +158,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testGroupByValuesCorrectLeaves() throws Exception {
|
||||
public void testGroupByValuesCorrectLeaves() {
|
||||
SliceTreeStructure treeStructure = configureTree("DuplicateLeaves");
|
||||
SliceRootNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -192,7 +203,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertEquals(child.getValue().getElement(), leaf);
|
||||
}
|
||||
|
||||
public void testNullness() throws Exception {
|
||||
public void testNullness() {
|
||||
SliceTreeStructure treeStructure = configureTree("Nulls");
|
||||
SliceRootNode root = treeStructure.getRootElement();
|
||||
Map<SliceNode, JavaSliceNullnessAnalyzer.NullAnalysisResult> map = SliceNullnessAnalyzerBase.createMap();
|
||||
@@ -292,7 +303,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertEquals(dataExpected, dataActual);
|
||||
}
|
||||
|
||||
public void testDoubleNullness() throws Exception {
|
||||
public void testDoubleNullness() {
|
||||
SliceTreeStructure treeStructure = configureTree("DoubleNulls");
|
||||
SliceRootNode root = treeStructure.getRootElement();
|
||||
Map<SliceNode, JavaSliceNullnessAnalyzer.NullAnalysisResult> map = SliceNullnessAnalyzerBase.createMap();
|
||||
@@ -310,7 +321,7 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
""");
|
||||
}
|
||||
|
||||
public void testGroupByLeavesWithLists() throws Exception {
|
||||
public void testGroupByLeavesWithLists() {
|
||||
SliceTreeStructure treeStructure = configureTree(getTestName(false));
|
||||
SliceRootNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -321,13 +332,13 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
assertEquals(ContainerUtil.newHashSet("\"uuu\"", "\"xxx\""), names);
|
||||
}
|
||||
|
||||
public void testCollectionTrack() throws Exception {
|
||||
public void testCollectionTrack() {
|
||||
Set<String> names = groupByLeaves();
|
||||
assertEquals(3, names.size());
|
||||
assertEquals(ContainerUtil.newHashSet("\"uuu\"", "\"x\"", "\"y\""), names);
|
||||
}
|
||||
|
||||
private Set<String> groupByLeaves() throws Exception {
|
||||
private Set<String> groupByLeaves() {
|
||||
SliceTreeStructure treeStructure = configureTree(getTestName(false));
|
||||
SliceRootNode root = treeStructure.getRootElement();
|
||||
SliceLeafAnalyzer analyzer = JavaSlicerAnalysisUtil.createLeafAnalyzer();
|
||||
@@ -336,17 +347,17 @@ public class SliceTreeTest extends SliceTestCase {
|
||||
return ContainerUtil.map2Set(leaves, PsiElement::getText);
|
||||
}
|
||||
|
||||
public void testArrayCopyTrack() throws Exception {
|
||||
public void testArrayCopyTrack() {
|
||||
Set<String> names = groupByLeaves();
|
||||
assertOrderedEquals(Collections.singletonList("\"x\""), assertOneElement(names));
|
||||
}
|
||||
|
||||
public void testMapValuesTrack() throws Exception {
|
||||
public void testMapValuesTrack() {
|
||||
Set<String> names = groupByLeaves();
|
||||
assertOrderedEquals(Collections.singletonList("\"y\""), assertOneElement(names));
|
||||
}
|
||||
|
||||
public void testMapKeysTrack() throws Exception {
|
||||
public void testMapKeysTrack() {
|
||||
Set<String> names = groupByLeaves();
|
||||
assertOrderedEquals(Collections.singletonList("\"x\""), assertOneElement(names));
|
||||
}
|
||||
|
||||
@@ -100,10 +100,6 @@ public class PackagesTreeStructureTest extends TestSourceBasedTestCase {
|
||||
SwingUtilities.class
|
||||
-PsiPackage: META-INF
|
||||
MANIFEST.MF
|
||||
MANIFEST.MF
|
||||
-PsiPackage: org
|
||||
+PsiPackage: intellij.lang.annotations
|
||||
+PsiPackage: jetbrains.annotations
|
||||
LICENSE
|
||||
"""
|
||||
, 4);
|
||||
@@ -151,10 +147,6 @@ public class PackagesTreeStructureTest extends TestSourceBasedTestCase {
|
||||
SwingUtilities.class
|
||||
-PsiPackage: META-INF
|
||||
MANIFEST.MF
|
||||
MANIFEST.MF
|
||||
-PsiPackage: org
|
||||
+PsiPackage: intellij.lang.annotations
|
||||
+PsiPackage: jetbrains.annotations
|
||||
LICENSE
|
||||
"""
|
||||
, 3);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
package com.siyeh.ig.fixes;
|
||||
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.controlflow.PointlessBooleanExpressionInspection;
|
||||
@@ -17,6 +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);
|
||||
}
|
||||
|
||||
public void testNegation() { doTest(); }
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
package com.siyeh.ig.fixes.dataflow;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
|
||||
@@ -14,6 +16,7 @@ public class CreateNullBranchFixTest extends IGQuickFixesTestCase {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myRelativePath = "dataflow/create_null_branch";
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
package com.siyeh.ig.fixes.migration;
|
||||
|
||||
import com.intellij.codeInspection.CommonQuickFixBundle;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.migration.IfCanBeSwitchInspection;
|
||||
|
||||
@@ -18,6 +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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,10 @@ package com.siyeh.ig.fixes.style;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.style.LambdaCanBeReplacedWithAnonymousInspection;
|
||||
@@ -29,6 +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);
|
||||
}
|
||||
|
||||
public void testSimpleRunnable() {
|
||||
|
||||
Binary file not shown.
@@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2000-2016 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.
|
||||
Binary file not shown.
@@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2000-2016 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.
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,12 +2,16 @@
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleTypeId;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.impl.JavaPsiFacadeEx;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
@@ -90,6 +94,16 @@ public abstract class LightJavaCodeInsightTestCase extends LightPlatformCodeInsi
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return new SimpleLightProjectDescriptor(getModuleTypeId(), getProjectJDK()) {
|
||||
@Override
|
||||
protected void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getModuleTypeId() {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DefaultLightProjectDescriptor extends LightProjectDescriptor {
|
||||
|
||||
private static final String JETBRAINS_ANNOTATIONS_COORDINATES = "org.jetbrains:annotations-java5:24.0.0";
|
||||
private @Nullable Supplier<? extends Sdk> customSdk;
|
||||
private final List<RequiredLibrary> mavenLibraries = new ArrayList<>();
|
||||
|
||||
@@ -80,6 +80,20 @@ public class DefaultLightProjectDescriptor extends LightProjectDescriptor {
|
||||
mavenLibraries.add(new RequiredLibrary(library, includeTransitive));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultLightProjectDescriptor withJetBrainsAnnotations() {
|
||||
return withRepositoryLibrary(JETBRAINS_ANNOTATIONS_COORDINATES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds old non-type-use JetBrains annotations as a module dependency.
|
||||
* Currently, many tests assume that this dependency is present.
|
||||
*
|
||||
* @param model model to modify
|
||||
*/
|
||||
public static void addJetBrainsAnnotations(@NotNull ModifiableRootModel model) {
|
||||
MavenDependencyUtil.addFromMaven(model, JETBRAINS_ANNOTATIONS_COORDINATES);
|
||||
}
|
||||
|
||||
private static class RequiredLibrary {
|
||||
public final String mavenCoordinates;
|
||||
|
||||
@@ -56,6 +56,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
|
||||
public static final @NotNull LightProjectDescriptor JAVA_15 = new ProjectDescriptor(LanguageLevel.JDK_15);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_16 = new ProjectDescriptor(LanguageLevel.JDK_16);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_17 = new ProjectDescriptor(LanguageLevel.JDK_17);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_17_ANNOTATED = new ProjectDescriptor(LanguageLevel.JDK_17, true);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_18 = new ProjectDescriptor(LanguageLevel.JDK_18);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_19 = new ProjectDescriptor(LanguageLevel.JDK_19);
|
||||
public static final @NotNull LightProjectDescriptor JAVA_20 = new ProjectDescriptor(LanguageLevel.JDK_20_PREVIEW);
|
||||
|
||||
@@ -13,6 +13,8 @@ import com.intellij.testFramework.fixtures.*;
|
||||
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_1_7;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
@@ -25,7 +27,7 @@ public abstract class SSBasedInspectionTestCase extends UsefulTestCase {
|
||||
super.setUp();
|
||||
final IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
final TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder =
|
||||
factory.createLightFixtureBuilder(new DefaultLightProjectDescriptor(), getTestName(false));
|
||||
factory.createLightFixtureBuilder(JAVA_1_7, getTestName(false));
|
||||
final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
|
||||
myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl(true));
|
||||
myInspection = new SSBasedInspection();
|
||||
|
||||
@@ -36,10 +36,7 @@ import com.intellij.openapi.project.RootsChangeRescanningInfo;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.project.impl.ProjectImpl;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.AnnotationOrderRootType;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
|
||||
import com.intellij.openapi.roots.impl.ProjectRootManagerImpl;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryTableTracker;
|
||||
@@ -626,7 +623,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
ourProject = project;
|
||||
}
|
||||
|
||||
private static class SimpleLightProjectDescriptor extends LightProjectDescriptor {
|
||||
protected static class SimpleLightProjectDescriptor extends LightProjectDescriptor {
|
||||
private final @NotNull String myModuleTypeId;
|
||||
private final @Nullable Sdk mySdk;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.fileEditor.TextEditor
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.ui.TestDialog
|
||||
import com.intellij.openapi.ui.TestDialogManager
|
||||
import com.intellij.openapi.util.TextRange
|
||||
@@ -23,6 +24,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import com.intellij.psi.injection.Injectable
|
||||
import com.intellij.psi.util.parentOfType
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.InjectionTestFixture
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
||||
import com.intellij.util.SmartList
|
||||
@@ -35,6 +37,11 @@ import org.jetbrains.uast.expressions.UStringConcatenationsFacade
|
||||
|
||||
class JavaInjectedFileChangesHandlerTest : JavaCodeInsightFixtureTestCase() {
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations)
|
||||
}
|
||||
|
||||
fun `test edit multiline in fragment-editor`() {
|
||||
with(myFixture) {
|
||||
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
package org.jetbrains.idea.devkit.kotlin.navigation
|
||||
|
||||
import com.intellij.codeInsight.assertFolded
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
||||
import com.intellij.util.PathUtil
|
||||
|
||||
class KtPropertyKeyFoldingTest : JavaCodeInsightFixtureTestCase() {
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations)
|
||||
}
|
||||
|
||||
override fun tuneFixture(moduleBuilder: JavaModuleFixtureBuilder<*>) {
|
||||
super.tuneFixture(moduleBuilder)
|
||||
moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().path)
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
@@ -27,6 +30,11 @@ import org.jetbrains.idea.devkit.module.PluginModuleType;
|
||||
public abstract class PluginModuleTestCase extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
private static final DefaultLightProjectDescriptor ourProjectDescriptor = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
super.configureModule(module, model, contentEntry);
|
||||
addJetBrainsAnnotations(model);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.inspections.internal;
|
||||
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.JavaRecursiveElementWalkingVisitor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -15,6 +17,7 @@ public abstract class UnsafeReturnStatementVisitorInspectionTestBase extends Jav
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new UnsafeReturnStatementVisitorInspection());
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1436,7 +1436,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
configure('@T<caret> @interface Foo {}')
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'TMetaAnno', 'Target', 'TabLayoutPolicy', 'TabPlacement'
|
||||
myFixture.assertPreferredCompletionItems 0, 'TMetaAnno', 'Target', 'TestOnly', 'TabLayoutPolicy', 'TabPlacement'
|
||||
}
|
||||
|
||||
void testDiamondCompletion1() {
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.intellij.codeInspection.duplicateStringLiteral.DuplicateStringLiteral
|
||||
import com.intellij.java.i18n.JavaI18nBundle;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,6 +19,7 @@ public class DuplicateStringLiteralInspectionTest extends JavaCodeInsightFixture
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(myInspection);
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,9 +17,17 @@ package com.intellij.codeInspection.i18n;
|
||||
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.testFramework.JavaInspectionTestCase;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
|
||||
public class InvalidPropertyKeyInspectionTest extends JavaInspectionTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
ModuleRootModificationUtil.updateModel(getModule(), DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(new InvalidPropertyKeyInspection());
|
||||
doTest("invalidPropertyKey/" + getTestName(true), tool);
|
||||
|
||||
@@ -2,13 +2,20 @@
|
||||
package com.intellij.codeInspection.i18n
|
||||
|
||||
import com.intellij.codeInsight.assertFolded
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
||||
import com.intellij.util.PathUtil
|
||||
|
||||
class PropertyKeyFoldingTest : JavaCodeInsightFixtureTestCase() {
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations)
|
||||
}
|
||||
|
||||
override fun tuneFixture(moduleBuilder: JavaModuleFixtureBuilder<*>) {
|
||||
super.tuneFixture(moduleBuilder)
|
||||
moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().path)
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.idea.completion.test
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ModifiableRootModel
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
|
||||
@@ -41,5 +42,9 @@ object KotlinJdkAndLibraryProjectDescriptorOnJdk8 : KotlinJdkAndLibraryProjectDe
|
||||
libraryFiles = KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance().libraryFiles,
|
||||
librarySourceFiles = KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance().librarySourceFiles,
|
||||
) {
|
||||
override fun addDefaultLibraries(model: ModifiableRootModel) {
|
||||
// Skip adding JetBrains annotation for completion tests
|
||||
}
|
||||
|
||||
override fun getSdk(): Sdk = IdeaTestUtil.getMockJdk18()
|
||||
}
|
||||
@@ -7,9 +7,11 @@ import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.siyeh.ig.bugs.StaticCallOnSubclassInspection;
|
||||
import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
@@ -94,6 +96,8 @@ public abstract class AbstractJavaAgainstKotlinCheckerTest extends KotlinDaemonA
|
||||
protected Module createMainModule() throws IOException {
|
||||
Module module = super.createMainModule();
|
||||
|
||||
ModuleRootModificationUtil.updateModel(module, DefaultLightProjectDescriptor::addJetBrainsAnnotations);
|
||||
|
||||
String configFileText = getConfigFileText();
|
||||
if (configFileText == null) {
|
||||
return module;
|
||||
|
||||
@@ -90,7 +90,8 @@ abstract class AbstractOutOfBlockModificationTest : KotlinLightCodeInsightFixtur
|
||||
|
||||
}
|
||||
|
||||
assertEquals("no library dependencies have to be recalculated",0, resolverTracker.librariesComputed.size)
|
||||
assertEquals("no library dependencies have to be recalculated",0,
|
||||
resolverTracker.librariesComputed.filterNot { it.name?.startsWith("org.jetbrains:annotations") ?: false }.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ abstract class AbstractJvmDecompiledTextTest : AbstractDecompiledTextTest("/deco
|
||||
|
||||
fun findTestLibraryRoot(module: Module): VirtualFile? {
|
||||
for (orderEntry in ModuleRootManager.getInstance(module).orderEntries) {
|
||||
if (orderEntry is LibraryOrderEntry) {
|
||||
if (orderEntry is LibraryOrderEntry && orderEntry.libraryName?.startsWith("org.jetbrains:annotations") != true) {
|
||||
return orderEntry.getRootFiles(OrderRootType.CLASSES)[0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.MavenDependencyUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class KotlinLightProjectDescriptor extends LightProjectDescriptor {
|
||||
@@ -30,9 +32,14 @@ public class KotlinLightProjectDescriptor extends LightProjectDescriptor {
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
addDefaultLibraries(model);
|
||||
configureModule(module, model);
|
||||
}
|
||||
|
||||
protected void addDefaultLibraries(@NotNull ModifiableRootModel model) {
|
||||
DefaultLightProjectDescriptor.addJetBrainsAnnotations(model);
|
||||
}
|
||||
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,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);
|
||||
MavenDependencyUtil.addFromMaven(model, LOMBOK_MAVEN_COORDINATES);
|
||||
MavenDependencyUtil.addFromMaven(model, JACKSON_MAVEN_COORDINATES);
|
||||
MavenDependencyUtil.addFromMaven(model, "com.google.guava:guava:27.0.1-jre");
|
||||
|
||||
Reference in New Issue
Block a user