Skip to content

Commit 04be59a

Browse files
committed
Modernizing the code base a bit
1 parent 7b830d9 commit 04be59a

16 files changed

Lines changed: 55 additions & 61 deletions

src/main/java/org/fife/rtext/AbstractParserNoticeWindow.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public Class<?> getColumnClass(int col) {
195195
public void addRow(Object[] data) {
196196
// NOTE: It's valid for data[1] to be Strings, in which case
197197
// it's taken to be the full path of a file.
198-
if (data[1] instanceof RTextEditorPane) {
199-
data[1] = new TextAreaWrapper((RTextEditorPane)data[1]);
198+
if (data[1] instanceof RTextEditorPane pane) {
199+
data[1] = new TextAreaWrapper(pane);
200200
}
201-
else if (data[1] instanceof String) {
202-
data[1] = new TextAreaWrapper((String)data[1]);
201+
else if (data[1] instanceof String str) {
202+
data[1] = new TextAreaWrapper(str);
203203
}
204204
super.addRow(data);
205205
}

src/main/java/org/fife/rtext/RTextUtilities.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,14 @@ public static void setDropShadowsEnabledInEditor(boolean enabled) {
746746
@Override
747747
public void decorate(JWindow window) {
748748
Container cp = window.getContentPane();
749-
if (cp instanceof JComponent) {
749+
if (cp instanceof JComponent jc) {
750750
TranslucencyUtil util =
751751
TranslucencyUtil.get();
752752
util.setOpaque(window, false);
753-
((JComponent)cp).setBorder(
753+
jc.setBorder(
754754
BorderFactory.createCompoundBorder(
755755
ShadowPopupBorder.getInstance(),
756-
((JComponent)cp).getBorder()));
756+
jc.getBorder()));
757757
}
758758
}
759759
});

src/main/java/org/fife/rtext/RemoteFileChooser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ protected void escapePressed() {
311311
@Override
312312
public void focusGained(FocusEvent e) {
313313
Object source = e.getSource();
314-
if (source instanceof JTextComponent) {
315-
((JTextComponent)source).selectAll();
314+
if (source instanceof JTextComponent tc) {
315+
tc.selectAll();
316316
}
317317
}
318318

src/main/java/org/fife/rtext/SyntaxFilters.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,14 @@ public static boolean isValidFileFilterString(String fileFilterString) {
204204
for (int i=0; i<length; i++) {
205205
char c = fileFilterString.charAt(i);
206206
switch (c) {
207-
case '*':
208-
case '?':
209-
case '.':
210-
case '-':
211-
case '_':
212-
case '$':
213-
case ' ':
214-
continue;
215-
default:
207+
case '*', '?', '.', '-', '_', '$', ' ' -> {
208+
// Valid special character, keep going
209+
}
210+
default -> {
216211
if (!Character.isLetterOrDigit(c)) {
217212
return false;
218213
}
219-
break;
214+
}
220215
}
221216
}
222217
return true;

src/main/java/org/fife/rtext/TabbedPaneViewTransferHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public boolean importData(JComponent c, Transferable t) {
8787
protected void selectTab(final JTabbedPane tabbedPane, final int index) {
8888
SwingUtilities.invokeLater(() -> {
8989
Container parent = tabbedPane.getParent();
90-
if (parent instanceof AbstractMainView) {
91-
((AbstractMainView)parent).setSelectedIndex(index);
90+
if (parent instanceof AbstractMainView mainView) {
91+
mainView.setSelectedIndex(index);
9292
}
9393
else {
9494
// Should never happen.

src/main/java/org/fife/rtext/plugins/console/RubyShellTextArea.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ private void handleSubmitImpl(String code, boolean appendPrompt) {
145145

146146
} catch (Exception e) {
147147
// Peel off wrapper ScriptException
148-
if (e instanceof ScriptException) {
149-
append(massageScriptException((ScriptException)e), STYLE_STDERR);
148+
if (e instanceof ScriptException se) {
149+
append(massageScriptException(se), STYLE_STDERR);
150150
}
151151
else {
152152
StringWriter sw = new StringWriter();

src/main/java/org/fife/rtext/plugins/langsupport/LangSupportUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ private LangSupportUtils() {
3535
* @return The file.
3636
*/
3737
public static File getClassFileLocation(LibraryInfo li) {
38-
if (li instanceof JarLibraryInfo) {
39-
return ((JarLibraryInfo)li).getJarFile();
38+
if (li instanceof JarLibraryInfo jli) {
39+
return jli.getJarFile();
4040
}
4141
else if (li instanceof DirLibraryInfo) {
4242
return new File(li.getLocationAsString());
4343
}
44-
else if (li instanceof Jdk9LibraryInfo) {
45-
return ((Jdk9LibraryInfo)li).getJreHome();
44+
else if (li instanceof Jdk9LibraryInfo j9li) {
45+
return j9li.getJreHome();
4646
}
4747
throw new IllegalArgumentException("Unknown LibraryInfo type: " + li.getClass().getName());
4848
}

src/main/java/org/fife/rtext/plugins/macros/Macro.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ else if (o!=null) {
9292
*/
9393
@Override
9494
public boolean equals(Object o) {
95-
return o instanceof Macro && compareTo((Macro)o)==0;
95+
return o instanceof Macro other && compareTo(other)==0;
9696
}
9797

9898

src/main/java/org/fife/rtext/plugins/project/model/FileProjectEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void accept(WorkspaceVisitor visitor) {
4444

4545
@Override
4646
public int compareTo(ProjectEntry entry) {
47-
if (entry instanceof FileProjectEntry) {
48-
return file.compareTo(entry.getFile());
47+
if (entry instanceof FileProjectEntry other) {
48+
return file.compareTo(other.getFile());
4949
}
5050
return -1;
5151
}
@@ -56,8 +56,8 @@ public final boolean equals(Object o) {
5656
if (o==this) {
5757
return true;
5858
}
59-
return o instanceof FileProjectEntry &&
60-
compareTo((FileProjectEntry)o)==0;
59+
return o instanceof FileProjectEntry other &&
60+
compareTo(other)==0;
6161
}
6262

6363

src/main/java/org/fife/rtext/plugins/project/model/FolderProjectEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void accept(WorkspaceVisitor visitor) {
4545

4646
@Override
4747
public int compareTo(ProjectEntry o) {
48-
if (o instanceof FolderProjectEntry) {
49-
return dir.compareTo(o.getFile());
48+
if (o instanceof FolderProjectEntry other) {
49+
return dir.compareTo(other.getFile());
5050
}
5151
return -1;
5252
}
@@ -57,8 +57,8 @@ public final boolean equals(Object o) {
5757
if (o==this) {
5858
return true;
5959
}
60-
return o instanceof FolderProjectEntry &&
61-
compareTo((FolderProjectEntry)o)==0;
60+
return o instanceof FolderProjectEntry other &&
61+
compareTo(other)==0;
6262
}
6363

6464

0 commit comments

Comments
 (0)