Skip to content

Commit 2bdb873

Browse files
committed
Added Mathematica version 10.0 to possible language levels.
1 parent 5981d0e commit 2bdb873

6 files changed

Lines changed: 140 additions & 14 deletions

File tree

.idea/dictionaries/patrick.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/de/halirutan/mathematica/MathematicaBundle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, O
4242
return CommonBundle.message(getBundle(), key, params);
4343
}
4444

45+
4546
private static ResourceBundle getBundle() {
4647
ResourceBundle bundle = null;
4748
if (ourBundle != null) bundle = ourBundle.get();

src/de/halirutan/mathematica/codeinsight/inspections/bugs/UnsupportedVersion.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
import de.halirutan.mathematica.codeinsight.inspections.AbstractInspection;
3636
import de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionBundle;
3737
import de.halirutan.mathematica.filetypes.MathematicaFileType;
38-
import de.halirutan.mathematica.sdk.MathematicaLanguageLevel;
3938
import de.halirutan.mathematica.parsing.psi.MathematicaVisitor;
4039
import de.halirutan.mathematica.parsing.psi.api.Symbol;
40+
import de.halirutan.mathematica.sdk.MathematicaLanguageLevel;
4141
import de.halirutan.mathematica.sdk.MathematicaSdkType;
4242
import org.jetbrains.annotations.Nls;
4343
import org.jetbrains.annotations.NotNull;
@@ -171,17 +171,13 @@ public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, fina
171171
*/
172172
private static class WrongVersionVisitor extends MathematicaVisitor {
173173

174-
private HashMap<String, Double> mySymbolVersions = SymbolVersionProvider.getSymbolNames();
174+
private final HashMap<String, Double> mySymbolVersions = SymbolVersionProvider.getSymbolNames();
175175
private MathematicaLanguageLevel myLanguageLevel = MathematicaLanguageLevel.HIGHEST;
176176
private final ProblemsHolder myHolder;
177177

178178
WrongVersionVisitor(final ProblemsHolder holder, final MathematicaLanguageLevel usedLanguageVersion) {
179179
this.myHolder = holder;
180-
final Sdk projectSdk = ProjectRootManager.getInstance(myHolder.getProject()).getProjectSdk();
181-
if (projectSdk != null && projectSdk.getSdkType() instanceof MathematicaSdkType) {
182180
myLanguageLevel = usedLanguageVersion;
183-
}
184-
185181
}
186182

187183
private void registerProblem(final PsiElement element, final String message) {

src/de/halirutan/mathematica/sdk/MathematicaLanguageLevel.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import org.jetbrains.annotations.NotNull;
2828

2929
/**
30-
* Provides a way to represent the different versions of a Mathematica SDK
30+
* Provides a way to represent the different versions of a Mathematica SDK. We will not use all possible different builds
31+
* of Mathematica, but only represent Major and Minor version jumps.
3132
* @author patrick (11/22/2016)
3233
*/
3334
@SuppressWarnings({"EnumeratedConstantNamingConvention", "WeakerAccess"})
@@ -53,6 +54,20 @@ public enum MathematicaLanguageLevel {
5354
myVersionNumber = Double.parseDouble(name);
5455
}
5556

57+
/**
58+
* The parsed version string from an Sdk of type {@link MathematicaSdkType} will look like this: </br>
59+
* <ul>
60+
* <li>10.0.2.5206630</li>
61+
* <li>11.0.1.5597743</li>
62+
* <li>9.0.1.4055646</li>
63+
* </ul>
64+
*
65+
* The last long number seems to be some built-number, while the part in the front is the version number the user
66+
* usually sees.
67+
*
68+
* @param sdk an Sdk of type {@link MathematicaSdkType}
69+
* @return the extracted language version
70+
*/
5671
public static MathematicaLanguageLevel createFromSdk(@NotNull Sdk sdk) {
5772
if (sdk.getSdkType() instanceof MathematicaSdkType) {
5873
final String version = sdk.getVersionString();
@@ -62,6 +77,7 @@ public static MathematicaLanguageLevel createFromSdk(@NotNull Sdk sdk) {
6277
if (version.matches("10\\.3.*")) return M_10_3;
6378
if (version.matches("10\\.2.*")) return M_10_2;
6479
if (version.matches("10\\.1.*")) return M_10_1;
80+
if (version.matches("10\\.0.*")) return M_10;
6581
if (version.matches("9.*")) return M_9;
6682
if (version.matches("8.*")) return M_8;
6783
}
@@ -85,11 +101,11 @@ public String getPresentableText() {
85101
}
86102

87103
public boolean isAtLeast(@NotNull MathematicaLanguageLevel level) {
88-
return compareTo(level) >= 0;
104+
return compareTo(level) <= 0;
89105
}
90106

91107
public boolean isLessThan(@NotNull MathematicaLanguageLevel level) {
92-
return compareTo(level) < 0;
108+
return compareTo(level) > 0;
93109
}
94110

95111

src/de/halirutan/mathematica/sdk/MathematicaSdkType.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@
3838
import java.util.regex.Pattern;
3939

4040
/**
41+
* Provides a way to systematically extract information like version, AddOns packages, and JLink.jar location from a
42+
* Mathematica installation. I don't support versions < 8.
43+
*
4144
* @author patrick (4/27/13)
4245
*/
4346
public class MathematicaSdkType extends SdkType {
44-
private static final Pattern PACKAGE_INIT_PATTERN = Pattern.compile(".*Kernel/init\\.m");
4547

48+
private static final Pattern PACKAGE_INIT_PATTERN = Pattern.compile(".*Kernel/init\\.m");
4649
private static final String OS = System.getProperty("os.name").toLowerCase();
4750

4851
public MathematicaSdkType() {
@@ -76,11 +79,11 @@ private static void addJLinkJars(SdkModificator sdkModificator, String homePath)
7679
Pattern jlinkPattern = Pattern.compile(".*JLink.jar");
7780
List<File> jlinkFiles = FileUtil.findFilesByMask(jlinkPattern, new File(homePath));
7881
for (File jlinkFile : jlinkFiles) {
79-
jarFileSystem.setNoCopyJarForPath(jlinkFile.getAbsolutePath()+ JarFileSystem.JAR_SEPARATOR);
80-
VirtualFile vFile = jarFileSystem.findFileByPath(jlinkFile.getAbsolutePath()+ JarFileSystem.JAR_SEPARATOR);
82+
jarFileSystem.setNoCopyJarForPath(jlinkFile.getAbsolutePath() + JarFileSystem.JAR_SEPARATOR);
83+
VirtualFile vFile = jarFileSystem.findFileByPath(jlinkFile.getAbsolutePath() + JarFileSystem.JAR_SEPARATOR);
8184
sdkModificator.addRoot(vFile, OrderRootType.CLASSES);
8285
}
83-
}
86+
}
8487

8588
private static void addAddOnPackageSources(SdkModificator sdkModificator, String homePath) {
8689
String addOnsPath = homePath + File.separatorChar + "AddOns";
@@ -171,7 +174,7 @@ public String getPresentableName() {
171174
}
172175

173176
@Override
174-
public void saveAdditionalData(@NotNull SdkAdditionalData sdkAdditionalData, @NotNull Element element) {
177+
public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) {
175178

176179
}
177180

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2016 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.sdk;
23+
24+
import org.junit.Test;
25+
26+
import static org.junit.Assert.*;
27+
28+
/**
29+
* @author patrick (27.11.16).
30+
*/
31+
@SuppressWarnings("NonBooleanMethodNameMayNotStartWithQuestion")
32+
public class MathematicaLanguageLevelTest {
33+
@Test
34+
public void isAtLeast() throws Exception {
35+
// Using the same version
36+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_11));
37+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_10_4));
38+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_10_3));
39+
assertTrue(MathematicaLanguageLevel.M_10_2.isAtLeast(MathematicaLanguageLevel.M_10_2));
40+
assertTrue(MathematicaLanguageLevel.M_10_1.isAtLeast(MathematicaLanguageLevel.M_10_1));
41+
assertTrue(MathematicaLanguageLevel.M_10.isAtLeast(MathematicaLanguageLevel.M_10));
42+
assertTrue(MathematicaLanguageLevel.M_9.isAtLeast(MathematicaLanguageLevel.M_9));
43+
assertTrue(MathematicaLanguageLevel.M_8.isAtLeast(MathematicaLanguageLevel.M_8));
44+
45+
// Using all combinations of smaller versions
46+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_10_4));
47+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_10_3));
48+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_10_2));
49+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_10_1));
50+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_10));
51+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_9));
52+
assertTrue(MathematicaLanguageLevel.M_11.isAtLeast(MathematicaLanguageLevel.M_8));
53+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_10_3));
54+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_10_2));
55+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_10_1));
56+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_10));
57+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_9));
58+
assertTrue(MathematicaLanguageLevel.M_10_4.isAtLeast(MathematicaLanguageLevel.M_8));
59+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_10_2));
60+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_10_1));
61+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_10));
62+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_9));
63+
assertTrue(MathematicaLanguageLevel.M_10_3.isAtLeast(MathematicaLanguageLevel.M_8));
64+
assertTrue(MathematicaLanguageLevel.M_10_2.isAtLeast(MathematicaLanguageLevel.M_10_1));
65+
assertTrue(MathematicaLanguageLevel.M_10_2.isAtLeast(MathematicaLanguageLevel.M_10));
66+
assertTrue(MathematicaLanguageLevel.M_10_2.isAtLeast(MathematicaLanguageLevel.M_9));
67+
assertTrue(MathematicaLanguageLevel.M_10_2.isAtLeast(MathematicaLanguageLevel.M_8));
68+
assertTrue(MathematicaLanguageLevel.M_10_1.isAtLeast(MathematicaLanguageLevel.M_10));
69+
assertTrue(MathematicaLanguageLevel.M_10_1.isAtLeast(MathematicaLanguageLevel.M_9));
70+
assertTrue(MathematicaLanguageLevel.M_10_1.isAtLeast(MathematicaLanguageLevel.M_8));
71+
assertTrue(MathematicaLanguageLevel.M_10.isAtLeast(MathematicaLanguageLevel.M_9));
72+
assertTrue(MathematicaLanguageLevel.M_10.isAtLeast(MathematicaLanguageLevel.M_8));
73+
assertTrue(MathematicaLanguageLevel.M_9.isAtLeast(MathematicaLanguageLevel.M_8));
74+
75+
}
76+
77+
@Test
78+
public void isLessThan() throws Exception {
79+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_9));
80+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_10));
81+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_10_1));
82+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_10_2));
83+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_10_3));
84+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_10_4));
85+
assertTrue(MathematicaLanguageLevel.M_8.isLessThan(MathematicaLanguageLevel.M_11));
86+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_10));
87+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_10_1));
88+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_10_2));
89+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_10_3));
90+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_10_4));
91+
assertTrue(MathematicaLanguageLevel.M_9.isLessThan(MathematicaLanguageLevel.M_11));
92+
assertTrue(MathematicaLanguageLevel.M_10.isLessThan(MathematicaLanguageLevel.M_10_1));
93+
assertTrue(MathematicaLanguageLevel.M_10.isLessThan(MathematicaLanguageLevel.M_10_2));
94+
assertTrue(MathematicaLanguageLevel.M_10.isLessThan(MathematicaLanguageLevel.M_10_3));
95+
assertTrue(MathematicaLanguageLevel.M_10.isLessThan(MathematicaLanguageLevel.M_10_4));
96+
assertTrue(MathematicaLanguageLevel.M_10.isLessThan(MathematicaLanguageLevel.M_11));
97+
assertTrue(MathematicaLanguageLevel.M_10_1.isLessThan(MathematicaLanguageLevel.M_10_2));
98+
assertTrue(MathematicaLanguageLevel.M_10_1.isLessThan(MathematicaLanguageLevel.M_10_3));
99+
assertTrue(MathematicaLanguageLevel.M_10_1.isLessThan(MathematicaLanguageLevel.M_10_4));
100+
assertTrue(MathematicaLanguageLevel.M_10_1.isLessThan(MathematicaLanguageLevel.M_11));
101+
assertTrue(MathematicaLanguageLevel.M_10_2.isLessThan(MathematicaLanguageLevel.M_10_3));
102+
assertTrue(MathematicaLanguageLevel.M_10_2.isLessThan(MathematicaLanguageLevel.M_10_4));
103+
assertTrue(MathematicaLanguageLevel.M_10_2.isLessThan(MathematicaLanguageLevel.M_11));
104+
assertTrue(MathematicaLanguageLevel.M_10_3.isLessThan(MathematicaLanguageLevel.M_10_4));
105+
assertTrue(MathematicaLanguageLevel.M_10_3.isLessThan(MathematicaLanguageLevel.M_11));
106+
assertTrue(MathematicaLanguageLevel.M_10_4.isLessThan(MathematicaLanguageLevel.M_11));
107+
}
108+
109+
}

0 commit comments

Comments
 (0)