Skip to content

Commit

Permalink
Fixing some unnecessary local variable initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbylight committed Jan 7, 2023
1 parent ac5d990 commit 330009e
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Dimension getPreferredSize() {

private String getText(int offsToRender) {

int line = 0;
int line;
try {
line = textArea.getLineOfOffset(offsToRender);
} catch (BadLocationException ble) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public void startElement(String uri, String localName, String qName,

if (field.getType()==int.class) {

int index = 0;
int index;
try {
index = field.getInt(scheme);
} catch (IllegalArgumentException | IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ else if ("tokenStyles".equals(qName)) {
else if ("style".equals(qName)) {

String type = attrs.getValue("token");
Field field = null;
Field field;
try {
field = Token.class.getField(type);
} catch (RuntimeException re) {
Expand All @@ -842,7 +842,7 @@ else if ("style".equals(qName)) {

if (field.getType()==int.class) {

int index = 0;
int index;
try {
index = field.getInt(theme.scheme);
} catch (IllegalArgumentException | IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public int getListOffset(RSyntaxTextArea textArea, TabExpander e,
float stableX = x0; // Cached ending x-coord. of last tab or token.
TokenImpl token = this;
int last = getOffset();
FontMetrics fm = null;
FontMetrics fm;

while (token != null && token.isPaintable()) {

Expand Down Expand Up @@ -719,7 +719,7 @@ public Rectangle listOffsetToView(RSyntaxTextArea textArea, TabExpander e,

int stableX = x0; // Cached ending x-coord. of last tab or token.
TokenImpl token = this;
FontMetrics fm = null;
FontMetrics fm;
Segment s = new Segment();

while (token != null && token.isPaintable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public float getMinimumSpan(int axis) {
@Override
public float getPreferredSpan(int axis) {
updateMetrics();
float span = 0;
float span;
if (axis==View.X_AXIS) { // Add EOL marker
span = super.getPreferredSpan(axis);
span += metrics.charWidth('\u00b6'); // metrics set in updateMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public List<Fold> getFolds(RSyntaxTextArea textArea) {

if (importStartLine>-1) {
if (lastSeenImportLine>importStartLine) {
Fold fold = null;
Fold fold;
// Any imports found *should* be a top-level fold,
// but we're extra lenient here and allow groups
// of them anywhere to keep our parser better-behaved
Expand Down Expand Up @@ -193,7 +193,7 @@ else if (isLeftCurly(t)) {

if (importStartLine>-1) {
if (lastSeenImportLine>importStartLine) {
Fold fold = null;
Fold fold;
// Any imports found *should* be a top-level fold,
// but we're extra lenient here and allow groups
// of them anywhere to keep our parser better-behaved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private String getTextIndented(String text,int firstNewline,String indent) {
if (firstNewline==-1) {
return text;
}
int pos = 0;
int pos;
int old = firstNewline+1;
StringBuilder sb = new StringBuilder(text.substring(0, old));
sb.append(indent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ private void readObject(ObjectInputStream s)
* @see #getAlpha
*/
public void setAlpha(float alpha) {
this.alpha = alpha;
this.alpha = Math.max(alpha, 0.0f);
this.alpha = Math.min(1.0f, alpha);
this.alpha = Math.min(1.0f, this.alpha);
alphaComposite = null; // So it is recreated with new alpha.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public String getToolTipText(MouseEvent e) {
FoldManager fm = rsta.getFoldManager();
int pos = rsta.viewToModel(new Point(0, e.getY()));
if (pos>=0) { // Not -1
int line = 0;
int line;
try {
line = rsta.getLineOfOffset(pos);
} catch (BadLocationException ble) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public static Font getDefaultFont() {
// Use StyleContext to get a composite font for better Asian language
// support; see Sun bug S282887.
StyleContext sc = StyleContext.getDefaultStyleContext();
Font font = null;
Font font;

if (isOSX()) {
// Snow Leopard (1.6) uses Menlo as default monospaced font,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public BeginLineAction(String name, boolean select) {
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

int newPos = 0;
int newPos;

try {

Expand Down Expand Up @@ -1305,7 +1305,7 @@ public EndLineAction(String name, boolean select) {
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
int offs = textArea.getCaretPosition();
int endOffs = 0;
int endOffs;
try {
if (textArea.getLineWrap()) {
// Must check per character, since one logical line may be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void setLineNumbersEnabled(boolean enabled) {
@Override
public void setViewportView(Component view) {

RTextArea rtaCandidate = null;
RTextArea rtaCandidate;

if (!(view instanceof RTextArea)) {
rtaCandidate = getFirstRTextAreaDescendant(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ public void addPropertyChangeListener(PropertyChangeListener l) {
@Override
public SearchContext clone() {
try {
SearchContext context = null;
context = (SearchContext)super.clone();
SearchContext context = (SearchContext)super.clone();
// Don't copy over listeners
context.support = new PropertyChangeSupport(context);
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static SearchResult findImpl(String findIn, SearchContext context) {
// Regex matches can have varying widths. The returned point's
// x- and y-values represent the start and end indices of the
// match in findIn.
Point regExPos = null;
Point regExPos;
int start = 0;
do {
regExPos = getNextMatchPosRegEx(text, findIn.substring(start),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.fife.ui.rsyntaxtextarea;

import org.fife.ui.SwingRunnerExtension;
import org.fife.ui.rtextarea.RTextArea;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.fife.ui.rsyntaxtextarea;

import org.fife.ui.SwingRunnerExtension;
import org.fife.ui.rtextarea.RTextArea;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TokenIteratorTest {
@Test
void testBasicIteration() throws Exception {

RSyntaxDocument doc = null;
RSyntaxDocument doc;

// A well-formed Java document.
doc = loadResource("TokenIteratorTest_JavaBasic.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/
package org.fife.ui.rsyntaxtextarea.modes;

import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenImpl;
import org.fife.ui.rsyntaxtextarea.TokenMaker;
import org.fife.ui.rsyntaxtextarea.TokenTypes;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ void testGetSetAlpha() {
}


@Test
void testGetSetAlpha_negative() {
ChangeableHighlightPainter painter = new ChangeableHighlightPainter();
Assertions.assertEquals(1f, painter.getAlpha(), 0.00001);
painter.setAlpha(-1f);
Assertions.assertEquals(0, painter.getAlpha(), 0.00001);
}


@Test
void testGetSetAlpha_greaterThanOne() {
ChangeableHighlightPainter painter = new ChangeableHighlightPainter();
Assertions.assertEquals(1f, painter.getAlpha(), 0.00001);
painter.setAlpha(2f);
Assertions.assertEquals(1f, painter.getAlpha(), 0.00001);
}


@Test
void testGetSetPaint() {
ChangeableHighlightPainter painter = new ChangeableHighlightPainter();
Expand Down

0 comments on commit 330009e

Please sign in to comment.