Skip to content

Commit d442642

Browse files
committed
Strings refactored to Paths
1 parent a1f0aa8 commit d442642

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/layergen/UpdateCenterLayerGen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.UnsupportedEncodingException;
1515
import java.net.MalformedURLException;
1616
import java.net.URL;
17+
import java.nio.file.Paths;
1718
import java.util.Collection;
1819

1920
/**
@@ -44,7 +45,7 @@ public InputStream openInputStream() {
4445
public UpdateCenterLayerGen() {
4546
synchronized (UpdateCenterLayerGen.class) {
4647
if (!callbackRegistered) {
47-
CallbackURLStreamHandler.registerCallback(CALLBACK_NAME, callback);
48+
CallbackURLStreamHandler.registerCallback(Paths.get(CALLBACK_NAME), callback);
4849
}
4950
callbackRegistered = true;
5051
}

tmc-plugin/src/fi/helsinki/cs/tmc/model/NbTmcSettings.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import fi.helsinki.cs.tmc.tailoring.Tailoring;
88
import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
99
import fi.helsinki.cs.tmc.core.domain.Course;
10+
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
1013
import java.util.Locale;
1114

1215
/**
@@ -143,7 +146,7 @@ public void setSavingPassword(boolean shouldSave) {
143146
if (shouldSave) {
144147
settings.put(PREF_PASSWORD, unsavedPassword);
145148
} else {
146-
settings.remove(PREF_PASSWORD);
149+
settings.remove(PREF_PASSWORD);
147150
}
148151
}
149152

@@ -153,9 +156,9 @@ public boolean isSavingPassword() {
153156

154157
@Override
155158
public String getTmcMainDirectory() {
156-
String path = settings.get(PREF_PROJECT_ROOT_DIR, null);
159+
Path path = Paths.get(settings.get(PREF_PROJECT_ROOT_DIR, null));
157160
if (path != null) {
158-
return path;
161+
return path.toString();
159162
} else {
160163
// Can sometimes take a while. That's why we don't pass it as a default above.
161164
return ProjectMediator.getDefaultProjectRootDir();

tmc-plugin/src/fi/helsinki/cs/tmc/model/ProjectMediator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import fi.helsinki.cs.tmc.core.domain.Exercise;
44
import fi.helsinki.cs.tmc.utilities.ExceptionUtils;
5+
56
import java.io.File;
67
import java.io.IOException;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
710
import java.util.ArrayList;
811
import java.util.Arrays;
912
import java.util.Collection;
@@ -113,13 +116,13 @@ public File getCourseRootDir(String courseName) {
113116
* The exercise must have a course name set.
114117
*/
115118
public File getProjectDirForExercise(Exercise ex) {
116-
String path =
119+
Path path = Paths.get(
117120
getProjectRootDir()
118121
+ File.separator
119122
+ ex.getCourseName()
120123
+ File.separator
121-
+ ex.getName().replaceAll("-", "/");
122-
File file = new File(path);
124+
+ ex.getName().replaceAll("-", "/"));
125+
File file = path.toFile();
123126
return FileUtil.normalizeFile(file);
124127
}
125128

tmc-plugin/src/fi/helsinki/cs/tmc/model/SourceFileLookup.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import fi.helsinki.cs.tmc.core.domain.Exercise;
44

5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
58
import org.netbeans.api.java.classpath.GlobalPathRegistry;
69
import org.openide.filesystems.FileObject;
710

@@ -24,20 +27,20 @@ private SourceFileLookup(
2427

2528
public FileObject findSourceFileFor(Exercise exercise, String className) {
2629
String outerClassName = className.replaceAll("\\$.*$", "");
27-
String path = outerClassName.replace('.', '/') + ".java";
30+
Path path = Paths.get(outerClassName.replace('.', '/') + ".java");
2831

2932
TmcProjectInfo correctProject = projectMediator.tryGetProjectForExercise(exercise);
3033
for (FileObject sr : globalPathRegistry.getSourceRoots()) {
3134
TmcProjectInfo p = projectMediator.tryGetProjectOwningFile(sr);
3235
if (p != null && p.equals(correctProject)) {
33-
FileObject result = sr.getFileObject(path);
36+
FileObject result = sr.getFileObject(path.toString());
3437
if (result != null) {
3538
return result;
3639
}
3740
}
3841
}
3942

4043
// Fall back to findResource picking a source root from any project.
41-
return GlobalPathRegistry.getDefault().findResource(path);
44+
return GlobalPathRegistry.getDefault().findResource(path.toString());
4245
}
4346
}

tmc-plugin/src/fi/helsinki/cs/tmc/utilities/urlcallback/CallbackURLStreamHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.net.URL;
1010
import java.net.URLConnection;
1111
import java.net.URLStreamHandler;
12+
import java.nio.file.Path;
1213
import java.util.Map;
1314

1415
/**
@@ -23,11 +24,11 @@ public class CallbackURLStreamHandler extends URLStreamHandler {
2324

2425
private static final Map<String, URLCallback> callbacks = Maps.newHashMap();
2526

26-
public static void registerCallback(String path, URLCallback callback) {
27+
public static void registerCallback(Path path, URLCallback callback) {
2728
if (callback == null) {
28-
callbacks.remove(path);
29+
callbacks.remove(path.toString());
2930
} else {
30-
callbacks.put(path, callback);
31+
callbacks.put(path.toString(), callback);
3132
}
3233
}
3334

0 commit comments

Comments
 (0)