From b42cccab3540a86110483c1619cb8c8bd4d1233e Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 2 Mar 2019 20:27:51 +0100 Subject: [PATCH 1/3] Improve error mesage on save, add current field content --- .../jabref/logic/bibtex/LatexFieldFormatter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java index 64346eb96cb..2bca1001975 100644 --- a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java @@ -48,26 +48,26 @@ private static void checkBraces(String text) throws InvalidFieldValueException { char item = text.charAt(i); boolean charBeforeIsEscape = false; - if (i > 0 && text.charAt(i - 1) == '\\') { + if ((i > 0) && (text.charAt(i - 1) == '\\')) { charBeforeIsEscape = true; } - if (!charBeforeIsEscape && item == '{') { + if (!charBeforeIsEscape && (item == '{')) { left++; - } else if (!charBeforeIsEscape && item == '}') { + } else if (!charBeforeIsEscape && (item == '}')) { right++; } } // Then we throw an exception if the error criteria are met. if (!(right == 0) && (left == 0)) { - throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely."); + throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text); } if (!(right == 0) && (right < left)) { - throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely."); + throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text); } if (left != right) { - throw new InvalidFieldValueException("Braces don't match."); + throw new InvalidFieldValueException("Braces don't match. Field value: " + text); } } @@ -148,7 +148,7 @@ private String formatAndResolveStrings(String content, String fieldName) throws throw new InvalidFieldValueException( "The # character is not allowed in BibTeX strings unless escaped as in '\\#'.\n" + "In JabRef, use pairs of # characters to indicate a string.\n" - + "Note that the entry causing the problem has been selected."); + + "Note that the entry causing the problem has been selected. Field value: "+content); } } } From 6681d79917cfa602c51fb7e18465b98641b32b8e Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 3 Mar 2019 12:07:04 +0100 Subject: [PATCH 2/3] fix spaces around plus sign --- .../java/org/jabref/logic/bibtex/LatexFieldFormatter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java index 2bca1001975..5118573fbd6 100644 --- a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java @@ -61,10 +61,10 @@ private static void checkBraces(String text) throws InvalidFieldValueException { // Then we throw an exception if the error criteria are met. if (!(right == 0) && (left == 0)) { - throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text); + throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: " + text); } if (!(right == 0) && (right < left)) { - throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text); + throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: " + text); } if (left != right) { throw new InvalidFieldValueException("Braces don't match. Field value: " + text); From 5dce546e9c3e8e2af3d64bd2283f8e3c26912794 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 3 Mar 2019 12:31:20 +0100 Subject: [PATCH 3/3] fix formatting --- .../logic/bibtex/LatexFieldFormatter.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java index 5118573fbd6..b69a6480a71 100644 --- a/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java +++ b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java @@ -23,7 +23,6 @@ public class LatexFieldFormatter { private final FieldContentParser parser; private StringBuilder stringBuilder; - public LatexFieldFormatter(LatexFieldFormatterPreferences prefs) { this(true, prefs); } @@ -146,9 +145,9 @@ private String formatAndResolveStrings(String content, String fieldName) throws pos1 = content.length(); // just write out the rest of the text, and throw no exception } else { throw new InvalidFieldValueException( - "The # character is not allowed in BibTeX strings unless escaped as in '\\#'.\n" - + "In JabRef, use pairs of # characters to indicate a string.\n" - + "Note that the entry causing the problem has been selected. Field value: "+content); + "The # character is not allowed in BibTeX strings unless escaped as in '\\#'.\n" + + "In JabRef, use pairs of # characters to indicate a string.\n" + + "Note that the entry causing the problem has been selected. Field value: " + content); } } } @@ -161,7 +160,7 @@ private String formatAndResolveStrings(String content, String fieldName) throws // an occurrence of ## will simply be ignored. Should it instead // cause an error message? writeStringLabel(content, pos1 + 1, pos2, pos1 == pivot, - (pos2 + 1) == content.length()); + (pos2 + 1) == content.length()); } if (pos2 > -1) { @@ -187,7 +186,7 @@ private boolean shouldResolveStrings(String fieldName) { } else { // Default operation - we only resolve strings for standard fields: resolveStrings = InternalBibtexFields.isStandardField(fieldName) - || BIBTEX_STRING.equals(fieldName); + || BIBTEX_STRING.equals(fieldName); } return resolveStrings; } @@ -195,8 +194,7 @@ private boolean shouldResolveStrings(String fieldName) { private String formatWithoutResolvingStrings(String content, String fieldName) throws InvalidFieldValueException { checkBraces(content); - stringBuilder = new StringBuilder( - String.valueOf(FIELD_START)); + stringBuilder = new StringBuilder(String.valueOf(FIELD_START)); stringBuilder.append(parser.format(content, fieldName)); @@ -258,7 +256,7 @@ private void writeText(String text, int startPos, int endPos) { // We add a backslash before any ampersand characters, with one exception: if // we are inside an \\url{...} command, we should write it as it is. Maybe. if ((c == '&') && !escape && !(inCommand && "url".equals(commandName.toString())) - && (nestedEnvironments == 0)) { + && (nestedEnvironments == 0)) { stringBuilder.append("\\&"); } else { stringBuilder.append(c); @@ -271,7 +269,7 @@ private void writeText(String text, int startPos, int endPos) { private void writeStringLabel(String text, int startPos, int endPos, boolean first, boolean last) { putIn((first ? "" : " # ") + text.substring(startPos, endPos) - + (last ? "" : " # ")); + + (last ? "" : " # ")); } private void putIn(String s) {