From 2d140567edf035fe665f66b78d488bc12c0f157b Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 30 Mar 2020 20:58:40 -0400 Subject: Clean up warnings Clear up some warnings that had popped up. Mostly, closing some input streams after we're done with them. --- .settings/org.eclipse.jdt.core.prefs | 3 +++ .../bjc/inflexion/examples/InflexionTester.java | 15 +++++++++++---- src/main/java/bjc/inflexion/InflectionML.java | 14 ++++++++++++-- src/main/java/bjc/inflexion/InflectionString.java | 22 ++++++++++++++++------ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 55d9710..3270413 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -20,6 +20,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=info +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled @@ -64,6 +65,7 @@ org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=info org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=info org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=info +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled @@ -100,4 +102,5 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=info org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/examples/java/bjc/inflexion/examples/InflexionTester.java b/src/examples/java/bjc/inflexion/examples/InflexionTester.java index ff5dcd7..0595cfa 100644 --- a/src/examples/java/bjc/inflexion/examples/InflexionTester.java +++ b/src/examples/java/bjc/inflexion/examples/InflexionTester.java @@ -48,11 +48,18 @@ public class InflexionTester { */ public static void main(final String[] args) { final Prepositions prepositionDB = new Prepositions(); - prepositionDB.loadFromStream( - InflexionTester.class.getResourceAsStream("/prepositions.txt")); + try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) { + prepositionDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } - final Nouns nounDB = new Nouns(prepositionDB); - nounDB.loadFromStream(InflexionTester.class.getResourceAsStream("/nouns.txt")); + Nouns nounDB = new Nouns(prepositionDB); + try (InputStream strim = InflectionML.class.getResourceAsStream("/nouns.txt")) { + nounDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } final Scanner scn = new Scanner(System.in); diff --git a/src/main/java/bjc/inflexion/InflectionML.java b/src/main/java/bjc/inflexion/InflectionML.java index f5fbb02..e92e171 100644 --- a/src/main/java/bjc/inflexion/InflectionML.java +++ b/src/main/java/bjc/inflexion/InflectionML.java @@ -13,6 +13,8 @@ */ package bjc.inflexion; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -57,10 +59,18 @@ public class InflectionML { /* Load DBs from files. */ static { final Prepositions prepositionDB = new Prepositions(); - prepositionDB.loadFromStream(InflectionML.class.getResourceAsStream("/prepositions.txt")); + try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) { + prepositionDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } nounDB = new Nouns(prepositionDB); - nounDB.loadFromStream(InflectionML.class.getResourceAsStream("/nouns.txt")); + try (InputStream strim = InflectionML.class.getResourceAsStream("/nouns.txt")) { + nounDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } } /** diff --git a/src/main/java/bjc/inflexion/InflectionString.java b/src/main/java/bjc/inflexion/InflectionString.java index 486c93b..7310374 100644 --- a/src/main/java/bjc/inflexion/InflectionString.java +++ b/src/main/java/bjc/inflexion/InflectionString.java @@ -20,6 +20,8 @@ import static bjc.inflexion.InflectionString.InflectionDirective.numeric; import static bjc.inflexion.InflectionString.InflectionDirective.variable; import static java.util.Arrays.asList; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -743,12 +745,12 @@ public class InflectionString { // Directive nesting level int level = 0; - int prevPos = pos;; + int prevPos = pos; char prevChar = ' '; boolean parsingVar = false; - for (pos = pos; pos < strang.length(); pos++) { + for (; pos < strang.length(); pos++) { // Backslash escapes a character if (prevChar == '\\') continue; @@ -825,10 +827,18 @@ public class InflectionString { /* Load DBs from files. */ static { final Prepositions prepositionDB = new Prepositions(); - prepositionDB.loadFromStream(InflectionML.class.getResourceAsStream("/prepositions.txt")); + try (InputStream strim = InflectionML.class.getResourceAsStream("/prepositions.txt")) { + prepositionDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } nounDB = new Nouns(prepositionDB); - nounDB.loadFromStream(InflectionML.class.getResourceAsStream("/nouns.txt")); + try (InputStream strim = InflectionML.class.getResourceAsStream("/nouns.txt")) { + nounDB.loadFromStream(strim); + } catch (IOException ioex) { + ioex.printStackTrace(); + } } /* @@ -1137,7 +1147,7 @@ public class InflectionString { public String toString() { if (rawString != null) return rawString; - else - return super.toString(); + + return super.toString(); } } -- cgit v1.2.3