mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[multiple] Cleanup: use record patterns
GitOrigin-RevId: dca054f83dadfb60c9aa1b0d950423fc55e3a7a3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c387faa3f6
commit
fd093ea5ff
+8
-11
@@ -270,22 +270,19 @@ public final class JavaPatternExhaustivenessUtil {
|
||||
List<? extends PatternDescriptor> patternDescriptions = basePattern.list();
|
||||
for (int i = 0; i < patternDescriptions.size(); i++) {
|
||||
PatternDescriptor baseDescription = patternDescriptions.get(i);
|
||||
if (!(baseDescription instanceof PatternTypeTestDescriptor baseTypeDescription)) continue;
|
||||
if (baseTypeDescription.psiClass == null) continue;
|
||||
if (!JavaPsiSealedUtil.isAbstractSealed(baseTypeDescription.psiClass)) continue;
|
||||
if (!(baseDescription instanceof PatternTypeTestDescriptor(PsiType baseType, PsiClass baseClass))) continue;
|
||||
if (baseClass == null) continue;
|
||||
if (!JavaPsiSealedUtil.isAbstractSealed(baseClass)) continue;
|
||||
for (PatternDeconstructionDescriptor comparedPattern : deconstructionExistedPatternWithTheSameType) {
|
||||
if (comparedPattern == basePattern) continue;
|
||||
if (!comparedPattern.type().equals(basePattern.type())) continue;
|
||||
if (comparedPattern.list().size() != patternDescriptions.size()) continue;
|
||||
PatternDescriptor comparedDescription = comparedPattern.list().get(i);
|
||||
if (!(comparedDescription instanceof PatternTypeTestDescriptor comparedTypeDescription)) continue;
|
||||
if (comparedTypeDescription.psiClass == null) continue;
|
||||
if (baseTypeDescription.psiClass.getManager()
|
||||
.areElementsEquivalent(baseTypeDescription.psiClass, comparedTypeDescription.psiClass)) {
|
||||
continue;
|
||||
}
|
||||
if (!baseTypeDescription.type.isAssignableFrom(comparedTypeDescription.type)) continue;
|
||||
if (!isDirectSealedPath(comparedTypeDescription.psiClass, baseTypeDescription.psiClass, cache, new HashSet<>())) {
|
||||
if (!(comparedDescription instanceof PatternTypeTestDescriptor(PsiType cmpType, PsiClass cmpClass))) continue;
|
||||
if (cmpClass == null) continue;
|
||||
if (baseClass.getManager().areElementsEquivalent(baseClass, cmpClass)) continue;
|
||||
if (!baseType.isAssignableFrom(cmpType)) continue;
|
||||
if (!isDirectSealedPath(cmpClass, baseClass, cache, new HashSet<>())) {
|
||||
continue;
|
||||
}
|
||||
result.addAll(createPatternsFrom(i, Set.of(comparedDescription), basePattern));
|
||||
|
||||
+2
-2
@@ -181,9 +181,9 @@ public final class BytecodeAnalysisIndex extends ScalarIndexExtension<HMember> {
|
||||
}
|
||||
writeDataValue(out, effects.returnValue);
|
||||
}
|
||||
else if (rhs instanceof FieldAccess fieldAccess) {
|
||||
else if (rhs instanceof FieldAccess(String name)) {
|
||||
DataInputOutputUtil.writeINT(out, maxFinal + 1);
|
||||
out.writeUTF(fieldAccess.name());
|
||||
out.writeUTF(name);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unsupported result: " + rhs + " in " + eqs);
|
||||
|
||||
+2
-2
@@ -81,9 +81,9 @@ public class ProjectBytecodeAnalysis {
|
||||
if (eKey == null) return null;
|
||||
EKey accessKey = myEquationProvider.adaptKey(eKey);
|
||||
for (Equations equation : myEquationProvider.getEquations(accessKey.member)) {
|
||||
if (equation.find(direction).orElse(null) instanceof FieldAccess access) {
|
||||
if (equation.find(direction).orElse(null) instanceof FieldAccess(String fieldName)) {
|
||||
PsiClass containingClass = accessor.getContainingClass();
|
||||
return containingClass != null ? containingClass.findFieldByName(access.name(), false) : null;
|
||||
return containingClass != null ? containingClass.findFieldByName(fieldName, false) : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+3
-3
@@ -547,13 +547,13 @@ public final class TypeConstraints {
|
||||
|
||||
@Override
|
||||
public boolean isAssignableFrom(@NotNull Exact other) {
|
||||
return other instanceof ExactArray exactArray && component.isAssignableFrom(exactArray.component);
|
||||
return other instanceof ExactArray(Exact otherComponent) && component.isAssignableFrom(otherComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConvertibleFrom(@NotNull Exact other) {
|
||||
if (other instanceof ExactArray exactArray) {
|
||||
return component.isConvertibleFrom(exactArray.component);
|
||||
if (other instanceof ExactArray(Exact otherComponent)) {
|
||||
return component.isConvertibleFrom(otherComponent);
|
||||
}
|
||||
if (other instanceof ArraySuperInterface) return true;
|
||||
if (other == EXACTLY_OBJECT) return true;
|
||||
|
||||
+2
-2
@@ -222,7 +222,7 @@ final class OverwrittenFieldAnalyzer {
|
||||
if (dest instanceof DfaVariableValue var) {
|
||||
List<DfaVariableValue> varsToFlush = StreamEx.of(myFactory.getValues())
|
||||
.select(DfaVariableValue.class)
|
||||
.filter(v -> v.getDescriptor() instanceof WriteAnchorDescriptor desc && desc.var.dependsOn(var))
|
||||
.filter(v -> v.getDescriptor() instanceof WriteAnchorDescriptor(var written) && written.dependsOn(var))
|
||||
.toList();
|
||||
varsToFlush.forEach(state::flushVariable);
|
||||
if (var.getPsiVariable() instanceof PsiField && anchor != null) {
|
||||
@@ -235,7 +235,7 @@ final class OverwrittenFieldAnalyzer {
|
||||
private void markAsRead(@NotNull DfaMemoryState state, @NotNull DfaVariableValue var) {
|
||||
List<DfaVariableValue> varsToMark = StreamEx.of(myFactory.getValues())
|
||||
.select(DfaVariableValue.class)
|
||||
.filter(v -> v.getDescriptor() instanceof WriteAnchorDescriptor desc && desc.var.dependsOn(var))
|
||||
.filter(v -> v.getDescriptor() instanceof WriteAnchorDescriptor(var written) && written.dependsOn(var))
|
||||
.toList();
|
||||
varsToMark.forEach(variable -> setAnchorToRead(state, variable));
|
||||
}
|
||||
|
||||
+4
-4
@@ -198,10 +198,10 @@ final class MoveInitializerToIfBranchFixer implements EffectivelyFinalFixer {
|
||||
@Override
|
||||
public @NotNull InitMode join(@NotNull InitMode nextMode) {
|
||||
if (nextMode == ExactMode.NOT_INITIALIZED) return this;
|
||||
if (!(nextMode instanceof Branched branched)) return ExactMode.BOTTOM;
|
||||
if (ifStatement() != branched.ifStatement()) return ExactMode.BOTTOM;
|
||||
InitMode newThen = thenBranch().join(branched.thenBranch());
|
||||
InitMode newElse = elseBranch().join(branched.elseBranch());
|
||||
if (!(nextMode instanceof Branched(PsiIfStatement nextIf, InitMode nextThen, InitMode nextElse))) return ExactMode.BOTTOM;
|
||||
if (ifStatement() != nextIf) return ExactMode.BOTTOM;
|
||||
InitMode newThen = thenBranch().join(nextThen);
|
||||
InitMode newElse = elseBranch().join(nextElse);
|
||||
if (newThen == ExactMode.BOTTOM || newElse == ExactMode.BOTTOM) return ExactMode.BOTTOM;
|
||||
if (newThen == newElse) return newThen;
|
||||
return new Branched(ifStatement(), newThen, newElse);
|
||||
|
||||
@@ -721,18 +721,18 @@ public class SnippetMarkup {
|
||||
Replace replace = (Replace)markupNode;
|
||||
Selector selector = replace.selector();
|
||||
String replacement = replace.replacement();
|
||||
if (selector instanceof Regex regex) {
|
||||
if (selector instanceof Regex(Pattern pattern)) {
|
||||
boolean addLineBreak = false;
|
||||
if (content.endsWith("\n")) {
|
||||
content = content.substring(0, content.length() - 1);
|
||||
addLineBreak = true;
|
||||
}
|
||||
try {
|
||||
content = regex.pattern().matcher(StringUtil.newBombedCharSequence(content, 1000)).replaceAll(replacement);
|
||||
content = pattern.matcher(StringUtil.newBombedCharSequence(content, 1000)).replaceAll(replacement);
|
||||
}
|
||||
catch (StackOverflowError | ProcessCanceledException e) {
|
||||
ErrorMarkup replacementError = new ErrorMarkup(
|
||||
replace.range(), JavaBundle.message("javadoc.snippet.error.regex.too.complex", "replace", regex.pattern().pattern()));
|
||||
replace.range(), JavaBundle.message("javadoc.snippet.error.regex.too.complex", "replace", pattern.pattern()));
|
||||
visitor.visitError(replacementError);
|
||||
}
|
||||
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
|
||||
@@ -744,8 +744,8 @@ public class SnippetMarkup {
|
||||
content += "\n";
|
||||
}
|
||||
}
|
||||
else if (selector instanceof Substring substring) {
|
||||
content = content.replace(substring.substring(), replacement);
|
||||
else if (selector instanceof Substring(String substring)) {
|
||||
content = content.replace(substring, replacement);
|
||||
}
|
||||
else {
|
||||
content = replacement;
|
||||
|
||||
@@ -164,9 +164,9 @@ class JavaGreenIntentionPolicy extends JavaIntentionPolicy {
|
||||
|
||||
@Override
|
||||
public @Nullable String validateCommand(@NotNull ModCommand modCommand) {
|
||||
if (modCommand instanceof ModShowConflicts conflicts) {
|
||||
if (modCommand instanceof ModShowConflicts(var conflicts)) {
|
||||
return "Conflict; may break compilation: " +
|
||||
conflicts.conflicts().values().stream().flatMap(c -> c.messages().stream()).distinct().collect(Collectors.joining("; "));
|
||||
conflicts.values().stream().flatMap(c -> c.messages().stream()).distinct().collect(Collectors.joining("; "));
|
||||
}
|
||||
return super.validateCommand(modCommand);
|
||||
}
|
||||
|
||||
@@ -351,12 +351,12 @@ public sealed interface ModCommand
|
||||
if (sub instanceof ModUpdateFileText updateFileText && updateFileText.file().equals(virtualFile)) {
|
||||
offset = updateFileText.translateOffset(offset, leanRight);
|
||||
}
|
||||
if (sub instanceof ModDeleteFile deleteFile && deleteFile.file().equals(virtualFile)) {
|
||||
if (sub instanceof ModDeleteFile(VirtualFile fileToDelete) && fileToDelete.equals(virtualFile)) {
|
||||
// Navigation is useless: we are removing the target file
|
||||
return command;
|
||||
}
|
||||
if (sub instanceof ModMoveFile moveFile && moveFile.file().equals(virtualFile)) {
|
||||
virtualFile = moveFile.targetFile();
|
||||
if (sub instanceof ModMoveFile(VirtualFile fileToMove, FutureVirtualFile targetFile) && fileToMove.equals(virtualFile)) {
|
||||
virtualFile = targetFile;
|
||||
}
|
||||
if (!(sub instanceof ModNavigate)) {
|
||||
finalCommand = finalCommand.andThen(sub);
|
||||
|
||||
@@ -32,8 +32,8 @@ public record ModUpdateSystemOptions(@NotNull List<@NotNull ModifiedOption> opti
|
||||
|
||||
@Override
|
||||
public @NotNull ModCommand andThen(@NotNull ModCommand next) {
|
||||
if (next instanceof ModUpdateSystemOptions nextUpdate) {
|
||||
return new ModUpdateSystemOptions(ContainerUtil.concat(options, nextUpdate.options));
|
||||
if (next instanceof ModUpdateSystemOptions(var nextOptions)) {
|
||||
return new ModUpdateSystemOptions(ContainerUtil.concat(options, nextOptions));
|
||||
}
|
||||
return ModCommand.super.andThen(next);
|
||||
}
|
||||
|
||||
+54
-65
@@ -77,51 +77,43 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
if (command.isEmpty()) {
|
||||
return Result.NOTHING;
|
||||
}
|
||||
if (command instanceof ModUpdateFileText upd) {
|
||||
return executeUpdate(project, upd) ? Result.SUCCESS : Result.ABORT;
|
||||
}
|
||||
if (command instanceof ModCreateFile create) {
|
||||
String message = executeCreate(project, create);
|
||||
return message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
if (command instanceof ModDeleteFile deleteFile) {
|
||||
String message = executeDelete(deleteFile);
|
||||
return message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
if (command instanceof ModMoveFile moveFile) {
|
||||
String message = executeMove(moveFile);
|
||||
return message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
if (command instanceof ModCompositeCommand cmp) {
|
||||
BatchExecutionResult result = Result.NOTHING;
|
||||
for (ModCommand subCommand : cmp.commands()) {
|
||||
result = result.compose(doExecuteInBatch(context, subCommand));
|
||||
if (result == Result.ABORT || result instanceof Error) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (command instanceof ModChooseAction chooser) {
|
||||
return executeChooseInBatch(context, chooser);
|
||||
}
|
||||
if (command instanceof ModNavigate || command instanceof ModHighlight ||
|
||||
command instanceof ModCopyToClipboard || command instanceof ModStartRename ||
|
||||
command instanceof ModStartTemplate || command instanceof ModUpdateSystemOptions ||
|
||||
command instanceof ModUpdateReferences || command instanceof ModOpenUrl) {
|
||||
return Result.INTERACTIVE;
|
||||
}
|
||||
if (command instanceof ModShowConflicts) {
|
||||
return Result.CONFLICTS;
|
||||
}
|
||||
if (command instanceof ModEditOptions<?> editOptions) {
|
||||
return bypassEditOptions(editOptions, context);
|
||||
}
|
||||
if (command instanceof ModDisplayMessage message) {
|
||||
if (message.kind() == ModDisplayMessage.MessageKind.ERROR) {
|
||||
return new Error(message.messageText());
|
||||
return switch (command) {
|
||||
case ModUpdateFileText upd -> executeUpdate(project, upd) ? Result.SUCCESS : Result.ABORT;
|
||||
case ModCreateFile create -> {
|
||||
String message = executeCreate(project, create);
|
||||
yield message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
return Result.INTERACTIVE;
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown command: " + command);
|
||||
case ModDeleteFile deleteFile -> {
|
||||
String message = executeDelete(deleteFile);
|
||||
yield message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
case ModMoveFile moveFile -> {
|
||||
String message = executeMove(moveFile);
|
||||
yield message == null ? Result.SUCCESS : new Error(message);
|
||||
}
|
||||
case ModCompositeCommand(var commands) -> {
|
||||
BatchExecutionResult result = Result.NOTHING;
|
||||
for (ModCommand subCommand : commands) {
|
||||
result = result.compose(doExecuteInBatch(context, subCommand));
|
||||
if (result == Result.ABORT || result instanceof Error) break;
|
||||
}
|
||||
yield result;
|
||||
}
|
||||
case ModChooseAction chooser -> executeChooseInBatch(context, chooser);
|
||||
case ModShowConflicts ignored -> Result.CONFLICTS;
|
||||
case ModEditOptions<?> editOptions -> bypassEditOptions(editOptions, context);
|
||||
case ModDisplayMessage(String text, var kind) -> switch (kind) {
|
||||
case ERROR -> new Error(text);
|
||||
case INFORMATION -> Result.INTERACTIVE;
|
||||
};
|
||||
default -> throw new IllegalArgumentException("Unknown command: " + command);
|
||||
};
|
||||
}
|
||||
|
||||
private <T extends OptionContainer> BatchExecutionResult bypassEditOptions(@NotNull ModEditOptions<T> options, @NotNull ActionContext context) {
|
||||
@@ -201,15 +193,15 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
return null;
|
||||
}
|
||||
VirtualFile newFile = parent.createChildData(this, file.getName());
|
||||
if (create.content() instanceof ModCreateFile.Text text) {
|
||||
if (create.content() instanceof ModCreateFile.Text(String text)) {
|
||||
PsiFile psiFile = PsiManager.getInstance(project).findFile(newFile);
|
||||
if (psiFile == null) return AnalysisBundle.message("modcommand.executor.unable.to.find.the.new.file", file.getName());
|
||||
Document document = psiFile.getViewProvider().getDocument();
|
||||
document.setText(text.text());
|
||||
document.setText(text);
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
}
|
||||
else if (create.content() instanceof ModCreateFile.Binary binary) {
|
||||
newFile.setBinaryContent(binary.bytes());
|
||||
else if (create.content() instanceof ModCreateFile.Binary(byte[] bytes)) {
|
||||
newFile.setBinaryContent(bytes);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@@ -302,17 +294,16 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
modFile.newText(),
|
||||
true));
|
||||
}
|
||||
else if (command instanceof ModCreateFile createFile) {
|
||||
VirtualFile vFile = createFile.file();
|
||||
if (createFile.content() instanceof ModCreateFile.Directory) {
|
||||
createdDirs.add(getFileNamePresentation(project, vFile));
|
||||
else if (command instanceof ModCreateFile(FutureVirtualFile createdFile, ModCreateFile.Content content)) {
|
||||
if (content instanceof ModCreateFile.Directory) {
|
||||
createdDirs.add(getFileNamePresentation(project, createdFile));
|
||||
} else {
|
||||
String content =
|
||||
createFile.content() instanceof ModCreateFile.Text text ? text.text() : AnalysisBundle.message("preview.binary.content");
|
||||
customDiffList.add(new IntentionPreviewInfo.CustomDiff(vFile.getFileType(),
|
||||
getFileNamePresentation(project, vFile),
|
||||
String contentRepresentation =
|
||||
content instanceof ModCreateFile.Text(String text) ? text : AnalysisBundle.message("preview.binary.content");
|
||||
customDiffList.add(new IntentionPreviewInfo.CustomDiff(createdFile.getFileType(),
|
||||
getFileNamePresentation(project, createdFile),
|
||||
"",
|
||||
content,
|
||||
contentRepresentation,
|
||||
true));
|
||||
}
|
||||
}
|
||||
@@ -331,31 +322,29 @@ public class ModCommandBatchExecutorImpl implements ModCommandExecutor {
|
||||
else if (command instanceof ModEditOptions<?> target) {
|
||||
return getEditOptionsPreview(context, target);
|
||||
}
|
||||
else if (command instanceof ModDisplayMessage message) {
|
||||
if (message.kind() == ModDisplayMessage.MessageKind.ERROR) {
|
||||
else if (command instanceof ModDisplayMessage(String text, ModDisplayMessage.MessageKind kind)) {
|
||||
if (kind == ModDisplayMessage.MessageKind.ERROR) {
|
||||
return new IntentionPreviewInfo.Html(new HtmlBuilder().append(
|
||||
AnalysisBundle.message("preview.cannot.perform.action")).br().append(message.messageText()).toFragment(),
|
||||
IntentionPreviewInfo.InfoKind.ERROR);
|
||||
AnalysisBundle.message("preview.cannot.perform.action")).br().append(text).toFragment(), IntentionPreviewInfo.InfoKind.ERROR);
|
||||
}
|
||||
else if (navigateInfo == IntentionPreviewInfo.EMPTY) {
|
||||
navigateInfo = new IntentionPreviewInfo.Html(message.messageText());
|
||||
navigateInfo = new IntentionPreviewInfo.Html(text);
|
||||
}
|
||||
}
|
||||
else if (command instanceof ModCopyToClipboard copy) {
|
||||
else if (command instanceof ModCopyToClipboard(String content)) {
|
||||
navigateInfo = new IntentionPreviewInfo.Html(text(
|
||||
AnalysisBundle.message("preview.copy.to.clipboard", StringUtil.shortenTextWithEllipsis(copy.content(), 50, 10))));
|
||||
AnalysisBundle.message("preview.copy.to.clipboard", StringUtil.shortenTextWithEllipsis(content, 50, 10))));
|
||||
}
|
||||
else if (command instanceof ModOpenUrl openUrl) {
|
||||
else if (command instanceof ModOpenUrl(String url)) {
|
||||
navigateInfo = new IntentionPreviewInfo.Html(text(
|
||||
AnalysisBundle.message("preview.open.url", StringUtil.shortenTextWithEllipsis(openUrl.url(), 50, 10))));
|
||||
AnalysisBundle.message("preview.open.url", StringUtil.shortenTextWithEllipsis(url, 50, 10))));
|
||||
}
|
||||
else if (command instanceof ModMoveFile moveFile) {
|
||||
FutureVirtualFile targetFile = moveFile.targetFile();
|
||||
else if (command instanceof ModMoveFile(VirtualFile fileToCreate, FutureVirtualFile targetFile)) {
|
||||
IntentionPreviewInfo.Html html;
|
||||
if (targetFile.getName().equals(moveFile.file().getName())) {
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.moveToDirectory(moveFile.file(), targetFile.getParent());
|
||||
if (targetFile.getName().equals(fileToCreate.getName())) {
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.moveToDirectory(fileToCreate, targetFile.getParent());
|
||||
} else {
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.rename(moveFile.file(), targetFile.getName());
|
||||
html = (IntentionPreviewInfo.Html)IntentionPreviewInfo.rename(fileToCreate, targetFile.getName());
|
||||
}
|
||||
fsActions.add(html.content());
|
||||
}
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ public abstract class RunLineMarkerContributor implements PossiblyDumbAware {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof TooltipProvider other && Arrays.equals(actions, other.actions);
|
||||
return obj instanceof TooltipProvider(AnAction[] otherActions) && Arrays.equals(actions, otherActions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -256,21 +256,21 @@ public class ModCommandExecutorImpl extends ModCommandBatchExecutorImpl {
|
||||
WriteAction.run(() -> {
|
||||
TemplateBuilderImpl builder = new TemplateBuilderImpl(psiFile);
|
||||
for (ModStartTemplate.TemplateField field : template.fields()) {
|
||||
if (field instanceof ModStartTemplate.ExpressionField expr) {
|
||||
if (expr.varName() != null) {
|
||||
builder.replaceElement(psiFile, expr.range(), expr.varName(), expr.expression(), true);
|
||||
} else {
|
||||
builder.replaceElement(psiFile, expr.range(), expr.expression());
|
||||
switch (field) {
|
||||
case ModStartTemplate.ExpressionField(TextRange range, String varName, Expression expression) -> {
|
||||
if (varName != null) {
|
||||
builder.replaceElement(psiFile, range, varName, expression, true);
|
||||
} else {
|
||||
builder.replaceElement(psiFile, range, expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (field instanceof ModStartTemplate.DependantVariableField variableField) {
|
||||
builder.replaceElement(psiFile, variableField.range(), variableField.varName(),
|
||||
variableField.dependantVariableName(), variableField.alwaysStopAt());
|
||||
}
|
||||
else if (field instanceof ModStartTemplate.EndField endField) {
|
||||
PsiElement leaf = psiFile.findElementAt(endField.range().getStartOffset());
|
||||
if (leaf != null) {
|
||||
builder.setEndVariableBefore(leaf);
|
||||
case ModStartTemplate.DependantVariableField(TextRange range, String varName, String variableName, boolean alwaysStopAt) ->
|
||||
builder.replaceElement(psiFile, range, varName, variableName, alwaysStopAt);
|
||||
case ModStartTemplate.EndField(TextRange range) -> {
|
||||
PsiElement leaf = psiFile.findElementAt(range.getStartOffset());
|
||||
if (leaf != null) {
|
||||
builder.setEndVariableBefore(leaf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public interface JBAccountInfoService {
|
||||
LoginSession loginSession = startLoginSession(LoginMode.AUTO);
|
||||
loginSession.onCompleted()
|
||||
.thenAccept(result -> {
|
||||
if (result instanceof LoginResult.LoginSuccessful successful && userIdConsumer != null) {
|
||||
userIdConsumer.accept(successful.jbaUser().id);
|
||||
if (result instanceof LoginResult.LoginSuccessful(JBAData user) && userIdConsumer != null) {
|
||||
userIdConsumer.accept(user.id);
|
||||
}
|
||||
if (result instanceof LoginResult.LoginFailed && onFailure != null) {
|
||||
onFailure.run();
|
||||
|
||||
+5
-7
@@ -123,12 +123,10 @@ public class IntentionPolicy {
|
||||
*/
|
||||
public @Nullable String validateCommand(@NotNull ModCommand modCommand) {
|
||||
// TODO: debug commands that do nothing. This should not be generally the case
|
||||
if (modCommand instanceof ModDisplayMessage message && message.kind() == ModDisplayMessage.MessageKind.ERROR) {
|
||||
return "Error: " + message.messageText();
|
||||
}
|
||||
if (modCommand instanceof ModUpdateSystemOptions option) {
|
||||
return "Updates " + option.options().stream().map(opt -> opt.bindId()).collect(Collectors.joining("; "));
|
||||
}
|
||||
return null;
|
||||
return switch (modCommand) {
|
||||
case ModDisplayMessage(var text, var kind) when kind == ModDisplayMessage.MessageKind.ERROR -> "Error: " + text;
|
||||
case ModUpdateSystemOptions(var options) -> "Updates " + options.stream().map(opt -> opt.bindId()).collect(Collectors.joining("; "));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,8 +764,8 @@ public final class TypoTolerantMatcher extends MinusculeMatcher {
|
||||
}
|
||||
|
||||
private static char[] applyError(char[] pattern, ErrorWithIndex error) {
|
||||
if (error.error instanceof TypoError typoError) {
|
||||
pattern[error.index] = typoError.correctChar;
|
||||
if (error.error instanceof TypoError(char correctChar)) {
|
||||
pattern[error.index] = correctChar;
|
||||
return pattern;
|
||||
}
|
||||
else if (error.error instanceof SwapError) {
|
||||
@@ -775,8 +775,8 @@ public final class TypoTolerantMatcher extends MinusculeMatcher {
|
||||
pattern[index + 1] = c;
|
||||
return pattern;
|
||||
}
|
||||
else if (error.error instanceof MissError missError) {
|
||||
return ArrayUtil.insert(pattern, error.index, missError.missedChar);
|
||||
else if (error.error instanceof MissError(char missedChar)) {
|
||||
return ArrayUtil.insert(pattern, error.index, missedChar);
|
||||
}
|
||||
|
||||
return pattern;
|
||||
|
||||
Reference in New Issue
Block a user