Skip to content

Commit 2a23b80

Browse files
committed
refactoring: applies lint fixes
1 parent 5d1e03d commit 2a23b80

36 files changed

+398
-559
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242

4343
// Logging
4444
implementation("org.slf4j:slf4j-api:2.0.7")
45-
implementation("ch.qos.logback:logback-classic:1.5.13")
45+
implementation("ch.qos.logback:logback-classic:1.5.28")
4646

4747
implementation("com.opencastsoftware:prettier4j:0.3.2")
4848
}

src/main/java/me/fponzi/tlaplusformatter/DocUtils.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,31 @@
22

33
import com.opencastsoftware.prettier4j.Doc;
44

5-
import java.util.Arrays;
65
import java.util.List;
76

87
/**
98
* Utility methods for creating common Doc patterns.
109
* These are truly generic utilities not specific to TLA+ constructs.
1110
*/
1211
public class DocUtils {
13-
12+
1413
private DocUtils() {
1514
// Utility class
1615
}
17-
18-
/**
19-
* Creates an infix expression: left op right
20-
*/
21-
public static Doc infixExpression(Doc left, String operator, Doc right) {
22-
return Doc.group(
23-
left
24-
.append(Doc.text(" " + operator + " "))
25-
.append(right)
26-
);
27-
}
28-
29-
/**
30-
* Creates a parenthesized expression: (expr)
31-
*/
32-
public static Doc parentheses(Doc inner) {
33-
return Doc.text("(")
34-
.append(inner)
35-
.append(Doc.text(")"));
36-
}
37-
38-
/**
39-
* Creates a sequence of documents separated by lines
40-
*/
41-
public static Doc lines(Doc... docs) {
42-
return lines(Arrays.asList(docs));
43-
}
44-
16+
4517
/**
4618
* Creates a sequence of documents separated by lines
4719
*/
4820
public static Doc lines(List<Doc> docs) {
4921
if (docs.isEmpty()) {
5022
return Doc.empty();
5123
}
52-
24+
5325
Doc result = docs.get(0);
5426
for (int i = 1; i < docs.size(); i++) {
5527
result = result.appendLine(docs.get(i));
5628
}
5729
return result;
5830
}
59-
60-
/**
61-
* Creates a comment line starting with \*
62-
*/
63-
public static Doc comment(String text) {
64-
return Doc.text("\\* " + text);
65-
}
31+
6632
}

src/main/java/me/fponzi/tlaplusformatter/FormatConfig.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,6 @@ private void setConstructSetting(String constructName, String settingName, Objec
9292
constructSettings.put(key, value);
9393
}
9494

95-
/**
96-
* Get all construct settings.
97-
*
98-
* @return Unmodifiable map of all construct settings
99-
*/
100-
public Map<String, Object> getAllConstructSettings() {
101-
return Map.copyOf(constructSettings);
102-
}
103-
10495
/**
10596
* Create a copy of this config with the same settings.
10697
*

src/main/java/me/fponzi/tlaplusformatter/SANYWrapper.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import me.fponzi.tlaplusformatter.exceptions.SanyFrontendException;
55
import me.fponzi.tlaplusformatter.exceptions.SanySemanticException;
66
import me.fponzi.tlaplusformatter.exceptions.SanySyntaxException;
7-
import tla2sany.st.TreeNode;
87
import org.apache.commons.io.output.WriterOutputStream;
98
import tla2sany.drivers.FrontEndException;
109
import tla2sany.drivers.SANY;
1110
import tla2sany.modanalyzer.ParseUnit;
1211
import tla2sany.modanalyzer.SpecObj;
12+
import tla2sany.output.LogLevel;
13+
import tla2sany.output.SimpleSanyOutput;
14+
import tla2sany.st.TreeNode;
1315
import util.SimpleFilenameToStream;
1416

1517
import java.io.File;
@@ -52,7 +54,7 @@ public static void loadSpecObject(SpecObj specObj, File file, StringWriter errBu
5254
SANY.frontEndMain(
5355
specObj,
5456
file.getAbsolutePath(),
55-
new PrintStream(outStream, false, StandardCharsets.UTF_8)
57+
new SimpleSanyOutput(new PrintStream(outStream, false, StandardCharsets.UTF_8), LogLevel.INFO)
5658
);
5759
} catch (FrontEndException e) {
5860
throw new SanyFrontendException(e);
@@ -95,20 +97,20 @@ private static List<String> getAdditionalModulePaths() {
9597
List<String> paths = new ArrayList<>();
9698
// Check for community modules, TLAPS, and Apalache in common locations
9799
String[] possiblePaths = {
98-
// Community modules
99-
System.getenv("TLA_COMMUNITY_MODULES"),
100-
"/tmp/CommunityModules/modules",
101-
"/tmp/CommunityModules",
102-
System.getProperty("user.home") + "/.tlaplus/CommunityModules/modules",
103-
// TLAPS library
104-
System.getenv("TLAPS_LIBRARY"),
105-
"/tmp/tlapm/library",
106-
System.getProperty("user.home") + "/.tlaplus/tlaps/library",
107-
"/usr/local/lib/tlaps/library",
108-
// Apalache modules
109-
System.getenv("APALACHE_HOME") != null ? System.getenv("APALACHE_HOME") + "/src/tla" : null,
110-
"/tmp/apalache/src/tla",
111-
System.getProperty("user.home") + "/.tlaplus/apalache/src/tla"
100+
// Community modules
101+
System.getenv("TLA_COMMUNITY_MODULES"),
102+
"/tmp/CommunityModules/modules",
103+
"/tmp/CommunityModules",
104+
System.getProperty("user.home") + "/.tlaplus/CommunityModules/modules",
105+
// TLAPS library
106+
System.getenv("TLAPS_LIBRARY"),
107+
"/tmp/tlapm/library",
108+
System.getProperty("user.home") + "/.tlaplus/tlaps/library",
109+
"/usr/local/lib/tlaps/library",
110+
// Apalache modules
111+
System.getenv("APALACHE_HOME") != null ? System.getenv("APALACHE_HOME") + "/src/tla" : null,
112+
"/tmp/apalache/src/tla",
113+
System.getProperty("user.home") + "/.tlaplus/apalache/src/tla"
112114
};
113115
for (String path : possiblePaths) {
114116
if (path != null) {

src/main/java/me/fponzi/tlaplusformatter/TLAPlusFormatter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public String getOutput() {
5555
* <p>
5656
* Safety: The input spec should be called "Spec" otherwise SANY will complain.
5757
*
58-
* @param spec
59-
* @throws IOException
6058
*/
6159
public TLAPlusFormatter(String spec) throws IOException, SanyFrontendException {
6260
this(storeToTmp(spec), new FormatConfig(), true);

src/main/java/me/fponzi/tlaplusformatter/VersionInfo.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ public final class VersionInfo {
2121
COMMIT_ID = props.getProperty("git.commit", "unknown");
2222
}
2323

24-
private VersionInfo() {}
25-
26-
public static String getVersion() {
27-
return VERSION;
28-
}
29-
30-
public static String getCommitId() {
31-
return COMMIT_ID;
24+
private VersionInfo() {
3225
}
3326

3427
public static String getFullVersion() {

src/main/java/me/fponzi/tlaplusformatter/constructs/BaseConstructFormatter.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,4 @@ protected static Function<String, Doc> stringFormatter() {
121121
return Doc::text;
122122
}
123123

124-
/**
125-
* Determine appropriate formatting strategy based on list size and configuration.
126-
*/
127-
protected ListFormatStrategy determineStrategy(String constructName, int itemCount) {
128-
// Check construct-specific settings
129-
ListFormatStrategy configuredStrategy = config.getConstructSetting(
130-
constructName, "breakStrategy", null);
131-
132-
if (configuredStrategy != null) {
133-
return configuredStrategy;
134-
}
135-
136-
// Default strategy based on item count
137-
if (itemCount <= 1) {
138-
return ListFormatStrategy.SINGLE_LINE;
139-
} else if (itemCount <= 3) {
140-
return ListFormatStrategy.SINGLE_LINE;
141-
} else {
142-
return ListFormatStrategy.SMART_BREAK;
143-
}
144-
}
145124
}

src/main/java/me/fponzi/tlaplusformatter/constructs/ConstructContext.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
import com.opencastsoftware.prettier4j.Doc;
44
import me.fponzi.tlaplusformatter.FormatConfig;
55
import me.fponzi.tlaplusformatter.TlaDocBuilder;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
86
import tla2sany.st.TreeNode;
97

10-
import java.lang.invoke.MethodHandles;
118
import java.util.ArrayList;
12-
import java.util.Arrays;
139
import java.util.List;
14-
import java.util.stream.Collectors;
1510

1611
/**
1712
* Context object that provides access to shared services and utilities
@@ -99,10 +94,7 @@ private static boolean isCommentStart(String s) {
9994
return true;
10095
}
10196
// Check for line comment start \*
102-
if (i + 1 < s.length() && s.charAt(i) == '\\' && s.charAt(i + 1) == '*') {
103-
return true;
104-
}
105-
return false;
97+
return i + 1 < s.length() && s.charAt(i) == '\\' && s.charAt(i + 1) == '*';
10698
}
10799

108100
/**
@@ -166,19 +158,6 @@ public boolean isValidNode(TreeNode node) {
166158
return nodeAnalyzer.isValid(node);
167159
}
168160

169-
/**
170-
* Get a construct-specific configuration setting.
171-
*
172-
* @param constructName Name of the construct
173-
* @param settingName Name of the setting
174-
* @param defaultValue Default value if setting is not found
175-
* @param <T> Type of the setting value
176-
* @return The setting value or default value
177-
*/
178-
public <T> T getConstructSetting(String constructName, String settingName, T defaultValue) {
179-
return config.getConstructSetting(constructName, settingName, defaultValue);
180-
}
181-
182161
/**
183162
* Get preserved spacing after a node based on original source.
184163
*
@@ -193,8 +172,6 @@ public Doc getSpacingAfter(TreeNode node, TreeNode next) {
193172
* Helper class for common node analysis operations.
194173
*/
195174
private static class NodeAnalyzer {
196-
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
197-
198175
/**
199176
* Check if a node is valid (has a real location, not a placeholder).
200177
*/

src/main/java/me/fponzi/tlaplusformatter/constructs/NodeKind.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* Enum representing SANY node kinds with metadata.
55
*/
6+
@SuppressWarnings("unused")
67
public enum NodeKind {
78

89
NULL_ID(327, "Null ID"),
@@ -139,11 +140,6 @@ public enum NodeKind {
139140
this.description = description;
140141
}
141142

142-
/**
143-
* Get all node kind IDs handled by this NodeKind.
144-
*
145-
* @return Set of all node kind IDs
146-
*/
147143
public int getId() {
148144
return id;
149145
}

src/main/java/me/fponzi/tlaplusformatter/constructs/TlaConstruct.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,13 @@ public interface TlaConstruct {
1919
*/
2020
int getSupportedNodeKind();
2121

22-
/**
23-
* Check if this construct can handle the given node.
24-
* Default implementation checks if the node kind is in getSupportedNodeKinds().
25-
*
26-
* @param node The tree node to check
27-
* @return true if this construct can handle the node
28-
*/
29-
default boolean canHandle(TreeNode node) {
30-
return node != null && getSupportedNodeKind() == node.getKind();
31-
}
32-
3322
/**
3423
* Build a Doc object for formatting this construct.
3524
*
36-
* @param node The SANY tree node representing this construct
37-
* @param context Context object providing access to configuration and utilities
38-
* @param indentSize
25+
* @param node The SANY tree node representing this construct
26+
* @param context Context object providing access to configuration and utilities
3927
* @return A Doc object for pretty printing
4028
*/
4129
Doc buildDoc(TreeNode node, ConstructContext context, int indentSize);
4230

43-
/**
44-
* Default indent size, pulled from the formatter configuration.
45-
*
46-
* @param context Construct context providing access to config
47-
* @return indent size from config
48-
*/
49-
default int indentSize(ConstructContext context) {
50-
return context.getConfig().getIndentSize();
51-
}
5231
}

0 commit comments

Comments
 (0)