diff --git a/.gitignore b/.gitignore index e3b98dcf5f..c57a023c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -92,4 +92,7 @@ bin-test # VS Code Java project files .project -.vscode/ \ No newline at end of file +.vscode/ + +# ANTLR intermediate files +java/src/processing/mode/java/preproc/.antlr \ No newline at end of file diff --git a/app/build.xml b/app/build.xml index c48adeb02d..b8cec68c86 100644 --- a/app/build.xml +++ b/app/build.xml @@ -160,7 +160,9 @@ lib/ant-launcher.jar; lib/flatlaf.jar; lib/jna.jar; - lib/jna-platform.jar" + lib/jna-platform.jar; + lib/build-flexmark-all.jar; + lib/ST-4.3.4.jar" debug="on" nowarn="true"> diff --git a/app/lib/build-flexmark-all.jar b/app/lib/build-flexmark-all.jar new file mode 100644 index 0000000000..9e17821c0c Binary files /dev/null and b/app/lib/build-flexmark-all.jar differ diff --git a/app/src/processing/app/ui/EditorStatus.java b/app/src/processing/app/ui/EditorStatus.java index 02a85f10e1..348f27551d 100644 --- a/app/src/processing/app/ui/EditorStatus.java +++ b/app/src/processing/app/ui/EditorStatus.java @@ -35,15 +35,30 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.*; +import java.awt.BorderLayout; +import java.awt.Desktop; import javax.swing.*; import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; +import javax.swing.JScrollPane; +import javax.swing.event.*; +import javax.swing.border.Border; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.net.URI; + +import java.io.IOException; import processing.app.Platform; import processing.app.Preferences; import processing.core.PApplet; +import com.vladsch.flexmark.html.HtmlRenderer; +import com.vladsch.flexmark.parser.Parser; +import com.vladsch.flexmark.util.ast.Node; +import com.vladsch.flexmark.util.data.MutableDataSet; /** * Panel just below the editing area that contains status messages. @@ -68,6 +83,7 @@ public class EditorStatus extends BasicSplitPaneDivider { int mode; String message = ""; + String friendlyMessage = ""; int messageRight; String url; @@ -79,6 +95,8 @@ public class EditorStatus extends BasicSplitPaneDivider { static final int COLLAPSE_PRESSED = 4; static final int CLIPBOARD_ROLLOVER = 5; static final int CLIPBOARD_PRESSED = 6; + static final int MORE_INFO_ROLLOVER = 7; + static final int MORE_INFO_PRESSED = 8; int mouseState; Font font; @@ -91,6 +109,8 @@ public class EditorStatus extends BasicSplitPaneDivider { ImageIcon[] searchIcon; ImageIcon[] collapseIcon; ImageIcon[] expandIcon; + ImageIcon[] moreInfoIcon; + float btnEnabledAlpha; float btnRolloverAlpha; @@ -108,7 +128,121 @@ public class EditorStatus extends BasicSplitPaneDivider { boolean indeterminate; Thread thread; + /** + * The friendly instance variable that determines whether a given error passed in is friendly (has additional information to be shown in a popup). + */ + public boolean friendly = false; + + + /* + * Popup that shows additional info about the error message that shows up in the status bar. + */ + + public class FriendlyErrorPopup{ + + private JFrame popupFrame; + final int PROCESSING_SAYS_OFFSET = 6; + + private String markdownToHtml(String target) { + MutableDataSet options = new MutableDataSet(); + Parser parser = Parser.builder(options).build(); + HtmlRenderer renderer = HtmlRenderer.builder(options).build(); + Node document = parser.parse(target); + String html = renderer.render(document); + html = "

πŸ”΅Processing says:" + html + "
" ; + return html; + } + + /** + * Constructor for FriendlyErrorPopup class. + * @param messageText a String containing the full message to be simplified. + */ + public FriendlyErrorPopup(String messageText){ + + int firstLineIndex = messageText.indexOf("
"); + int lineCounter = 0; + int newLineCount = 0; + + String firstSentence = messageText.substring(0,firstLineIndex); + String pureText = messageText; + + Pattern newLineCounter = Pattern.compile("
"); + Pattern linkSkipper = Pattern.compile("\\[([^\\]]+)\\]\\([^\\)]+\\)"); + Matcher newLineMatcher = newLineCounter.matcher(pureText); + Matcher linkSkipperMatcher = linkSkipper.matcher(pureText); + + // allows for error messages with markdown links in the first line although there currently are none + while (linkSkipperMatcher.find()){ + pureText = pureText.replace(linkSkipperMatcher.group(0),linkSkipperMatcher.group(1)); + } + + firstSentence = pureText.substring(0,pureText.indexOf("
")); + firstLineIndex = firstSentence.length(); + + int index = 0; + + while (index < pureText.length()) { + lineCounter++; + int nextBreakIndex = pureText.indexOf("
", index); + index = (((nextBreakIndex - index) <= firstLineIndex) && nextBreakIndex != -1) ? nextBreakIndex + 4 : index + firstLineIndex; + } + + pureText = pureText.replaceAll("
",""); + messageText = markdownToHtml(messageText); + + JEditorPane errorPane = new JEditorPane(); + errorPane.setContentType("text/html"); + + JScrollPane scrollPane = new JScrollPane(errorPane); + + errorPane.setFont(new Font("Source Code PRO", Font.PLAIN, 13)); //not actually necessary but it allows the window resizing to work + errorPane.setText(messageText); + errorPane.setBackground(Color.decode("#fafcff")); + errorPane.setEditable(false); + + java.awt.FontMetrics fontMetrics = errorPane.getFontMetrics(errorPane.getFont()); + + int popupWidth = fontMetrics.stringWidth(firstSentence) - 25; + int popupHeight = (lineCounter + PROCESSING_SAYS_OFFSET) * fontMetrics.getHeight(); + + errorPane.addHyperlinkListener((event) -> { + HyperlinkEvent.EventType eventType = event.getEventType(); + boolean linkClicked = eventType == HyperlinkEvent.EventType.ACTIVATED; + if (linkClicked) { + String url = event.getURL().toString(); + URI targetUri = URI.create(url); + try { + Desktop.getDesktop().browse(targetUri); + } + catch(IOException e) { + } + } + }); + + JFrame frame = new JFrame("Error Details"); + + Border paddingBorder = BorderFactory.createEmptyBorder(0, 20, 0, 0); + Border border = BorderFactory.createLineBorder(java.awt.Color.decode("#58a2d1"), 10); + Border compoundBorder = BorderFactory.createCompoundBorder(border, paddingBorder); + + errorPane.setBorder(compoundBorder); + scrollPane.setBorder(null); + frame.setSize(popupWidth, popupHeight); + + JPanel containerPanel = new JPanel(new BorderLayout()); + containerPanel.add(scrollPane, BorderLayout.CENTER); + frame.setContentPane(containerPanel); + frame.setVisible(true); + } + } + /** + * A constructor for the EditorStatus class. It interacts with the BasicSplitPaneUI and Editor objects + * to handle mouse events for opening URLs, copying text to the clipboard, and toggling collapse. + * + * @param ui an instance of the BasicSplitPaneUI class. + * @param editor the editor panel associated with this status. + */ public EditorStatus(BasicSplitPaneUI ui, Editor editor) { super(ui); this.editor = editor; @@ -222,18 +356,26 @@ void updateMouse(MouseEvent e, boolean pressed) { } else if (url != null && mouseX > LEFT_MARGIN && mouseX < messageRight) { mouseState = pressed ? URL_PRESSED : URL_ROLLOVER; } + else if (mouseX > sizeW - (buttonEach * 3) && mouseX < sizeW - (2 * buttonEach)) { + mouseState = pressed ? MORE_INFO_PRESSED : MORE_INFO_ROLLOVER; + } } } // only change on the rollover, no need to update on press switch (mouseState) { case CLIPBOARD_ROLLOVER: + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + break; case URL_ROLLOVER: setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); break; case COLLAPSE_ROLLOVER: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); break; + case MORE_INFO_ROLLOVER: + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + break; case NONE: setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); break; @@ -250,7 +392,6 @@ static String findURL(String message) { return null; } - protected void updateTheme() { urlEnabledAlpha = 255 * Theme.getInteger("status.url.enabled.alpha") / 100; urlRolloverAlpha = 255 * Theme.getInteger("status.url.rollover.alpha") / 100; @@ -268,6 +409,8 @@ protected void updateTheme() { searchIcon = renderIcons("status/search", stateColors); collapseIcon = renderIcons("status/console-collapse", stateColors); expandIcon = renderIcons("status/console-expand", stateColors); + moreInfoIcon = renderIcons("status/more-info", stateColors); + btnEnabledAlpha = Theme.getInteger("status.button.enabled.alpha") / 100f; btnRolloverAlpha = Theme.getInteger("status.button.rollover.alpha") / 100f; @@ -310,12 +453,23 @@ public void empty() { repaint(); } - - public void message(String message, int mode) { - this.message = message; + /** + * The message method updates the message and mode instance variables and determines whether the error message being passed in is friendly or not. + * @param message the error message being passed in. + * @param mode represents whether the message is friendly or not. + */ + public void message(String message, int mode) { + + String newMessage = message; + int indexOfNewLine = message.indexOf("
"); + if (indexOfNewLine != -1) { + this.friendly = true; + this.friendlyMessage = message; + newMessage = message.substring(0,indexOfNewLine); + } + this.message = newMessage; this.mode = mode; - - url = findURL(message); + url = findURL(newMessage); repaint(); } @@ -449,9 +603,24 @@ public void paint(Graphics g) { alpha = btnEnabledAlpha; } drawButton(g, 0, glyph, alpha); + + // draw more info button + if (friendly) { + ImageIcon glyph2; + glyph2 = moreInfoIcon[mode]; + if (mouseState == MORE_INFO_ROLLOVER) { + alpha = btnRolloverAlpha; + } else if (mouseState == MORE_INFO_PRESSED) { + alpha = btnPressedAlpha; + FriendlyErrorPopup friendlyPopup = new FriendlyErrorPopup(friendlyMessage); + } + else { + alpha = btnEnabledAlpha; + } + drawButton(g,2,moreInfoIcon[mode],alpha); + } } - /** * @param pos A zero-based button index with 0 as the rightmost button */ diff --git a/build/build.xml b/build/build.xml index b20fa8357d..4035f6b0c0 100644 --- a/build/build.xml +++ b/build/build.xml @@ -186,6 +186,8 @@ + + @@ -534,6 +536,9 @@ + + + @@ -1636,4 +1641,4 @@ - + \ No newline at end of file diff --git a/build/shared/lib/languages/PDE.properties b/build/shared/lib/languages/PDE.properties index fb2042f225..01a931b024 100644 --- a/build/shared/lib/languages/PDE.properties +++ b/build/shared/lib/languages/PDE.properties @@ -390,19 +390,21 @@ editor.status.archiver.cancel = Archive sketch canceled. # Errors editor.status.warning = Warning editor.status.error = Error -editor.status.error.syntax = Syntax Error - %s +editor.status.error.syntax = Syntax Error - $statement$ +editor.status.error.syntaxdefault = Issue near $statement$ editor.status.error_on = Error on β€œ%s” -editor.status.missing.default = Missing β€œ%c” +editor.status.missing.default = Missing β€œ$character$” + editor.status.missing.semicolon = Missing a semicolon β€œ;” editor.status.missing.left_sq_bracket = Missing left square bracket β€œ[” editor.status.missing.right_sq_bracket = Missing right square bracket β€œ]” editor.status.missing.left_paren = Missing left parenthesis β€œ(” editor.status.missing.right_paren = Missing right parenthesis β€œ)” -editor.status.missing.left_curly_bracket = Missing left curly bracket β€œ{” -editor.status.missing.right_curly_bracket = Missing right curly bracket β€œ}” +editor.status.missing.left_curly_bracket = It looks like there is a missing left curly bracket β€˜{β€˜ somewhere near line β€˜$linenumber$’.

Hint:
[Curly brackets](https://processing.org/reference/curlybraces.html) are used to group lines of code that should be executed together. These groups are often known as code blocks. It may be helpful to think of a code block as a set of instructions that Processing follows in the order that they are written. If a left curly bracket is missing, Processing doesn’t know where the code block begins.

Suggestion:
Try adding the missing left curly bracket before $statement$. Double check that you are adding it before the first line of code that you want to include in the code block.

For more:
[Variable Scope Example](https://processing.org/examples/variablescope.html)
[Methods / Functions Example](https://processing.org/examples/functions.html) +editor.status.missing.right_curly_bracket = It looks like there is a missing right curly bracket β€˜}β€˜ somewhere near line β€˜$linenumber$’.

Hint:
[Curly bracket](https://processing.org/reference/curlybraces.html) are used to group lines of code that should be executed together. These groups are often known as code blocks. It may be helpful to think of a code block as a set of instructions that Processing follows in the order that they are written. If a right curly bracket is missing, Processing doesn’t know where the code block ends.

Suggestion:
Try adding the missing right curly bracket after $statement$. Double check that you are adding it after the last line of code that you want to include in the code block.

For more:
[Variable Scope Example](https://processing.org/examples/variablescope.html)
[Methods / Functions Example](https://processing.org/examples/functions.html) editor.status.missing.add = Consider adding β€œ%s” editor.status.bad_curly_quote = Curly quotes like %s don’t work. Use straight quotes. Ctrl-T to autocorrect. -editor.status.reserved_words = β€œcolor” and β€œint” are reserved words & cannot be used as variable names +editor.status.reserved_words = β€œ%s” and β€œ%s” are reserved words & cannot be used as variable names editor.status.undefined_method = The function β€œ%s(%s)” does not exist editor.status.undefined_constructor = The constructor β€œ%s(%s)” does not exist editor.status.empty_param = The function β€œ%s()” does not expect any parameters @@ -411,23 +413,27 @@ editor.status.undef_global_var = The global variable β€œ%s” does not exist editor.status.undef_class = The class β€œ%s” does not exist editor.status.undef_var = The variable β€œ%s” does not exist editor.status.undef_name = The name β€œ%s” cannot be recognized -editor.status.unterm_string_curly = String literal is not closed by a straight double quote. Curly quotes like %s won’t help. +editor.status.unterm_string_curly = String literal is not closed by a straight double quote. Curly quotes like $statement$ won’t help. editor.status.type_mismatch = Type mismatch, β€œ%s” does not match with β€œ%s” editor.status.unused_variable = The value of the local variable β€œ%s” is not used editor.status.uninitialized_variable = The local variable β€œ%s” may not have been initialized editor.status.no_effect_assignment = The assignment to variable β€œ%s” has no effect editor.status.hiding_enclosing_type = The class β€œ%s” cannot have the same name as your sketch or its enclosing class -editor.status.bad.assignment = Possible error on variable assignment near β€˜%s’? -editor.status.bad.generic = Possibly missing type in generic near β€˜%s’? -editor.status.bad.identifier = Bad identifier? Did you forget a variable or start an identifier with digits near β€˜%s’? -editor.status.bad.parameter = Error on parameter or method declaration near β€˜%s’? +editor.status.bad.assignment = There seems to be some trouble with how a variable is being assigned near line $linenumber$!

Hint:
There is an issue with how a variable is being set to a certain value. This is also known as variable [assignment](https://processing.org/reference/assign.html). We suspect that the problem is near β€˜$statement$’.

Suggestion:
It’s important to double check that the variable is named properly (see the variable example below) and that you have included all of the necessary parts of a variable assignment. You should also make sure that you chose an appropriate [datatype](https://processing.org/reference/#data) for your variable so that it can hold the value that you are assigning to it.

Example:To assign variables you need the type, name, assignment operator (=), the value you want to assign the variable to and a semicolon. Here’s the basic format:
[data type] [name] = [value];
Example:
int num = 4;

For more: [Variable Example](https://processing.org/examples/variables.html) +editor.status.bad.generic = It looks like something (a generic) was not given a type to hold near line $linenumber$ near $statement$.

Hint:
When we're working with things like lists or arrays in Processing, you need to tell it what type of data it will hold. It seems like you forgot to specify the type of data you're using somewhere near line$linenumber$.

Suggestion:
The syntax for informing Processing about the intended data type of a data structure involves the use of angle brackets ('<>') referred to as generics. Typically, these angle brackets are placed after the name of the data structure.

Example:
If you want to store integers in a list, you would declare it like this: List myList = new ArrayList();

For More: [Example of Data Structure ArrayList that Uses Generics](https://processing.org/examples/arraylistclass.html) +editor.status.bad.identifier = There is an issue with how something in the code was named near line $linenumber$.

Hint:
It’s likely that $statement$ is not a valid name. In Processing, identifiers (names of variables, methods, classes, etc.) cannot start with a number and should only include letters, numbers, dollar signs ($) or underscores (_).

Suggestion:
Double check that your name starts with a letter, dollar sign or an underscore and that the name is not a keyword that is part of the language like "true", β€œclass” or β€œsetup”.

For more:
[Variable Examples](https://processing.org/examples/variables.html)
[Function Examples](https://processing.org/examples/functions.html) +editor.status.bad.parameter = It looks like the wrong type of parameter was given to a method near line $linenumber$.

Hint:
This likely means that a variable of the wrong [type](https://processing.org/reference/#data) was given to the method near β€˜$statement$’.

Suggestion:Make sure that the data type that the method is expecting is the one that is being passed in.

Example:
β€˜int count(int num){
return num;}
The above method β€œcount” accepts an [integer](https://processing.org/reference/int.html) as a parameter. This means it is expecting an integer to be given to count to use in the code that it runs. If instead of getting an integer, it getsa [String](https://processing.org/reference/String.html):
β€˜count(β€œone”);’
Then the method cannot run properly.

For more: [Methods / Functions Example](https://processing.org/examples/functions.html) editor.status.bad.import = Import not allowed here. editor.status.bad.mixed_mode = You may be mixing active and static modes. -editor.status.extraneous = Incomplete statement or extra code near β€˜%s’? -editor.status.mismatched = Missing operator, semicolon, or β€˜}’ near β€˜%s’? -editor.status.missing.name = Missing name or ; near β€˜%s’? -editor.status.missing.type = Missing name or ; or type near β€˜%s’? +editor.status.extraneous = Incomplete statement or extra code near β€˜$statement$’? +editor.status.mismatched = Missing operator, semicolon, or β€˜}’ near β€˜$statement$’? + +# turn into 3 separate error codes for MissingIdentifierSimplifierStrategy, MissingClassNameStrategy & MethodMissingNameStrategy +editor.status.missing.name = Missing name or ; near β€˜$statement$’? + + +editor.status.missing.type = There seems to be some trouble with how a variable is being declared near line $linenumber$!

Hint:
Somewhere along the line there is an issue with how a variable is being created (also known as being declared). We suspect that the problem is near β€˜$statement$’.

Suggestion:
It’s important to double check that the variable is named properly (see the variable example below) and that you have included all of the necessary parts of a variable declaration. It is also possible that you forgot a [semicolon(https://processing.org/reference/semicolon.html).

Example:To declare variables you need the type, name and a semicolon. Here’s the basic format:
Β [data type] [name] = [value];
Example:
int num;

For more: [Variable Example](https://processing.org/examples/variables.html) # Footer buttons diff --git a/build/shared/lib/status/more-info.svg b/build/shared/lib/status/more-info.svg new file mode 100644 index 0000000000..7cc930afbe --- /dev/null +++ b/build/shared/lib/status/more-info.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/build/windows/processing.bat b/build/windows/processing.bat index ab0a36bf27..9be6afff0f 100755 --- a/build/windows/processing.bat +++ b/build/windows/processing.bat @@ -1,3 +1,3 @@ @echo off -.\java\bin\java -cp lib\pde.jar;core\library\core.jar;lib\jna.jar;lib\jna-platform.jar;lib\antlr-4.7.2-complete.jar;lib\ant.jar;lib\ant-launcher.jar processing.app.Base +.\java\bin\java -cp lib\pde.jar;core\library\core.jar;lib\jna.jar;lib\jna-platform.jar;lib\antlr-4.7.2-complete.jar;\ant.jar;lib\ant-launcher.jar processing.app.Base diff --git a/java/.classpath b/java/.classpath index 5607a9971a..2c49d43a85 100644 --- a/java/.classpath +++ b/java/.classpath @@ -10,6 +10,7 @@ + @@ -24,6 +25,7 @@ + diff --git a/java/build.xml b/java/build.xml index ca2e32f4fb..c1705a65c0 100644 --- a/java/build.xml +++ b/java/build.xml @@ -97,6 +97,9 @@ + + + @@ -116,6 +119,7 @@ + diff --git a/java/processing4-java.iml b/java/processing4-java.iml index 953c28d4d5..4a93141a1c 100644 --- a/java/processing4-java.iml +++ b/java/processing4-java.iml @@ -16,6 +16,7 @@ + diff --git a/java/src/processing/mode/java/debug/VariableNode.java b/java/src/processing/mode/java/debug/VariableNode.java index a7018ff149..c93cd9529c 100644 --- a/java/src/processing/mode/java/debug/VariableNode.java +++ b/java/src/processing/mode/java/debug/VariableNode.java @@ -54,9 +54,9 @@ public class VariableNode implements MutableTreeNode { public static final int TYPE_BYTE = 9; public static final int TYPE_SHORT = 10; public static final int TYPE_VOID = 11; - + private static final Pattern ARRAY_REGEX = Pattern.compile("^(?[^\\[]+)(?(\\[\\])+)(?(\\[\\d+\\])+)(?[^\\[]*)$"); - + protected String type; protected String name; protected Value value; diff --git a/java/src/processing/mode/java/preproc/PdeIssueEmitter.java b/java/src/processing/mode/java/preproc/PdeIssueEmitter.java index 7e5b48c5aa..175bbd0c29 100644 --- a/java/src/processing/mode/java/preproc/PdeIssueEmitter.java +++ b/java/src/processing/mode/java/preproc/PdeIssueEmitter.java @@ -77,7 +77,7 @@ public void syntaxError(Recognizer recognizer, Object offendingSymbol, int int charPositionInLine, String msg, RecognitionException e) { PreprocessIssueMessageSimplifier facade = PreprocessIssueMessageSimplifier.get(); - IssueMessageSimplification simplification = facade.simplify(msg); + IssueMessageSimplification simplification = facade.simplify(msg, line); IssueLocation issueLocation; diff --git a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java index 74c9f14962..655b1cff56 100644 --- a/java/src/processing/mode/java/preproc/PdeParseTreeListener.java +++ b/java/src/processing/mode/java/preproc/PdeParseTreeListener.java @@ -1214,6 +1214,7 @@ protected void writeExtraFieldsAndMethods(PrintWriterWithEditGen classBodyWriter } String newCode = String.format(settingsOuterTemplate, settingsInner.toString()); + System.out.println("newCode: " + newCode); classBodyWriter.addEmptyLine(); classBodyWriter.addCodeLine(newCode); diff --git a/java/src/processing/mode/java/preproc/PreprocessIssueMessageSimplifier.java b/java/src/processing/mode/java/preproc/PreprocessIssueMessageSimplifier.java index 4e112d161d..2137d68ed6 100644 --- a/java/src/processing/mode/java/preproc/PreprocessIssueMessageSimplifier.java +++ b/java/src/processing/mode/java/preproc/PreprocessIssueMessageSimplifier.java @@ -31,6 +31,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.stringtemplate.v4.*; + /** * Utility class that generates localized error messages for incorrect sketch syntax. @@ -84,23 +86,28 @@ public static String getLocalStr(String stringName) { if (Platform.isAvailable()) { errStr = Language.text("editor.status.error.syntax"); retStr = Language.text(stringName); + } else { errStr = DefaultErrorLocalStrSet.get().get("editor.status.error.syntax").orElse("Error"); retStr = DefaultErrorLocalStrSet.get().get(stringName).orElse(stringName); } - return String.format(errStr, retStr); + ST messageTemplate = new ST (errStr, '$', '$'); + messageTemplate.add("statement", retStr); + + return messageTemplate.render(); } /** * Attempt to improve an error message. * * @param originalMessage Error message generated from ANTLR. + * @param line The line number associated to the error. * @return An improved error message or the originalMessage if no improvements could be made. */ - public PdeIssueEmitter.IssueMessageSimplification simplify(String originalMessage) { + public PdeIssueEmitter.IssueMessageSimplification simplify(String originalMessage, int line) { Optional matching = strategies.stream() - .map((x) -> x.simplify(originalMessage)) + .map((x) -> x.simplify(originalMessage, line)) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); @@ -195,8 +202,11 @@ private static String getOffendingArea(String area, boolean removeNewline) { * @return Semi-localized message. */ private static String getLocalizedGenericError(String unlocalized) { - String template = getLocalStr("editor.status.error_on"); - return String.format(template, unlocalized); + + ST messageTemplate = new ST(getLocalStr("editor.status.error_on"), '$', '$'); + messageTemplate.add("statement", unlocalized); + + return messageTemplate.render(); } /* ================================== @@ -213,10 +223,11 @@ protected interface PreprocIssueMessageSimplifierStrategy { * Attempt to simplify an error message. * * @param message The message to be simplified. + * @param line The line number associated with the error message. * @return An optional with an improved message or an empty optional if no improvements could be * made by this strategy. */ - Optional simplify(String message); + Optional simplify(String message, int line); } @@ -265,8 +276,15 @@ protected EvenCountTemplateMessageSimplifierStrategy(String newToken, String new filter = Optional.of(newFilter); } + + /** + * Simplifies a message based on a given String input and line number. + * @param message the message generated by ANTLR + * @param line the line number the error occured on + * @return returns an optional object containing an instance of PdeIssueEmitter.IssueMessageSimplification or an empty value. + */ @Override - public Optional simplify(String message) { + public Optional simplify(String message, int line) { String messageContent = getOffendingArea(message); if (filter.isPresent()) { @@ -278,12 +296,11 @@ public Optional simplify(String mess if (count % 2 == 0) { return Optional.empty(); } else { - String newMessage = String.format( - getLocalStr("editor.status.missing.default").replace("%c", "%s"), - token - ); + + ST messageTemplate = new ST (getLocalStr("editor.status.missing.default"), '$', '$'); + messageTemplate.add("character",token); return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render()) ); } } @@ -339,7 +356,7 @@ public TokenPairTemplateMessageSimplifierStrategy(String newToken1, String newTo } @Override - public Optional simplify(String message) { + public Optional simplify(String message, int line) { String messageContent = getOffendingArea(message); int count1 = SourceUtil.getCount(messageContent, token1); @@ -356,12 +373,11 @@ public Optional simplify(String mess missingToken = token2; } - String newMessage = String.format( - getLocalStr("editor.status.missing.default") - .replace("%c", "%s"), missingToken); - + ST messageTemplate = new ST (getLocalStr("editor.status.missing.default"), '$', '$'); + messageTemplate.add("character", missingToken); + return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render()) ); } @@ -420,23 +436,25 @@ public RegexTemplateMessageSimplifierStrategy(String newRegex, String newHintTem } @Override - public Optional simplify(String message) { + public Optional simplify(String message, int line) { if (pattern.matcher(message).find()) { - String newMessage = String.format( - hintTemplate, - getOffendingArea(message) - ); + + ST messageTemplate = new ST (hintTemplate,'$','$'); + messageTemplate.add("statement",getOffendingArea(message)); + messageTemplate.add("linenumber",line); return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage, getAttributeToPrior()) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render(), getAttributeToPrior()) ); + } else { return Optional.empty(); } } /** - * Determine if this issue should be attributed to the prior token. + * Determine if this issue should be git reset --hard origin/ + to the prior token. * * @return True if should be attributed to prior token. False otherwise. */ @@ -545,14 +563,13 @@ protected PreprocIssueMessageSimplifierStrategy createInvalidGenericDefinitionSt */ protected PreprocIssueMessageSimplifierStrategy createMissingCurlyAtStartSimplifierStrategy() { - return message -> { + return (message, line) -> { boolean matches = message.endsWith("expecting {'throws', '{'}"); matches = matches || message.endsWith("expecting {'throws', '{', '[', ';'}"); if (!matches) { return Optional.empty(); } - return Optional.of(new PdeIssueEmitter.IssueMessageSimplification( getLocalStr("editor.status.missing.left_curly_bracket") )); @@ -563,7 +580,7 @@ protected PreprocIssueMessageSimplifierStrategy createMissingCurlyAtStartSimplif * Strategy to catch a missing curly at a semicolon. */ protected PreprocIssueMessageSimplifierStrategy createMissingCurlyAtSemicolonSimplifierStrategy() { - return message -> { + return (message, line) -> { if (!message.equals("missing ';' at '{'")) { return Optional.empty(); } @@ -578,14 +595,15 @@ protected PreprocIssueMessageSimplifierStrategy createMissingCurlyAtSemicolonSim * Strategy to check for an error indicating that an identifier was expected but not given. */ protected PreprocIssueMessageSimplifierStrategy createMissingIdentifierSimplifierStrategy() { - return message -> { + return (message, line) -> { if (message.toLowerCase().contains("missing identifier at")) { - String newMessage = String.format( - getLocalStr("editor.status.missing.name"), - message.replace("missing Identifier at", "") - ); + + ST messageTemplate = new ST(getLocalStr("editor.status.missing.name"), '$', '$'); + messageTemplate.add("statement", message.replace("missing Identifier at", "")); + messageTemplate.add("linenumber", line); + return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render()) ); } else { return Optional.empty(); @@ -598,7 +616,7 @@ protected PreprocIssueMessageSimplifierStrategy createMissingIdentifierSimplifie */ protected PreprocIssueMessageSimplifierStrategy createKnownMissingSimplifierStrategy() { final Pattern parsePattern = Pattern.compile(".*missing '(.*)' at .*"); - return message -> { + return (message, line) -> { if (message.toLowerCase().contains("missing")) { String missingPiece; Matcher matcher = parsePattern.matcher(message); @@ -608,12 +626,11 @@ protected PreprocIssueMessageSimplifierStrategy createKnownMissingSimplifierStra missingPiece = "character"; } - String langTemplate = getLocalStr("editor.status.missing.default") - .replace("%c", "%s"); + ST messageTemplate = new ST(getLocalStr("editor.status.missing.default"), '$', '$'); + messageTemplate.add("character", missingPiece); + messageTemplate.add("linenumber", line); - String newMessage = String.format(langTemplate, missingPiece); - - return Optional.of(new PdeIssueEmitter.IssueMessageSimplification(newMessage)); + return Optional.of(new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render())); } else { return Optional.empty(); } @@ -624,15 +641,15 @@ protected PreprocIssueMessageSimplifierStrategy createKnownMissingSimplifierStra * Strategy to handle extraneous input messages. */ protected PreprocIssueMessageSimplifierStrategy createExtraneousInputSimplifierStrategy() { - return message -> { + return (message, line) -> { if (message.toLowerCase().contains("extraneous")) { - String innerMsg = getOffendingArea(message); - - String newMessageOuter = getLocalStr("editor.status.extraneous"); - String newMessage = String.format(newMessageOuter, innerMsg); + + ST messageTemplate = new ST(getLocalStr("editor.status.extraneous"), '$', '$'); + messageTemplate.add("statement", getOffendingArea(message)); + messageTemplate.add("linenumber", line); return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render()) ); } else { return Optional.empty(); @@ -645,18 +662,17 @@ protected PreprocIssueMessageSimplifierStrategy createExtraneousInputSimplifierS */ protected PreprocIssueMessageSimplifierStrategy createMismatchedInputSimplifierStrategy() { final Pattern parser = Pattern.compile("mismatched input '(.*)' expecting "); - return message -> { + return (message, line) -> { if (message.toLowerCase().contains("mismatched input")) { Matcher matcher = parser.matcher(message); - String newMessage = String.format( - getLocalStr("editor.status.mismatched"), - matcher.find() ? matcher.group(1) : message - ); + ST messageTemplate = new ST( getLocalStr("editor.status.mismatched"), '$', '$'); + messageTemplate.add("statement", matcher.find() ? matcher.group(1) : message); + messageTemplate.add("linenumber", line); return Optional.of( new PdeIssueEmitter.IssueMessageSimplification( - newMessage + messageTemplate.render() ) ); } else { @@ -671,14 +687,14 @@ protected PreprocIssueMessageSimplifierStrategy createMismatchedInputSimplifierS protected static class DefaultMessageSimplifier implements PreprocIssueMessageSimplifierStrategy { @Override - public Optional simplify(String message) { + public Optional simplify(String message, int line) { if (message.contains("viable alternative")) { - String newMessage = String.format( - getLocalizedGenericError("%s"), - getOffendingArea(message) - ); + + ST messageTemplate = new ST(getLocalStr("editor.status.error.syntaxdefault"), '$', '$'); + messageTemplate.add("statement", getOffendingArea(message)); + return Optional.of( - new PdeIssueEmitter.IssueMessageSimplification(newMessage) + new PdeIssueEmitter.IssueMessageSimplification(messageTemplate.render()) ); } else { return Optional.of( @@ -1025,15 +1041,15 @@ public static DefaultErrorLocalStrSet get() { */ private DefaultErrorLocalStrSet() { localizations.put("editor.status.error", "Error"); - localizations.put("editor.status.error.syntax", "Syntax Error - %s"); - localizations.put("editor.status.bad.assignment", "Error on variable assignment near %s?"); - localizations.put("editor.status.bad.identifier", "Identifier cannot start with digits near %s?"); - localizations.put("editor.status.bad.parameter", "Error on parameter or method declaration near %s?"); - localizations.put("editor.status.extraneous", "Unexpected extra code near %s?"); - localizations.put("editor.status.mismatched", "Missing operator or semicolon near %s?"); - localizations.put("editor.status.missing.name", "Missing name near %s?"); - localizations.put("editor.status.missing.type", "Missing name or type near %s?"); - localizations.put("editor.status.missing.default", "Missing '%s'?"); + localizations.put("editor.status.error.syntax", "Syntax Error - $statement$"); + localizations.put("editor.status.bad.assignment", "Error on variable assignment near $statement$?"); + localizations.put("editor.status.bad.identifier", "Identifier cannot start with digits near $statement$?"); + localizations.put("editor.status.bad.parameter", "Error on parameter or method declaration near $statement$?"); + localizations.put("editor.status.extraneous", "Unexpected extra code near $statement$?"); + localizations.put("editor.status.mismatched", "Missing operator or semicolon near $statement$?"); + localizations.put("editor.status.missing.name", "Missing name near $statement$?"); + localizations.put("editor.status.missing.type", "Missing name or type near $statement$?"); + localizations.put("editor.status.missing.default", "Missing '$character$'?"); localizations.put("editor.status.missing.right_curly_bracket", "Missing '}'"); localizations.put("editor.status.missing.left_curly_bracket", "Missing '{'"); } @@ -1049,4 +1065,4 @@ public Optional get(String key) { } } -} +} \ No newline at end of file diff --git a/java/test/processing/mode/java/preproc/AssignmentMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/AssignmentMessageSimplifierStrategyTest.java index 22a2f53df4..eccd325f16 100644 --- a/java/test/processing/mode/java/preproc/AssignmentMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/AssignmentMessageSimplifierStrategyTest.java @@ -20,19 +20,19 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify(" int x ="); + Optional msg = strategy.simplify(" int x =", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentDiamond() { - Optional msg = strategy.simplify(" List x ="); + Optional msg = strategy.simplify(" List x =", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("class {"); + Optional msg = strategy.simplify("class {", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/BadIdentifierMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/BadIdentifierMessageSimplifierStrategyTest.java index 7a6e51997b..2c29eebd48 100644 --- a/java/test/processing/mode/java/preproc/BadIdentifierMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/BadIdentifierMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("test(a,01a"); + Optional msg = strategy.simplify("test(a,01a", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("class {"); + Optional msg = strategy.simplify("class {", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/BadParamMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/BadParamMessageSimplifierStrategyTest.java index b0fb9a0b11..ec6dcefba3 100644 --- a/java/test/processing/mode/java/preproc/BadParamMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/BadParamMessageSimplifierStrategyTest.java @@ -20,25 +20,25 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("void test (int x,\ny) \n{"); + Optional msg = strategy.simplify("void test (int x,\ny) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentUnderscore() { - Optional msg = strategy.simplify("void test (int x,\ny_y) \n{"); + Optional msg = strategy.simplify("void test (int x,\ny_y) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentVarType() { - Optional msg = strategy.simplify("void test (int x,\nint) \n{"); + Optional msg = strategy.simplify("void test (int x,\nint) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("int x = y"); + Optional msg = strategy.simplify("int x = y", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/ExtraneousInputMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/ExtraneousInputMessageSimplifierStrategyTest.java index 69b8d09f09..6bc69bfe9c 100644 --- a/java/test/processing/mode/java/preproc/ExtraneousInputMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/ExtraneousInputMessageSimplifierStrategyTest.java @@ -21,13 +21,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("extraneous input 'test' expecting ';'"); + Optional msg = strategy.simplify("extraneous input 'test' expecting ';'", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("String x = \" \\\" \""); + Optional msg = strategy.simplify("String x = \" \\\" \"", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/KnownMissingMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/KnownMissingMessageSimplifierStrategyTest.java index 587cd45c42..61d5ccba49 100644 --- a/java/test/processing/mode/java/preproc/KnownMissingMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/KnownMissingMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("missing ';' at 'addCircle'"); + Optional msg = strategy.simplify("missing ';' at 'addCircle'", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("String x = \" \\\" \""); + Optional msg = strategy.simplify("String x = \" \\\" \"", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MismatchedInputMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MismatchedInputMessageSimplifierStrategyTest.java index c3da11d8db..f470459fea 100644 --- a/java/test/processing/mode/java/preproc/MismatchedInputMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MismatchedInputMessageSimplifierStrategyTest.java @@ -21,13 +21,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("mismatched input 'final' expecting {'instanceof', ';', ',', '.', '>', '<', '==', '<=', '>=', '!=', '&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%', '::'}"); + Optional msg = strategy.simplify("mismatched input 'final' expecting {'instanceof', ';', ',', '.', '>', '<', '==', '<=', '>=', '!=', '&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%', '::'}", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("String x = \" \\\" \""); + Optional msg = strategy.simplify("String x = \" \\\" \"", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingChevMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingChevMessageSimplifierStrategyTest.java index 9b6d4d6c8a..d9895d17c2 100644 --- a/java/test/processing/mode/java/preproc/MissingChevMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingChevMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("class Test msg = strategy.simplify("class Test msg = strategy.simplify("class {"); + Optional msg = strategy.simplify("class {", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingClassNameMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingClassNameMessageSimplifierStrategyTest.java index ebbfe6659c..889257f279 100644 --- a/java/test/processing/mode/java/preproc/MissingClassNameMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingClassNameMessageSimplifierStrategyTest.java @@ -20,19 +20,19 @@ public void setup() { @Test public void testPresentExtends() { - Optional msg = strategy.simplify("class extends Base\n{"); + Optional msg = strategy.simplify("class extends Base\n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentNoExtends() { - Optional msg = strategy.simplify("class \n{"); + Optional msg = strategy.simplify("class \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("int x = y"); + Optional msg = strategy.simplify("int x = y", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingCurlyMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingCurlyMessageSimplifierStrategyTest.java index c63e33f134..85dc05fa03 100644 --- a/java/test/processing/mode/java/preproc/MissingCurlyMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingCurlyMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("class Test {"); + Optional msg = strategy.simplify("class Test {", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("class Test { }"); + Optional msg = strategy.simplify("class Test { }", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingDoubleQuoteMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingDoubleQuoteMessageSimplifierStrategyTest.java index bb4e79c3bb..c70b2ef8c9 100644 --- a/java/test/processing/mode/java/preproc/MissingDoubleQuoteMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingDoubleQuoteMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("String x = \" \" \""); + Optional msg = strategy.simplify("String x = \" \" \"", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("String x = \" \\\" \""); + Optional msg = strategy.simplify("String x = \" \\\" \"", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingGenericTypeMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingGenericTypeMessageSimplifierStrategyTest.java index e6847470f9..644bdb0ec9 100644 --- a/java/test/processing/mode/java/preproc/MissingGenericTypeMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingGenericTypeMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("<>'"); + Optional msg = strategy.simplify("<>'", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("class {"); + Optional msg = strategy.simplify("class {", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingIdentifierMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingIdentifierMessageSimplifierStrategyTest.java index 924aec011f..8733109359 100644 --- a/java/test/processing/mode/java/preproc/MissingIdentifierMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingIdentifierMessageSimplifierStrategyTest.java @@ -21,13 +21,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("Missing identifier at ';'"); + Optional msg = strategy.simplify("Missing identifier at ';'", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("String x = \" \\\" \""); + Optional msg = strategy.simplify("String x = \" \\\" \"", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingMethodNameMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingMethodNameMessageSimplifierStrategyTest.java index e94dba63bd..9ffc8c6aae 100644 --- a/java/test/processing/mode/java/preproc/MissingMethodNameMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingMethodNameMessageSimplifierStrategyTest.java @@ -20,25 +20,25 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("void (int x) \n{"); + Optional msg = strategy.simplify("void (int x) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentNoSpace() { - Optional msg = strategy.simplify("test(int x) \n{"); + Optional msg = strategy.simplify("test(int x) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testPresentUnderscore() { - Optional msg = strategy.simplify("void (int x_y) \n{"); + Optional msg = strategy.simplify("void (int x_y) \n{", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("int x = y"); + Optional msg = strategy.simplify("int x = y", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingParenMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingParenMessageSimplifierStrategyTest.java index f6e8e3de27..522917a389 100644 --- a/java/test/processing/mode/java/preproc/MissingParenMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingParenMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("int x = ((5 + 4) / 3"); + Optional msg = strategy.simplify("int x = ((5 + 4) / 3", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("int x = (y/5)/(\n4)"); + Optional msg = strategy.simplify("int x = (y/5)/(\n4)", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingSingleQuoteMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingSingleQuoteMessageSimplifierStrategyTest.java index 0c53c1df65..60169c987e 100644 --- a/java/test/processing/mode/java/preproc/MissingSingleQuoteMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingSingleQuoteMessageSimplifierStrategyTest.java @@ -19,13 +19,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("char x = '"); + Optional msg = strategy.simplify("char x = '", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("char x = '\\''"); + Optional msg = strategy.simplify("char x = '\\''", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/MissingVariableNameMessageSimplifierStrategyTest.java b/java/test/processing/mode/java/preproc/MissingVariableNameMessageSimplifierStrategyTest.java index e2c69757a4..7864466cd3 100644 --- a/java/test/processing/mode/java/preproc/MissingVariableNameMessageSimplifierStrategyTest.java +++ b/java/test/processing/mode/java/preproc/MissingVariableNameMessageSimplifierStrategyTest.java @@ -20,13 +20,13 @@ public void setup() { @Test public void testPresent() { - Optional msg = strategy.simplify("char = ';"); + Optional msg = strategy.simplify("char = ';", 123); Assert.assertTrue(msg.isPresent()); } @Test public void testNotPresent() { - Optional msg = strategy.simplify("class test {"); + Optional msg = strategy.simplify("class test {", 123); Assert.assertTrue(msg.isEmpty()); } diff --git a/java/test/processing/mode/java/preproc/util/PreprocessIssueMessageSimplifierTest.java b/java/test/processing/mode/java/preproc/util/PreprocessIssueMessageSimplifierTest.java index 617313b468..c5eb85c5c2 100644 --- a/java/test/processing/mode/java/preproc/util/PreprocessIssueMessageSimplifierTest.java +++ b/java/test/processing/mode/java/preproc/util/PreprocessIssueMessageSimplifierTest.java @@ -10,56 +10,59 @@ public class PreprocessIssueMessageSimplifierTest { @Test public void testAssignment() { String input = "List ="; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); - Assert.assertTrue(output.contains("assignment")); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); + Assert.assertTrue(output.contains("assignment")&&!(output.contains("$statement$") || output.contains("$character$") || output.contains("$linenumber$"))); } @Test public void testBadIdentifier() { String input = "List 9"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); - Assert.assertTrue(output.contains("digit")); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); + System.out.println("output:"+output); + Assert.assertTrue(output.contains("digit")&&!(output.contains("$statement$") || output.contains("$character$") || output.contains("$linenumber$"))); } @Test public void testBadParamLead() { String input = "x,"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); - Assert.assertTrue(output.contains("parameter")); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); + Assert.assertTrue(output.contains("parameter")&&!(output.contains("$statement$") || output.contains("$character$") || output.contains("$linenumber$"))); } @Test public void testBadParamEnd() { String input = "colorGen),"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); Assert.assertTrue(output.contains("parameter")); } @Test public void testCaret() { String input = "List")); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); + System.out.println("testCaret output:" + output); + Assert.assertTrue(output.contains(">")&&!(output.contains("$statement$") || output.contains("$character$") || output.contains("$linenumber$"))); } @Test public void testMissingIdentifier() { String input = "missing Identifier at '{'"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); - Assert.assertTrue(output.contains("{")); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); + System.out.println("testMissingIdentifieroutput:" + output); + Assert.assertTrue(output.contains("{")&&!(output.contains("$statement$") || output.contains("$character$") || output.contains("$linenumber$"))); } @Test public void simplifyParen() { String input = "no viable alternative at input 'ellipse(\n\nellipse();'"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); Assert.assertNotNull(output); } @Test public void simplifySemicolon() { String input = "no viable alternative at input 'ellipse(\n\nellipse())'"; - String output = PreprocessIssueMessageSimplifier.get().simplify(input).getMessage(); + String output = PreprocessIssueMessageSimplifier.get().simplify(input, 123).getMessage(); Assert.assertNotNull(output); }