Skip to content

Commit db8ae28

Browse files
committed
Fixed issue with blank lines in google-java-formatter
1 parent 18e1720 commit db8ae28

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/main/java/de/funfried/netbeans/plugins/external/formatter/AbstractFormatJob.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import javax.swing.text.StyledDocument;
2121

2222
import org.apache.commons.collections4.CollectionUtils;
23-
import org.apache.commons.lang3.StringUtils;
2423
import org.apache.commons.lang3.mutable.MutableInt;
2524
import org.apache.commons.lang3.tuple.Pair;
2625
import org.netbeans.api.annotations.common.NonNull;
@@ -154,7 +153,15 @@ protected boolean setFormattedCode(String code, String formattedContent) throws
154153
* @return The content of the {@code document}
155154
*/
156155
protected String getCode() {
157-
return StringUtils.trim(DocumentUtilities.getText(document).toString());
156+
try {
157+
// returns the actual content of the document
158+
return document.getText(0, document.getLength());
159+
} catch (BadLocationException ex) {
160+
log.log(Level.WARNING, "Could not fetch text, falling back to utility method", ex);
161+
162+
// returns only the trimmed content of the document
163+
return DocumentUtilities.getText(document).toString();
164+
}
158165
}
159166

160167
/**

src/main/java/de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterWrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public final class GoogleJavaFormatterWrapper {
4040
* Formats the given {@code code} with the given configurations and returns
4141
* the formatted code.
4242
*
43-
* @param code the unformatted code
44-
* @param codeStyle the code {@link JavaFormatterOptions.Style} to use,
45-
* if {@code null} the {@link JavaFormatterOptions.Style#GOOGLE}
46-
* style will be used
43+
* @param code the unformatted code
44+
* @param codeStyle the code {@link JavaFormatterOptions.Style} to use,
45+
* if {@code null} the {@link JavaFormatterOptions.Style#GOOGLE}
46+
* style will be used
4747
* @param changedElements a {@link SortedSet} containing ranges as {@link Pair}
48-
* objects defining the offsets which should be formatted
48+
* objects defining the offsets which should be formatted
4949
*
5050
* @return the formatted code
5151
*

0 commit comments

Comments
 (0)