Eclipse-Formatter-Plugin fails due to wrong assumptions
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Beginne damit, die minimale Test-Klasse mit dem Eclipse API-Snippet zu reproduzieren, und lies dann SnippetFormatter.java und dessen Methode toReplacements(). Verfolge, wie der Vergleich ohne Whitespace dazu führt, dass der Eclipse-Formatter null zurückgibt. Erledigt ist die Aufgabe, wenn der Beispielquelltext ohne diesen Fehler über das Plugin formatiert werden kann und das Verhalten durch einen Regressionstest verifiziert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
The Eclipse-Plugin has sometimes a problem when I call the formatter programatically inside Eclipse. I am using the Snippet from https://help.eclipse.org/latest/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_codeformatter.htm to format a complete Java-File. I have created a minimal Test-Class:
package test;
/**
* Test Class
*
* Generated
*
*/
public class Test
{
}
The standalone-Formatter-Jar adds a HTML-Tag
before the "Generated". Unfortunately, when I call the plugin via the Eclipse-APIs:
final TextEdit edit =
codeFormatter.format(
CodeFormatter.K_COMPILATION_UNIT, // format a compilation unit
content, // source to format
0, // starting position
content.length(), // length
0, // initial indentation
"\r\n" // line separator
);
the method returns a null because it can not format the content. I have tracked the problem back to the class SnippetFormatter.java, Method toReplacements(). This method has the condition which checks the unformatted and the formatted source:
if (!NOT_WHITESPACE.retainFrom(source).equals(NOT_WHITESPACE.retainFrom(replacement))) {
throw new IllegalArgumentException(
"source = \"" + source + "\", replacement = \"" + replacement + "\"");
}
This condition checks that there are only whitespace-changes in the new formatted source. The Javadoc says:
under the assumption that they differ in whitespace alone.
Unfortunately, this assumption is not correct. The source has (as mentioned above) an additional non-whitespace change and the IllegalArgumentException is thrown. This Exception causes the Eclipse-Formatter-Class to fail and to return only null, thereby denying to format the source.
- Vorherrschende Sprache
- Java
- Sterne
- 6.2k
- Forks
- 940
- Ø Merge
- 7 Std. 46 Min.
- Gemergte PRs (30 T.)
- 11
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google/google-java-format
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
google/google-java-format#1094 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
google/google-java-format#1470 · 5 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
IndexOutOfBoundsException - Wrong formatted content when dealing with latex StringEvtl. wieder frei @Amlan2000 hat das vor 61 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
google/google-java-format#1439 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
unused import removal leaves extra blank line between package declaration and class Javadoc / declarationEvtl. vergeben @arimu1 hat das vor 70 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
google/google-java-format#1436 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Eclipse
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
google/google-java-format#1428 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in google/google-java-format
Ähnliche Issues
-
agent-java community triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
elastic/apm-agent-java#4594 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area/plugin good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
kestra-io/plugin-soda#137 ·
-
area/plugin good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
kestra-io/plugin-aws#816 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
area/plugin good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
kestra-io/plugin-kestra#200 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug untriaged
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
opensearch-project/search-relevance#618 ·
Maintainer antworten meist innerhalb von 3 Tagen