Cleanup (unneeded util class)

This commit is contained in:
Roman Shevchenko
2017-04-18 16:25:13 +02:00
parent b99e7e0616
commit 9f1f6321e9
2 changed files with 33 additions and 43 deletions

View File

@@ -17,6 +17,7 @@ package com.intellij.openapi.projectRoots;
import com.intellij.pom.java.LanguageLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -27,25 +28,25 @@ import java.util.Arrays;
* @see LanguageLevel
*/
public enum JavaSdkVersion {
JDK_1_0(LanguageLevel.JDK_1_3, "1.0"),
JDK_1_1(LanguageLevel.JDK_1_3, "1.1"),
JDK_1_2(LanguageLevel.JDK_1_3, "1.2"),
JDK_1_3(LanguageLevel.JDK_1_3, "1.3"),
JDK_1_4(LanguageLevel.JDK_1_4, "1.4"),
JDK_1_5(LanguageLevel.JDK_1_5, "1.5"),
JDK_1_6(LanguageLevel.JDK_1_6, "1.6"),
JDK_1_7(LanguageLevel.JDK_1_7, "1.7"),
JDK_1_8(LanguageLevel.JDK_1_8, "1.8"),
JDK_1_9(LanguageLevel.JDK_1_9, "1.9");
JDK_1_0(LanguageLevel.JDK_1_3, new String[]{"1.0"}),
JDK_1_1(LanguageLevel.JDK_1_3, new String[]{"1.1"}),
JDK_1_2(LanguageLevel.JDK_1_3, new String[]{"1.2"}),
JDK_1_3(LanguageLevel.JDK_1_3, new String[]{"1.3"}),
JDK_1_4(LanguageLevel.JDK_1_4, new String[]{"1.4"}),
JDK_1_5(LanguageLevel.JDK_1_5, new String[]{"1.5", "5.0"}),
JDK_1_6(LanguageLevel.JDK_1_6, new String[]{"1.6", "6.0"}),
JDK_1_7(LanguageLevel.JDK_1_7, new String[]{"1.7", "7.0"}),
JDK_1_8(LanguageLevel.JDK_1_8, new String[]{"1.8", "8.0"}),
JDK_1_9(LanguageLevel.JDK_1_9, new String[]{"1.9", "9.0", "9-ea"});
private static final JavaSdkVersion MAX_JDK = JDK_1_9;
private final LanguageLevel myMaxLanguageLevel;
private final String myDescription;
private final String[] myVersionStrings;
JavaSdkVersion(@NotNull LanguageLevel maxLanguageLevel, @NotNull String description) {
JavaSdkVersion(@NotNull LanguageLevel maxLanguageLevel, @NotNull String[] description) {
myMaxLanguageLevel = maxLanguageLevel;
myDescription = description;
myVersionStrings = description;
}
@NotNull
@@ -55,7 +56,7 @@ public enum JavaSdkVersion {
@NotNull
public String getDescription() {
return myDescription;
return myVersionStrings[0];
}
public boolean isAtLeast(@NotNull JavaSdkVersion version) {
@@ -64,7 +65,7 @@ public enum JavaSdkVersion {
@Override
public String toString() {
return super.toString() + ", description: " + myDescription;
return super.toString() + ", description: " + getDescription();
}
@NotNull
@@ -84,4 +85,16 @@ public enum JavaSdkVersion {
"Can't map Java SDK by language level " + languageLevel + ". Available values: " + Arrays.toString(values())
);
}
@Nullable
public static JavaSdkVersion fromVersionString(@NotNull String versionString) {
for (JavaSdkVersion version : values()) {
for (String pattern : version.myVersionStrings) {
if (versionString.contains(pattern)) {
return version;
}
}
}
return null;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,33 +17,10 @@ package com.intellij.openapi.projectRoots;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
import java.util.Map;
@SuppressWarnings("unused")
public class JdkVersionUtil {
private static final Map<JavaSdkVersion, String[]> VERSION_STRINGS = new EnumMap<>(JavaSdkVersion.class);
static {
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_0, new String[]{"1.0"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_1, new String[]{"1.1"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_2, new String[]{"1.2"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_3, new String[]{"1.3"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_4, new String[]{"1.4"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_5, new String[]{"1.5", "5.0"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_6, new String[]{"1.6", "6.0"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_7, new String[]{"1.7", "7.0"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_8, new String[]{"1.8", "8.0"});
VERSION_STRINGS.put(JavaSdkVersion.JDK_1_9, new String[]{"1.9", "9.0", "9-ea"});
}
/** @deprecated use {@link JavaSdkVersion#fromVersionString(String)} (to be removed in IDEA 2018) */
public static JavaSdkVersion getVersion(@NotNull String versionString) {
for (Map.Entry<JavaSdkVersion, String[]> entry : VERSION_STRINGS.entrySet()) {
for (String s : entry.getValue()) {
if (versionString.contains(s)) {
return entry.getKey();
}
}
}
return null;
return JavaSdkVersion.fromVersionString(versionString);
}
}
}