8000 Argument exceptions2 by willkroboth · Pull Request #476 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Argument exceptions2 #476

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

Draft
wants to merge 28 commits into
base: dev/dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
da16444
Remake argument-exceptions branch
willkroboth Jul 30, 2023
bb78f3e
Create InitialParseExceptionParser because TriFunction was being weird
willkroboth Jul 31, 2023
10cd400
Fix implementation of NMS_Common#extractTranslationKey for pre 1.19
willkroboth Jul 31, 2023
17543b6
Fix method reflection in ExceptionHandlingArgumentSerializers
willkroboth Jul 31, 2023
7191cd9
Fix Brigadier exposure when using IntegerArgument
willkroboth Jul 31, 2023
a1bf7b2
Address some SonarCloud code smells on `argument-exceptions2`
willkroboth Jul 31, 2023
e6d987b
Refactor negated pattern variables
willkroboth Aug 14, 2023
ba7c67e
Add javadocs to WrapperStringReader methods
willkroboth Aug 14, 2023
05d01f3
Add `InitialParse` to the name of `ExceptionHandlingArgumentType` and…
willkroboth Aug 14, 2023
a426196
Fix `Initial`ParseExceptionHandlingArgumentType accidentally being na…
willkroboth Aug 14, 2023
c1ff4d3
Create InitialParseExceptionNumberArgument to share ExceptionInformat…
willkroboth Aug 14, 2023
11a24b8
Clean up InitialParseExceptionNumberArgument
willkroboth Aug 14, 2023
62587ec
Move parse exception related classes in `dev.jorel.commandapi.argumen…
willkroboth Aug 14, 2023
1974b30
Fix javadoc link to IntegerArgument in InitialParseExceptionNumberArg…
willkroboth Aug 14, 2023
e2b8e99
Fix variable name capitalization in InitialParseExceptionHandlingArgu…
willkroboth Aug 14, 2023
149d4d7
Add InitialParseExceptionTextArgument for Arguments that use `StringA…
willkroboth Aug 14, 2023
0fac123
Add cursorStart to InitialParseExceptionContext
willkroboth Aug 14, 2023
e3f65d3
Add rawItem to ListArgumentCommon.ArgumentParseExceptionInformation
willkroboth Aug 14, 2023
5861f00
Add test for substituting values when using an ArgumentParseException…
willkroboth Aug 14, 2023
ae0fac4
Add package for `parseexceptions` tests
willkroboth Aug 14, 2023
5a1a16e
Fix javadocs in InitialParseExceptionNumberArgument that refer to `in…
willkroboth Aug 16, 2023
c41f567
Add tests for InitialParseExceptionNumberArguments usage
willkroboth Aug 16, 2023
d18e3d4
Remove public modifier from new tests
willkroboth Aug 16, 2023
f9ff517
Add `InitialParseExceptionContextVerifier` and `ArgumentParseExceptio…
willkroboth Aug 16, 2023
412a0ef
Add `assertCorrectContext` method to ArgumentParseExceptionContextVer…
willkroboth Aug 17, 2023
f7cc6d8
Add `argumentParseExceptionTestWithListArgument`
willkroboth Aug 17, 2023
3c72dde
Add `initialParseExceptionTestWithListTextArgument`
willkroboth Aug 17, 2023
8d40f57
Change `exceptionHandlers` maps to `WeakHashMaps`
willkroboth Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor negated pattern variables
  • Loading branch information
willkroboth committed Aug 17, 2023
commit e6d987b7ce4ef824a0cf48a8833d89eab9e9e1f3
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,16 @@ <T, EI> ArgumentType<T> wrapArgumentType(Argument argument, ArgumentType<T> rawT
return wrapArgumentType(((WrapperArgument<Argument>) argument).getBaseArgument(), rawType);
}

if (!(argument instanceof InitialParseExceptionArgument)) return rawType;
if (argument instanceof InitialParseExceptionArgument) {
InitialParseExceptionArgument<T, EI, ?> iPEA = (InitialParseExceptionArgument<T, EI, ?>) argument.instance();
Optional<InitialParseExceptionHandler<T, EI>> handler = iPEA.getInitialParseExceptionHandler();

InitialParseExceptionArgument<T, EI, ?> iPEA = (InitialParseExceptionArgument<T, EI, ?>) argument.instance();
if (handler.isPresent()) {
return new ExceptionHandlingArgumentType<>(rawType, handler.get(), iPEA::parseInitialParseException);
}
}

Optional<InitialParseExceptionHandler<T, EI>> handler = iPEA.getInitialParseExceptionHandler();
if (handler.isEmpty()) return rawType;
return new ExceptionHandlingArgumentType<>(rawType, handler.get(), iPEA::parseInitialParseException);
return rawType;
}

CommandArguments generatePreviousArguments(CommandContext<Source> context, Argument[] args, String nodeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,6 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof ChatMessage chat)) return null;

return chat.getKey();
return (message instanceof ChatMessage chat) ? chat.getKey() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,7 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof TranslatableComponent chat)) return null;

return chat.getKey();
return (message instanceof TranslatableComponent chat) ? chat.getKey() : null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,16 @@ public String extractTranslationKey(CommandSyntaxException exception) {
// which has a repeated structure that holds the translation key
// It might work for other exception sources ¯\_(ツ)_/¯
Message message = exception.getRawMessage();
if(!(message instanceof MutableComponent component)) return null;

ComponentContents contents = component.getContents();
if(!(contents instanceof TranslatableContents translatableContents)) return null;
if (message instanceof MutableComponent component) {
ComponentContents contents = component.getContents();

return translatableContents.getKey();
if (contents instanceof TranslatableContents translatableContents) {
return translatableContents.getKey();
}
}

return null;
}

@SuppressWarnings("unchecked")
Expand Down
0