Skip to content

Commit

Permalink
Fixed issue #998.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Nov 1, 2023
1 parent c396f04 commit 275b97a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ public void close(CTabFolderEvent event) {
if (!vm.isUpdated()) return;
Set<TreeItem> items = new HashSet<>();
Set<String> sorts = new HashSet<>();
boolean fixArgumentCount = false;
for (TreeItem sort1 : treeProblemsPtr[0].getSelection()) {
if (sort1 == null) continue;
if (sort1.equals(treeItemHintsPtr[0])) {
Expand All @@ -1451,6 +1452,11 @@ public void close(CTabFolderEvent event) {
} else if (sort1.getText(2).startsWith("[E01]")) { //$NON-NLS-1$
if (!sorts.contains(sort1.getText(2)))
sorts.add(sort1.getText(2));
} else if (sort1.getText(2).startsWith("[E47]")) { //$NON-NLS-1$
if (!sorts.contains(sort1.getText(2))) {
sorts.add(sort1.getText(2));
fixArgumentCount = true;
}
} else {
if (!sorts.contains(sort1.getText(0)))
sorts.add(sort1.getText(0));
Expand All @@ -1462,7 +1468,7 @@ public void close(CTabFolderEvent event) {
items.add(sort2);
}
for (TreeItem sort3 : treeItemErrorsPtr[0].getItems()) {
if (sorts.contains(sort3.getText(0)) && !items.contains(sort3))
if (sorts.contains(sort3.getText(0)) && !items.contains(sort3) || fixArgumentCount && sort3.getText(2).startsWith("[E47]") && !items.contains(sort3)) //$NON-NLS-1$
items.add(sort3);
}
for (TreeItem sort4 : treeItemWarningsPtr[0].getItems()) {
Expand Down
65 changes: 65 additions & 0 deletions src/org/nschmidt/ldparteditor/helper/compositetext/ErrorFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.Collectors;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
Expand Down Expand Up @@ -548,6 +550,69 @@ public static String fix(int lineNumber, String sort, String line, String text,
}
}
break;
case 71: // Wrong argument count (reference, line, triangle, quad, condline) [15+, 8, 11, 14, 14]
{
final String[] dataSegments = line.trim().split("\\s+"); //$NON-NLS-1$
final String lineType = dataSegments[0]; // The first segment is always there
final String[] newDataSegments;

switch (lineType) {
case "1": { //$NON-NLS-1$
newDataSegments = new String[15];
System.arraycopy(dataSegments, 0, newDataSegments, 0, Math.min(15, dataSegments.length));
// Fill missing data with defaults
for (int i = dataSegments.length; i < 15; i++) {
if (i == 1) {
newDataSegments[i] = "16"; //$NON-NLS-1$
} else if (i == 14) {
newDataSegments[i] = "subfile.dat"; //$NON-NLS-1$
} else {
newDataSegments[i] = "0"; //$NON-NLS-1$
}
}

break;
}
case "2": { //$NON-NLS-1$
newDataSegments = new String[8];
System.arraycopy(dataSegments, 0, newDataSegments, 0, Math.min(8, dataSegments.length));
// Fill missing data with defaults
for (int i = dataSegments.length; i < 8; i++) newDataSegments[i] = i == 1 ? "24" : "0"; //$NON-NLS-1$ //$NON-NLS-2$

break;
}
case "3": { //$NON-NLS-1$
newDataSegments = new String[11];
System.arraycopy(dataSegments, 0, newDataSegments, 0, Math.min(11, dataSegments.length));
// Fill missing data with defaults
for (int i = dataSegments.length; i < 11; i++) newDataSegments[i] = i == 1 ? "16" : "0"; //$NON-NLS-1$ //$NON-NLS-2$

break;
}
case "4": { //$NON-NLS-1$
newDataSegments = new String[14];
System.arraycopy(dataSegments, 0, newDataSegments, 0, Math.min(14, dataSegments.length));
// Fill missing data with defaults
for (int i = dataSegments.length; i < 14; i++) newDataSegments[i] = i == 1 ? "16" : "0"; //$NON-NLS-1$ //$NON-NLS-2$

break;
}
case "5": { //$NON-NLS-1$
newDataSegments = new String[14];
System.arraycopy(dataSegments, 0, newDataSegments, 0, Math.min(14, dataSegments.length));
// Fill missing data with defaults
for (int i = dataSegments.length; i < 14; i++) newDataSegments[i] = i == 1 ? "24" : "0"; //$NON-NLS-1$ //$NON-NLS-2$

break;
}
default:
newDataSegments = dataSegments;
break;
}

text = QuickFixer.setLine(lineNumber + 1, Arrays.stream(newDataSegments).collect(Collectors.joining(" ")), text); //$NON-NLS-1$
}
break;
default:
break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/org/nschmidt/ldparteditor/text/DatParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ private static List<ParsingResult> parseReference(String[] dataSegments, int dep
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_WRONG_ARGUMENT_COUNT);
result.add(new ParsingResult(formatter.format(messageArguments), "[E99] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
result.add(new ParsingResult(formatter.format(messageArguments), "[E47] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
} else {
// [ERROR] Check colour
GColour colour = validateColour(dataSegments[1], r, g, b, a);
Expand Down Expand Up @@ -853,7 +853,7 @@ private static List<ParsingResult> parseLine(String[] dataSegments, float r, flo
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_WRONG_ARGUMENT_COUNT);
result.add(new ParsingResult(formatter.format(messageArguments), "[E99] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
result.add(new ParsingResult(formatter.format(messageArguments), "[E47] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
} else {
// [ERROR] Check colour
GColour colour = validateColour(dataSegments[1], r, g, b, a);
Expand Down Expand Up @@ -916,7 +916,7 @@ private static List<ParsingResult> parseTriangle(String[] dataSegments, float r,
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_WRONG_ARGUMENT_COUNT);
result.add(new ParsingResult(formatter.format(messageArguments), "[E99] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
result.add(new ParsingResult(formatter.format(messageArguments), "[E47] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
} else {
// [ERROR] Check colour
GColour colour = validateColour(dataSegments[1], r, g, b, a);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ private static List<ParsingResult> parseQuad(String[] dataSegments, float r, flo
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_WRONG_ARGUMENT_COUNT);
result.add(new ParsingResult(formatter.format(messageArguments), "[E99] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
result.add(new ParsingResult(formatter.format(messageArguments), "[E47] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
} else {
// [ERROR] Check colour
GColour colour = validateColour(dataSegments[1], r, g, b, a);
Expand Down Expand Up @@ -1215,7 +1215,7 @@ private static List<ParsingResult> parseCondline(String[] dataSegments, float r,
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.DATPARSER_WRONG_ARGUMENT_COUNT);
result.add(new ParsingResult(formatter.format(messageArguments), "[E99] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
result.add(new ParsingResult(formatter.format(messageArguments), "[E47] " + I18n.DATPARSER_SYNTAX_ERROR, ResultType.ERROR)); //$NON-NLS-1$
} else {
// [ERROR] Check colour
GColour colour = validateColour(dataSegments[1], r, g, b, a);
Expand Down

0 comments on commit 275b97a

Please sign in to comment.