Skip to content

Commit

Permalink
Pseudo-Merge 51fa835 address further error-prone warnings (#699)
Browse files Browse the repository at this point in the history
commit 51fa835
Author:     Gerwin Klein <lsf@jflex.de>
AuthorDate: Fri Jan 3 13:56:43 2020 +0800
Commit:     GitHub <noreply@github.com>
CommitDate: Fri Jan 3 13:56:43 2020 +0800

    address further error-prone warnings (#699)

     * make final where possible
     * avoid implicit use of platform default charset (also fixes #470)
     * Vector -> ArrayList
     * Stack -> Deque

    The charset for skeletons and graphviz dot files is UTF-8 (docs updated), for spec input/output files, Options.enconding.

Updated from target/jflex-parent-1.8.0-SNAPSHOT-sources.jar
  • Loading branch information
traviscibot committed Jan 3, 2020
1 parent f099da5 commit 2a9bddf
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 86 deletions.
8 changes: 5 additions & 3 deletions java/jflex/anttask/JFlexTask.java
Expand Up @@ -11,9 +11,11 @@
package jflex.anttask;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jflex.core.OptionUtils;
Expand Down Expand Up @@ -93,8 +95,8 @@ public void findPackageAndClass() throws IOException {
// find name of the package and class in jflex source file
packageName = null;
className = null;

try (LineNumberReader reader = new LineNumberReader(new FileReader(inputFile))) {
Reader r = Files.newBufferedReader(inputFile.toPath(), StandardCharsets.UTF_8);
try (LineNumberReader reader = new LineNumberReader(r)) {
while (className == null || packageName == null) {
String line = reader.readLine();
if (line == null) {
Expand Down
14 changes: 7 additions & 7 deletions java/jflex/core/AbstractLexScan.java
@@ -1,11 +1,12 @@
package jflex.core;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java_cup.runtime.Symbol;
import jflex.core.unicode.CharClasses;
import jflex.core.unicode.ILexScan;
Expand All @@ -22,8 +23,7 @@ public abstract class AbstractLexScan implements ILexScan {

File file;

@SuppressWarnings("JdkObsolete")
private final Stack<File> files = new Stack<>();
private final Deque<File> files = new ArrayDeque<>();

StringBuilder userCode = new StringBuilder();

Expand Down Expand Up @@ -186,15 +186,15 @@ void includeFile(String filePath) {
throw new ScannerException(file, ErrorMessages.NOT_READABLE, lexLine());
}
// check for cycle
if (files.search(f) > 0) {
if (files.contains(f)) {
throw new ScannerException(file, ErrorMessages.FILE_CYCLE, lexLine());
}
try {
lexPushStream(f);
files.push(file);
file = f;
Out.println("Including \"" + file + "\"");
} catch (FileNotFoundException e) {
} catch (IOException e) {
throw new ScannerException(file, ErrorMessages.NOT_READABLE, lexLine());
}
}
Expand Down Expand Up @@ -387,5 +387,5 @@ public boolean isColumnCount() {
protected abstract String lexText();

@SuppressWarnings("WeakerAccess") // Implemented by generated LexScan
protected abstract void lexPushStream(File f) throws FileNotFoundException;
protected abstract void lexPushStream(File f) throws IOException;
}
16 changes: 8 additions & 8 deletions java/jflex/core/LexScan.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 34 additions & 36 deletions java/jflex/core/unicode/IntCharSet.java
Expand Up @@ -168,50 +168,48 @@ public void add(Interval interval) {
for (int i = 0; i < size; i++) {
Interval elem = intervals.get(i);

if (elem.end + 1 < interval.start) {
continue;
}

if (elem.contains(interval)) {
if (DEBUG) assert invariants();
return;
}

if (elem.start > interval.end + 1) {
intervals.add(i, Interval.copyOf(interval));
if (DEBUG) assert invariants();
return;
}

if (interval.start < elem.start) {
elem.start = interval.start;
}
if (elem.end + 1 >= interval.start) {
if (elem.contains(interval)) {
if (DEBUG) assert invariants();
return;
}

if (interval.end <= elem.end) {
if (DEBUG) assert invariants();
return;
}
if (elem.start > interval.end + 1) {
intervals.add(i, Interval.copyOf(interval));
if (DEBUG) assert invariants();
return;
}

elem.end = interval.end;
if (interval.start < elem.start) {
elem.start = interval.start;
}

i++;
// delete all x with x.contains( interval.end )
while (i < size) {
Interval x = intervals.get(i);
if (x.start > elem.end + 1) {
if (interval.end <= elem.end) {
if (DEBUG) assert invariants();
return;
}

if (x.end > elem.end) {
elem.end = x.end;
elem.end = interval.end;

i++;
// delete all x with x.contains( interval.end )
while (i < size) {
Interval x = intervals.get(i);
if (x.start > elem.end + 1) {
if (DEBUG) assert invariants();
return;
}

if (x.end > elem.end) {
elem.end = x.end;
}
intervals.remove(i);
size--;
}
intervals.remove(i);
size--;
}

if (DEBUG) assert invariants();
return;
if (DEBUG) assert invariants();
return;
}
}

intervals.add(Interval.copyOf(interval));
Expand Down Expand Up @@ -612,7 +610,7 @@ Interval getFirstInterval() {
/** Iterator for enumerating the elements of this IntCharSet */
public class IntCharSetIterator implements PrimitiveIterator.OfInt {
/** Iterator over the Interval list */
private Iterator<Interval> intervalsIterator;
private final Iterator<Interval> intervalsIterator;
/** Iterator within the current Interval */
private IntervalIterator current;

Expand Down
2 changes: 1 addition & 1 deletion java/jflex/core/unicode/UnicodeProperties.java
Expand Up @@ -29,7 +29,7 @@ public class UnicodeProperties {
private static final Pattern WORD_SEP_PATTERN = Pattern.compile("[-_\\s()]");

private int maximumCodePoint;
private Map<String, IntCharSet> propertyValueIntervals = new HashMap<>();
private final Map<String, IntCharSet> propertyValueIntervals = new HashMap<>();
private String caselessMatchPartitions;
private int caselessMatchPartitionSize;
private IntCharSet caselessMatches[];
Expand Down
8 changes: 6 additions & 2 deletions java/jflex/dfa/DFA.java
Expand Up @@ -10,9 +10,11 @@
package jflex.dfa;

import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -252,7 +254,9 @@ private static boolean tableEquals(int[][] a, int[][] b) {
*/
public void writeDot(File file) {
try {
PrintWriter writer = new PrintWriter(new FileWriter(file));
PrintWriter writer =
new PrintWriter(
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
writer.println(dotFormat());
writer.close();
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion java/jflex/exceptions/SilentExit.java
Expand Up @@ -18,7 +18,7 @@
public class SilentExit extends Exception {

/** Program exit code if this exception is taken */
private int exitCode;
private final int exitCode;

/**
* SilentExit with specified program exit code.
Expand Down
2 changes: 1 addition & 1 deletion java/jflex/gui/GeneratorThread.java
Expand Up @@ -35,7 +35,7 @@ public class GeneratorThread extends Thread {
String outputDir;

/** main UI component, likes to be notified when generator finishes */
MainFrame parent;
final MainFrame parent;

/**
* Create a new GeneratorThread, but do not run it yet.
Expand Down
22 changes: 7 additions & 15 deletions java/jflex/gui/GridPanel.java
Expand Up @@ -10,7 +10,8 @@
package jflex.gui;

import java.awt.*;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;

/**
* Grid layout manager like GridLayout but with predefinable grid size.
Expand All @@ -28,7 +29,7 @@ public class GridPanel extends Panel implements Handles {
private final int hgap;
private final int vgap;

private final Vector<GridPanelConstraint> constraints = new Vector<>();
private final List<GridPanelConstraint> constraints = new ArrayList<>();
private Insets insets = new Insets(0, 0, 0, 0);

/** {@inheritDoc} */
Expand Down Expand Up @@ -62,7 +63,7 @@ public void doLayout() {
float cellHeight = size.height / rows;

for (int i = 0; i < constraints.size(); i++) {
GridPanelConstraint c = constraints.elementAt(i);
GridPanelConstraint c = constraints.get(i);

float x = cellWidth * c.x + insets.left + hgap / 2;
float y = cellHeight * c.y + insets.right + vgap / 2;
Expand Down Expand Up @@ -124,7 +125,7 @@ public Dimension getPreferredSize() {
float dx = 0;

for (int i = 0; i < constraints.size(); i++) {
GridPanelConstraint c = constraints.elementAt(i);
GridPanelConstraint c = constraints.get(i);

Dimension d = c.component.getPreferredSize();

Expand Down Expand Up @@ -168,18 +169,9 @@ public void add(int x, int y, int dx, int dy, Component c) {
add(x, y, dx, dy, FILL, c);
}

/**
* add.
*
* @param x a int.
* @param y a int.
* @param dx a int.
* @param dy a int.
* @param handle a int.
* @param c a {@link java.awt.Component} object.
*/
/** Add a component to this panel. */
public void add(int x, int y, int dx, int dy, int handle, Component c) {
super.add(c);
constraints.addElement(new GridPanelConstraint(x, y, dx, dy, handle, c));
constraints.add(new GridPanelConstraint(x, y, dx, dy, handle, c));
}
}
8 changes: 6 additions & 2 deletions java/jflex/gui/GridPanelConstraint.java
Expand Up @@ -18,8 +18,12 @@
*/
public class GridPanelConstraint {

int x, y, width, height, handle;
Component component;
final int x;
final int y;
final int width;
final int height;
final int handle;
final Component component;

/**
* Constructor for GridPanelConstraint.
Expand Down
1 change: 0 additions & 1 deletion java/jflex/gui/MainFrame.java
Expand Up @@ -28,7 +28,6 @@
*/
public final class MainFrame extends Frame implements Handles {

/** */
private static final long serialVersionUID = 3296137982410640865L;

private volatile boolean choosing;
Expand Down
2 changes: 1 addition & 1 deletion java/jflex/gui/OptionsDialog.java
Expand Up @@ -32,7 +32,7 @@ public class OptionsDialog extends Dialog {

private static final long serialVersionUID = 6807759416163314769L;

private Frame owner;
private final Frame owner;

private TextField skelFile;

Expand Down
4 changes: 2 additions & 2 deletions java/jflex/logging/Out.java
Expand Up @@ -12,9 +12,9 @@
import java.awt.TextArea;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import jflex.base.Build;
import jflex.exceptions.GeneratorException;
import jflex.l10n.ErrorMessages;
Expand Down Expand Up @@ -385,7 +385,7 @@ public static void showPosition(File file, int line) {
* @throws IOException if any error occurs
*/
private static String getLine(File file, int line) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
BufferedReader reader = Files.newBufferedReader(file.toPath(), Options.encoding);

String msg = "";

Expand Down

0 comments on commit 2a9bddf

Please sign in to comment.