-
Couldn't load subscription status.
- Fork 20
Feat/add lombok #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/add lombok #87
Changes from 4 commits
a045da7
ffa2d92
5376f2e
5b893e7
be7db4c
7147345
d232cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,28 @@ | ||||||||||||||||||||||||||||||
| package com.mycmd; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||||||||||||
| import lombok.Setter; | ||||||||||||||||||||||||||||||
| import lombok.NonNull; | ||||||||||||||||||||||||||||||
| import java.io.*; | ||||||||||||||||||||||||||||||
| import java.util.*; | ||||||||||||||||||||||||||||||
| import java.time.Instant; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||||||||||
| public class ShellContext { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @Setter | ||||||||||||||||||||||||||||||
| @NonNull | ||||||||||||||||||||||||||||||
| private File currentDir; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private List<String> history; | ||||||||||||||||||||||||||||||
| private Map<String, String> aliases; | ||||||||||||||||||||||||||||||
| private static final String ALIAS_FILE = ".mycmd_aliases"; | ||||||||||||||||||||||||||||||
| private static final int MAX_HISTORY = 100; | ||||||||||||||||||||||||||||||
| private final List<String> commandHistory; | ||||||||||||||||||||||||||||||
| private final Instant startTime; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private final Map<String, String> envVars = new HashMap<>(); | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add @Getter(AccessLevel.NONE) to the envVars field. The Apply this diff: + @Getter(AccessLevel.NONE)
private final Map<String, String> envVars = new HashMap<>();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public ShellContext() { | ||||||||||||||||||||||||||||||
| this.currentDir = new File(System.getProperty("user.dir")); | ||||||||||||||||||||||||||||||
| this.history = new ArrayList<>(); | ||||||||||||||||||||||||||||||
|
|
@@ -22,34 +32,33 @@ public ShellContext() { | |||||||||||||||||||||||||||||
| loadAliases(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public File getCurrentDir() { | ||||||||||||||||||||||||||||||
| return currentDir; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public void setCurrentDir(File dir) { | ||||||||||||||||||||||||||||||
| this.currentDir = dir; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public void addToHistory(String command) { | ||||||||||||||||||||||||||||||
| history.add(command); | ||||||||||||||||||||||||||||||
| commandHistory.add(command); // Add to command history | ||||||||||||||||||||||||||||||
| commandHistory.add(command); | ||||||||||||||||||||||||||||||
| if (history.size() > MAX_HISTORY) { | ||||||||||||||||||||||||||||||
| history.remove(0); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY | ||||||||||||||||||||||||||||||
| * to prevent external code from modifying the shell directly. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||
| public List<String> getHistory() { | ||||||||||||||||||||||||||||||
| return new ArrayList<>(history); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| /** * OVERRIDES Lombok's generated getter to return a DEFENSIVE COPY | |
| * to prevent external code from modifying the shell directly. | |
| */ | |
| @Override | |
| public List<String> getHistory() { | |
| return new ArrayList<>(history); | |
| } | |
| /** | |
| * Returns a defensive copy of the command history | |
| * to prevent external code from modifying it directly. | |
| */ | |
| public List<String> getHistory() { | |
| return new ArrayList<>(history); | |
| } |
🧰 Tools
🪛 GitHub Actions: ⚙️ Java CI Build
[error] 46-46: Override annotation error: method does not override or implement a method from a supertype.
🤖 Prompt for AI Agents
In src/main/java/com/mycmd/ShellContext.java around lines 43 to 49, remove the
invalid @Override annotation from the getHistory() method (it causes a
compilation error because Lombok generates the getter in the same class), and
update the Javadoc to remove the "OVERRIDES" wording — instead document that
this is a custom getter that returns a defensive copy to prevent external
mutation; keep the method body returning new ArrayList<>(history) and ensure you
have previously added @Getter(AccessLevel.NONE) to the history field so Lombok
does not generate a conflicting getter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: Class-level @Getter conflicts with custom getter implementations.
The class-level
@Gettergenerates getters for all fields, but you're attempting to provide custom implementations forgetHistory(),getAliases(), andgetEnvVars()that return defensive copies. This approach causes the@Overridecompilation errors on lines 46, 51, and 56 because you cannot override methods generated in the same class.Solution: Exclude specific fields from the class-level
@Getterby annotating them with@Getter(AccessLevel.NONE), then provide your custom getters without@Override.Apply this diff:
Then remove the
@Overrideannotations from lines 46, 51, and 56 (see separate comments below).🤖 Prompt for AI Agents