From 8334e3139ce7aa54e26d21fc9adead7349c0c31e Mon Sep 17 00:00:00 2001 From: Bruce Collie Date: Thu, 26 Oct 2023 12:23:17 +0100 Subject: [PATCH] Apply "silent code cleanup" from IntelliJ (#3755) This PR applies all automatic cleanups that IntelliJ is confident enough to apply silently with no further user input; a rough summary of the different kinds of change are: * Removal of redundant casts (`T t = (T) v` where `v` already has type `T`). * Removal of unnecessary calls to `toString()` * Insertion of `final` where possible * Collapsing of redundant boolean conditions `if (cond) return true else return false` * Syntactic fixes (`;;` etc.) * Use of `StandardCharsets.UTF_8` to simplify exception checks when encoding strings * Removal of redundant explicit key checks when removing values from hashmaps As ever, I'm happy to bikeshed these changes - I can redo the analysis and disable some subset of the checks if anyone has objections to the specific results we get. ~~To avoid merge conflicts, this PR is based on #3746 and should only be merged when that PR is merged.~~ --------- Co-authored-by: rv-jenkins --- .../kframework/kore/convertors/BaseTest.java | 2 +- .../com/davekoelle/AlphanumComparator.java | 4 ++-- .../kframework/backend/kore/ModuleToKORE.java | 13 +++---------- .../kframework/compile/AddSortInjections.java | 2 +- .../java/org/kframework/compile/Backend.java | 4 ++-- .../org/kframework/compile/CloseCells.java | 18 +++++++++--------- .../ComputeTransitiveFunctionDependencies.java | 2 +- .../compile/ConvertDataStructureToLookup.java | 6 +++--- .../DeconstructIntegerAndFloatLiterals.java | 4 ++-- .../org/kframework/compile/ExpandMacros.java | 4 ++-- .../org/kframework/compile/FloatBuiltin.java | 9 +++------ .../GenerateSentencesFromConfigDecl.java | 6 +++--- .../compile/GenerateSortPredicateRules.java | 6 +++--- .../compile/GenerateSortPredicateSyntax.java | 2 +- .../compile/GenerateSortProjections.java | 2 +- .../kframework/compile/GuardOrPatterns.java | 4 ++-- .../org/kframework/compile/PropagateMacro.java | 2 +- .../org/kframework/compile/RefreshRules.java | 2 +- .../org/kframework/compile/ResolveAnonVar.java | 4 ++-- .../kframework/compile/ResolveContexts.java | 4 ++-- .../compile/ResolveFreshConfigConstants.java | 2 +- .../compile/ResolveFreshConstants.java | 8 ++++---- .../compile/ResolveFunctionWithConfig.java | 5 +---- .../kframework/compile/ResolveIOStreams.java | 2 +- .../compile/ResolveSemanticCasts.java | 4 ++-- .../java/org/kframework/compile/SortCells.java | 8 ++++---- .../kframework/compile/checks/CheckAtt.java | 4 ++-- .../checks/CheckConfigurationCells.java | 2 +- .../compile/checks/CheckListDecl.java | 2 +- .../compile/checks/CheckRHSVariables.java | 2 +- .../compile/checks/CheckSortTopUniqueness.java | 2 +- .../java/org/kframework/kdep/KDepFrontEnd.java | 2 +- .../main/java/org/kframework/kil/Lexical.java | 6 ++---- .../java/org/kframework/kil/NonTerminal.java | 6 ++---- .../java/org/kframework/kil/Production.java | 7 ++----- .../java/org/kframework/kil/SortSynonym.java | 4 +--- .../org/kframework/kil/StringSentence.java | 4 ++-- .../java/org/kframework/kil/SyntaxLexical.java | 4 +--- .../main/java/org/kframework/kil/Terminal.java | 4 +--- .../main/java/org/kframework/kil/UserList.java | 4 +--- .../kframework/kompile/CompiledDefinition.java | 4 ++-- .../java/org/kframework/kompile/Kompile.java | 15 ++++++--------- .../kframework/kore/convertors/KILtoKORE.java | 2 +- .../ksearchpattern/KSearchPatternFrontEnd.java | 2 +- .../org/kframework/lsp/KWorkspaceService.java | 2 +- .../org/kframework/main/GlobalOptions.java | 6 +++--- .../java/org/kframework/parser/InputModes.java | 2 +- .../org/kframework/parser/ParserUtils.java | 2 +- .../kframework/parser/binary/BinaryParser.java | 6 +++--- .../parser/inner/RuleGrammarGenerator.java | 8 ++++---- .../inner/disambiguation/TypeInferencer.java | 8 ++------ .../parser/inner/kernel/KSyntax2Bison.java | 6 +++--- .../parser/inner/kernel/Scanner.java | 5 +++-- .../org/kframework/parser/json/JsonParser.java | 13 +++---------- .../org/kframework/unparser/AddBrackets.java | 9 ++------- .../java/org/kframework/unparser/KPrint.java | 2 +- .../java/org/kframework/unparser/ToBinary.java | 6 +++--- .../java/org/kframework/unparser/ToLatex.java | 2 +- .../java/org/kframework/utils/ColorUtil.java | 6 +++--- .../kframework/utils/IndentingFormatter.java | 4 ++-- .../java/org/kframework/utils/Stopwatch.java | 2 +- .../org/kframework/utils/file/FileUtil.java | 2 +- .../org/kframework/utils/file/JarInfo.java | 12 ++++-------- .../kframework/utils/inject/GraphInjector.java | 3 ++- .../utils/inject/JCommanderModule.java | 2 +- .../kframework/utils/inject/SimpleScope.java | 2 +- .../compile/ConstantFoldingTest.java | 2 +- .../GenerateSentencesFromConfigDeclTest.java | 2 +- .../parser/inner/RuleGrammarTest.java | 2 +- .../disambiguation/AddEmptyListsTest.java | 2 +- .../parser/json/JsonSerializationTests.java | 3 ++- .../kframework/unparser/AddBracketsTest.java | 2 +- .../org/kframework/unparser/KPrintTest.java | 7 ++----- .../java/org/kframework/compile/LabelInfo.java | 7 ++----- .../java/org/kframework/kore/AttCompare.java | 4 ++-- .../main/java/org/kframework/kore/FindK.java | 2 +- .../src/main/java/org/kframework/utils/OS.java | 2 +- .../java/org/kframework/utils/StringUtil.java | 2 +- .../utils/errorsystem/KException.java | 16 ++++++++-------- .../org/kframework/kore/InterfaceTest.java | 2 +- 80 files changed, 158 insertions(+), 212 deletions(-) diff --git a/k-distribution/src/test/java/org/kframework/kore/convertors/BaseTest.java b/k-distribution/src/test/java/org/kframework/kore/convertors/BaseTest.java index 9d4024b3de4..7cebecbbefe 100644 --- a/k-distribution/src/test/java/org/kframework/kore/convertors/BaseTest.java +++ b/k-distribution/src/test/java/org/kframework/kore/convertors/BaseTest.java @@ -54,7 +54,7 @@ protected File testResource(String baseName) { } // WARNING: only use this after checking the results manually - private static boolean forceFixAssertionFiles = false; + private static final boolean forceFixAssertionFiles = false; private void testConversion(Function parse) throws IOException { File kilDefinitionFile = testResource("/convertor-tests/" + name.getMethodName() + ".k"); diff --git a/kernel/src/main/java/com/davekoelle/AlphanumComparator.java b/kernel/src/main/java/com/davekoelle/AlphanumComparator.java index 9763194f9d6..7bb24b20402 100644 --- a/kernel/src/main/java/com/davekoelle/AlphanumComparator.java +++ b/kernel/src/main/java/com/davekoelle/AlphanumComparator.java @@ -83,8 +83,8 @@ public int compare(String o1, String o2) { return 0; } - String s1 = (String)o1; - String s2 = (String)o2; + String s1 = o1; + String s2 = o2; int thisMarker = 0; int thatMarker = 0; diff --git a/kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java b/kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java index e9b27b88f53..fda179960ff 100644 --- a/kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java +++ b/kernel/src/main/java/org/kframework/backend/kore/ModuleToKORE.java @@ -953,7 +953,7 @@ private void convertRule(RuleOrClaim rule, int ruleIndex, boolean heatCoolEq, St boolean constructorBased = constructorChecks.isConstructorBased(left); RuleInfo ruleInfo = getRuleInfo(rule, heatCoolEq, topCellSortStr); sb.append("// "); - sb.append(rule.toString()); + sb.append(rule); sb.append("\n"); if (ruleInfo.isCeil && options.disableCeilSimplificationRules) { return; @@ -1561,11 +1561,7 @@ private Att addKoreAttributes(Production prod, SetMultimap functio colors.append(conn).append(att.get(Att.COLOR())); conn = ","; } - if (format.charAt(i) == '%') { - escape = true; - } else { - escape = false; - } + escape = format.charAt(i) == '%'; } att = att.add(Att.COLORS(), colors.toString()); } @@ -1608,10 +1604,7 @@ private KList getAssoc(scala.collection.Set> assoc, KLabel klab } private boolean isFunction(Production prod) { - if (!prod.att().contains(Att.FUNCTION())) { - return false; - } - return true; + return prod.att().contains(Att.FUNCTION()); } // Assume that there is no quantifiers diff --git a/kernel/src/main/java/org/kframework/compile/AddSortInjections.java b/kernel/src/main/java/org/kframework/compile/AddSortInjections.java index 3cb2a329ca1..588a9fc9ea7 100644 --- a/kernel/src/main/java/org/kframework/compile/AddSortInjections.java +++ b/kernel/src/main/java/org/kframework/compile/AddSortInjections.java @@ -50,7 +50,7 @@ public class AddSortInjections { private final ConfigurationInfoFromModule configurationInfo; private int freshSortParamCounter = 0; - private Set sortParams = new HashSet<>(); + private final Set sortParams = new HashSet<>(); public static final String SORTPARAM_NAME = "#SortParam"; private boolean isLHS = false; diff --git a/kernel/src/main/java/org/kframework/compile/Backend.java b/kernel/src/main/java/org/kframework/compile/Backend.java index 51af8e75d36..a5323023217 100644 --- a/kernel/src/main/java/org/kframework/compile/Backend.java +++ b/kernel/src/main/java/org/kframework/compile/Backend.java @@ -17,13 +17,13 @@ */ public interface Backend { - public class Holder { + class Holder { public CompiledDefinition def; public Holder(CompiledDefinition def) { this.def = def; } - }; + } void accept(Holder def); diff --git a/kernel/src/main/java/org/kframework/compile/CloseCells.java b/kernel/src/main/java/org/kframework/compile/CloseCells.java index a0d17fa2e7b..0c433c5211a 100644 --- a/kernel/src/main/java/org/kframework/compile/CloseCells.java +++ b/kernel/src/main/java/org/kframework/compile/CloseCells.java @@ -78,7 +78,7 @@ public synchronized Sentence close(Sentence s) { } private int counter = 0; - private Set vars = Sets.newHashSet(); + private final Set vars = Sets.newHashSet(); private KRewrite rhsOf = null; void resetVars() { @@ -173,10 +173,10 @@ protected KApply closeCell(KApply cell) { } else { if (requiredLeft.equals(requiredRight)) { throw KEMException.compilerError("Closed parent cell missing " + - "required children " + requiredLeft.toString(), cell); + "required children " + requiredLeft, cell); } else { throw KEMException.compilerError("Closed parent cell missing " + - "required children " + requiredLeft.toString() + " on left hand side and " + requiredRight.toString() + " on right hand side.", cell); + "required children " + requiredLeft + " on left hand side and " + requiredRight + " on right hand side.", cell); } } } @@ -206,7 +206,7 @@ protected KApply closeCell(KApply cell) { // Is a leaf cell if (contents.size() != 1) { throw KEMException.criticalError("Leaf cells should contain exactly 1 body term," - + " but there are " + contents.size() + " in " + cell.toString()); + + " but there are " + contents.size() + " in " + cell); } if (!openLeft && !openRight) { @@ -214,7 +214,7 @@ protected KApply closeCell(KApply cell) { } if (rhsOf != null) { throw KEMException.criticalError("Leaf cells on right hand side of a rewrite" + - " may not be open, but " + cell.toString() + " is right of " + rhsOf.toString()); + " may not be open, but " + cell + " is right of " + rhsOf.toString()); } K body = contents.get(0); @@ -244,14 +244,14 @@ protected KApply closeCell(KApply cell) { KLabel closeOperator = sortInfo.getCloseOperator(cellType); if (closeOperator == null) { throw KEMException.criticalError("No operator registered for closing cells of sort " - + cellType.toString() + " when closing cell " + cell.toString()); + + cellType + " when closing cell " + cell); } LabelInfo.AssocInfo info = labelInfo.getAssocInfo(closeOperator); if (!info.isAssoc() && openLeft && openRight) { throw KEMException.criticalError( - "Ambiguity closing a cell. Operator " + closeOperator.toString() - + " for sort " + cellType.toString() + " is not associative, " - + "but the cell has ellipses on both sides " + cell.toString()); + "Ambiguity closing a cell. Operator " + closeOperator + + " for sort " + cellType + " is not associative, " + + "but the cell has ellipses on both sides " + cell); } if (info.isComm() && (!openLeft || !openRight || info.isAssoc())) { openLeft = false; diff --git a/kernel/src/main/java/org/kframework/compile/ComputeTransitiveFunctionDependencies.java b/kernel/src/main/java/org/kframework/compile/ComputeTransitiveFunctionDependencies.java index ba0b95868f1..f11ee68875e 100644 --- a/kernel/src/main/java/org/kframework/compile/ComputeTransitiveFunctionDependencies.java +++ b/kernel/src/main/java/org/kframework/compile/ComputeTransitiveFunctionDependencies.java @@ -106,5 +106,5 @@ public Set ancestors(Set labels) { return ancestors(labels, dependencies); } - private DirectedGraph dependencies; + private final DirectedGraph dependencies; } diff --git a/kernel/src/main/java/org/kframework/compile/ConvertDataStructureToLookup.java b/kernel/src/main/java/org/kframework/compile/ConvertDataStructureToLookup.java index 6f0759b24a3..e07f5ec062a 100644 --- a/kernel/src/main/java/org/kframework/compile/ConvertDataStructureToLookup.java +++ b/kernel/src/main/java/org/kframework/compile/ConvertDataStructureToLookup.java @@ -79,8 +79,8 @@ public class ConvertDataStructureToLookup { - private Set state = new HashSet<>(); - private Multiset vars = HashMultiset.create(); + private final Set state = new HashSet<>(); + private final Multiset vars = HashMultiset.create(); void reset() { state.clear(); @@ -223,7 +223,7 @@ private Stream getSortedLookups() { } } } - }; + } List topologicalSorted = mutable(TopologicalSort.tsort(immutable(edges)).toList()); return state.stream().sorted((k1, k2) -> (topologicalSorted.indexOf(k1) - topologicalSorted.indexOf(k2))); } diff --git a/kernel/src/main/java/org/kframework/compile/DeconstructIntegerAndFloatLiterals.java b/kernel/src/main/java/org/kframework/compile/DeconstructIntegerAndFloatLiterals.java index 87d1e4473c4..d66152214a0 100644 --- a/kernel/src/main/java/org/kframework/compile/DeconstructIntegerAndFloatLiterals.java +++ b/kernel/src/main/java/org/kframework/compile/DeconstructIntegerAndFloatLiterals.java @@ -28,8 +28,8 @@ */ public class DeconstructIntegerAndFloatLiterals { - private Set state = new HashSet<>(); - private Set vars = new HashSet<>(); + private final Set state = new HashSet<>(); + private final Set vars = new HashSet<>(); void reset() { state.clear(); diff --git a/kernel/src/main/java/org/kframework/compile/ExpandMacros.java b/kernel/src/main/java/org/kframework/compile/ExpandMacros.java index f4f39e35f5c..d860de110cf 100644 --- a/kernel/src/main/java/org/kframework/compile/ExpandMacros.java +++ b/kernel/src/main/java/org/kframework/compile/ExpandMacros.java @@ -128,7 +128,7 @@ private boolean isMacro(Att att, boolean reverse) { return att.contains(Att.ALIAS_REC()) || att.contains(Att.ALIAS()) || (!reverse && (att.contains(Att.MACRO()) || att.contains(Att.MACRO_REC()))); } - private Set vars = new HashSet<>(); + private final Set vars = new HashSet<>(); void resetVars() { vars.clear(); @@ -250,7 +250,7 @@ private K applyMacros(T k, List rules, Function superA final Map subst = new HashMap<>(); if (match(subst, left, applied, r) && (r.att().contains(Att.MACRO_REC()) || r.att().contains(Att.ALIAS_REC()) || !appliedRules.contains(r))) { if (cover) { - if (!r.att().contains(Att.UNIQUE_ID())) System.out.println(r.toString()); + if (!r.att().contains(Att.UNIQUE_ID())) System.out.println(r); coverage.println(r.att().get(Att.UNIQUE_ID())); } Set oldAppliedRules = appliedRules; diff --git a/kernel/src/main/java/org/kframework/compile/FloatBuiltin.java b/kernel/src/main/java/org/kframework/compile/FloatBuiltin.java index e70f841c7e0..026c5b2c04c 100644 --- a/kernel/src/main/java/org/kframework/compile/FloatBuiltin.java +++ b/kernel/src/main/java/org/kframework/compile/FloatBuiltin.java @@ -14,7 +14,7 @@ public class FloatBuiltin { /* Token cache */ - private static Map, FloatBuiltin> tokenCache = new HashMap<>(); + private static final Map, FloatBuiltin> tokenCache = new HashMap<>(); /** * Returns a {@link FloatBuiltin} representing the given {@link BigFloat} value @@ -73,7 +73,7 @@ private FloatBuiltin(BigFloat value, int exponent) { this.exponent = exponent; } - private static Pattern precisionAndExponent = Pattern.compile("(.*)[pP](\\d+)[xX](\\d+)"); + private static final Pattern precisionAndExponent = Pattern.compile("(.*)[pP](\\d+)[xX](\\d+)"); public static Pair parseKFloat(String s) { try { Matcher m = precisionAndExponent.matcher(s); @@ -187,10 +187,7 @@ public boolean equals(Object object) { if (!value.equals(other.value)) { return false; } - if (exponent != other.exponent) { - return false; - } - return true; + return exponent == other.exponent; } @Override diff --git a/kernel/src/main/java/org/kframework/compile/GenerateSentencesFromConfigDecl.java b/kernel/src/main/java/org/kframework/compile/GenerateSentencesFromConfigDecl.java index 2f40bc08d47..8b7273f7c87 100644 --- a/kernel/src/main/java/org/kframework/compile/GenerateSentencesFromConfigDecl.java +++ b/kernel/src/main/java/org/kframework/compile/GenerateSentencesFromConfigDecl.java @@ -277,7 +277,7 @@ public K apply(KToken k) { }.apply(leafContents), h.sentences); } - private static KVariable INIT = KVariable("Init", Att.empty().add(Sort.class, Sorts.Map())); + private static final KVariable INIT = KVariable("Init", Att.empty().add(Sort.class, Sorts.Map())); /** * Generates the sentences associated with a particular cell. @@ -398,8 +398,8 @@ private static Tuple4, Sort, K, Boolean> computeSentencesOfWellFor fragmentItems.add(NonTerminal(childOptSort)); sentences.add(Production(Seq(), childOptSort, List(NonTerminal(childSort)))); - if (!m.definedKLabels().contains(KLabel("no"+childSort.toString()))) { - sentences.add(Production(KLabel("no"+childSort.toString()), childOptSort, List(Terminal("no"+childSort.toString())), + if (!m.definedKLabels().contains(KLabel("no" + childSort))) { + sentences.add(Production(KLabel("no" + childSort), childOptSort, List(Terminal("no" + childSort)), Att().add(Att.CELL_OPT_ABSENT(),Sort.class,childSort))); } } diff --git a/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateRules.java b/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateRules.java index 5271f25a578..925f63ec8c8 100644 --- a/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateRules.java +++ b/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateRules.java @@ -49,11 +49,11 @@ public Module gen(Module mod) { private Stream gen(Sort sort) { if (sort.equals(Sorts.K())) { - return Stream.of(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); + return Stream.of(Rule(KRewrite(KApply(KLabel("is" + sort), KVariable("K")), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); } else { List res = new ArrayList<>(); - res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable(sort.name(), Att().add(Sort.class, sort))), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); - res.add(Rule(KRewrite(KApply(KLabel("is" + sort.toString()), KVariable("K")), BooleanUtils.FALSE), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add(Att.OWISE()))); + res.add(Rule(KRewrite(KApply(KLabel("is" + sort), KVariable(sort.name(), Att().add(Sort.class, sort))), BooleanUtils.TRUE), BooleanUtils.TRUE, BooleanUtils.TRUE)); + res.add(Rule(KRewrite(KApply(KLabel("is" + sort), KVariable("K")), BooleanUtils.FALSE), BooleanUtils.TRUE, BooleanUtils.TRUE, Att().add(Att.OWISE()))); return res.stream(); } } diff --git a/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateSyntax.java b/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateSyntax.java index 327dabcbb93..bbc405f8de1 100644 --- a/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateSyntax.java +++ b/kernel/src/main/java/org/kframework/compile/GenerateSortPredicateSyntax.java @@ -34,7 +34,7 @@ public Module gen(Module mod) { public Set gen(Module mod, Sort sort) { Production prod = Production(KLabel("is" + sort.toString()), Sorts.Bool(), - Seq(Terminal("is" + sort.toString()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), + Seq(Terminal("is" + sort), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Att.FUNCTION()).add(Att.TOTAL()).add(Att.PREDICATE(), Sort.class, sort)); if (!mod.productions().contains(prod)) return Collections.singleton(prod); diff --git a/kernel/src/main/java/org/kframework/compile/GenerateSortProjections.java b/kernel/src/main/java/org/kframework/compile/GenerateSortProjections.java index 5e58c2eddb0..89ff228a0e0 100644 --- a/kernel/src/main/java/org/kframework/compile/GenerateSortProjections.java +++ b/kernel/src/main/java/org/kframework/compile/GenerateSortProjections.java @@ -69,7 +69,7 @@ public Stream gen(Sort sort) { } Production prod = Production(lbl, sort, Seq(Terminal(lbl.name()), Terminal("("), NonTerminal(Sorts.K()), Terminal(")")), Att().add(Att.FUNCTION()).add(Att.PROJECTION())); if (cover) { - KLabel sideEffectLbl = KLabel("sideEffect:" + sort.toString()); + KLabel sideEffectLbl = KLabel("sideEffect:" + sort); Production sideEffect = Production(sideEffectLbl, sort, Seq(Terminal(sideEffectLbl.name()), Terminal("("), NonTerminal(Sorts.K()), Terminal(","), NonTerminal(sort), Terminal(")")), Att().add(Att.FUNCTION())); Rule sideEffectR = Rule(KRewrite(KApply(sideEffectLbl, KVariable("K2", Att.empty().add(Sort.class, Sorts.K())), var), var), BooleanUtils.TRUE, BooleanUtils.TRUE); return stream(Set(prod, r, sideEffect, sideEffectR)); diff --git a/kernel/src/main/java/org/kframework/compile/GuardOrPatterns.java b/kernel/src/main/java/org/kframework/compile/GuardOrPatterns.java index 24e0f94f279..d15b075f20d 100644 --- a/kernel/src/main/java/org/kframework/compile/GuardOrPatterns.java +++ b/kernel/src/main/java/org/kframework/compile/GuardOrPatterns.java @@ -18,7 +18,7 @@ public class GuardOrPatterns { - private Set vars = new HashSet<>(); + private final Set vars = new HashSet<>(); void resetVars() { vars.clear(); @@ -47,7 +47,7 @@ private Context resolve(Module m, Context context) { } public K resolveK(Module m, K k) { - resetVars();; + resetVars(); gatherVars(k); return transform(k, m); } diff --git a/kernel/src/main/java/org/kframework/compile/PropagateMacro.java b/kernel/src/main/java/org/kframework/compile/PropagateMacro.java index c41d1cccd6e..7eeb05b5432 100644 --- a/kernel/src/main/java/org/kframework/compile/PropagateMacro.java +++ b/kernel/src/main/java/org/kframework/compile/PropagateMacro.java @@ -15,7 +15,7 @@ public record PropagateMacro(Module m) { public Sentence propagate(Sentence s) { - if (s instanceof Rule && m.ruleLhsHasMacroKLabel((Rule) s) && !((Rule) s).att().contains(Att.SIMPLIFICATION())) { + if (s instanceof Rule && m.ruleLhsHasMacroKLabel((Rule) s) && !s.att().contains(Att.SIMPLIFICATION())) { Att macroAtt = m.attributesFor().apply(m.matchKLabel((Rule) s)); return Rule.apply(((Rule) s).body(), ((Rule) s).requires(), ((Rule) s).ensures(), s.att().add(macroAtt.getMacro().get())); } diff --git a/kernel/src/main/java/org/kframework/compile/RefreshRules.java b/kernel/src/main/java/org/kframework/compile/RefreshRules.java index 5f0a0f5c4b2..d7b6f5622f2 100644 --- a/kernel/src/main/java/org/kframework/compile/RefreshRules.java +++ b/kernel/src/main/java/org/kframework/compile/RefreshRules.java @@ -28,7 +28,7 @@ public class RefreshRules { private final Set avoidVars; private int counter = 0; - private Map vars = new HashMap<>(); + private final Map vars = new HashMap<>(); public RefreshRules(Set avoidVars) { this.avoidVars = avoidVars; diff --git a/kernel/src/main/java/org/kframework/compile/ResolveAnonVar.java b/kernel/src/main/java/org/kframework/compile/ResolveAnonVar.java index a19cd31f644..bfaef719619 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveAnonVar.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveAnonVar.java @@ -35,7 +35,7 @@ public static boolean isAnonVarOrNamedAnonVar(KVariable var) { } - private Set vars = new HashSet<>(); + private final Set vars = new HashSet<>(); void resetVars() { vars.clear(); @@ -75,7 +75,7 @@ private ContextAlias resolve(ContextAlias context) { } public K resolveK(K k) { - resetVars();; + resetVars(); gatherVars(k); return transform(k); } diff --git a/kernel/src/main/java/org/kframework/compile/ResolveContexts.java b/kernel/src/main/java/org/kframework/compile/ResolveContexts.java index 3c5ade584ba..ba21995981b 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveContexts.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveContexts.java @@ -91,8 +91,8 @@ private Stream resolve(Context context, Module input) { K requiresHeat = context.requires(); K requiresCool = BooleanUtils.TRUE; - int currentHolePosition[] = new int[] { 0 }; - int finalHolePosition[] = new int[] { 0 }; + int[] currentHolePosition = new int[] { 0 }; + int[] finalHolePosition = new int[] { 0 }; // does this context have a main cell? boolean hasMainCell = new FoldK() { @Override diff --git a/kernel/src/main/java/org/kframework/compile/ResolveFreshConfigConstants.java b/kernel/src/main/java/org/kframework/compile/ResolveFreshConfigConstants.java index b722627a9d4..8f90f346b9c 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveFreshConfigConstants.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveFreshConfigConstants.java @@ -22,7 +22,7 @@ public class ResolveFreshConfigConstants { private int currentFresh = 0; - private Map freshMap = new HashMap<>(); + private final Map freshMap = new HashMap<>(); /** * Replaces fresh variables in the RHS of cell initializer rules with a fresh constant. diff --git a/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java b/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java index 3c96a020dd1..41b6de448f0 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveFreshConstants.java @@ -49,10 +49,10 @@ public class ResolveFreshConstants { private final Definition def; private final FileUtil files; private Module m; - private java.util.Set freshVars = new HashSet<>(); - private Map offsets = new HashMap<>(); + private final java.util.Set freshVars = new HashSet<>(); + private final Map offsets = new HashMap<>(); private final String manualTopCell; - private int initialFresh; + private final int initialFresh; private void reset() { freshVars.clear(); @@ -123,7 +123,7 @@ private void finishAnalysis() { } } - private static KVariable FRESH = KVariable("#Fresh", Att.empty().add(Sort.class, Sorts.Int())); + private static final KVariable FRESH = KVariable("#Fresh", Att.empty().add(Sort.class, Sorts.Int())); private K transform(K term) { return new TransformK() { diff --git a/kernel/src/main/java/org/kframework/compile/ResolveFunctionWithConfig.java b/kernel/src/main/java/org/kframework/compile/ResolveFunctionWithConfig.java index aa832c24f59..4d438c92cff 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveFunctionWithConfig.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveFunctionWithConfig.java @@ -76,10 +76,7 @@ public Boolean apply(KVariable k) { return k.name().startsWith("!") || k.name().equals("#Configuration"); } }; - if (hasVarNeedsConfig.apply(RewriteToTop.toRight(r.body())) || hasVarNeedsConfig.apply(r.requires()) || hasVarNeedsConfig.apply(r.ensures())) { - return true; - } - return false; + return hasVarNeedsConfig.apply(RewriteToTop.toRight(r.body())) || hasVarNeedsConfig.apply(r.requires()) || hasVarNeedsConfig.apply(r.ensures()); } public RuleOrClaim resolve(RuleOrClaim rule, Module m) { diff --git a/kernel/src/main/java/org/kframework/compile/ResolveIOStreams.java b/kernel/src/main/java/org/kframework/compile/ResolveIOStreams.java index 42f0908cf15..dbea035d9a9 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveIOStreams.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveIOStreams.java @@ -103,7 +103,7 @@ private void checkStreamName(String streamName) { if (!streams.contains(streamName)) { throw KEMException.compilerError("Make sure you give the correct stream names: " + streamName + - "\nIt should be one of " + streams.toString()); + "\nIt should be one of " + streams); } } diff --git a/kernel/src/main/java/org/kframework/compile/ResolveSemanticCasts.java b/kernel/src/main/java/org/kframework/compile/ResolveSemanticCasts.java index fc066d02f86..abf21c3ab5a 100644 --- a/kernel/src/main/java/org/kframework/compile/ResolveSemanticCasts.java +++ b/kernel/src/main/java/org/kframework/compile/ResolveSemanticCasts.java @@ -28,8 +28,8 @@ public class ResolveSemanticCasts { private final boolean skipSortPredicates; - private Set casts = new HashSet<>(); - private Map varToTypedVar = new HashMap<>(); + private final Set casts = new HashSet<>(); + private final Map varToTypedVar = new HashMap<>(); public ResolveSemanticCasts(boolean skipSortPredicates) { diff --git a/kernel/src/main/java/org/kframework/compile/SortCells.java b/kernel/src/main/java/org/kframework/compile/SortCells.java index a5f41346c40..faaffb962ec 100644 --- a/kernel/src/main/java/org/kframework/compile/SortCells.java +++ b/kernel/src/main/java/org/kframework/compile/SortCells.java @@ -219,9 +219,9 @@ KVariable newDotVariable(Att att) { return newLabel; } - private Map variables = new HashMap<>(); - private Map cellVariables = new HashMap<>(); - private Set previousVars = new HashSet<>(); + private final Map variables = new HashMap<>(); + private final Map cellVariables = new HashMap<>(); + private final Set previousVars = new HashSet<>(); private void resetVars() { variables.clear(); cellVariables.clear(); previousVars.clear(); counter = 0; @@ -784,7 +784,7 @@ public void apply(KApply k) { } @Override public void apply(KVariable var) { - if (!inKCell && cellFragmentVars.containsKey(var)) { + if (!inKCell) { cellFragmentVars.remove(var); } } diff --git a/kernel/src/main/java/org/kframework/compile/checks/CheckAtt.java b/kernel/src/main/java/org/kframework/compile/checks/CheckAtt.java index b47da2a6b2c..66ebcd5df50 100644 --- a/kernel/src/main/java/org/kframework/compile/checks/CheckAtt.java +++ b/kernel/src/main/java/org/kframework/compile/checks/CheckAtt.java @@ -54,7 +54,7 @@ public void check(Sentence sentence) { checkUnrecognizedAtts(sentence); checkRestrictedAtts(sentence); if (sentence instanceof Rule) { - check(((Rule) sentence).att(), sentence); + check(sentence.att(), sentence); check((Rule) sentence); } else if (sentence instanceof Production) { check((Production) sentence); @@ -161,7 +161,7 @@ private void check(Production prod) { i--; int idx = Integer.parseInt(sb.toString()); if (idx == 0 || idx > prod.items().size()) { - errors.add(KEMException.compilerError("Invalid format escape sequence '%" + sb.toString() + "'. Expected a number between 1 and " + prod.items().size(), prod)); + errors.add(KEMException.compilerError("Invalid format escape sequence '%" + sb + "'. Expected a number between 1 and " + prod.items().size(), prod)); } else { ProductionItem pi = prod.items().apply(idx-1); if (pi instanceof RegexTerminal) { diff --git a/kernel/src/main/java/org/kframework/compile/checks/CheckConfigurationCells.java b/kernel/src/main/java/org/kframework/compile/checks/CheckConfigurationCells.java index 1b53ff61127..e3700ad27a1 100644 --- a/kernel/src/main/java/org/kframework/compile/checks/CheckConfigurationCells.java +++ b/kernel/src/main/java/org/kframework/compile/checks/CheckConfigurationCells.java @@ -38,7 +38,7 @@ public void check(Sentence s) { } } - private Set cells = new HashSet<>(); + private final Set cells = new HashSet<>(); private void check(Production p) { if (p.att().contains(Att.CELL())) { diff --git a/kernel/src/main/java/org/kframework/compile/checks/CheckListDecl.java b/kernel/src/main/java/org/kframework/compile/checks/CheckListDecl.java index f8a6744abf7..fd58b25c86e 100644 --- a/kernel/src/main/java/org/kframework/compile/checks/CheckListDecl.java +++ b/kernel/src/main/java/org/kframework/compile/checks/CheckListDecl.java @@ -28,7 +28,7 @@ public static void check(Module m) { m.getItems().stream().forEach(CheckListDecl::check); // i -> check(i) } - private static Set BASE_SORTS = ImmutableSet.of(Sorts.K(), Sorts.KResult(), Sorts.KItem(), + private static final Set BASE_SORTS = ImmutableSet.of(Sorts.K(), Sorts.KResult(), Sorts.KItem(), Sorts.KList(), Sorts.Bag(), Sorts.KLabel()); private static boolean isBaseSort(Sort sort) { diff --git a/kernel/src/main/java/org/kframework/compile/checks/CheckRHSVariables.java b/kernel/src/main/java/org/kframework/compile/checks/CheckRHSVariables.java index e4b19f27166..19c80ae5177 100644 --- a/kernel/src/main/java/org/kframework/compile/checks/CheckRHSVariables.java +++ b/kernel/src/main/java/org/kframework/compile/checks/CheckRHSVariables.java @@ -100,7 +100,7 @@ private Set getUnboundVarNames(RuleOrClaim rule) { return unboundVariableNames; } - private Set vars = Sets.newHashSet(); + private final Set vars = Sets.newHashSet(); void resetVars() { vars.clear(); diff --git a/kernel/src/main/java/org/kframework/compile/checks/CheckSortTopUniqueness.java b/kernel/src/main/java/org/kframework/compile/checks/CheckSortTopUniqueness.java index 06f0150b345..c813d08109f 100644 --- a/kernel/src/main/java/org/kframework/compile/checks/CheckSortTopUniqueness.java +++ b/kernel/src/main/java/org/kframework/compile/checks/CheckSortTopUniqueness.java @@ -40,7 +40,7 @@ private void check(Sort s, Sentence p) { if (!s.equals(Sorts.Cell()) && module.subsorts().lessThan(s, Sorts.KList()) && module.subsorts().lessThan(s, Sorts.Bag())) { - errors.add(KEMException.compilerError("Multiple top sorts found for " + s.toString() + ": KList and Bag.", p)); + errors.add(KEMException.compilerError("Multiple top sorts found for " + s + ": KList and Bag.", p)); } } } diff --git a/kernel/src/main/java/org/kframework/kdep/KDepFrontEnd.java b/kernel/src/main/java/org/kframework/kdep/KDepFrontEnd.java index 0fc0fb5ec6e..8a7c15c3220 100644 --- a/kernel/src/main/java/org/kframework/kdep/KDepFrontEnd.java +++ b/kernel/src/main/java/org/kframework/kdep/KDepFrontEnd.java @@ -104,7 +104,7 @@ protected int run() { source, currentDirectory, lookupDirectories, - requiredFiles));; + requiredFiles)); Set allFiles = modules.stream().map(m -> new File(m.getSource().source())).collect(Collectors.toSet()); System.out.println(files.get().resolveWorkingDirectory(".").toURI().relativize(files.get().resolveKompiled("timestamp").toURI()).getPath() + " : \\"); diff --git a/kernel/src/main/java/org/kframework/kil/Lexical.java b/kernel/src/main/java/org/kframework/kil/Lexical.java index 1e444c401a3..7c65e35be40 100644 --- a/kernel/src/main/java/org/kframework/kil/Lexical.java +++ b/kernel/src/main/java/org/kframework/kil/Lexical.java @@ -6,7 +6,7 @@ /** A terminal in a {@link Production}. */ public class Lexical extends ProductionItem { - private String lexicalRule; + private final String lexicalRule; private String follow; public Lexical(String terminal, String follow) { @@ -30,9 +30,7 @@ public boolean equals(Object obj) { if (!(obj instanceof Lexical trm)) return false; - if (!trm.lexicalRule.equals(this.lexicalRule)) - return false; - return true; + return trm.lexicalRule.equals(this.lexicalRule); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/NonTerminal.java b/kernel/src/main/java/org/kframework/kil/NonTerminal.java index e8d4c2bef17..64c58213481 100644 --- a/kernel/src/main/java/org/kframework/kil/NonTerminal.java +++ b/kernel/src/main/java/org/kframework/kil/NonTerminal.java @@ -11,7 +11,7 @@ public class NonTerminal extends ProductionItem { private Sort sort; - private Optional name; + private final Optional name; public NonTerminal(Sort sort, Optional name) { super(); @@ -55,9 +55,7 @@ public boolean equals(Object obj) { if (!(obj instanceof NonTerminal nt)) return false; - if (!sort.equals(nt.sort)) - return false; - return true; + return sort.equals(nt.sort); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/Production.java b/kernel/src/main/java/org/kframework/kil/Production.java index c85e7de16bc..e0d89b95a83 100644 --- a/kernel/src/main/java/org/kframework/kil/Production.java +++ b/kernel/src/main/java/org/kframework/kil/Production.java @@ -221,11 +221,8 @@ public boolean equals(Object obj) { } else if (!sort.equals(other.sort)) return false; if (binderMap == null) { - if (other.binderMap != null) - return false; - } else if (!binderMap.equals(other.binderMap)) - return false; - return true; + return other.binderMap == null; + } else return binderMap.equals(other.binderMap); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/SortSynonym.java b/kernel/src/main/java/org/kframework/kil/SortSynonym.java index a3cdc85dbf0..dc172a4c367 100644 --- a/kernel/src/main/java/org/kframework/kil/SortSynonym.java +++ b/kernel/src/main/java/org/kframework/kil/SortSynonym.java @@ -25,9 +25,7 @@ public boolean equals(Object obj) { SortSynonym other = (SortSynonym) obj; if (!newSort.equals(other.newSort)) return false; - if (!oldSort.equals(other.oldSort)) - return false; - return true; + return oldSort.equals(other.oldSort); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/StringSentence.java b/kernel/src/main/java/org/kframework/kil/StringSentence.java index beb00217d24..17c0d31050a 100644 --- a/kernel/src/main/java/org/kframework/kil/StringSentence.java +++ b/kernel/src/main/java/org/kframework/kil/StringSentence.java @@ -9,8 +9,8 @@ */ public class StringSentence extends ModuleItem { private String content; - private int contentStartLine; - private int contentStartColumn; + private final int contentStartLine; + private final int contentStartColumn; private String label; private String type; diff --git a/kernel/src/main/java/org/kframework/kil/SyntaxLexical.java b/kernel/src/main/java/org/kframework/kil/SyntaxLexical.java index a8c74b9c7e3..7a10192bd21 100644 --- a/kernel/src/main/java/org/kframework/kil/SyntaxLexical.java +++ b/kernel/src/main/java/org/kframework/kil/SyntaxLexical.java @@ -25,9 +25,7 @@ public boolean equals(Object obj) { SyntaxLexical other = (SyntaxLexical) obj; if (!name.equals(other.name)) return false; - if (!regex.equals(other.regex)) - return false; - return true; + return regex.equals(other.regex); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/Terminal.java b/kernel/src/main/java/org/kframework/kil/Terminal.java index e3c6783a961..3091c35d98e 100644 --- a/kernel/src/main/java/org/kframework/kil/Terminal.java +++ b/kernel/src/main/java/org/kframework/kil/Terminal.java @@ -35,9 +35,7 @@ public boolean equals(Object obj) { if (!(obj instanceof Terminal trm)) return false; - if (!trm.terminal.equals(this.terminal)) - return false; - return true; + return trm.terminal.equals(this.terminal); } @Override diff --git a/kernel/src/main/java/org/kframework/kil/UserList.java b/kernel/src/main/java/org/kframework/kil/UserList.java index 162c0ccf7e7..48f4e9abaf6 100644 --- a/kernel/src/main/java/org/kframework/kil/UserList.java +++ b/kernel/src/main/java/org/kframework/kil/UserList.java @@ -63,9 +63,7 @@ public boolean equals(Object obj) { if (!sort.equals(srt.getSort())) return false; - if (!separator.equals(srt.getSeparator())) - return false; - return true; + return separator.equals(srt.getSeparator()); } @Override diff --git a/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java b/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java index 3201c8b9a48..a7f045feaab 100644 --- a/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java +++ b/kernel/src/main/java/org/kframework/kompile/CompiledDefinition.java @@ -60,8 +60,8 @@ public class CompiledDefinition implements Serializable { public final HashMap configurationVariableDefaultSorts = new HashMap<>(); public final KLabel topCellInitializer; private final Module languageParsingModule; - private Map cachedcompiledPatterns = new ConcurrentHashMap<>(); - private Map cachedParsedPatterns = new ConcurrentHashMap<>(); + private final Map cachedcompiledPatterns = new ConcurrentHashMap<>(); + private final Map cachedParsedPatterns = new ConcurrentHashMap<>(); public CompiledDefinition(KompileOptions kompileOptions, OuterParsingOptions outerParsingOptions, InnerParsingOptions innerParsingOptions, GlobalOptions globalOptions, Definition parsedDefinition, Definition kompiledDefinition, FileUtil files, KExceptionManager kem, KLabel topCellInitializer) { diff --git a/kernel/src/main/java/org/kframework/kompile/Kompile.java b/kernel/src/main/java/org/kframework/kompile/Kompile.java index f54868b20c6..266c8a8d0b8 100644 --- a/kernel/src/main/java/org/kframework/kompile/Kompile.java +++ b/kernel/src/main/java/org/kframework/kompile/Kompile.java @@ -61,6 +61,7 @@ import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; @@ -170,14 +171,10 @@ public CompiledDefinition run(File definitionFile, String mainModuleName, String files.saveToKompiled("allRules.txt", ruleSourceMap(kompiledDefinition)); if (kompileOptions.emitJson) { - try { - Stopwatch sw = new Stopwatch(globalOptions); - files.saveToKompiled("parsed.json", new String(ToJson.apply(parsedDef), "UTF-8")); - files.saveToKompiled("compiled.json", new String(ToJson.apply(kompiledDefinition), "UTF-8")); - sw.printIntermediate(" Emit parsed & compiled JSON"); - } catch (UnsupportedEncodingException e) { - throw KEMException.criticalError("Unsupported encoding `UTF-8` when saving JSON definition."); - } + Stopwatch sw = new Stopwatch(globalOptions); + files.saveToKompiled("parsed.json", new String(ToJson.apply(parsedDef), StandardCharsets.UTF_8)); + files.saveToKompiled("compiled.json", new String(ToJson.apply(kompiledDefinition), StandardCharsets.UTF_8)); + sw.printIntermediate(" Emit parsed & compiled JSON"); } ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(kompiledDefinition.mainModule()); @@ -252,7 +249,7 @@ private Definition postProcessJSON(Definition defn, String postProcess) { Map environment = new HashMap<>(); File compiledJson; try { - String inputDefinition = new String(ToJson.apply(defn), "UTF-8"); + String inputDefinition = new String(ToJson.apply(defn), StandardCharsets.UTF_8); compiledJson = files.resolveTemp("post-process-compiled.json"); FileUtils.writeStringToFile(compiledJson, inputDefinition); } catch (UnsupportedEncodingException e) { diff --git a/kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java b/kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java index d68fa14ef4d..af9b5cbeecb 100644 --- a/kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java +++ b/kernel/src/main/java/org/kframework/kore/convertors/KILtoKORE.java @@ -36,7 +36,7 @@ public class KILtoKORE extends KILTransformation { - private org.kframework.kil.loader.Context context; + private final org.kframework.kil.loader.Context context; private final boolean syntactic; private String moduleName; private final boolean bisonLists; diff --git a/kernel/src/main/java/org/kframework/ksearchpattern/KSearchPatternFrontEnd.java b/kernel/src/main/java/org/kframework/ksearchpattern/KSearchPatternFrontEnd.java index 318e8366fb5..ed495154d8c 100644 --- a/kernel/src/main/java/org/kframework/ksearchpattern/KSearchPatternFrontEnd.java +++ b/kernel/src/main/java/org/kframework/ksearchpattern/KSearchPatternFrontEnd.java @@ -108,7 +108,7 @@ protected int run() { sb.append(", \\dv{SortBool{}}(\"true\"))"); } sb.append(")"); - System.out.println(sb.toString()); + System.out.println(sb); return 0; } finally { scope.exit(); diff --git a/kernel/src/main/java/org/kframework/lsp/KWorkspaceService.java b/kernel/src/main/java/org/kframework/lsp/KWorkspaceService.java index f7b3724a89f..7e0852a1362 100644 --- a/kernel/src/main/java/org/kframework/lsp/KWorkspaceService.java +++ b/kernel/src/main/java/org/kframework/lsp/KWorkspaceService.java @@ -11,7 +11,7 @@ */ public class KWorkspaceService implements WorkspaceService { - private KLanguageServer languageServer; + private final KLanguageServer languageServer; LSClientLogger clientLogger; public KWorkspaceService(KLanguageServer languageServer) { diff --git a/kernel/src/main/java/org/kframework/main/GlobalOptions.java b/kernel/src/main/java/org/kframework/main/GlobalOptions.java index d78fad84535..a9558dabf7c 100644 --- a/kernel/src/main/java/org/kframework/main/GlobalOptions.java +++ b/kernel/src/main/java/org/kframework/main/GlobalOptions.java @@ -32,7 +32,7 @@ public GlobalOptions(boolean debug, Warnings warnings, boolean verbose, boolean this.warnings2errors = warnings2errors; } - public static enum Warnings { + public enum Warnings { /** * All warnings and errors */ @@ -48,10 +48,10 @@ public static enum Warnings { */ NONE(EnumSet.of(ExceptionType.ERROR)); - private Warnings(Set types) { + Warnings(Set types) { typesIncluded = types; } - private Set typesIncluded; + private final Set typesIncluded; public Set getTypesIncluded() { return typesIncluded; } } diff --git a/kernel/src/main/java/org/kframework/parser/InputModes.java b/kernel/src/main/java/org/kframework/parser/InputModes.java index 029ca21ca3c..f545727b9c5 100644 --- a/kernel/src/main/java/org/kframework/parser/InputModes.java +++ b/kernel/src/main/java/org/kframework/parser/InputModes.java @@ -2,5 +2,5 @@ package org.kframework.parser; public enum InputModes { - PROGRAM, BINARY, JSON, KAST, KORE, RULE; + PROGRAM, BINARY, JSON, KAST, KORE, RULE } diff --git a/kernel/src/main/java/org/kframework/parser/ParserUtils.java b/kernel/src/main/java/org/kframework/parser/ParserUtils.java index 5f5a011c4ab..711997864f4 100644 --- a/kernel/src/main/java/org/kframework/parser/ParserUtils.java +++ b/kernel/src/main/java/org/kframework/parser/ParserUtils.java @@ -250,7 +250,7 @@ public Set loadModules( } if (preprocess) { - System.out.println(def.toString()); + System.out.println(def); } KILtoKORE kilToKore = new KILtoKORE(context, false, leftAssoc); diff --git a/kernel/src/main/java/org/kframework/parser/binary/BinaryParser.java b/kernel/src/main/java/org/kframework/parser/binary/BinaryParser.java index 918b51af59d..dead9cabc35 100644 --- a/kernel/src/main/java/org/kframework/parser/binary/BinaryParser.java +++ b/kernel/src/main/java/org/kframework/parser/binary/BinaryParser.java @@ -68,7 +68,7 @@ public class BinaryParser { private final List interns = new ArrayList<>(); private final List kInterns = new ArrayList<>(); - private static K[] EMPTY_KLIST = new K[0]; + private static final K[] EMPTY_KLIST = new K[0]; private BinaryParser(ByteBuffer data) { this.data = data; @@ -145,8 +145,8 @@ private K read400(boolean _401) throws IOException { return stack.peek(); } - private Map klabelCache = new HashMap<>(); - private Map> ktokenCache = new HashMap<>(); + private final Map klabelCache = new HashMap<>(); + private final Map> ktokenCache = new HashMap<>(); private KLabel readKLabel() throws IOException { String lbl = readString(); diff --git a/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java b/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java index b99c38a3be5..9181ef13773 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java +++ b/kernel/src/main/java/org/kframework/parser/inner/RuleGrammarGenerator.java @@ -386,7 +386,7 @@ public static Tuple3 getCombinedGrammarImpl(Module mod, boolean addRuleCells; if (mod.importedModuleNames().contains(RULE_CELLS)) { // prepare cell productions for rule parsing // make sure a configuration actually exists, otherwise ConfigurationInfoFromModule explodes. - addRuleCells = mod.sentences().exists(p -> p instanceof Production && ((Production) p).att().contains(Att.CELL())); + addRuleCells = mod.sentences().exists(p -> p instanceof Production && p.att().contains(Att.CELL())); } else { addRuleCells = false; } @@ -565,9 +565,9 @@ private static Set makeCasts(Sort outerSort, Sort innerSort, Sort cast Set prods = new HashSet<>(); Att attrs1 = Att().add(Sort.class, castSort); prods.add(Production(KLabel("#SyntacticCast"), castSort, Seq(NonTerminal(labelSort), Terminal("::" + castSort.toString())), attrs1.add(Att.FORMAT(), "%1%2"))); - prods.add(Production(KLabel("#SemanticCastTo" + labelSort.toString()), labelSort, Seq(NonTerminal(labelSort), Terminal(":" + castSort.toString())), attrs1.add(Att.FORMAT(), "%1%2"))); - prods.add(Production(KLabel("#InnerCast"), castSort, Seq(Terminal("{"), NonTerminal(labelSort), Terminal("}"), Terminal("<:" + castSort.toString())), attrs1.add(Att.FORMAT(), "%1 %2 %3%4"))); - prods.add(Production(KLabel("#OuterCast"), labelSort, Seq(Terminal("{"), NonTerminal(innerSort), Terminal("}"), Terminal(":>" + castSort.toString())), attrs1.add(Att.FORMAT(), "%1 %2 %3%4"))); + prods.add(Production(KLabel("#SemanticCastTo" + labelSort.toString()), labelSort, Seq(NonTerminal(labelSort), Terminal(":" + castSort)), attrs1.add(Att.FORMAT(), "%1%2"))); + prods.add(Production(KLabel("#InnerCast"), castSort, Seq(Terminal("{"), NonTerminal(labelSort), Terminal("}"), Terminal("<:" + castSort)), attrs1.add(Att.FORMAT(), "%1 %2 %3%4"))); + prods.add(Production(KLabel("#OuterCast"), labelSort, Seq(Terminal("{"), NonTerminal(innerSort), Terminal("}"), Terminal(":>" + castSort)), attrs1.add(Att.FORMAT(), "%1 %2 %3%4"))); return prods; } } diff --git a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/TypeInferencer.java b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/TypeInferencer.java index e9325d9c7f3..e373279f727 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/TypeInferencer.java +++ b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/TypeInferencer.java @@ -104,11 +104,7 @@ public TypeInferencer(Module mod, boolean debug) { int major = Integer.valueOf(parts[0]); int minor = Integer.valueOf(parts[1]); int patch = Integer.valueOf(parts[2].split(" ")[0]); - if (major < 4 || (major == 4 && minor < 6) || (major == 4 && minor == 8 && patch == 9)) { - destroyOnReset = true; - } else { - destroyOnReset = false; - } + destroyOnReset = major < 4 || (major == 4 && minor < 6) || (major == 4 && minor == 8 && patch == 9); } catch (IOException e) { throw KEMException.internalError("Could not read from z3 process", e); } @@ -491,7 +487,7 @@ public class ExpectedSortsVisitor { private int ambId = 0; // cache for sharing ambiguity nodes - private Map> ambCache = new IdentityHashMap<>(); + private final Map> ambCache = new IdentityHashMap<>(); /** * diff --git a/kernel/src/main/java/org/kframework/parser/inner/kernel/KSyntax2Bison.java b/kernel/src/main/java/org/kframework/parser/inner/kernel/KSyntax2Bison.java index c341eedb048..83ce516a63e 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/kernel/KSyntax2Bison.java +++ b/kernel/src/main/java/org/kframework/parser/inner/kernel/KSyntax2Bison.java @@ -187,7 +187,7 @@ public static void writeParser(Module module, Module disambModule, Scanner scann do { Sort s = workList.poll(); if (reachableSorts.add(s)) { - List prodsForSort = prods.getOrDefault(s, java.util.Collections.emptyList()); + List prodsForSort = prods.getOrDefault(s, java.util.Collections.emptyList()); for (Production prod : prodsForSort) { for (NonTerminal nt : iterable(prod.nonterminals())) { workList.offer(nt.sort()); @@ -511,13 +511,13 @@ private static void encodeKore(KLabel klabel, StringBuilder bison) { StringBuilder sb = new StringBuilder(); ModuleToKORE.convert(klabel, sb); String quoted = StringUtil.enquoteCString(sb.toString()); - bison.append(quoted.substring(1, quoted.length() - 1)); + bison.append(quoted, 1, quoted.length() - 1); } private static void encodeKore(Sort sort, StringBuilder bison) { StringBuilder sb = new StringBuilder(); ModuleToKORE.convert(sort, sb); String quoted = StringUtil.enquoteCString(sb.toString()); - bison.append(quoted.substring(1, quoted.length() - 1)); + bison.append(quoted, 1, quoted.length() - 1); } } diff --git a/kernel/src/main/java/org/kframework/parser/inner/kernel/Scanner.java b/kernel/src/main/java/org/kframework/parser/inner/kernel/Scanner.java index 5ff062ab00f..9a9185ef256 100644 --- a/kernel/src/main/java/org/kframework/parser/inner/kernel/Scanner.java +++ b/kernel/src/main/java/org/kframework/parser/inner/kernel/Scanner.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; import java.nio.file.StandardCopyOption; import java.nio.file.Files; import java.util.*; @@ -412,7 +413,7 @@ public Token[] tokenize(String input, Source source, int[] lines, int[] columns) } } - byte[] buf = input.getBytes("UTF-8"); + byte[] buf = input.getBytes(StandardCharsets.UTF_8); ByteBuffer size = ByteBuffer.allocate(4); size.order(ByteOrder.nativeOrder()); size.putInt(buf.length); @@ -445,7 +446,7 @@ private Token[] readTokenizedOutput(Process process, Source source, int[] lines, int len = byteBuf.getInt(); byte[] bytes = new byte[len]; IOUtils.readFully(process.getInputStream(), bytes); - String value = new String(bytes, "UTF-8"); + String value = new String(bytes, StandardCharsets.UTF_8); Token t = new Token(kind, value, startLoc, endLoc); if (kind == -1) { String msg = "Scanner error: unexpected character sequence '" + value + "'."; diff --git a/kernel/src/main/java/org/kframework/parser/json/JsonParser.java b/kernel/src/main/java/org/kframework/parser/json/JsonParser.java index 54cf32d61b4..83252ae20a1 100644 --- a/kernel/src/main/java/org/kframework/parser/json/JsonParser.java +++ b/kernel/src/main/java/org/kframework/parser/json/JsonParser.java @@ -44,6 +44,7 @@ import java.io.IOException; import java.io.StringReader; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -93,11 +94,7 @@ public class JsonParser { ///////////////////////////// public static Definition parseDefinition(byte[] data) { - try { - return parseDefinition(new String(data, "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 encoding not supported"); - } + return parseDefinition(new String(data, StandardCharsets.UTF_8)); } public static Definition parseDefinition(String data) { @@ -347,11 +344,7 @@ public static Att toAtt(JsonObject data) { //////////////////// public static K parse(byte[] data) { - try { - return parse(new String(data, "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 encoding not supported"); - } + return parse(new String(data, StandardCharsets.UTF_8)); } public static K parse(String data) { diff --git a/kernel/src/main/java/org/kframework/unparser/AddBrackets.java b/kernel/src/main/java/org/kframework/unparser/AddBrackets.java index 4e38384f5b3..4dcfa92dada 100644 --- a/kernel/src/main/java/org/kframework/unparser/AddBrackets.java +++ b/kernel/src/main/java/org/kframework/unparser/AddBrackets.java @@ -105,9 +105,7 @@ boolean requiresBracketWithSimpleAlgorithm(ProductionReference outer, Production if (innerFixity.contains(Fixity.BARE_LEFT) && leftCapture != null) { inversePriority = isPriorityWrong(inner, leftCapture, 0); EnumSet leftCaptureFixity = getFixity(leftCapture); - if (!inversePriority && leftCaptureFixity.contains(Fixity.BARE_RIGHT)) { - return true; - } + return !inversePriority && leftCaptureFixity.contains(Fixity.BARE_RIGHT); } return false; } @@ -127,10 +125,7 @@ private boolean isPriorityWrong(ProductionReference outer, ProductionReference i if (m.leftAssoc().contains(new Tuple2<>(parentLabel, localLabel)) && position == outer.production().items().size() - 1) { return true; } - if (m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel)) && position == 0) { - return true; - } - return false; + return m.rightAssoc().contains(new Tuple2<>(parentLabel, localLabel)) && position == 0; } private enum Fixity { diff --git a/kernel/src/main/java/org/kframework/unparser/KPrint.java b/kernel/src/main/java/org/kframework/unparser/KPrint.java index 7c137c71e62..983ca441291 100644 --- a/kernel/src/main/java/org/kframework/unparser/KPrint.java +++ b/kernel/src/main/java/org/kframework/unparser/KPrint.java @@ -315,7 +315,7 @@ public K apply(KApply k) { private K alphaRename(K input) { return new TransformK() { - Map renames = new HashMap<>(); + final Map renames = new HashMap<>(); int newCount = 0; @Override diff --git a/kernel/src/main/java/org/kframework/unparser/ToBinary.java b/kernel/src/main/java/org/kframework/unparser/ToBinary.java index 7682b23b0cf..217a67ae643 100644 --- a/kernel/src/main/java/org/kframework/unparser/ToBinary.java +++ b/kernel/src/main/java/org/kframework/unparser/ToBinary.java @@ -48,9 +48,9 @@ public static byte[] apply(K k) { return out.toByteArray(); } - private DataOutputStream data; - private Map interns = new HashMap<>(); - private Map kInterns = new IdentityHashMap<>(); + private final DataOutputStream data; + private final Map interns = new HashMap<>(); + private final Map kInterns = new IdentityHashMap<>(); private int numTermsWritten; private ToBinary(DataOutputStream data) { diff --git a/kernel/src/main/java/org/kframework/unparser/ToLatex.java b/kernel/src/main/java/org/kframework/unparser/ToLatex.java index 67436d15531..2b99a1ca0e0 100644 --- a/kernel/src/main/java/org/kframework/unparser/ToLatex.java +++ b/kernel/src/main/java/org/kframework/unparser/ToLatex.java @@ -59,7 +59,7 @@ private static String[] asciiReadableEncodingLatexCalc() { public static String latexedKLabel(String orig) { StringBuilder buffer = new StringBuilder(); StringUtil.encodeStringToAlphanumeric(buffer, orig, asciiReadableEncodingLatex, identChar, "z"); - return "klabel" + buffer.toString(); + return "klabel" + buffer; } private static void writeString(DataOutputStream out, String str) throws IOException { diff --git a/kernel/src/main/java/org/kframework/utils/ColorUtil.java b/kernel/src/main/java/org/kframework/utils/ColorUtil.java index 9aaf2d06123..f202543f20b 100644 --- a/kernel/src/main/java/org/kframework/utils/ColorUtil.java +++ b/kernel/src/main/java/org/kframework/utils/ColorUtil.java @@ -20,18 +20,18 @@ private ColorUtil() {} * Terminal code corresponding to closest color for this one, from the list of basic 8 * terminal codes only. */ - private static Map ansiColorsToTerminalCodes; + private static final Map ansiColorsToTerminalCodes; /** * Terminal code corresponding to closest color for this one, from the list of 216 colors supported by * linux terminals. */ - private static Map eightBitColorsToTerminalCodes; + private static final Map eightBitColorsToTerminalCodes; /** * A cache to avoid computing the closest terminal color for a given color each time it is needed. */ - private static Map, Map> colorToCodeConvertCache; + private static final Map, Map> colorToCodeConvertCache; public static Map colors() { colors = doInitColors(); diff --git a/kernel/src/main/java/org/kframework/utils/IndentingFormatter.java b/kernel/src/main/java/org/kframework/utils/IndentingFormatter.java index 051d1168503..ea4113d0f82 100644 --- a/kernel/src/main/java/org/kframework/utils/IndentingFormatter.java +++ b/kernel/src/main/java/org/kframework/utils/IndentingFormatter.java @@ -13,8 +13,8 @@ public class IndentingFormatter { public static final String ENDL = "\n"; - private Formatter formatter; - private String endlReplacement; + private final Formatter formatter; + private final String endlReplacement; public IndentingFormatter(@Nonnull Formatter formatter, @Nonnull String indent) { this.formatter = formatter; diff --git a/kernel/src/main/java/org/kframework/utils/Stopwatch.java b/kernel/src/main/java/org/kframework/utils/Stopwatch.java index 94df2fba706..f0d295ab8b7 100644 --- a/kernel/src/main/java/org/kframework/utils/Stopwatch.java +++ b/kernel/src/main/java/org/kframework/utils/Stopwatch.java @@ -12,7 +12,7 @@ */ @RequestScoped public class Stopwatch { - private long start; + private final long start; private long lastIntermediate; Formatter f = new Formatter(System.out); private final GlobalOptions options; diff --git a/kernel/src/main/java/org/kframework/utils/file/FileUtil.java b/kernel/src/main/java/org/kframework/utils/file/FileUtil.java index 968c6a764ef..49c5514c3cd 100644 --- a/kernel/src/main/java/org/kframework/utils/file/FileUtil.java +++ b/kernel/src/main/java/org/kframework/utils/file/FileUtil.java @@ -97,7 +97,7 @@ public static String generateUniqueFolderName(String dirName) { DateFormat df = new SimpleDateFormat("-yyyy-MM-dd-HH-mm-ss-SSS-"); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); - return dirName + reportDate + UUID.randomUUID().toString(); + return dirName + reportDate + UUID.randomUUID(); } /** diff --git a/kernel/src/main/java/org/kframework/utils/file/JarInfo.java b/kernel/src/main/java/org/kframework/utils/file/JarInfo.java index adc55aebe1c..b3b58d0b1bd 100644 --- a/kernel/src/main/java/org/kframework/utils/file/JarInfo.java +++ b/kernel/src/main/java/org/kframework/utils/file/JarInfo.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Date; @@ -30,14 +31,9 @@ public static String getKBase() { String path = new File(JarInfo.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath(); if (!path.endsWith(".jar") || new File(path).getParentFile().getName().equals("target")) path = new File(path).getParentFile().getParentFile().getParentFile().getAbsolutePath() + "/" + JAR_PATH; - try { - String decodedPath = URLDecoder.decode(path, "UTF-8"); - File parent = new File(decodedPath).getParentFile().getParentFile().getParentFile().getParentFile(); - return parent.getAbsolutePath(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return null; + String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8); + File parent = new File(decodedPath).getParentFile().getParentFile().getParentFile().getParentFile(); + return parent.getAbsolutePath(); } /** diff --git a/kernel/src/main/java/org/kframework/utils/inject/GraphInjector.java b/kernel/src/main/java/org/kframework/utils/inject/GraphInjector.java index 7996d71ad33..b1f6b8383d4 100644 --- a/kernel/src/main/java/org/kframework/utils/inject/GraphInjector.java +++ b/kernel/src/main/java/org/kframework/utils/inject/GraphInjector.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import com.google.inject.Guice; @@ -22,7 +23,7 @@ public static void main(String[] args) throws IOException { } private static void graph(String filename, Injector demoInjector) throws IOException { - PrintWriter out = new PrintWriter(new File(filename), "UTF-8"); + PrintWriter out = new PrintWriter(new File(filename), StandardCharsets.UTF_8); Injector injector = Guice.createInjector(new GraphvizModule()); GraphvizGrapher grapher = injector.getInstance(GraphvizGrapher.class); diff --git a/kernel/src/main/java/org/kframework/utils/inject/JCommanderModule.java b/kernel/src/main/java/org/kframework/utils/inject/JCommanderModule.java index 495db016164..a8d4693ddc1 100644 --- a/kernel/src/main/java/org/kframework/utils/inject/JCommanderModule.java +++ b/kernel/src/main/java/org/kframework/utils/inject/JCommanderModule.java @@ -33,7 +33,7 @@ public class JCommanderModule extends AbstractModule { protected void configure() { binder().requireAtInjectOnConstructors(); bind(String[].class).annotatedWith(Options.class) - .toProvider(SimpleScope.seededKeyProvider()).in(RequestScoped.class);; + .toProvider(SimpleScope.seededKeyProvider()).in(RequestScoped.class); } @Provides @RequestScoped diff --git a/kernel/src/main/java/org/kframework/utils/inject/SimpleScope.java b/kernel/src/main/java/org/kframework/utils/inject/SimpleScope.java index ed36b9c9f38..7555a85ade8 100644 --- a/kernel/src/main/java/org/kframework/utils/inject/SimpleScope.java +++ b/kernel/src/main/java/org/kframework/utils/inject/SimpleScope.java @@ -65,7 +65,7 @@ public Object get() { public void enter() { checkState(values.get() == null, "A scoping block is already in progress"); - values.set(Maps., Object> newHashMap()); + values.set(Maps.newHashMap()); } public void exit() { diff --git a/kernel/src/test/java/org/kframework/compile/ConstantFoldingTest.java b/kernel/src/test/java/org/kframework/compile/ConstantFoldingTest.java index ce9c68ffbd7..22d8697cc75 100644 --- a/kernel/src/test/java/org/kframework/compile/ConstantFoldingTest.java +++ b/kernel/src/test/java/org/kframework/compile/ConstantFoldingTest.java @@ -810,7 +810,7 @@ public void testFloatNeg() { testUnaryOp(cf::FLOAT_neg, a -> -a); } - private double[] refs = new double[] {0.0, -0.0, 1.0/0.0, -1.0/0.0, 1.0, -1.0, 3.0, 0.5, 0.0/0.0}; + private final double[] refs = new double[] {0.0, -0.0, 1.0/0.0, -1.0/0.0, 1.0, -1.0, 3.0, 0.5, 0.0/0.0}; private void testUnaryOp(Function op, Function refOp) { testUnaryOp(op, refOp, Double.MIN_VALUE); diff --git a/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java b/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java index 378d621a0a7..0d0da8fd386 100644 --- a/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java +++ b/kernel/src/test/java/org/kframework/kore/compile/GenerateSentencesFromConfigDeclTest.java @@ -44,7 +44,7 @@ public void setUp() { String definitionText; files = FileUtil.testFileUtil(); ParserUtils parser = new ParserUtils(files, new KExceptionManager(new GlobalOptions())); - File definitionFile = new File(Kompile.BUILTIN_DIRECTORY.toString() + "/prelude.md"); + File definitionFile = new File(Kompile.BUILTIN_DIRECTORY + "/prelude.md"); definitionText = files.loadFromWorkingDirectory(definitionFile.getPath()); def = diff --git a/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java b/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java index e21c8951caf..89c3e0f819e 100644 --- a/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java +++ b/kernel/src/test/java/org/kframework/parser/inner/RuleGrammarTest.java @@ -45,7 +45,7 @@ public RuleGrammarGenerator makeRuleGrammarGenerator() { String definitionText; files = FileUtil.testFileUtil(); ParserUtils parser = new ParserUtils(files, new KExceptionManager(new GlobalOptions())); - File definitionFile = new File(Kompile.BUILTIN_DIRECTORY.toString() + "/prelude.md"); + File definitionFile = new File(Kompile.BUILTIN_DIRECTORY + "/prelude.md"); definitionText = files.loadFromWorkingDirectory(definitionFile.getPath()); Definition baseK = diff --git a/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java b/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java index ae018e8a1ec..3e24d2fce8f 100644 --- a/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java +++ b/kernel/src/test/java/org/kframework/parser/inner/disambiguation/AddEmptyListsTest.java @@ -53,7 +53,7 @@ private RuleGrammarGenerator makeRuleGrammarGenerator() { String definitionText; files = FileUtil.testFileUtil(); ParserUtils parser = new ParserUtils(files, new KExceptionManager(new GlobalOptions())); - File definitionFile = new File(Kompile.BUILTIN_DIRECTORY.toString() + "/prelude.md"); + File definitionFile = new File(Kompile.BUILTIN_DIRECTORY + "/prelude.md"); definitionText = files.loadFromWorkingDirectory(definitionFile.getPath()); Definition baseK = diff --git a/kernel/src/test/java/org/kframework/parser/json/JsonSerializationTests.java b/kernel/src/test/java/org/kframework/parser/json/JsonSerializationTests.java index 98bb20c7521..ca9e9b7868b 100644 --- a/kernel/src/test/java/org/kframework/parser/json/JsonSerializationTests.java +++ b/kernel/src/test/java/org/kframework/parser/json/JsonSerializationTests.java @@ -16,6 +16,7 @@ import javax.json.JsonObjectBuilder; import javax.json.JsonStructure; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import static org.kframework.Collections.immutable; import static org.kframework.kore.KORE.*; @@ -76,7 +77,7 @@ public void test3() throws UnsupportedEncodingException { Module mod = ParserUtils.parseMainModuleOuterSyntax(defstr, Source.apply("generated by RuleGrammarTest"), "TEST"); Definition def1 = Definition.apply(mod, immutable(Sets.newHashSet(mod)), Att.empty()); - String inputDefinition = new String(ToJson.apply(def1), "UTF-8"); + String inputDefinition = new String(ToJson.apply(def1), StandardCharsets.UTF_8); Definition def2 = JsonParser.parseDefinition(inputDefinition); Assert.assertEquals(def1, def2); diff --git a/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java b/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java index 963d6e7e85c..9242ae61968 100644 --- a/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java +++ b/kernel/src/test/java/org/kframework/unparser/AddBracketsTest.java @@ -41,7 +41,7 @@ public RuleGrammarGenerator makeRuleGrammarGenerator() { String definitionText; files = FileUtil.testFileUtil(); ParserUtils parser = new ParserUtils(files, new KExceptionManager(new GlobalOptions())); - File definitionFile = new File(Kompile.BUILTIN_DIRECTORY.toString() + "/prelude.md"); + File definitionFile = new File(Kompile.BUILTIN_DIRECTORY + "/prelude.md"); definitionText = files.loadFromWorkingDirectory(definitionFile.getPath()); Definition baseK = diff --git a/kernel/src/test/java/org/kframework/unparser/KPrintTest.java b/kernel/src/test/java/org/kframework/unparser/KPrintTest.java index 68111ca261c..05e7cd185d5 100644 --- a/kernel/src/test/java/org/kframework/unparser/KPrintTest.java +++ b/kernel/src/test/java/org/kframework/unparser/KPrintTest.java @@ -9,6 +9,7 @@ import org.kframework.parser.kast.KastParser; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -27,11 +28,7 @@ private K cell(String cellName, K cellContent) { }; private String bytes2String(byte[] input) { - try { - return new String(input, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new AssertionError("UTF-8 encoding not supported"); - } + return new String(input, StandardCharsets.UTF_8); } private String asKast(K term) { diff --git a/kore/src/main/java/org/kframework/compile/LabelInfo.java b/kore/src/main/java/org/kframework/compile/LabelInfo.java index c3835df7859..bb747d4a021 100644 --- a/kore/src/main/java/org/kframework/compile/LabelInfo.java +++ b/kore/src/main/java/org/kframework/compile/LabelInfo.java @@ -78,11 +78,8 @@ public boolean isFunction(K term) { if (term instanceof KApply && isFunction(((KApply) term).klabel())) { return true; } - if (term instanceof KRewrite && ((KRewrite) term).left() instanceof KApply - && isFunction(((KApply) ((KRewrite) term).left()).klabel())) { - return true; - } - return false; + return term instanceof KRewrite && ((KRewrite) term).left() instanceof KApply + && isFunction(((KApply) ((KRewrite) term).left()).klabel()); } /** diff --git a/kore/src/main/java/org/kframework/kore/AttCompare.java b/kore/src/main/java/org/kframework/kore/AttCompare.java index 425b3c66b30..7d2ad93715d 100644 --- a/kore/src/main/java/org/kframework/kore/AttCompare.java +++ b/kore/src/main/java/org/kframework/kore/AttCompare.java @@ -12,8 +12,8 @@ * Created by dwightguth on 6/17/15. */ public class AttCompare { - private K k; - private List attNames; + private final K k; + private final List attNames; public AttCompare(K k, Att.Key... attNames) { this.k = k; diff --git a/kore/src/main/java/org/kframework/kore/FindK.java b/kore/src/main/java/org/kframework/kore/FindK.java index d14847c0f56..1df92bdfe57 100644 --- a/kore/src/main/java/org/kframework/kore/FindK.java +++ b/kore/src/main/java/org/kframework/kore/FindK.java @@ -10,7 +10,7 @@ public class FindK extends AbstractFoldK> { @Override public Set unit() { - return Collections.Set(); + return Collections.Set(); } @Override diff --git a/kore/src/main/java/org/kframework/utils/OS.java b/kore/src/main/java/org/kframework/utils/OS.java index 481c77c8ee0..71dd5315006 100644 --- a/kore/src/main/java/org/kframework/utils/OS.java +++ b/kore/src/main/java/org/kframework/utils/OS.java @@ -9,7 +9,7 @@ public enum OS { OSX(true), LINUX(true), UNKNOWN(false), WINDOWS(false); - private OS(boolean isPosix) { + OS(boolean isPosix) { this.isPosix = isPosix; } diff --git a/kore/src/main/java/org/kframework/utils/StringUtil.java b/kore/src/main/java/org/kframework/utils/StringUtil.java index 347308fc379..b2361b6cfc5 100644 --- a/kore/src/main/java/org/kframework/utils/StringUtil.java +++ b/kore/src/main/java/org/kframework/utils/StringUtil.java @@ -690,7 +690,7 @@ public static void encodeStringToAlphanumeric(StringBuilder sb, String name, Str inIdent = false; sb.append(escapeChar); } - int charAt = (int) name.charAt(i); + int charAt = name.charAt(i); if (charAt < 128 && asciiReadableEncodingTable[charAt] != null) { sb.append(asciiReadableEncodingTable[charAt]); } else { diff --git a/kore/src/main/java/org/kframework/utils/errorsystem/KException.java b/kore/src/main/java/org/kframework/utils/errorsystem/KException.java index 92d6aedc235..b36dd587828 100755 --- a/kore/src/main/java/org/kframework/utils/errorsystem/KException.java +++ b/kore/src/main/java/org/kframework/utils/errorsystem/KException.java @@ -21,7 +21,7 @@ public class KException implements Serializable, HasLocation { private final Throwable exception; private final boolean printException; private final String sourceText; - private StringBuilder trace = new StringBuilder(); + private final StringBuilder trace = new StringBuilder(); private static final Map labels; static { @@ -41,11 +41,11 @@ public static KException criticalError(String message) { } public KException(ExceptionType type, KExceptionGroup label, String message) { - this(type, label, message, null, (Location) null, null); + this(type, label, message, null, null, null); } public KException(ExceptionType type, KExceptionGroup label, String message, Throwable e) { - this(type, label, message, null, (Location) null, e); + this(type, label, message, null, null, e); } public KException(ExceptionType type, KExceptionGroup label, String message, Source source, Location location) { @@ -221,7 +221,7 @@ private String getSourceLine() throws java.io.IOException { StringBuilder sourceText = new StringBuilder(); sourceText.append("\n\t"); - sourceText.append(String.valueOf(location.startLine()) + " |\t"); + sourceText.append(location.startLine() + " |\t"); Stream lines = Files.lines(Paths.get(getSource().source())); sourceText.append((String) lines.skip(location.startLine() - 1).findFirst().orElse("")); @@ -258,13 +258,13 @@ private String getSourceLine(int errorLineCount) throws java.io.IOException { } sourceText.append("\n\t"); int padding = String.valueOf(location.endLine()).length() - String.valueOf(location.startLine()).length(); - sourceText.append(StringUtils.repeat(' ', padding) + String.valueOf(location.startLine()) + " |\t"); + sourceText.append(StringUtils.repeat(' ', padding) + location.startLine() + " |\t"); sourceText.append(firstLine); if (errorLineCount == 3) { sourceText.append("\n\t"); int padding2 = String.valueOf(location.endLine()).length() - String.valueOf(location.startLine() + 1).length(); - sourceText.append(StringUtils.repeat(' ', padding2) + String.valueOf(location.startLine() + 1) + " |\t"); + sourceText.append(StringUtils.repeat(' ', padding2) + (location.startLine() + 1) + " |\t"); Stream secondline = Files.lines(Paths.get(getSource().source())); sourceText.append((String) secondline.skip(location.startLine()).findFirst().get()); } else if (errorLineCount > 3) { @@ -276,8 +276,8 @@ private String getSourceLine(int errorLineCount) throws java.io.IOException { } sourceText.append("\n\t"); - sourceText.append(String.valueOf(location.endLine()) + " |\t"); - String lastLine = (String)Files.lines(Paths.get(getSource().source())).skip(location.endLine() -1).findFirst().get(); + sourceText.append(location.endLine() + " |\t"); + String lastLine = Files.lines(Paths.get(getSource().source())).skip(location.endLine() -1).findFirst().get(); int firstCharIndex = lastLine.indexOf(lastLine.trim()); sourceText.append(lastLine); diff --git a/kore/src/test/java/org/kframework/kore/InterfaceTest.java b/kore/src/test/java/org/kframework/kore/InterfaceTest.java index 2d5afc9cdc7..a36ea1faee9 100644 --- a/kore/src/test/java/org/kframework/kore/InterfaceTest.java +++ b/kore/src/test/java/org/kframework/kore/InterfaceTest.java @@ -16,7 +16,7 @@ public void example() { // Creating "A + 0 => A" programmatically KRewrite k = KRewrite( - KApply(KLabel("_+_"), (K)KVariable("A"), (K)KToken("0", Sort("Int"))), + KApply(KLabel("_+_"), KVariable("A"), KToken("0", Sort("Int"))), KVariable("A")); // Navigating it