mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[test framework] extracts common code for mock JDK and Java project descriptors
This commit is contained in:
@@ -18,6 +18,7 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -65,8 +66,10 @@ public class IdeaTestUtil extends PlatformTestUtil {
|
||||
Disposer.register(parentDisposable, () -> setModuleLanguageLevel(module, prev));
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk17() {
|
||||
return getMockJdk17("java 1.7");
|
||||
public static Sdk getMockJdk(JavaVersion version) {
|
||||
int mockJdk = version.feature >= 9 ? 9 : version.feature >= 7 ? version.feature : version.feature >= 5 ? 7 : 4;
|
||||
String path = getPathForJdkNamed(MOCK_JDK_DIR_NAME_PREFIX + "1." + mockJdk).getPath();
|
||||
return createMockJdk("java " + version, path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -74,20 +77,24 @@ public class IdeaTestUtil extends PlatformTestUtil {
|
||||
return ((JavaSdkImpl)JavaSdk.getInstance()).createMockJdk(name, path, false);
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk14() {
|
||||
return getMockJdk(JavaVersion.compose(4));
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk17() {
|
||||
return getMockJdk(JavaVersion.compose(7));
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk17(@NotNull String name) {
|
||||
return createMockJdk(name, getMockJdk17Path().getPath());
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk18() {
|
||||
return createMockJdk("java 1.8", getMockJdk18Path().getPath());
|
||||
return getMockJdk(JavaVersion.compose(8));
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk9() {
|
||||
return createMockJdk("java 9", getMockJdk9Path().getPath());
|
||||
}
|
||||
|
||||
public static Sdk getMockJdk14() {
|
||||
return createMockJdk("java 1.4", getMockJdk14Path().getPath());
|
||||
return getMockJdk(JavaVersion.compose(9));
|
||||
}
|
||||
|
||||
public static File getMockJdk14Path() {
|
||||
|
||||
+20
-60
@@ -1,6 +1,4 @@
|
||||
// Copyright 2000-2017 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.
|
||||
// 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.testFramework.fixtures;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
@@ -28,77 +26,39 @@ import java.io.File;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase {
|
||||
public static final LightProjectDescriptor JAVA_1_4 = new DefaultLightProjectDescriptor() {
|
||||
protected static class ProjectDescriptor extends DefaultLightProjectDescriptor {
|
||||
private final LanguageLevel myLanguageLevel;
|
||||
|
||||
public ProjectDescriptor(@NotNull LanguageLevel languageLevel) {
|
||||
myLanguageLevel = languageLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return IdeaTestUtil.getMockJdk14();
|
||||
return IdeaTestUtil.getMockJdk(myLanguageLevel.toJavaVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_4);
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static final LightProjectDescriptor JAVA_1_5 = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
};
|
||||
public static final LightProjectDescriptor JAVA_1_4 = new ProjectDescriptor(LanguageLevel.JDK_1_4);
|
||||
public static final LightProjectDescriptor JAVA_1_5 = new ProjectDescriptor(LanguageLevel.JDK_1_5);
|
||||
public static final LightProjectDescriptor JAVA_1_6 = new ProjectDescriptor(LanguageLevel.JDK_1_6);
|
||||
public static final LightProjectDescriptor JAVA_1_7 = new ProjectDescriptor(LanguageLevel.JDK_1_7);
|
||||
public static final LightProjectDescriptor JAVA_8 = new ProjectDescriptor(LanguageLevel.JDK_1_8);
|
||||
public static final LightProjectDescriptor JAVA_9 = new ProjectDescriptor(LanguageLevel.JDK_1_9);
|
||||
public static final LightProjectDescriptor JAVA_10 = new ProjectDescriptor(LanguageLevel.JDK_10);
|
||||
|
||||
public static final LightProjectDescriptor JAVA_1_6 = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_6);
|
||||
}
|
||||
};
|
||||
|
||||
public static final LightProjectDescriptor JAVA_1_7 = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
}
|
||||
};
|
||||
|
||||
public static final LightProjectDescriptor JAVA_8 = new DefaultLightProjectDescriptor() {
|
||||
public static final LightProjectDescriptor JAVA_LATEST = new ProjectDescriptor(LanguageLevel.HIGHEST) {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
return IdeaTestUtil.getMockJdk17();
|
||||
}
|
||||
};
|
||||
|
||||
public static final LightProjectDescriptor JAVA_9 = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return IdeaTestUtil.getMockJdk9();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_9);
|
||||
}
|
||||
};
|
||||
|
||||
public static final LightProjectDescriptor JAVA_X = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return IdeaTestUtil.getMockJdk9();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_X);
|
||||
}
|
||||
};
|
||||
|
||||
public static final LightProjectDescriptor JAVA_LATEST = new DefaultLightProjectDescriptor();
|
||||
|
||||
protected JavaCodeInsightTestFixture myFixture;
|
||||
protected Module myModule;
|
||||
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// 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.siyeh.ig.numeric;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
@@ -21,6 +22,6 @@ public class UnnecessaryExplicitNumericCastInspectionTest extends LightInspectio
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_X;
|
||||
return JAVA_10;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user