From 08cb0cd6f686f310f8af826e6013246157f264df Mon Sep 17 00:00:00 2001 From: Eirik Bakke Date: Thu, 13 Sep 2018 15:24:23 -0400 Subject: [PATCH] Adjust PR code style; use {} around one-line ifs. Also do "return preferredMaximumBreakOffset" instead of "ret = preferredMaximumBreakOffset" in adjustBreakOffsetToWord, as suggested in PR comment. They are logically equivalent at this point in the code. --- .../view/CharSequenceCharacterIterator.java | 9 ++++++--- .../editor/lib2/view/HighlightsViewUtils.java | 17 +++++++++++------ .../lib2/view/AdjustBreakOffsetToWordTest.java | 18 ++++++++++++------ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/CharSequenceCharacterIterator.java b/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/CharSequenceCharacterIterator.java index 77ef5b417f26..e4726efd54da 100644 --- a/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/CharSequenceCharacterIterator.java +++ b/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/CharSequenceCharacterIterator.java @@ -34,8 +34,9 @@ class CharSequenceCharacterIterator implements CharacterIterator { private int index; public CharSequenceCharacterIterator(CharSequence charSequence) { - if (charSequence == null) + if (charSequence == null) { throw new NullPointerException(); + } this.charSequence = charSequence; } @@ -46,8 +47,9 @@ public int getIndex() { @Override public char setIndex(int position) { - if (position < getBeginIndex() || position > getEndIndex()) + if (position < getBeginIndex() || position > getEndIndex()) { throw new IllegalArgumentException(); + } this.index = position; return current(); } @@ -70,8 +72,9 @@ public char last() { @Override public char next() { - if (index < getEndIndex()) + if (index < getEndIndex()) { index++; + } return current(); } diff --git a/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewUtils.java b/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewUtils.java index 77200d538d84..f13c6e78517e 100644 --- a/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewUtils.java +++ b/ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewUtils.java @@ -785,10 +785,12 @@ static View breakView(int axis, int breakPartStartOffset, float x, float len, static int adjustBreakOffsetToWord(CharSequence paragraph, final int preferredMaximumBreakOffset, boolean allowWhitespaceBeyondEnd) { - if (preferredMaximumBreakOffset < 0) + if (preferredMaximumBreakOffset < 0) { throw new IllegalArgumentException(); - if (preferredMaximumBreakOffset > paragraph.length()) + } + if (preferredMaximumBreakOffset > paragraph.length()) { throw new IllegalArgumentException(); + } /* BreakIterator.getLineInstance already seems to have a cache; creating a new instance here is just the cost of BreakIterator.clone(). So don't bother trying to cache the BreakIterator here. */ @@ -812,16 +814,18 @@ static int adjustBreakOffsetToWord(CharSequence paragraph, ret = bi.isBoundary(preferredMaximumBreakOffset) ? preferredMaximumBreakOffset : bi.preceding(preferredMaximumBreakOffset); - if (ret == BreakIterator.DONE) - ret = preferredMaximumBreakOffset; + if (ret == BreakIterator.DONE) { + return preferredMaximumBreakOffset; + } } if (ret == 0) { // Skip forward to next boundary (for words longer than the preferred break offset). ret = preferredMaximumBreakOffset > 0 && bi.isBoundary(preferredMaximumBreakOffset) ? preferredMaximumBreakOffset : bi.following(preferredMaximumBreakOffset); - if (ret == BreakIterator.DONE) + if (ret == BreakIterator.DONE) { ret = preferredMaximumBreakOffset; + } /* The line-based break iterator will include whitespace trailing a word as well. Strip this off so we can apply our own policy here. */ int retBeforeTrim = ret; @@ -832,8 +836,9 @@ static int adjustBreakOffsetToWord(CharSequence paragraph, } /* If allowWhitespaceBeyondEnd is true, allow at most one whitespace character to trail the word at the end. */ - if ((allowWhitespaceBeyondEnd || ret == 0) && retBeforeTrim > ret) + if ((allowWhitespaceBeyondEnd || ret == 0) && retBeforeTrim > ret) { ret++; + } } return ret; } diff --git a/ide/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/view/AdjustBreakOffsetToWordTest.java b/ide/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/view/AdjustBreakOffsetToWordTest.java index 8c3380dcd0d8..278753093155 100644 --- a/ide/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/view/AdjustBreakOffsetToWordTest.java +++ b/ide/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/view/AdjustBreakOffsetToWordTest.java @@ -225,15 +225,18 @@ public TextWithCaret(String text, int caret) { } private TextWithCaret(String text, int caret, boolean check) { - if (text == null) + if (text == null) { throw new NullPointerException(); - if (caret < 0 || caret > text.length()) + } + if (caret < 0 || caret > text.length()) { throw new IllegalArgumentException(); + } this.text = text; this.caret = caret; - if (check && !equals(fromEncoded(toString()))) + if (check && !equals(fromEncoded(toString()))) { throw new AssertionError(); + } } /** @@ -244,15 +247,17 @@ public static TextWithCaret fromEncoded(String encoded) { Integer caret = null; for (char ec : encoded.toCharArray()) { if (ec == '|') { - if (caret != null) + if (caret != null) { throw new IllegalArgumentException("Multiple caret positions specified"); + } caret = psb.length(); } else { psb.append(ec); } } - if (caret == null) + if (caret == null) { throw new IllegalArgumentException("No caret position specified"); + } return new TextWithCaret(psb.toString(), caret, false); } @@ -263,8 +268,9 @@ public String toString() { @Override public boolean equals(Object obj) { - if (!(obj instanceof TextWithCaret)) + if (!(obj instanceof TextWithCaret)) { return false; + } TextWithCaret other = (TextWithCaret) obj; return this.text.equals(other.text) && this.caret == other.caret;