Skip to content

Commit 5b893e7

Browse files
committed
fix(lombok): Refine Lombok annotations
1 parent 5376f2e commit 5b893e7

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
<plugin>
3131
<groupId>org.apache.maven.plugins</groupId>
3232
<artifactId>maven-compiler-plugin</artifactId>
33-
<version>3.11.0</version> <configuration>
33+
<version>3.11.0</version>
34+
<configuration>
3435
<source>${maven.compiler.source}</source>
3536
<target>${maven.compiler.target}</target>
3637
<annotationProcessorPaths>
3738
<path>
3839
<groupId>org.projectlombok</groupId>
3940
<artifactId>lombok</artifactId>
40-
<version>1.18.32</version> </path>
41+
<version>1.18.32</version>
42+
</path>
4143
</annotationProcessorPaths>
4244
</configuration>
4345
</plugin>

src/main/java/com/mycmd/ShellContext.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import lombok.Getter;
44
import lombok.Setter;
5+
import lombok.NonNull;
56
import java.io.*;
67
import java.util.*;
78
import java.time.Instant;
89

910
@Getter
10-
@Setter
1111
public class ShellContext {
12+
13+
@Setter
14+
@NonNull
1215
private File currentDir;
16+
1317
private List<String> history;
1418
private Map<String, String> aliases;
1519
private static final String ALIAS_FILE = ".mycmd_aliases";
@@ -30,12 +34,30 @@ public ShellContext() {
3034

3135
public void addToHistory(String command) {
3236
history.add(command);
33-
commandHistory.add(command); // Add to command history
37+
commandHistory.add(command);
3438
if (history.size() > MAX_HISTORY) {
3539
history.remove(0);
3640
}
3741
}
3842

43+
/** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY
44+
* to prevent external code from modifying the shell directly.
45+
*/
46+
@Override
47+
public List<String> getHistory() {
48+
return new ArrayList<>(history);
49+
}
50+
51+
@Override
52+
public Map<String, String> getAliases() {
53+
return new HashMap<>(aliases);
54+
}
55+
56+
@Override
57+
public Map<String, String> getEnvVars() {
58+
return new HashMap<>(envVars);
59+
}
60+
3961

4062
public void clearHistory() {
4163
history.clear();
@@ -51,11 +73,27 @@ public void removeAlias(String name) {
5173
aliases.remove(name);
5274
saveAliases();
5375
}
76+
77+
public String getAlias(String name) {
78+
return aliases.get(name);
79+
}
5480

5581
public boolean hasAlias(String name) {
5682
return aliases.containsKey(name);
5783
}
5884

85+
// Environmental variable accessors
86+
public void setEnvVar(String key, String value) {
87+
envVars.put(key, value);
88+
}
89+
90+
public String getEnvVar(String key) {
91+
return envVars.get(key);
92+
}
93+
94+
95+
// --- Private Persistence Methods ---
96+
5997
private void loadAliases() {
6098
File aliasFile = new File(System.getProperty("user.home"), ALIAS_FILE);
6199
if (!aliasFile.exists()) {
@@ -109,5 +147,4 @@ public File resolvePath(String path) {
109147
return new File(currentDir, path);
110148
}
111149
}
112-
113-
}
150+
}

0 commit comments

Comments
 (0)