1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-28 09:24:14 +01:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Ricardo JL Rufino
744145adfd
Merge 0918a5b0b4 into 3278173ef8 2024-11-28 04:19:11 +01:00
Varshini Shree
3278173ef8
Add note re: Arduino IDE 2.x repo to readme, format readme 2024-10-18 09:32:19 -07:00
Ricardo JL Rufino
0918a5b0b4 Avoid erros on format multi-line comments, add Tests 2020-05-21 17:19:49 -03:00
Ricardo JL Rufino
cf81fdcbee format selection using AStyle control tags 2020-05-20 19:55:11 -03:00
Ricardo JL Rufino
7efb118156 fix code formatting 2020-05-14 10:59:21 -03:00
Ricardo JL Rufino
2ba0124871 [editor] Allow formatting only the selection 2020-05-14 01:31:22 -03:00
5 changed files with 310 additions and 73 deletions

View File

@ -1,97 +1,59 @@
<p align="center">
<img src="http://content.arduino.cc/brand/arduino-color.svg" width="50%" />
<img src="http://content.arduino.cc/brand/arduino-color.svg" width="50%" />
</p>
Arduino is an open-source physical computing platform based on a simple I/O
board and a development environment that implements the Processing/Wiring
language. Arduino can be used to develop stand-alone interactive objects or
can be connected to software on your computer (e.g. Flash, Processing and MaxMSP).
The boards can be assembled by hand or purchased preassembled; the open-source
IDE can be downloaded for free at [https://arduino.cc](https://www.arduino.cc/en/Main/Software)
**Important Notice**: This repository contains the legacy Arduino IDE 1.x, which is no longer in active development. For the latest features and updates, please visit the [Arduino IDE 2.x](https://github.com/arduino/arduino-ide) repository. If you encounter issues related to the newer IDE, please report them there.
Arduino is an open-source physical computing platform based on a simple I/O board and a development environment that implements the Processing/Wiring language. Arduino can be used to develop stand-alone interactive objects or can be connected to software on your computer (e.g. Flash, Processing and MaxMSP). The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free at [https://arduino.cc](https://www.arduino.cc/en/Main/Software).
![Github](https://img.shields.io/github/v/release/arduino/Arduino)
## More info at
- [Our website](https://www.arduino.cc/)
- [The forums](https://forum.arduino.cc/)
- Follow us on [Twitter](https://twitter.com/arduino)
- And like us at [Facebook](https://www.facebook.com/official.arduino)
- [Our website](https://www.arduino.cc/)
- [The forums](https://forum.arduino.cc/)
- Follow us on [Twitter](https://twitter.com/arduino)
- And like us at [Facebook](https://www.facebook.com/official.arduino)
## Bug reports and technical discussions
- To report a *bug* in the software or to request *a simple enhancement* go to [Github Issues](https://github.com/arduino/Arduino/issues)
- More complex requests and technical discussion should go on the [Arduino Developers
mailing list](https://groups.google.com/a/arduino.cc/forum/#!forum/developers)
- If you're interested in modifying or extending the Arduino software, we strongly
suggest discussing your ideas on the
[Developers mailing list](https://groups.google.com/a/arduino.cc/forum/#!forum/developers)
*before* starting to work on them.
That way you can coordinate with the Arduino Team and others,
giving your work a higher chance of being integrated into the official release
- To report a *bug* in the software or to request *a simple enhancement*, go to [Github Issues](https://github.com/arduino/Arduino/issues).
- More complex requests and technical discussions should go on the [Arduino Developers mailing list](https://groups.google.com/a/arduino.cc/forum/#!forum/developers).
- If you're interested in modifying or extending the Arduino software, we strongly suggest discussing your ideas on the [Developers mailing list](https://groups.google.com/a/arduino.cc/forum/#!forum/developers) *before* starting to work on them. That way you can coordinate with the Arduino Team and others, giving your work a higher chance of being integrated into the official release.
### Security
If you think you found a vulnerability or other security-related bug in this project, please read our
[security policy](https://github.com/arduino/Arduino/security/policy) and report the bug to our Security Team 🛡️
Thank you!
If you think you found a vulnerability or other security-related bug in this project, please read our [security policy](https://github.com/arduino/Arduino/security/policy) and report the bug to our Security Team 🛡️. Thank you!
e-mail contact: security@arduino.cc
## Installation
Detailed instructions for installation in popular operating systems can be found at:
Detailed instructions for installation on popular operating systems can be found at:
- [Linux](https://www.arduino.cc/en/Guide/Linux) (see also the [Arduino playground](https://playground.arduino.cc/Learning/Linux))
- [macOS](https://www.arduino.cc/en/Guide/macOS)
- [Windows](https://www.arduino.cc/en/Guide/Windows)
- [Linux](https://www.arduino.cc/en/Guide/Linux) (see also the [Arduino playground](https://playground.arduino.cc/Learning/Linux))
- [macOS](https://www.arduino.cc/en/Guide/macOS)
- [Windows](https://www.arduino.cc/en/Guide/Windows)
## Contents of this repository
This repository contains just the code for the Arduino IDE itself.
Originally, it also contained the AVR and SAM Arduino core and libraries
(i.e. the code that is compiled as part of a sketch and runs on the
actual Arduino device), but those have been moved into their own
repositories. They are still automatically downloaded as part of the
build process and included in built releases, though.
This repository contains just the code for the Arduino IDE itself. Originally, it also contained the AVR and SAM Arduino core and libraries (i.e. the code that is compiled as part of a sketch and runs on the actual Arduino device), but those have been moved into their own repositories. They are still automatically downloaded as part of the build process and included in built releases, though.
The repositories for these extra parts can be found here:
- Non-core specific Libraries are listed under: <https://github.com/arduino-libraries/>
(and also a few other places, see `build/build.xml`).
- The AVR core can be found at: <https://github.com/arduino/ArduinoCore-avr>
- Other cores are not included by default but installed through the
board manager. Their repositories can also be found under
<https://github.com/arduino/>.
- Non-core specific Libraries are listed under: [Arduino Libraries](https://github.com/arduino-libraries/) (and also a few other places, see `build/build.xml`).
- The AVR core can be found at: [ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr).
- Other cores are not included by default but can be installed through the board manager. Their repositories can also be found under [Arduino GitHub organization](https://github.com/arduino/).
## Building and testing
Instructions for building the IDE and running unit tests can be found on
the wiki:
- <https://github.com/arduino/Arduino/wiki/Building-Arduino>
- <https://github.com/arduino/Arduino/wiki/Testing-Arduino>
Instructions for building the IDE and running unit tests can be found on the wiki:
- [Building Arduino](https://github.com/arduino/Arduino/wiki/Building-Arduino)
- [Testing Arduino](https://github.com/arduino/Arduino/wiki/Testing-Arduino)
## Credits
Arduino is an open source project, supported by many.
Arduino is an open-source project, supported by many. The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe, and David A. Mellis.
The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe
and David A. Mellis.
Arduino uses
[GNU avr-gcc toolchain](https://gcc.gnu.org/wiki/avr-gcc),
[GCC ARM Embedded toolchain](https://launchpad.net/gcc-arm-embedded),
[avr-libc](https://www.nongnu.org/avr-libc/),
[avrdude](https://www.nongnu.org/avrdude/),
[bossac](http://www.shumatech.com/web/products/bossa),
[openOCD](http://openocd.org/)
and code from [Processing](https://www.processing.org)
and [Wiring](http://wiring.org.co).
Icon and about image designed by [ToDo](https://www.todo.to.it/)
Arduino uses [GNU avr-gcc toolchain](https://gcc.gnu.org/wiki/avr-gcc), [GCC ARM Embedded toolchain](https://launchpad.net/gcc-arm-embedded), [avr-libc](https://www.nongnu.org/avr-libc/), [avrdude](https://www.nongnu.org/avrdude/), [bossac](http://www.shumatech.com/web/products/bossa), [openOCD](http://openocd.org/), and code from [Processing](https://www.processing.org) and [Wiring](http://wiring.org.co).
Icon and about image designed by [ToDo](https://www.todo.to.it/).

View File

@ -29,16 +29,21 @@
package cc.arduino.packages.formatter;
import static processing.app.I18n.tr;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.Editor;
import processing.app.helpers.FileUtils;
import processing.app.syntax.SketchTextArea;
import processing.app.tools.Tool;
import java.io.File;
import java.io.IOException;
import static processing.app.I18n.tr;
import java.util.regex.Pattern;
import javax.swing.text.BadLocationException;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.Token;
public class AStyle implements Tool {
@ -76,19 +81,99 @@ public class AStyle implements Tool {
@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;
SketchTextArea textArea = editor.getCurrentTab().getTextArea();
String originalText = textArea.getSelectedText();
// If no selection use all file
if (originalText == null || originalText.isEmpty()) {
String formattedText = aStyleInterface.AStyleMain(textArea.getText(), formatterConfiguration);
editor.getCurrentTab().setText(formattedText);
} else {
try {
// apply indentation control keywords.
String FORMAT_ON = "\n// *INDENT-ON* DYN\n";
String FORMAT_OFF = "\n// *INDENT-OFF* DYN\n";
RSyntaxDocument content = (RSyntaxDocument) textArea.getDocument();
textArea.beginAtomicEdit();
int selStart = editor.getCurrentTab().getSelectionStart();
int selEnd = editor.getCurrentTab().getSelectionStop();
int lineStart = textArea.getLineOfOffset(selStart);
int lineEnd = textArea.getLineOfOffset(selEnd);
// Calculate offsets from begin and end of each line.
int fristLineOffset = textArea.getLineStartOffset(lineStart);
int lastLineOffset = textArea.getLineEndOffset(lineEnd);
// Avoid multi-line comments
fristLineOffset = navigateOffComments(textArea, fristLineOffset); // try caech (invalid selection)
lastLineOffset = navigateOffComments(textArea, lastLineOffset); // try caech (invalid selection)
// inserts change the length, use this to calculate new positios.
int offLength = FORMAT_OFF.length();
int onLength = FORMAT_ON.length();
content.insertString(0, FORMAT_OFF, null);
content.insertString(fristLineOffset + offLength, FORMAT_ON, null);
content.insertString(lastLineOffset + offLength + onLength, FORMAT_OFF,null);
originalText = content.getText(0, content.getLength());
String formattedText = aStyleInterface.AStyleMain(originalText, formatterConfiguration);
// Remove format tags
formattedText = formattedText.replaceAll(Pattern.quote(FORMAT_OFF), "");
formattedText = formattedText.replaceAll(Pattern.quote(FORMAT_ON), "");
textArea.setText(formattedText);
textArea.select(selStart, selStart);
} catch (BadLocationException e) {
editor.statusNotice(tr("Auto Format Error") + ": " + e.getLocalizedMessage());
e.printStackTrace();
return;
} finally {
textArea.endAtomicEdit();
}
}
editor.getCurrentTab().setText(formattedText);
// mark as finished
editor.statusNotice(tr("Auto Format finished."));
}
private int navigateOffComments(SketchTextArea textArea, int offset) throws BadLocationException {
Token token = textArea.modelToToken(offset);
// if line is a multiline comment, go back !!
if (token != null && token.getType() == Token.COMMENT_MULTILINE) {
int lineStart = textArea.getLineOfOffset(offset);
token = textArea.getTokenListForLine(lineStart);
while (token.getType() == Token.COMMENT_MULTILINE) {
if (lineStart == 0)
break;
token = token.getNextToken();
if (token == null)
token = textArea.getTokenListForLine(--lineStart);
}
return token.getOffset();
} else {
return offset;
}
}
@Override
public String getMenuTitle() {

View File

@ -0,0 +1,174 @@
/*
* This file is part of Arduino.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*
* 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.
*/
package processing.app;
import org.fest.swing.fixture.JMenuItemFixture;
import org.junit.Test;
import processing.app.helpers.SketchTextAreaFixture;
import static org.junit.Assert.assertEquals;
public class AutoformatSelectionTest extends AbstractGUITest {
private static String orig = "/**\n" +
" *Docs..\n" +
" */\n" +
"void loop() {\n" +
" // LED ON\n" +
"digitalWrite(LED_BUILTIN, HIGH);\n" +
"if (true) {\n" +
" delay( 1000)\n" +
"};\n" +
" digitalWrite(LED_BUILTIN, LOW);\n" +
" if (true) {delay( 1000 )}; // <<< UGLY FORMATTING\n" +
"}";
@Test
public void testSuite() {
selectIfMultilineCorrectSel();
selectIfMultilineCorrectPartialSel();
selectIfMultilineDocs();
selectIfSinglelineDocs();
}
/**
* select all if block
*/
public void selectIfMultilineCorrectSel() {
String espected = "/**\n" +
" *Docs..\n" +
" */\n" +
"void loop() {\n" +
" // LED ON\n" +
"digitalWrite(LED_BUILTIN, HIGH);\n" +
" if (true) {\n" +
" delay( 1000)\n" +
" };\n" +
" digitalWrite(LED_BUILTIN, LOW);\n" +
" if (true) {delay( 1000 )}; // <<< UGLY FORMATTING\n" +
"}";
validateFormat(78, 109, orig, espected);
}
/**
* selection starts in if (|true) and goto '}'
* expected: format entry block
*/
public void selectIfMultilineCorrectPartialSel() {
String espected = "/**\n" +
" *Docs..\n" +
" */\n" +
"void loop() {\n" +
" // LED ON\n" +
"digitalWrite(LED_BUILTIN, HIGH);\n" +
" if (true) {\n" +
" delay( 1000)\n" +
" };\n" +
" digitalWrite(LED_BUILTIN, LOW);\n" +
" if (true) {delay( 1000 )}; // <<< UGLY FORMATTING\n" +
"}";
validateFormat(81, 109, orig, espected);
}
/**
* selection starts in multiple docs /** *\/
* expected: format entry block
*/
public void selectIfMultilineDocs() {
String espected = "/**\n" +
" Docs..\n" +
"*/\n" +
"void loop() {\n" +
" // LED ON\n" +
" digitalWrite(LED_BUILTIN, HIGH);\n" +
"if (true) {\n" +
" delay( 1000)\n" +
"};\n" +
" digitalWrite(LED_BUILTIN, LOW);\n" +
" if (true) {delay( 1000 )}; // <<< UGLY FORMATTING\n" +
"}";
validateFormat(9, 51, orig, espected);
}
/**
* selection starts in single line coment // LED |ON
* expected: format comment
*/
public void selectIfSinglelineDocs() {
String espected = "/**\n" +
" *Docs..\n" +
" */\n" +
"void loop() {\n" +
" // LED ON\n" +
" digitalWrite(LED_BUILTIN, HIGH);\n" +
"if (true) {\n" +
" delay( 1000)\n" +
"};\n" +
" digitalWrite(LED_BUILTIN, LOW);\n" +
" if (true) {delay( 1000 )}; // <<< UGLY FORMATTING\n" +
"}";
validateFormat(42, 56, orig, espected);
}
public SketchTextAreaFixture validateFormat(int selStart, int selEnd, String orig, String espected) {
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
menuToolsAutoFormat.requireEnabled();
SketchTextAreaFixture editor = window.textArea("editor");
editor.setText(orig);
editor.select(selStart, selEnd); // select frist if
menuToolsAutoFormat.click();
assertEquals(espected, editor.getText());
return editor;
}
}

View File

@ -81,6 +81,17 @@ public class SketchTextAreaComponentDriver extends JComponentDriver {
});
}
public SketchTextArea select(final SketchTextArea target, int selectionStart, int selectionEnd) {
return GuiActionRunner.execute(new GuiQuery<SketchTextArea>() {
protected SketchTextArea executeInEDT() {
target.select(selectionStart, selectionEnd);
return target;
}
});
}
public Integer getCaretPosition(final SketchTextArea target) {
focusAndWaitForFocusGain(target);

View File

@ -71,6 +71,11 @@ public class SketchTextAreaFixture extends ComponentFixture {
driver.selectAll((SketchTextArea) target);
return this;
}
public SketchTextAreaFixture select(int selectionStart, int selectionEnd) {
driver.select((SketchTextArea) target, selectionStart, selectionEnd);
return this;
}
public int getCaretPosition() {
return driver.getCaretPosition((SketchTextArea) target);