8000 Fix more PMD violations by regisd · Pull Request #418 · jflex-de/jflex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix more PMD violations #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 7, 2018
8 changes: 4 additions & 4 deletions .lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# Path syntax is ant matcher https://confluence.atlassian.com/fisheye/pattern-matching-guide-298976797.html
path_classifiers:
test:
- "src/test/**"
- "src/test"
docs:
- "LICENSE*"
- "*.md"
third_party:
- "/cup/**"
- "/third_party/**"
- "/cup"
- "/third_party"
generated:
- "/jflex/src/main/java/jflex/unicode/data/**"
- "/jflex/src/main/java/jflex/unicode/data/Unicode_*.java"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;

import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
Expand All @@ -18,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import jflex.Main;
import jflex.Options;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -219,11 +222,11 @@ private void parseLexFile(File lexFile) throws MojoFailureException, MojoExecuti

Options.no_minimize = !minimize; // NOPMD
Options.no_backup = !backup; // NOPMD
if (!"pack".equals(generationMethod)) {
if (!Objects.equals("pack", generationMethod)) {
throw new MojoExecutionException("Illegal generation method: " + generationMethod);
}

if (!"".equals(encodingName)) {
if (!isNullOrEmpty(encodingName)) {
try {
Options.setEncoding(encodingName);
} catch (Exception e) {
Expand Down
23 changes: 12 additions & 11 deletions jflex-unicode-maven-plugin/src/main/java/jflex/DataFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -41,9 +42,9 @@ public void scan(URL url, UnicodeVersion version) throws IOException {
try (Reader reader = new InputStreamReader(url.openStream(), "UTF-8")) {
// Before Unicode 3.1, PropList-X.X.X.txt used a different format.
// Before Unicode 2.0, PropList-X.X.X.txt did not exist.
if (version.majorMinorVersion.equals("2.0")
|| version.majorMinorVersion.equals("2.1")
|| version.majorMinorVersion.equals("3.0")) {
if (Objects.equals(version.majorMinorVersion, "2.0")
|| Objects.equals(version.majorMinorVersion, "2.1")
|| Objects.equals(version.majorMinorVersion, "3.0")) {
ArchaicPropListScanner scanner = new ArchaicPropListScanner(reader, version);
scanner.scan();
} else {
Expand All @@ -69,10 +70,10 @@ public void scan(URL url, UnicodeVersion version) throws IOException {
// From Unicode 5.0 onward, the default Script property value is "Unknown".
// Prior to Unicode 3.1, Scripts(-X.X.X).txt did not exist.
String defaultPropertyValue = "Unknown";
if (version.majorMinorVersion.equals("3.1")
|| version.majorMinorVersion.equals("3.2")
|| version.majorMinorVersion.equals("4.0")
|| version.majorMinorVersion.equals("4.1")) {
if (Objects.equals(version.majorMinorVersion, "3.1")
|| Objects.equals(version.majorMinorVersion, "3.2")
|| Objects.equals(version.majorMinorVersion, "4.0")
|| Objects.equals(version.majorMinorVersion, "4.1")) {
defaultPropertyValue = "Common";
}
try (Reader reader = new InputStreamReader(url.openStream(), "UTF-8")) {
Expand All @@ -99,9 +100,9 @@ public void scan(URL url, UnicodeVersion version) throws IOException {
try (Reader reader = new InputStreamReader(url.openStream(), "UTF-8")) {
// Before Unicode 3.1, Blocks-X.txt used a different format.
// Before Unicode 2.0, Blocks-X.txt did not exist.
if (version.majorMinorVersion.equals("2.0")
|| version.majorMinorVersion.equals("2.1")
|| version.majorMinorVersion.equals("3.0")) {
if (Objects.equals(version.majorMinorVersion, "2.0")
|| Objects.equals(version.majorMinorVersion, "2.1")
|| Objects.equals(version.majorMinorVersion, "3.0")) {
ArchaicBlocksScanner scanner = new ArchaicBlocksScanner(reader, version);
scanner.scan();
} else {
Expand All @@ -118,7 +119,7 @@ public void scan(URL url, UnicodeVersion version) throws IOException {
try (Reader reader = new InputStreamReader(url.openStream(), "UTF-8")) {
// In Unicode 3.0, LineBreak-X.txt used a different format.
// Before Unicode 3.0, LineBreak-X.txt did not exist.
if (version.majorMinorVersion.equals("3.0")) {
if (Objects.equals(version.majorMinorVersion, "3.0")) {
ArchaicLineBreakScanner scanner = new ArchaicLineBreakScanner(reader, version);
scanner.scan();
} else {
Expand Down
29 changes: 24 additions & 5 deletions jflex-unicode-maven-plugin/src/main/java/jflex/NamedRange.java
10000
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package jflex;

import java.util.Objects;

/** Internal-use class to represent code point intervals. */
public class NamedRange implements Comparable<NamedRange> {

int start;
int end;
String name;
Expand All @@ -17,11 +20,27 @@ public class NamedRange implements Comparable<NamedRange> {
this.name = name;
}

public boolean equals(NamedRange other) {
return null != other
&& (start == other.start
&& end == other.end
&& ((null == name && null == other.name) || (null != name && name.equals(other.name))));
@Override
public boolean equals(Object obj) {
if (!(obj instanceof NamedRange)) {
return false;
}
NamedRange other = (NamedRange) obj;
return start == other.start && end == other.end && Objects.equals(name, other.name);
}

@Override
public int hashCode() {
int h = 1;
h *= 1_000_003;
h ^= start;
h *= 1_000_003;
h ^= end;
if (name != null) {
h *= 1_000_003;
h ^= name.hashCode();
}
return h;
}

public int compareTo(NamedRange other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
Expand Down Expand Up @@ -302,7 +303,7 @@ void addInterval(String propName, int startCodePoint, int endCodePoint) {
// U+4E00 is listed in UnicodeData-1.1.5.txt as having the "Lo" property
// value, as are the previous code points, so to include
// [ U+4E00 - U+9FFF ], this interval should be extended to U+9FFF.
if (range.end == 0x4E00 && majorMinorVersion.equals("1.1")) {
if (range.end == 0x4E00 && Objects.equals(majorMinorVersion, "1.1")) {
range.end = 0x9FFF;
}
intervals.add(new NamedRangeSet(range));
Expand Down Expand Up @@ -355,7 +356,8 @@ void addInterval(String propName, String propValue, int startCodePoint, int endC
List<NamedRange> ranges = removeSurrogates(startCodePoint, endCodePoint);
if (!ranges.isEmpty()) {
String canonicalValue = propName + '=' + propValue;
if (propName.equals(NORMALIZED_GENERAL_CATEGORY) || propName.equals(NORMALIZED_SCRIPT)) {
if (Objects.equals(propName, NORMALIZED_GENERAL_CATEGORY)
|| Objects.equals(propName, NORMALIZED_SCRIPT)) {
canonicalValue = propValue;
}
NamedRangeSet intervals = propertyValueIntervals.get(canonicalValue);
Expand All @@ -374,7 +376,9 @@ void addInterval(String propName, String propValue, int startCodePoint, int endC
// FE70; FEFF; Arabic Presentation Forms-B
// ...
// FEFF; FEFF; Specials
if (range.start == 0xFE70 && range.end == 0xFEFF && majorMinorVersion.equals("2.0")) {
if (range.start == 0xFE70
&& range.end == 0xFEFF
&& Objects.equals(majorMinorVersion, "2.0")) {
range.end = 0xFEFE;
}
intervals.add(new NamedRangeSet(range));
Expand All @@ -388,7 +392,7 @@ void addInterval(String propName, String propValue, int startCodePoint, int endC

// Initial letters of two-letter General Category property values
// should be put on the used property values list
if (propName.equals(NORMALIZED_GENERAL_CATEGORY) && propValue.length() == 2) {
if (Objects.equals(propName, NORMALIZED_GENERAL_CATEGORY) && propValue.length() == 2) {
String firstLetter = propValue.substring(0, 1);
usedValues.add(firstLetter);
}
Expand Down Expand Up @@ -493,7 +497,7 @@ SortedMap<String, String> getUsedPropertyValueAliases() {
SortedMap<String, String> usedPropertyValueAliases = new TreeMap<>();
for (String binaryProperty : usedBinaryProperties) {
for (String nameAlias : getPropertyAliases(binaryProperty)) {
if (!nameAlias.equals(binaryProperty)) {
if (!Objects.equals(nameAlias, binaryProperty)) {
usedPropertyValueAliases.put(nameAlias, binaryProperty);
}
}
Expand All @@ -509,10 +513,11 @@ SortedMap<String, String> getUsedPropertyValueAliases() {
String canonicalValue = propName + '=' + propValue;

// Add value-only aliases for General Category and Script properties.
if (propName.equals(NORMALIZED_SCRIPT) || propName.equals(NORMALIZED_GENERAL_CATEGORY)) {
if (Objects.equals(propName, NORMALIZED_SCRIPT)
|| Objects.equals(propName, NORMALIZED_GENERAL_CATEGORY)) {
canonicalValue = propValue;
for (String valueAlias : getPropertyValueAliases(propName, propValue)) {
if (!valueAlias.equals(propValue)) {
if (!Objects.equals(valueAlias, propValue)) {
usedPropertyValueAliases.put(valueAlias, propValue);
}
}
Expand All @@ -523,9 +528,10 @@ SortedMap<String, String> getUsedPropertyValueAliases() {
// all possible alias combinations, exclude the one that is the same
// as the full property name + full property value, unless the
// property is General Category or Script.
if (propName.equals(NORMALIZED_SCRIPT)
|| propName.equals(NORMALIZED_GENERAL_CATEGORY)
|| !(nameAlias.equals(propName) && valueAlias.equals(propValue))) {
if (Objects.equals(propName, NORMALIZED_SCRIPT)
|| Objects.equals(propName, NORMALIZED_GENERAL_CATEGORY)
|| !(Objects.equals(nameAlias, propName)
&& Objects.equals(valueAlias, propValue))) {
String alias = nameAlias + '=' + valueAlias;
usedPropertyValueAliases.put(alias, canonicalValue);
}
Expand Down
4 changes: 3 additions & 1 deletion jflex/src/main/java/jflex/Action.java
< 3D11 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package jflex;

import java.util.Objects;

/**
* Encapsulates an action in the specification.
*
Expand Down Expand Up @@ -116,7 +118,7 @@ public String toString() {
*/
public boolean isEquiv(Action a) {
return this == a
|| (this.content.equals(a.content)
|| (Objects.equals(this.content, a.content)
&& this.kind == a.kind
&& this.len == a.len
&& this.entryState == a.entryState);
Expand Down
7 changes: 4 additions & 3 deletions jflex/src/main/java/jflex/CharClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Character Classes.
Expand Down Expand Up @@ -129,15 +130,15 @@ public void makeClass(IntCharSet set, boolean caseless) {
for (int i = 0; i < oldSize; i++) {
IntCharSet x = classes.get(i);

if (x.equals(set)) return;
if (Objects.equals(x, set)) return;

IntCharSet and = x.and(set);

if (and.containsElements()) {
if (x.equals(and)) {
if (Objects.equals(x, and)) {
set.sub(and);
continue;
} else if (set.equals(and)) {
} else if (Objects.equals(set, and)) {
x.sub(and);
classes.add(and);
if (DEBUG) {
Expand Down
5 changes: 3 additions & 2 deletions jflex/src/main/java/jflex/DFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Deterministic finite automata representation in JFlex. Contains minimization algorithm.
Expand Down Expand Up @@ -173,7 +174,7 @@ public String toString() {
if (isFinal[i]) {
result.append("[FINAL");
String l = action[i].lookString();
if (!l.equals("")) {
if (!Objects.equals(l, "")) {
result.append(", ");
result.append(l);
}
Expand Down Expand Up @@ -255,7 +256,7 @@ public void checkActions(LexScan scanner, LexParse parser) {
EOFActions eofActions = parser.getEOFActions();

for (Action a : scanner.actions)
if (!a.equals(usedActions.get(a)) && !eofActions.isEOFAction(a))
if (!Objects.equals(a, usedActions.get(a)) && !eofActions.isEOFAction(a))
Out.warning(scanner.file, ErrorMessages.NEVER_MATCH, a.priority - 1, -1);
}

Expand Down
3 changes: 2 additions & 1 deletion jflex/src/main/java/jflex/IntCharSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import jflex.unicode.UnicodeProperties;

/**
Expand Down Expand Up @@ -212,7 +213,7 @@ public boolean equals(Object o) {
}
IntCharSet set = (IntCharSet) o;

return intervals.equals(set.intervals);
return Objects.equals(intervals, set.intervals);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions jflex/src/main/java/jflex/Macros.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

package jflex;

import static jflex.ErrorMessages.MACRO_CYCLE;
import static jflex.ErrorMessages.get;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* Symbol table and expander for macros.
Expand Down Expand Up @@ -156,8 +160,7 @@ private RegExp expandMacro(String name, RegExp definition) throws MacroException
case sym.MACROUSE:
String usename = (String) ((RegExp1) definition).content;

if (name.equals(usename))
throw new MacroException(ErrorMessages.get(ErrorMessages.MACRO_CYCLE, name));
if (Objects.equals(name, usename)) throw new MacroException(get(MACRO_CYCLE, name));

RegExp usedef = getDefinition(usename);

Expand Down
Loading
0