From 56e034928742bb35f74895ab650ed4fb02ceb84d Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 25 May 2015 12:53:51 +0200 Subject: [PATCH] Allowing editing .S files. Fixes #1616 and #3059 --- app/src/processing/app/Sketch.java | 4 ++-- .../src/processing/app/SketchData.java | 23 +++++++------------ .../src/processing/app/debug/Compiler.java | 4 ++-- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 74ca35733f5..586db2e6eed 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -836,7 +836,7 @@ public boolean addFile(File sourceFile) { destFile = new File(data.getCodeFolder(), filename); } else { - for (String extension : data.getExtensions()) { + for (String extension : SketchData.EXTENSIONS) { String lower = filename.toLowerCase(); if (lower.endsWith("." + extension)) { destFile = new File(data.getFolder(), filename); @@ -1345,7 +1345,7 @@ public boolean isDefaultExtension(String what) { * extensions. */ public boolean validExtension(String what) { - return data.getExtensions().contains(what); + return SketchData.EXTENSIONS.contains(what); } diff --git a/arduino-core/src/processing/app/SketchData.java b/arduino-core/src/processing/app/SketchData.java index 677edcc8004..cef17433e57 100644 --- a/arduino-core/src/processing/app/SketchData.java +++ b/arduino-core/src/processing/app/SketchData.java @@ -1,17 +1,19 @@ package processing.app; +import com.google.common.collect.FluentIterable; + import static processing.app.I18n._; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; public class SketchData { + public static final List SKETCH_EXTENSIONS = Arrays.asList("ino", "pde"); + public static final List OTHER_ALLOWED_EXTENSIONS = Arrays.asList("c", "cpp", "h", "s"); + public static final List EXTENSIONS = new LinkedList(FluentIterable.from(SKETCH_EXTENSIONS).append(OTHER_ALLOWED_EXTENSIONS).toList()); + /** main pde file for this sketch. */ private File primaryFile; @@ -105,8 +107,6 @@ protected void load() throws IOException { clearCodeDocs(); // data.setCodeDocs(codeDocs); - List extensions = getExtensions(); - for (String filename : list) { // Ignoring the dot prefix files is especially important to avoid files // with the ._ prefix on Mac OS X. (You'll see this with Mac files on @@ -119,7 +119,7 @@ protected void load() throws IOException { // figure out the name without any extension String base = filename; // now strip off the .pde and .java extensions - for (String extension : extensions) { + for (String extension : EXTENSIONS) { if (base.toLowerCase().endsWith("." + extension)) { base = base.substring(0, base.length() - (extension.length() + 1)); @@ -173,13 +173,6 @@ public String getDefaultExtension() { return "ino"; } - /** - * Returns a String[] array of proper extensions. - */ - public List getExtensions() { - return Arrays.asList("ino", "pde", "c", "cpp", "h"); - } - /** * Returns a file object for the primary .pde of this sketch. */ diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 53f7c41f9fc..34edc08b0d9 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -1201,7 +1201,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru StringBuffer bigCode = new StringBuffer(); int bigCount = 0; for (SketchCode sc : sketch.getCodes()) { - if (sc.isExtension("ino") || sc.isExtension("pde")) { + if (sc.isExtension(SketchData.SKETCH_EXTENSIONS)) { sc.setPreprocOffset(bigCount); // These #line directives help the compiler report errors with // correct the filename and line number (issue 281 & 907) @@ -1272,7 +1272,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru // 3. then loop over the code[] and save each .java file for (SketchCode sc : sketch.getCodes()) { - if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) { + if (sc.isExtension(SketchData.OTHER_ALLOWED_EXTENSIONS)) { // no pre-processing services necessary for java files // just write the the contents of 'program' to a .java file // into the build directory. uses byte stream and reader/writer