From 4a1ef0fecee011acf99485e34ed6032ec3c86f73 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 12:17:12 +0200 Subject: [PATCH 01/12] First implementation of ClangFormat class Still missing installation of clang-format binaries via build.xml --- .../formatter/clangformat/ClangFormat.java | 121 ++++++++++++++++++ app/src/processing/app/Editor.java | 19 ++- 2 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java new file mode 100644 index 00000000000..491c5ec19cc --- /dev/null +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -0,0 +1,121 @@ +/* + * This file is part of Arduino. + * + * Arduino is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2021 Arduino LLC (http://www.arduino.cc/) + */ + +package cc.arduino.packages.formatter.clangformat; + +import static processing.app.I18n.tr; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.logging.log4j.core.util.NullOutputStream; + +import processing.app.Editor; +import processing.app.helpers.ProcessUtils; +import processing.app.tools.Tool; + +public class ClangFormat implements Tool { + + private Editor editor; + + public ClangFormat() { + } + + @Override + public void init(Editor editor) { + this.editor = editor; + } + + @Override + public void run() { + String originalText = editor.getCurrentTab().getText(); + + try { + String formattedText = runClangFormatOn(originalText); + if (formattedText.equals(originalText)) { + editor.statusNotice(tr("No changes necessary for Auto Format.")); + return; + } + editor.getCurrentTab().setText(formattedText); + editor.statusNotice(tr("Auto Format finished.")); + } catch (IOException | InterruptedException e) { + editor.statusError("Auto format error: " + e.getMessage()); + e.printStackTrace(); + } + } + + @Override + public String getMenuTitle() { + return tr("Auto Format"); + } + + private Thread copyAndClose(InputStream input, OutputStream output) { + Thread t = new Thread(() -> { + try { + IOUtils.copy(input, output); + } catch (IOException e) { + e.printStackTrace(); + } + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + }); + t.start(); + return t; + } + + String runClangFormatOn(String source) + throws IOException, InterruptedException { + String cmd[] = new String[] { "clang-format" }; + + Process process = ProcessUtils.exec(cmd); + ByteArrayOutputStream result = new ByteArrayOutputStream(); + ByteArrayInputStream dataOut = new ByteArrayInputStream(source.getBytes()); + Thread out = copyAndClose(process.getInputStream(), result); + Thread err = copyAndClose(process.getErrorStream(), + NullOutputStream.getInstance()); + Thread in = copyAndClose(dataOut, process.getOutputStream()); + /* int r = */process.waitFor(); + in.join(); + out.join(); + err.join(); + return result.toString(); + } +} diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index c1be9b5efa2..9f8d5f54bf5 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -981,24 +981,21 @@ private Tool getOrCreateToolInstance(String className) { } private void addInternalTools(JMenu menu) { - JMenuItem item; - - item = createToolMenuItem("cc.arduino.packages.formatter.AStyle"); - if (item == null) { - throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable"); + JMenuItem formatItem = createToolMenuItem("cc.arduino.packages.formatter.clangformat.ClangFormat"); + if (formatItem == null) { + throw new NullPointerException("Tool cc.arduino.packages.formatter.clangformat.ClangFormat"); } - item.setName("menuToolsAutoFormat"); + formatItem.setName("menuToolsAutoFormat"); int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - item.setAccelerator(KeyStroke.getKeyStroke('T', modifiers)); - menu.add(item); + formatItem.setAccelerator(KeyStroke.getKeyStroke('T', modifiers)); + menu.add(formatItem); - //menu.add(createToolMenuItem("processing.app.tools.CreateFont")); - //menu.add(createToolMenuItem("processing.app.tools.ColorSelector")); + // menu.add(createToolMenuItem("processing.app.tools.CreateFont")); + // menu.add(createToolMenuItem("processing.app.tools.ColorSelector")); menu.add(createToolMenuItem("processing.app.tools.Archiver")); menu.add(createToolMenuItem("processing.app.tools.FixEncoding")); } - private void selectSerialPort(String name) { if(portMenu == null) { System.out.println(tr("serialMenu is null")); From 7ef8b06b17ee95ee14d512f5b3b49ff194264f77 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 17:19:44 +0200 Subject: [PATCH 02/12] Added clang-format download in build.xml --- .gitignore | 1 + .../formatter/clangformat/ClangFormat.java | 5 ++- build/build.xml | 31 +++++++++++++++++++ build/linux/clang_12.0.0_Linux_32bit.zip.sha | 1 + build/linux/clang_12.0.0_Linux_64bit.zip.sha | 1 + build/linux/clang_12.0.0_Linux_ARM64.zip.sha | 1 + build/linux/clang_12.0.0_Linux_ARMv6.zip.sha | 1 + build/macosx/clang_12.0.0_macOS_64bit.zip.sha | 1 + .../clang_12.0.0_Windows_32bit.zip.sha | 1 + 9 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 build/linux/clang_12.0.0_Linux_32bit.zip.sha create mode 100644 build/linux/clang_12.0.0_Linux_64bit.zip.sha create mode 100644 build/linux/clang_12.0.0_Linux_ARM64.zip.sha create mode 100644 build/linux/clang_12.0.0_Linux_ARMv6.zip.sha create mode 100644 build/macosx/clang_12.0.0_macOS_64bit.zip.sha create mode 100644 build/windows/clang_12.0.0_Windows_32bit.zip.sha diff --git a/.gitignore b/.gitignore index 52ef58c5d36..551fb12a088 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ build/windows/launch4j-*.zip build/windows/launcher/launch4j build/windows/WinAVR-*.zip build/macosx/arduino-*.zip +build/macosx/clang*.zip build/macosx/dist/*.tar.gz build/macosx/dist/*.tar.bz2 build/macosx/*.tar.bz2 diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index 491c5ec19cc..ec0847cc970 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -40,12 +40,15 @@ import org.apache.commons.compress.utils.IOUtils; import org.apache.logging.log4j.core.util.NullOutputStream; +import processing.app.Base; import processing.app.Editor; import processing.app.helpers.ProcessUtils; import processing.app.tools.Tool; public class ClangFormat implements Tool { + private final String clangExecutable = Base.getContentFile("clang-format") + .getAbsolutePath(); private Editor editor; public ClangFormat() { @@ -103,7 +106,7 @@ private Thread copyAndClose(InputStream input, OutputStream output) { String runClangFormatOn(String source) throws IOException, InterruptedException { - String cmd[] = new String[] { "clang-format" }; + String cmd[] = new String[] { clangExecutable }; Process process = ProcessUtils.exec(cmd); ByteArrayOutputStream result = new ByteArrayOutputStream(); diff --git a/build/build.xml b/build/build.xml index b4e0ef8ea1d..1752c01dbe5 100644 --- a/build/build.xml +++ b/build/build.xml @@ -50,6 +50,16 @@ + + + + + + + + + + @@ -108,6 +118,7 @@ + @@ -223,6 +234,8 @@ + + @@ -316,6 +329,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/build/linux/clang_12.0.0_Linux_32bit.zip.sha b/build/linux/clang_12.0.0_Linux_32bit.zip.sha new file mode 100644 index 00000000000..c0a4366e62c --- /dev/null +++ b/build/linux/clang_12.0.0_Linux_32bit.zip.sha @@ -0,0 +1 @@ +b10e77fb79a41880766439dc65cd8aaa328af5bc diff --git a/build/linux/clang_12.0.0_Linux_64bit.zip.sha b/build/linux/clang_12.0.0_Linux_64bit.zip.sha new file mode 100644 index 00000000000..344724de285 --- /dev/null +++ b/build/linux/clang_12.0.0_Linux_64bit.zip.sha @@ -0,0 +1 @@ +e3fe347cdb2e4b7b1c92b8e21b4aae49eeaaad55 diff --git a/build/linux/clang_12.0.0_Linux_ARM64.zip.sha b/build/linux/clang_12.0.0_Linux_ARM64.zip.sha new file mode 100644 index 00000000000..fdaa6199491 --- /dev/null +++ b/build/linux/clang_12.0.0_Linux_ARM64.zip.sha @@ -0,0 +1 @@ +a81b7e8c6c5922fbcd423228f13a1148a91a3932 diff --git a/build/linux/clang_12.0.0_Linux_ARMv6.zip.sha b/build/linux/clang_12.0.0_Linux_ARMv6.zip.sha new file mode 100644 index 00000000000..c6dc14dad63 --- /dev/null +++ b/build/linux/clang_12.0.0_Linux_ARMv6.zip.sha @@ -0,0 +1 @@ +d10ae0b04eadf9fd0fa52d16549a2c6bec482738 diff --git a/build/macosx/clang_12.0.0_macOS_64bit.zip.sha b/build/macosx/clang_12.0.0_macOS_64bit.zip.sha new file mode 100644 index 00000000000..c231be1880f --- /dev/null +++ b/build/macosx/clang_12.0.0_macOS_64bit.zip.sha @@ -0,0 +1 @@ +154b62e3062b5040594155702c7c7508d18c6b3a diff --git a/build/windows/clang_12.0.0_Windows_32bit.zip.sha b/build/windows/clang_12.0.0_Windows_32bit.zip.sha new file mode 100644 index 00000000000..938fb3a7d2f --- /dev/null +++ b/build/windows/clang_12.0.0_Windows_32bit.zip.sha @@ -0,0 +1 @@ +d2a5246fed18b61d96de49887e16520be5dad944 From f20d51222c29e5e969ff0cb262b92245a3fc2ad4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 17:48:25 +0200 Subject: [PATCH 03/12] ClangFormat is no more a Tool Being a plugin Tool is not mandatory and, in this case, it just makes things more complicated without any evident benefit. --- .../formatter/clangformat/ClangFormat.java | 14 ++----------- app/src/processing/app/Editor.java | 20 +++++++++---------- app/src/processing/app/EditorTab.java | 14 ++++++------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index ec0847cc970..1244a35e935 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -43,19 +43,14 @@ import processing.app.Base; import processing.app.Editor; import processing.app.helpers.ProcessUtils; -import processing.app.tools.Tool; -public class ClangFormat implements Tool { +public class ClangFormat implements Runnable { private final String clangExecutable = Base.getContentFile("clang-format") .getAbsolutePath(); private Editor editor; - public ClangFormat() { - } - - @Override - public void init(Editor editor) { + public ClangFormat(Editor editor) { this.editor = editor; } @@ -77,11 +72,6 @@ public void run() { } } - @Override - public String getMenuTitle() { - return tr("Auto Format"); - } - private Thread copyAndClose(InputStream input, OutputStream output) { Thread t = new Thread(() -> { try { diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 9f8d5f54bf5..e3d8de02ebd 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -89,6 +89,7 @@ import cc.arduino.packages.BoardPort; import cc.arduino.packages.MonitorFactory; import cc.arduino.packages.Uploader; +import cc.arduino.packages.formatter.clangformat.ClangFormat; import cc.arduino.packages.uploaders.SerialUploader; import cc.arduino.view.GoToLineNumber; import cc.arduino.view.StubMenuListener; @@ -236,11 +237,13 @@ public boolean test(SketchController controller) { private Map internalToolCache = new HashMap(); + final ClangFormat formatter; + public Editor(Base ibase, File file, int[] storedLocation, int[] defaultLocation, Platform platform) throws Exception { super("Arduino"); this.base = ibase; this.platform = platform; - + this.formatter = new ClangFormat(this); Base.setIcon(this); // Install default actions for Run, Present, etc. @@ -981,14 +984,12 @@ private Tool getOrCreateToolInstance(String className) { } private void addInternalTools(JMenu menu) { - JMenuItem formatItem = createToolMenuItem("cc.arduino.packages.formatter.clangformat.ClangFormat"); - if (formatItem == null) { - throw new NullPointerException("Tool cc.arduino.packages.formatter.clangformat.ClangFormat"); - } - formatItem.setName("menuToolsAutoFormat"); + JMenuItem autoFormat = new JMenuItem(tr("Auto Format")); + autoFormat.setName("menuToolsAutoFormat"); + autoFormat.addActionListener(event -> SwingUtilities.invokeLater(formatter)); int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - formatItem.setAccelerator(KeyStroke.getKeyStroke('T', modifiers)); - menu.add(formatItem); + autoFormat.setAccelerator(KeyStroke.getKeyStroke('T', modifiers)); + menu.add(autoFormat); // menu.add(createToolMenuItem("processing.app.tools.CreateFont")); // menu.add(createToolMenuItem("processing.app.tools.ColorSelector")); @@ -1893,8 +1894,7 @@ private boolean handleSave2() { boolean saved = false; try { if (PreferencesData.getBoolean("editor.autoformat_currentfile_before_saving")) { - Tool formatTool = getOrCreateToolInstance("cc.arduino.packages.formatter.AStyle"); - formatTool.run(); + formatter.run(); } boolean wasReadOnly = sketchController.isReadOnly(); diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index 5e8f3e4bfcf..e77b7a65fd6 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -39,6 +39,7 @@ import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; import javax.swing.border.MatteBorder; import javax.swing.event.PopupMenuEvent; @@ -197,15 +198,12 @@ private void configurePopupMenu(final SketchTextArea textarea){ menu.addSeparator(); - JMenuItem item = editor.createToolMenuItem("cc.arduino.packages.formatter.AStyle"); - if (item == null) { - throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable"); - } - item.setName("menuToolsAutoFormat"); - - menu.add(item); + JMenuItem autoFormat = new JMenuItem(tr("Auto Format")); + autoFormat.addActionListener(event -> SwingUtilities.invokeLater(editor.formatter)); + autoFormat.setName("menuToolsAutoFormat"); + menu.add(autoFormat); - item = new JMenuItem(tr("Comment/Uncomment"), '/'); + JMenuItem item = new JMenuItem(tr("Comment/Uncomment"), '/'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCommentUncomment(); From d33fc4e4db3520cdbafe14ea4c0cc9a480fb4481 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 17:51:56 +0200 Subject: [PATCH 04/12] Fixed some trivial warnings --- app/src/processing/app/Editor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index e3d8de02ebd..5d590b8c7bd 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -235,7 +235,7 @@ public boolean test(SketchController controller) { private UploadHandler uploadUsingProgrammerHandler; private Runnable timeoutUploadHandler; - private Map internalToolCache = new HashMap(); + private Map internalToolCache = new HashMap<>(); final ClangFormat formatter; @@ -1835,7 +1835,7 @@ public void updateTitle() { SketchFile current = getCurrentTab().getSketchFile(); String customFormat = PreferencesData.get("editor.custom_title_format"); if (customFormat != null && !customFormat.trim().isEmpty()) { - Map titleMap = new HashMap(); + Map titleMap = new HashMap<>(); titleMap.put("file", current.getFileName()); String path = sketch.getFolder().getAbsolutePath(); titleMap.put("folder", path); From 1f1dc7dd48fd021f887d717c9a4b69ab885bc3db Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 17:53:07 +0200 Subject: [PATCH 05/12] Removed libastyle --- .../cc/arduino/packages/formatter/AStyle.java | 98 ------------------- .../packages/formatter/AStyleInterface.java | 90 ----------------- build/build.xml | 47 --------- build/libastylej-2.05.1-5.zip.sha | 1 - 4 files changed, 236 deletions(-) delete mode 100644 app/src/cc/arduino/packages/formatter/AStyle.java delete mode 100644 app/src/cc/arduino/packages/formatter/AStyleInterface.java delete mode 100644 build/libastylej-2.05.1-5.zip.sha diff --git a/app/src/cc/arduino/packages/formatter/AStyle.java b/app/src/cc/arduino/packages/formatter/AStyle.java deleted file mode 100644 index 70b6717ff66..00000000000 --- a/app/src/cc/arduino/packages/formatter/AStyle.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of Arduino. - * - * Arduino is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package cc.arduino.packages.formatter; - -import processing.app.Base; -import processing.app.BaseNoGui; -import processing.app.Editor; -import processing.app.helpers.FileUtils; -import processing.app.tools.Tool; - -import java.io.File; -import java.io.IOException; - -import static processing.app.I18n.tr; - -public class AStyle implements Tool { - - private static final String FORMATTER_CONF = "formatter.conf"; - - private final AStyleInterface aStyleInterface; - private final String formatterConfiguration; - private Editor editor; - - public AStyle() { - this.aStyleInterface = new AStyleInterface(); - File customFormatterConf = BaseNoGui.getSettingsFile(FORMATTER_CONF); - File defaultFormatterConf = new File(Base.getContentFile("lib"), FORMATTER_CONF); - - File formatterConf; - if (customFormatterConf.exists()) { - formatterConf = customFormatterConf; - } else { - formatterConf = defaultFormatterConf; - } - String formatterConfiguration = ""; - - try { - formatterConfiguration = FileUtils.readFileToString(formatterConf); - } catch (IOException e) { - // ignored - } - this.formatterConfiguration = formatterConfiguration; - } - - @Override - public void init(Editor editor) { - this.editor = editor; - } - - @Override - public void run() { - String originalText = editor.getCurrentTab().getText(); - String formattedText = aStyleInterface.AStyleMain(originalText, formatterConfiguration); - - if (formattedText.equals(originalText)) { - editor.statusNotice(tr("No changes necessary for Auto Format.")); - return; - } - - editor.getCurrentTab().setText(formattedText); - - // mark as finished - editor.statusNotice(tr("Auto Format finished.")); - } - - @Override - public String getMenuTitle() { - return tr("Auto Format"); - } - -} diff --git a/app/src/cc/arduino/packages/formatter/AStyleInterface.java b/app/src/cc/arduino/packages/formatter/AStyleInterface.java deleted file mode 100644 index 4224bf164e7..00000000000 --- a/app/src/cc/arduino/packages/formatter/AStyleInterface.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of Arduino. - * - * Arduino is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, you may use this file as part of a free software - * library without restriction. Specifically, if other files instantiate - * templates or use macros or inline functions from this file, or you compile - * this file and link it with other files to produce an executable, this - * file does not by itself cause the resulting executable to be covered by - * the GNU General Public License. This exception does not however - * invalidate any other reasons why the executable file might be covered by - * the GNU General Public License. - * - * Copyright 2015 Arduino LLC (http://www.arduino.cc/) - */ - -package cc.arduino.packages.formatter; - -import processing.app.Base; -import processing.app.helpers.OSUtils; - -import java.io.File; - -public class AStyleInterface { - - static { - if (OSUtils.isWindows()) { - loadLib(Base.getContentFile(System.mapLibraryName("msvcp100"))); - loadLib(Base.getContentFile(System.mapLibraryName("msvcr100"))); - } - loadLib(new File(Base.getContentFile("lib"), System.mapLibraryName("astylej"))); - } - - private static void loadLib(File lib) { - try { - System.load(lib.getAbsolutePath()); - } catch (UnsatisfiedLinkError e) { - e.printStackTrace(); - System.out.println(e.getMessage()); - System.out.println("Cannot load native library " + lib.getAbsolutePath()); - System.out.println("The program has terminated!"); - System.exit(1); - } - } - - /** - * Calls the AStyleMain function in Artistic Style. - * - * @param textIn A string containing the source code to be formatted. - * @param options A string of options to Artistic Style. - * @return A String containing the formatted source from Artistic Style. - */ - public native String AStyleMain(String textIn, String options); - - /** - * Calls the AStyleGetVersion function in Artistic Style. - * - * @return A String containing the version number of Artistic Style. - */ - public native String AStyleGetVersion(); - - /** - * Error handler for messages from Artistic Style. - * This method is called only if there are errors when AStyleMain is called. - * This is for debugging and there should be no errors when the calling - * parameters are correct. - * Changing the method name requires changing Artistic Style. - * Signature: (ILjava/lang/String;)V. - * - * @param errorNumber The error number from Artistic Style. - * @param errorMessage The error message from Artistic Style. - */ - private void ErrorHandler(int errorNumber, String errorMessage) { - System.out.println("AStyle error " + String.valueOf(errorNumber) + " - " + errorMessage); - } - -} diff --git a/build/build.xml b/build/build.xml index 1752c01dbe5..1560e7978f4 100644 --- a/build/build.xml +++ b/build/build.xml @@ -523,17 +523,6 @@ - - - - - - - - - - - @@ -712,15 +701,6 @@ - - - - - - - - - @@ -733,19 +713,9 @@ - - - - - - - - - - @@ -758,7 +728,6 @@ - @@ -780,15 +749,6 @@ - - - - - - - - - @@ -1100,13 +1060,6 @@ - - - - - - - diff --git a/build/libastylej-2.05.1-5.zip.sha b/build/libastylej-2.05.1-5.zip.sha deleted file mode 100644 index 7ae7b7a6233..00000000000 --- a/build/libastylej-2.05.1-5.zip.sha +++ /dev/null @@ -1 +0,0 @@ -06032c6429c8cdd74e5b94cceaa2785987e442e0 From 7e76bc5b04fdb226f918bb6b8e04fea5680acd21 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 17:58:07 +0200 Subject: [PATCH 06/12] Renamed some build.xml ant task from libastyle to liblistserials The old name was a legacy leftover. --- build/build.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/build.xml b/build/build.xml index 1560e7978f4..3c1bf7cb614 100644 --- a/build/build.xml +++ b/build/build.xml @@ -700,7 +700,7 @@ - + @@ -715,7 +715,7 @@ - + @@ -730,7 +730,7 @@ - + @@ -748,7 +748,7 @@ - + @@ -763,7 +763,7 @@ - + @@ -781,7 +781,7 @@ - + @@ -799,7 +799,7 @@ - + From 66a001cf576a53f2981d9beeda3fa4a74342ee99 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 20 May 2021 18:16:48 +0200 Subject: [PATCH 07/12] Handle cursor positioning --- .../formatter/clangformat/ClangFormat.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index 1244a35e935..e65101b76fb 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -40,6 +40,9 @@ import org.apache.commons.compress.utils.IOUtils; import org.apache.logging.log4j.core.util.NullOutputStream; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + import processing.app.Base; import processing.app.Editor; import processing.app.helpers.ProcessUtils; @@ -57,14 +60,15 @@ public ClangFormat(Editor editor) { @Override public void run() { String originalText = editor.getCurrentTab().getText(); - + int cursorOffset = editor.getCurrentTab().getTextArea().getCaretPosition(); try { - String formattedText = runClangFormatOn(originalText); - if (formattedText.equals(originalText)) { + FormatResult result = runClangFormatOn(originalText, cursorOffset); + if (result.FormattedText.equals(originalText)) { editor.statusNotice(tr("No changes necessary for Auto Format.")); return; } - editor.getCurrentTab().setText(formattedText); + editor.getCurrentTab().setText(result.FormattedText); + editor.getCurrentTab().getTextArea().setCaretPosition(result.Cursor); editor.statusNotice(tr("Auto Format finished.")); } catch (IOException | InterruptedException e) { editor.statusError("Auto format error: " + e.getMessage()); @@ -94,21 +98,49 @@ private Thread copyAndClose(InputStream input, OutputStream output) { return t; } - String runClangFormatOn(String source) + FormatResult runClangFormatOn(String source, int cursorOffset) throws IOException, InterruptedException { - String cmd[] = new String[] { clangExecutable }; + String cmd[] = new String[] { clangExecutable, "--cursor=" + cursorOffset }; Process process = ProcessUtils.exec(cmd); - ByteArrayOutputStream result = new ByteArrayOutputStream(); + ByteArrayOutputStream clangOutput = new ByteArrayOutputStream(); ByteArrayInputStream dataOut = new ByteArrayInputStream(source.getBytes()); - Thread out = copyAndClose(process.getInputStream(), result); + + Thread in = copyAndClose(dataOut, process.getOutputStream()); Thread err = copyAndClose(process.getErrorStream(), NullOutputStream.getInstance()); - Thread in = copyAndClose(dataOut, process.getOutputStream()); + Thread out = copyAndClose(process.getInputStream(), clangOutput); + /* int r = */process.waitFor(); in.join(); out.join(); err.join(); - return result.toString(); + + // clang-format will output first a JSON object with: + // - the resulting cursor position and + // - a flag teling if the conversion was successful + // for example: + // + // { "Cursor": 34, "IncompleteFormat": false } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + FormatResult res = mapper.readValue(clangOutput.toByteArray(), + FormatResult.class); + + // After the JSON object above clang-format will output the formatted source + // code in plain text + String formattedText = clangOutput.toString(); + formattedText = formattedText.substring(formattedText.indexOf('}') + 1); + // handle different line endings + res.FormattedText = formattedText.replaceFirst("\\R", ""); + return res; } } + +class FormatResult { + public String FormattedText; + public int Cursor; + public boolean IncompleteFormat; +} From c4c5558b57ef1b8834fefdb41dd1592a73c69f11 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 20 May 2021 18:18:30 +0200 Subject: [PATCH 08/12] Slightly simplify subroutine --- .../packages/formatter/clangformat/ClangFormat.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index e65101b76fb..c92322ee6e8 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -45,6 +45,7 @@ import processing.app.Base; import processing.app.Editor; +import processing.app.EditorTab; import processing.app.helpers.ProcessUtils; public class ClangFormat implements Runnable { @@ -59,16 +60,17 @@ public ClangFormat(Editor editor) { @Override public void run() { - String originalText = editor.getCurrentTab().getText(); - int cursorOffset = editor.getCurrentTab().getTextArea().getCaretPosition(); + EditorTab tab = editor.getCurrentTab(); + String originalText = tab.getText(); + int cursorOffset = tab.getTextArea().getCaretPosition(); try { FormatResult result = runClangFormatOn(originalText, cursorOffset); if (result.FormattedText.equals(originalText)) { editor.statusNotice(tr("No changes necessary for Auto Format.")); return; } - editor.getCurrentTab().setText(result.FormattedText); - editor.getCurrentTab().getTextArea().setCaretPosition(result.Cursor); + tab.setText(result.FormattedText); + tab.getTextArea().setCaretPosition(result.Cursor); editor.statusNotice(tr("Auto Format finished.")); } catch (IOException | InterruptedException e) { editor.statusError("Auto format error: " + e.getMessage()); From 321eadbf0a85d2f385b0eb132c9639a50dcb8c4f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 21 May 2021 00:00:01 +0200 Subject: [PATCH 09/12] Catch clang-format error and report to user interface --- .../formatter/clangformat/ClangFormat.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index c92322ee6e8..e0711e3d20a 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -38,7 +38,6 @@ import java.io.OutputStream; import org.apache.commons.compress.utils.IOUtils; -import org.apache.logging.log4j.core.util.NullOutputStream; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,7 +45,6 @@ import processing.app.Base; import processing.app.Editor; import processing.app.EditorTab; -import processing.app.helpers.ProcessUtils; public class ClangFormat implements Runnable { @@ -75,6 +73,8 @@ public void run() { } catch (IOException | InterruptedException e) { editor.statusError("Auto format error: " + e.getMessage()); e.printStackTrace(); + } catch (ClangException e) { + editor.statusError("Auto format error: " + e.getMessage()); } } @@ -101,23 +101,27 @@ private Thread copyAndClose(InputStream input, OutputStream output) { } FormatResult runClangFormatOn(String source, int cursorOffset) - throws IOException, InterruptedException { + throws IOException, InterruptedException, ClangException { String cmd[] = new String[] { clangExecutable, "--cursor=" + cursorOffset }; Process process = ProcessUtils.exec(cmd); ByteArrayOutputStream clangOutput = new ByteArrayOutputStream(); + ByteArrayOutputStream clangError = new ByteArrayOutputStream(); ByteArrayInputStream dataOut = new ByteArrayInputStream(source.getBytes()); Thread in = copyAndClose(dataOut, process.getOutputStream()); - Thread err = copyAndClose(process.getErrorStream(), - NullOutputStream.getInstance()); + Thread err = copyAndClose(process.getErrorStream(), clangError); Thread out = copyAndClose(process.getInputStream(), clangOutput); - /* int r = */process.waitFor(); + int r = process.waitFor(); in.join(); out.join(); err.join(); + if (r != 0) { + throw new ClangException(clangError.toString()); + } + // clang-format will output first a JSON object with: // - the resulting cursor position and // - a flag teling if the conversion was successful @@ -141,6 +145,12 @@ FormatResult runClangFormatOn(String source, int cursorOffset) } } +class ClangException extends Exception { + public ClangException(String string) { + super(string); + } +} + class FormatResult { public String FormattedText; public int Cursor; From 752bcdbd89842767c65cb3f45f508a409fefaf48 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 21 May 2021 00:00:17 +0200 Subject: [PATCH 10/12] Added default clang-format configuration and user-customizable config support The places checked for a valid config are: - the sketch folder - the global data folder (behind preferences.txt) - the Arduino IDE app dir The default config is copied in the Arduino IDE app dir --- .../formatter/clangformat/ClangFormat.java | 20 ++- build/build.xml | 2 + build/shared/clang-format-arduino | 145 ++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 build/shared/clang-format-arduino diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index e0711e3d20a..85cd940566e 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -33,6 +33,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -43,6 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import processing.app.Base; +import processing.app.BaseNoGui; import processing.app.Editor; import processing.app.EditorTab; @@ -100,11 +102,27 @@ private Thread copyAndClose(InputStream input, OutputStream output) { return t; } + private File findConfigFile() { + // check if sketch has a config file + File sketchDir = editor.getSketch().getFolder(); + if (new File(sketchDir, ".clang-format").isFile()) { + return sketchDir; + } + + // check if a global config file exists + if (BaseNoGui.getSettingsFile(".clang-format").isFile()) { + return BaseNoGui.getSettingsFolder(); + } + + // otherwise: no custom configs, return Arduino IDE app dir. + return new File(clangExecutable).getParentFile(); + } + FormatResult runClangFormatOn(String source, int cursorOffset) throws IOException, InterruptedException, ClangException { String cmd[] = new String[] { clangExecutable, "--cursor=" + cursorOffset }; - Process process = ProcessUtils.exec(cmd); + Process process = Runtime.getRuntime().exec(cmd, null, findConfigFile()); ByteArrayOutputStream clangOutput = new ByteArrayOutputStream(); ByteArrayOutputStream clangError = new ByteArrayOutputStream(); ByteArrayInputStream dataOut = new ByteArrayInputStream(source.getBytes()); diff --git a/build/build.xml b/build/build.xml index 3c1bf7cb614..71810ed8b1f 100644 --- a/build/build.xml +++ b/build/build.xml @@ -345,6 +345,8 @@ + + diff --git a/build/shared/clang-format-arduino b/build/shared/clang-format-arduino new file mode 100644 index 00000000000..f95490cfdf4 --- /dev/null +++ b/build/shared/clang-format-arduino @@ -0,0 +1,145 @@ +# See: https://releases.llvm.org/11.0.1/tools/clang/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +# LLVM is the default style setting, used when a configuration option is not set here +BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: Empty +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: No +BinPackArguments: true +BinPackParameters: true +# Only used when "BreakBeforeBraces" set to "Custom" +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + #AfterObjCDeclaration: + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +# Java-specific +#BreakAfterJavaFieldAnnotations: +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +ColumnLimit: 0 +# "" matches none +CommentPragmas: "" +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +# Docs say "Do not use this in config files". The default (LLVM 11.0.1) is "false". +#ExperimentalAutoDetectBinPacking: +FixNamespaceComments: false +ForEachMacros: [] +IncludeBlocks: Preserve +IncludeCategories: [] +# "" matches none +IncludeIsMainRegex: "" +IncludeIsMainSourceRegex: "" +IndentCaseBlocks: true +IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +# Java-specific +#JavaImportGroups: +# JavaScript-specific +#JavaScriptQuotes: +#JavaScriptWrapImports +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: "" +MacroBlockEnd: "" +# Set to a large number to effectively disable +MaxEmptyLinesToKeep: 100000 +NamespaceIndentation: None +NamespaceMacros: [] +# Objective C-specific +#ObjCBinPackProtocolList: +#ObjCBlockIndentWidth: +#ObjCBreakBeforeNestedBlockParam: +#ObjCSpaceAfterProperty: +#ObjCSpaceBeforeProtocolList +PenaltyBreakAssignment: 1 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 1 +PenaltyBreakFirstLessLess: 1 +PenaltyBreakString: 1 +PenaltyBreakTemplateDeclaration: 1 +PenaltyExcessCharacter: 1 +PenaltyReturnTypeOnItsOwnLine: 1 +# Used as a fallback if alignment style can't be detected from code (DerivePointerAlignment: true) +PointerAlignment: Right +RawStringFormats: [] +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +StatementMacros: [] +TabWidth: 2 +TypenameMacros: [] +# Default to LF if line endings can't be detected from the content (DeriveLineEnding). +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: [] From 09c662651380b2af70bd9db8be16d2a192c480e1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 21 May 2021 12:16:24 +0200 Subject: [PATCH 11/12] Autoformat keeps cursor position after Undo --- .../formatter/clangformat/ClangFormat.java | 18 ++++++++++++++---- .../AutoformatProducesOneUndoActionTest.java | 3 ++- .../app/AutoformatSavesCaretPositionTest.java | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java index 85cd940566e..d4a69b6480b 100644 --- a/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java +++ b/app/src/cc/arduino/packages/formatter/clangformat/ClangFormat.java @@ -46,7 +46,7 @@ import processing.app.Base; import processing.app.BaseNoGui; import processing.app.Editor; -import processing.app.EditorTab; +import processing.app.syntax.SketchTextArea; public class ClangFormat implements Runnable { @@ -60,17 +60,27 @@ public ClangFormat(Editor editor) { @Override public void run() { - EditorTab tab = editor.getCurrentTab(); + SketchTextArea tab = editor.getCurrentTab().getTextArea(); String originalText = tab.getText(); - int cursorOffset = tab.getTextArea().getCaretPosition(); + int cursorOffset = tab.getCaretPosition(); try { FormatResult result = runClangFormatOn(originalText, cursorOffset); if (result.FormattedText.equals(originalText)) { editor.statusNotice(tr("No changes necessary for Auto Format.")); return; } + + // To keep cursor position after UNDO we produce a bogus edit (insertion + // and removal of a " " at cursor position) and we compound this change + // with the full auto-format update. + tab.beginAtomicEdit(); + tab.insert(" ", cursorOffset); + tab.replaceRange("", cursorOffset, cursorOffset + 1); tab.setText(result.FormattedText); - tab.getTextArea().setCaretPosition(result.Cursor); + tab.endAtomicEdit(); + + tab.setCaretPosition(result.Cursor); + editor.statusNotice(tr("Auto Format finished.")); } catch (IOException | InterruptedException e) { editor.statusError("Auto format error: " + e.getMessage()); diff --git a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java index 33314b4a197..df7cbc0878c 100644 --- a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java +++ b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java @@ -74,7 +74,8 @@ public void shouldSaveCaretPositionAfterAutoformat() { String formattedText = editor.getText(); assertEquals(SOURCE_AFTER, formattedText); - assertEquals(29, editor.getCaretPosition()); + // Autoformat with clang-format keeps cursor relative to source code + assertEquals(17, editor.getCaretPosition()); menuEditUndo.requireEnabled(); menuEditUndo.click(); diff --git a/app/test/processing/app/AutoformatSavesCaretPositionTest.java b/app/test/processing/app/AutoformatSavesCaretPositionTest.java index fb311707d53..1a3aeb1f96f 100644 --- a/app/test/processing/app/AutoformatSavesCaretPositionTest.java +++ b/app/test/processing/app/AutoformatSavesCaretPositionTest.java @@ -68,7 +68,8 @@ public void shouldSaveCaretPositionAfterAutoformat() { "\n" + "}", formattedText); - assertEquals(29, editor.getCaretPosition()); + // Autoformat with clang-format keeps cursor relative to source code + assertEquals(17, editor.getCaretPosition()); } From 7754b7fc8a127b46ee099fbea8e8a71b70d3486d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 19 May 2021 18:08:47 +0200 Subject: [PATCH 12/12] Fixed tests for new autoformat style --- .../processing/app/AutoformatProducesOneUndoActionTest.java | 2 -- app/test/processing/app/AutoformatSavesCaretPositionTest.java | 2 -- app/test/processing/app/AutoformatTest.java | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java index df7cbc0878c..f24ec92eaff 100644 --- a/app/test/processing/app/AutoformatProducesOneUndoActionTest.java +++ b/app/test/processing/app/AutoformatProducesOneUndoActionTest.java @@ -48,12 +48,10 @@ public class AutoformatProducesOneUndoActionTest extends AbstractGUITest { "}"; public static final String SOURCE_AFTER = "void setup() {\n" + " // put your setup code here, to run once:\n" + - "\n" + "}\n" + "\n" + "void loop() {\n" + " // put your main code here, to run repeatedly:\n" + - "\n" + "}"; @Test diff --git a/app/test/processing/app/AutoformatSavesCaretPositionTest.java b/app/test/processing/app/AutoformatSavesCaretPositionTest.java index 1a3aeb1f96f..15dc977ce07 100644 --- a/app/test/processing/app/AutoformatSavesCaretPositionTest.java +++ b/app/test/processing/app/AutoformatSavesCaretPositionTest.java @@ -60,12 +60,10 @@ public void shouldSaveCaretPositionAfterAutoformat() { String formattedText = editor.getText(); assertEquals("void setup() {\n" + " // put your setup code here, to run once:\n" + - "\n" + "}\n" + "\n" + "void loop() {\n" + " // put your main code here, to run repeatedly:\n" + - "\n" + "}", formattedText); // Autoformat with clang-format keeps cursor relative to source code diff --git a/app/test/processing/app/AutoformatTest.java b/app/test/processing/app/AutoformatTest.java index 2b87b17571c..c8f0edc066f 100644 --- a/app/test/processing/app/AutoformatTest.java +++ b/app/test/processing/app/AutoformatTest.java @@ -58,8 +58,8 @@ public void shouldProduceNicelyFormattedCode() throws Exception { String formattedText = editor.getText(); assertEquals("void setup() {\n" + " // put your setup code here, to run once:\n" + - " int foo[] = { 1, 2, 3, 4, 5};\n" + - " int foo[2][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};\n" + + " int foo[] = { 1, 2, 3, 4, 5 };\n" + + " int foo[2][5] = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 } };\n" + "}\n" + "\n" + "void loop() {\n" +