Skip to content

Commit 0c62ac8

Browse files
matthijskooijmanfacchinm
authored andcommitted
Do not store the sketch name in Sketch
Sketch already stores the sketch folder, and the sketch name should be identical to the folder name. In the case where the filename passed to the sketch constructor is not the primary .ino file (named after the sketch), this will slightly change behaviour. However, the calling code should prevent this from happening, and with the old code, some internal assumptions were probably violated, so this changes makes handling this situation a bit more robust. Since the actual filename passed to Sketch is no longer used, it is no longer required to pass the name of the primary .ino file. At some point, the constructor should probably be changed to accept a folder name instead of a filename, but that would require a lot of changes to trace this back through the code, so this is something for later.
1 parent 7a73d0b commit 0c62ac8

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

arduino-core/src/processing/app/Sketch.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ public class Sketch {
2525
*/
2626
private File folder;
2727

28-
/**
29-
* Name of sketch, which is the name of main file (without .pde or .java
30-
* extension)
31-
*/
32-
private String name;
33-
3428
private List<SketchFile> files = new ArrayList<SketchFile>();
3529

3630
private static final Comparator<SketchFile> CODE_DOCS_COMPARATOR = new Comparator<SketchFile>() {
@@ -49,15 +43,9 @@ public int compare(SketchFile x, SketchFile y) {
4943
* on disk to get populate the list of files in this sketch.
5044
*
5145
* @param file
52-
* The primary file for this sketch.
46+
* Any file inside the sketch directory.
5347
*/
5448
Sketch(File file) throws IOException {
55-
// get the name of the sketch by chopping .pde or .java
56-
// off of the main file name
57-
String mainFilename = primaryFile.getName();
58-
int suffixLength = getDefaultExtension().length() + 1;
59-
name = mainFilename.substring(0, mainFilename.length() - suffixLength);
60-
6149
folder = new File(file.getParent());
6250
files = listSketchFiles(true);
6351
}
@@ -195,7 +183,7 @@ protected void removeFile(SketchFile which) {
195183
}
196184

197185
public String getName() {
198-
return name;
186+
return folder.getName();
199187
}
200188

201189
public File getFolder() {

0 commit comments

Comments
 (0)