[java-highlighting] IDEA-378781 Quick fixes for typos in keywords

- more cases
- move primitive types to PsiTypes.java

GitOrigin-RevId: 3a94f2e8fe84e9e2cb95d84bc7ebb13f77579916
This commit is contained in:
Mikhail Pyltsin
2025-09-24 17:40:19 +00:00
committed by intellij-monorepo-bot
parent db6d880d4a
commit a99d6a79da
141 changed files with 1226 additions and 89 deletions
@@ -225,10 +225,12 @@ public final class DefaultJavaErrorFixProvider extends AbstractJavaErrorFixProvi
}
}
});
fix(STATEMENT_BAD_EXPRESSION, error -> HighlightFixTypoUtil.createKeywordTypoFix(error.psi()));
fix(STATEMENT_UNREACHABLE,
error -> myFactory.createDeleteFix(error.psi(), QuickFixBundle.message("delete.unreachable.statement.fix.text")));
fix(STATEMENT_UNREACHABLE_LOOP_BODY, error -> myFactory.createSimplifyBooleanFix(error.psi(), false));
fix(FOREACH_NOT_APPLICABLE, error -> myFactory.createNotIterableForEachLoopFix(error.psi()));
fix(LABEL_WITHOUT_STATEMENT, error -> HighlightFixTypoUtil.createKeywordTypoFix(error.psi()));
fix(SWITCH_LABEL_EXPECTED, error -> {
PsiSwitchLabeledRuleStatement previousRule = PsiTreeUtil.getPrevSiblingOfType(error.psi(), PsiSwitchLabeledRuleStatement.class);
return previousRule == null ? null : myFactory.createWrapSwitchRuleStatementsIntoBlockFix(previousRule);
@@ -256,6 +258,7 @@ public final class DefaultJavaErrorFixProvider extends AbstractJavaErrorFixProvi
error.psi().getErrorDescription().equals(JavaPsiBundle.message("expected.switch.rule"))
? myFactory.createWrapSwitchRuleStatementsIntoBlockFix(rule)
: null);
fix(SYNTAX_ERROR, error -> HighlightFixTypoUtil.createKeywordTypoFix(error.psi()));
}
private void createMethodFixes() {
@@ -622,6 +625,7 @@ public final class DefaultJavaErrorFixProvider extends AbstractJavaErrorFixProvi
(error, sink) -> HighlightFixUtil.registerMethodCallIntentions(sink, error.psi(), error.psi().getArgumentList()));
fixes(CALL_AMBIGUOUS, (error, sink) -> HighlightFixUtil.registerAmbiguousCallFixes(sink, error.psi(), error.context().results()));
fixes(CALL_AMBIGUOUS_NO_MATCH, (error, sink) -> HighlightFixUtil.registerAmbiguousCallFixes(sink, error.psi(), error.context()));
fix(CALL_AMBIGUOUS_NO_MATCH, error -> HighlightFixTypoUtil.createKeywordTypoFix(error.psi()));
fixes(REFERENCE_NON_STATIC_FROM_STATIC_CONTEXT, (error, sink) -> {
HighlightFixUtil.registerStaticProblemQuickFixAction(sink, error.context(), error.psi());
if (error.psi().getParent() instanceof PsiMethodCallExpression methodCall) {
@@ -667,7 +671,7 @@ public final class DefaultJavaErrorFixProvider extends AbstractJavaErrorFixProvi
QualifySuperArgumentFix.registerQuickFixAction(error.context(), sink));
fix(REFERENCE_UNRESOLVED, error -> HighlightFixUtil.createUnresolvedReferenceFix(error.psi()));
fix(REFERENCE_UNRESOLVED, error -> HighlightFixUtil.createVariableTypeFix(error.psi()));
fix(REFERENCE_UNRESOLVED, error -> HighlightFixUtil.createKeywordTypoFix(error.psi()));
fix(REFERENCE_UNRESOLVED, error -> HighlightFixTypoUtil.createKeywordTypoFix(error.psi()));
fix(REFERENCE_QUALIFIER_PRIMITIVE,
error -> error.psi() instanceof PsiReferenceExpression ref ? myFactory.createRenameWrongRefFix(ref) : null);
fix(CAST_INTERSECTION_NOT_INTERFACE, error -> {
@@ -0,0 +1,441 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeInsight.intention.CommonIntentionAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.java.syntax.JavaSyntaxBundle;
import com.intellij.java.syntax.parser.JavaKeywords;
import com.intellij.modcommand.ModCommandAction;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.pom.java.JavaFeature;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.siyeh.ig.psiutils.ExpectedTypeUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
public final class HighlightFixTypoUtil {
private HighlightFixTypoUtil() {
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiErrorElement psiErrorElement) {
if (psiErrorElement == null) return null;
ModCommandAction fix = createThrowsTypoFix(psiErrorElement);
if (fix != null) return fix;
fix = createImplementExtendTypoFix(psiErrorElement);
return fix;
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiStatement psiStatement) {
if (psiStatement == null) return null;
ModCommandAction fix = createSwitchDefaultTypoFix(psiStatement);
return fix;
}
private static ModCommandAction createSwitchDefaultTypoFix(@NotNull PsiStatement statement) {
if (!(statement instanceof PsiExpressionStatement expressionStatement)) return null;
if (!(expressionStatement.getExpression() instanceof PsiLambdaExpression lambdaExpression)) return null;
PsiParameterList parameterList = lambdaExpression.getParameterList();
if (parameterList.getParametersCount() != 1) return null;
PsiParameter parameter = parameterList.getParameter(0);
if (!(statement.getParent() instanceof PsiCodeBlock codeBlock &&
codeBlock.getParent() instanceof PsiSwitchBlock)) {
return null;
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(parameter, Collections.singleton(JavaKeywords.DEFAULT));
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiLabeledStatement labeledStatement) {
if (labeledStatement == null) return null;
ModCommandAction fix = createSwitchDefaultTypoFix(labeledStatement);
return fix;
}
private static @Nullable ModCommandAction createImplementExtendTypoFix(@NotNull PsiErrorElement psiErrorElement) {
boolean extendFound = false;
boolean implementFound = false;
PsiElement firstReferenceList = PsiTreeUtil.skipWhitespacesBackward(psiErrorElement);
if (!(firstReferenceList instanceof PsiReferenceList referenceList1)) return null;
PsiElement secondReferenceList = PsiTreeUtil.skipWhitespacesBackward(firstReferenceList);
if (!(secondReferenceList instanceof PsiReferenceList referenceList2)) return null;
for (PsiReferenceList list : Set.of(referenceList1, referenceList2)) {
if (list.getChildren().length != 0) {
PsiElement firstChild = list.getFirstChild();
if (firstChild instanceof PsiKeyword && JavaKeywords.EXTENDS.equals(firstChild.getText())) {
if (extendFound) return null;
extendFound = true;
}
else if (firstChild instanceof PsiJavaCodeReferenceElement ref && JavaKeywords.IMPLEMENTS.equals(ref.getText())) {
if (implementFound) return null;
implementFound = true;
}
}
}
PsiElement typeParameters = PsiTreeUtil.skipWhitespacesBackward(secondReferenceList);
if (!(typeParameters instanceof PsiTypeParameterList)) return null;
PsiElement identifier = PsiTreeUtil.skipWhitespacesBackward(typeParameters);
if (!(identifier instanceof PsiIdentifier)) return null;
PsiElement classKeyword = PsiTreeUtil.skipWhitespacesBackward(identifier);
if (!(classKeyword instanceof PsiKeyword)) return null;
PsiElement targetElement = psiErrorElement.getChildren().length < 2 ? psiErrorElement : psiErrorElement.getChildren()[0];
return switch (classKeyword.getText()) {
case JavaKeywords.CLASS -> {
Set<String> keywords = new HashSet<>();
if (!extendFound) keywords.add(JavaKeywords.EXTENDS);
if (!implementFound) keywords.add(JavaKeywords.IMPLEMENTS);
yield QuickFixFactory.getInstance().createChangeToSimilarKeyword(targetElement, keywords);
}
case JavaKeywords.INTERFACE -> {
Set<String> keywords = new HashSet<>();
if (!extendFound) keywords.add(JavaKeywords.EXTENDS);
yield QuickFixFactory.getInstance().createChangeToSimilarKeyword(targetElement, keywords);
}
case JavaKeywords.ENUM, JavaKeywords.RECORD -> {
Set<String> keywords = new HashSet<>();
if (!implementFound) keywords.add(JavaKeywords.IMPLEMENTS);
yield QuickFixFactory.getInstance().createChangeToSimilarKeyword(targetElement, keywords);
}
default -> null;
};
}
private static @Nullable ModCommandAction createThrowsTypoFix(@NotNull PsiErrorElement psiErrorElement) {
PsiElement prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(psiErrorElement);
if (!(prevVisibleLeaf instanceof PsiJavaToken token && token.getTokenType() == JavaTokenType.RPARENTH)) return null;
if (!(token.getParent() instanceof PsiParameterList parameterList && parameterList.getParent() instanceof PsiMethod)) {
return null;
}
PsiElement element = psiErrorElement.getChildren().length < 2 ? psiErrorElement : psiErrorElement.getChildren()[0];
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(element, Collections.singleton(JavaKeywords.THROWS));
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiMethodCallExpression methodCallExpression) {
if (methodCallExpression == null) return null;
if (methodCallExpression.getMethodExpression().getQualifierExpression() != null) return null;
CommonIntentionAction action = createSynchronizedSwitchTypoFix(methodCallExpression);
if (action != null) return action;
action = createCatchFinallyTypoFix(methodCallExpression.getMethodExpression());
return action;
}
@Nullable
private static CommonIntentionAction createSynchronizedSwitchTypoFix(@NotNull PsiMethodCallExpression methodCallExpression) {
PsiExpressionList argumentList = methodCallExpression.getArgumentList();
PsiExpression[] expressions = argumentList.getExpressions();
if (expressions.length != 0 && expressions.length != 1) return null;
Set<String> keywords = new HashSet<>();
PsiElement parent = methodCallExpression.getParent();
if (parent instanceof PsiExpressionStatement) {
keywords.add(JavaKeywords.SYNCHRONIZED);
keywords.add(JavaKeywords.SWITCH);
}
else if (parent instanceof PsiExpression ||
parent instanceof PsiExpressionList ||
parent instanceof PsiReturnStatement) {
keywords.add(JavaKeywords.SWITCH);
}
return QuickFixFactory.getInstance()
.createChangeToSimilarKeyword(methodCallExpression.getMethodExpression(), keywords);
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiJavaCodeReferenceElement ref) {
if (ref == null) return null;
if (ref.isQualified()) return null;
CommonIntentionAction action = createVariableTypeTypoFix(ref);
if (action != null) return action;
action = createBooleanNullTypoFix(ref);
if (action != null) return action;
action = createBreakContinueTypoFix(ref);
if (action != null) return action;
action = createSynchronizedSwitchTypoFix(ref);
if (action != null) return action;
action = createClassTypoFix(ref);
if (action != null) return action;
action = createModifiersTypoFix(ref);
if (action != null) return action;
action = createCatchFinallyTypoFix(ref);
if (action != null) return action;
action = createSwitchDefaultTypoFix(ref);
return action;
}
@Nullable
private static CommonIntentionAction createSwitchDefaultTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (!(ref instanceof PsiReferenceExpression &&
ref.getParent() instanceof PsiExpressionStatement expressionStatement &&
expressionStatement.getParent() instanceof PsiCodeBlock codeBlock &&
codeBlock.getParent() instanceof PsiSwitchBlock)) {
return null;
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, Collections.singleton(JavaKeywords.DEFAULT));
}
@Nullable
private static ModCommandAction createSwitchDefaultTypoFix(@NotNull PsiLabeledStatement labeledStatement) {
if (!(labeledStatement.getParent() instanceof PsiCodeBlock codeBlock &&
codeBlock.getParent() instanceof PsiSwitchBlock)) {
return null;
}
PsiElement[] children = labeledStatement.getChildren();
if (children.length < 2) return null;
PsiElement child = children[0];
if (!(child instanceof PsiIdentifier identifier)) return null;
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(identifier, Collections.singleton(JavaKeywords.DEFAULT));
}
@Nullable
private static CommonIntentionAction createCatchFinallyTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (!(ref instanceof PsiReferenceExpression)) return null;
PsiElement element = PsiTreeUtil.prevVisibleLeaf(ref);
if (!(element instanceof PsiJavaToken token && token.getTokenType() == JavaTokenType.RBRACE)) return null;
if (!(token.getParent() instanceof PsiCodeBlock block)) return null;
PsiElement parent = block.getParent();
if (!(parent instanceof PsiTryStatement || parent instanceof PsiCatchSection)) return null;
List<@NotNull String> keywords = ref.getParent() instanceof PsiMethodCallExpression ?
List.of(JavaKeywords.CATCH) :
List.of(JavaKeywords.CATCH, JavaKeywords.FINALLY);
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, keywords);
}
//it contains only basic checks, there can be more, but it is enough for now
private static final List<ModifierHandler> MODIFIERS =
List.of(new ModifierHandler(new String[]{JavaKeywords.PUBLIC, JavaKeywords.PROTECTED, JavaKeywords.PRIVATE}, e -> true, (m, e) -> true),
new ModifierHandler(new String[]{JavaKeywords.STATIC, JavaKeywords.DEFAULT}, e -> e.getParent() instanceof PsiClass,
(m, e) -> !JavaKeywords.DEFAULT.equals(m) ||
e.getParent() instanceof PsiClass psiClass &&
psiClass.isInterface() &&
PsiUtil.isAvailable(JavaFeature.STATIC_INTERFACE_CALLS, e)),
new ModifierHandler(new String[]{JavaKeywords.FINAL, JavaKeywords.ABSTRACT}, e -> true, (m, e) -> true),
new ModifierHandler(new String[]{JavaKeywords.SEALED, JavaKeywords.NON_SEALED}, e -> true,
(m, e) -> PsiUtil.isAvailable(JavaFeature.SEALED_CLASSES, e)),
new ModifierHandler(new String[]{JavaKeywords.VOLATILE}, e -> e.getParent() instanceof PsiField, (m, e) -> true));
private record ModifierHandler(String @NotNull [] modifiers, @NotNull Predicate<@NotNull PsiElement> condition,
@NotNull BiPredicate<@NotNull String, @NotNull PsiElement> modifierCondition) {
public void addModifier(@NotNull Set<@NotNull String> collected, @NotNull Set<@NotNull String> existing, @NotNull PsiElement element) {
if (!condition.test(element)) return;
for (String modifier : modifiers) {
if (existing.contains(modifier)) return;
}
for (String modifier : modifiers) {
if (modifierCondition.test(modifier, element)) {
collected.add(modifier);
}
}
}
}
@Nullable
private static CommonIntentionAction createModifiersTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (!(ref.getParent() instanceof PsiTypeElement psiTypeElement)) return null;
PsiElement parent = psiTypeElement.getParent();
if (!(parent instanceof PsiField || parent instanceof PsiClass || parent instanceof PsiJavaFile)) return null;
boolean canBeModifier = false;
PsiElement forward = PsiTreeUtil.skipWhitespacesForward(psiTypeElement);
Set<String> existedModifiers = new HashSet<>();
if (forward instanceof PsiIdentifier psiIdentifier &&
PsiTreeUtil.skipWhitespacesForward(psiIdentifier) instanceof PsiErrorElement errorElement &&
errorElement.getErrorDescription().equals(JavaSyntaxBundle.message("expected.semicolon"))) {
canBeModifier = true;
collectModifiers(psiIdentifier, existedModifiers);
}
if (!canBeModifier &&
forward instanceof PsiErrorElement errorElement &&
errorElement.getErrorDescription().equals(JavaSyntaxBundle.message("expected.identifier"))) {
canBeModifier = true;
PsiElement modifierListExpected = PsiTreeUtil.skipWhitespacesForward(errorElement);
if (modifierListExpected != null && modifierListExpected.textMatches("-")) {
modifierListExpected = PsiTreeUtil.nextVisibleLeaf(modifierListExpected);
}
if (modifierListExpected instanceof PsiIdentifier identifier) {
modifierListExpected = PsiTreeUtil.nextVisibleLeaf(identifier);
}
collectModifiers(modifierListExpected, existedModifiers);
}
if (!canBeModifier) return null;
PsiElement modifierListExpected = PsiTreeUtil.skipWhitespacesBackward(psiTypeElement);
if (modifierListExpected != null && modifierListExpected.getTextLength() == 0) {
modifierListExpected = PsiTreeUtil.prevVisibleLeaf(modifierListExpected);
}
if (modifierListExpected instanceof PsiJavaToken javaToken && javaToken.getTokenType() == JavaTokenType.MINUS) {
modifierListExpected = PsiTreeUtil.prevVisibleLeaf(modifierListExpected);
if (modifierListExpected instanceof PsiIdentifier identifier) {
modifierListExpected = PsiTreeUtil.prevVisibleLeaf(identifier);
}
}
collectModifiers(modifierListExpected, existedModifiers);
Set<String> modifiers = new HashSet<>();
for (ModifierHandler modifier : MODIFIERS) {
modifier.addModifier(modifiers, existedModifiers, psiTypeElement);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(psiTypeElement, modifiers);
}
private static void collectModifiers(@Nullable PsiElement modifierListExpected, @NotNull Set<String> existedModifiers) {
if (modifierListExpected == null) return;
PsiElement canBeModifierList = modifierListExpected;
if (canBeModifierList instanceof PsiModifierListOwner modifierListOwner) {
canBeModifierList = modifierListOwner.getModifierList();
}
if (canBeModifierList instanceof PsiModifierList modifierList) {
for (PsiElement element : modifierList.getChildren()) {
if (element instanceof PsiKeyword keyword) {
existedModifiers.add(keyword.getText());
}
}
}
if (modifierListExpected instanceof PsiField field) {
existedModifiers.add(tryExtendKeyword(field.getNameIdentifier()).first);
}
if (modifierListExpected instanceof PsiIdentifier || modifierListExpected instanceof PsiKeyword) {
existedModifiers.add(tryExtendKeyword(modifierListExpected).first);
}
}
@Nullable
private static CommonIntentionAction createClassTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (!(ref.getParent() instanceof PsiTypeElement typeElement)) return null;
PsiElement parent = typeElement.getParent();
//skip a case inside methods, it is not so popular
List<@NotNull String> keywords = List.of(JavaKeywords.CLASS, JavaKeywords.INTERFACE, JavaKeywords.ENUM, JavaKeywords.RECORD);
if (PsiTreeUtil.skipWhitespacesForward(typeElement) instanceof PsiErrorElement errorElement &&
errorElement.getErrorDescription().equals(JavaSyntaxBundle.message("expected.identifier")) &&
(parent instanceof PsiClass || parent instanceof PsiJavaFile)) {
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, keywords);
}
if (PsiTreeUtil.skipWhitespacesForward(typeElement) instanceof PsiIdentifier identifier &&
PsiTreeUtil.skipWhitespacesForward(identifier) instanceof PsiErrorElement errorElement &&
errorElement.getErrorDescription().equals(JavaSyntaxBundle.message("expected.semicolon")) &&
parent instanceof PsiField field &&
field.getInitializer() == null) {
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, keywords);
}
return null;
}
@Nullable
private static CommonIntentionAction createSynchronizedSwitchTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (ref.getParent() instanceof PsiExpressionStatement expressionStatement) {
PsiElement[] children = expressionStatement.getChildren();
if (children.length == 2 && children[0] == ref && children[1] instanceof PsiErrorElement) {
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref,
List.of(JavaKeywords.SYNCHRONIZED, JavaKeywords.SWITCH));
}
}
return null;
}
@Nullable
private static CommonIntentionAction createBreakContinueTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (ref.getParent() instanceof PsiExpressionStatement expressionStatement) {
PsiElement[] children = expressionStatement.getChildren();
if (children.length == 2 &&
children[0] == ref &&
(children[1] instanceof PsiErrorElement ||
children[1] instanceof PsiJavaToken javaToken && javaToken.getTokenType() == JavaTokenType.SEMICOLON)) {
Set<String> targetKeywords = new HashSet<>();
if (PsiTreeUtil.getParentOfType(expressionStatement, PsiLoopStatement.class) != null) {
targetKeywords.add(JavaKeywords.BREAK);
targetKeywords.add(JavaKeywords.CONTINUE);
}
if (PsiTreeUtil.getParentOfType(expressionStatement, PsiSwitchBlock.class) != null) {
targetKeywords.add(JavaKeywords.BREAK);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, targetKeywords);
}
}
return null;
}
private static CommonIntentionAction createBooleanNullTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (ref instanceof PsiReferenceExpression expression) {
Set<String> targetKeywords = new HashSet<>();
PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
if (expectedType != null) {
if (TypeConversionUtil.isAssignable(expectedType, PsiTypes.booleanType())) {
targetKeywords.add(JavaKeywords.TRUE);
targetKeywords.add(JavaKeywords.FALSE);
}
if (expectedType instanceof PsiClassType) {
targetKeywords.add(JavaKeywords.NULL);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, targetKeywords);
}
}
return null;
}
@Nullable
private static CommonIntentionAction createVariableTypeTypoFix(@NotNull PsiJavaCodeReferenceElement ref) {
if (ref.getParent() instanceof PsiTypeElement typeElement) {
PsiElement parent = typeElement.getParent();
if (parent instanceof PsiClass && typeElement.getNextSibling() instanceof PsiErrorElement) {
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, PsiTypes.primitiveTypeNames());
}
if (!(parent instanceof PsiVariable variable &&
!(parent instanceof PsiParameter parameter && !(parameter.getParent() instanceof PsiParameterList)))) {
return null;
}
Set<String> targetKeywords = new HashSet<>(PsiTypes.primitiveTypeNames());
PsiExpression initializer = variable.getInitializer();
if (initializer != null && initializer.getType() != null) {
PsiType initializerType = initializer.getType();
targetKeywords.removeIf(t -> {
PsiPrimitiveType targetType = PsiTypes.primitiveTypeByName(t);
if (targetType == null) return true;
return !TypeConversionUtil.isAssignable(targetType, initializerType);
});
}
if (parent instanceof PsiLocalVariable && PsiUtil.isAvailable(JavaFeature.LVTI, parent)) {
targetKeywords.add(JavaKeywords.VAR);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, targetKeywords);
}
if (ref.getParent() instanceof PsiExpressionStatement expressionStatement) {
PsiElement[] children = expressionStatement.getChildren();
if (children.length == 2 && children[0] == ref && children[1] instanceof PsiErrorElement) {
Set<String> targetKeywords = new HashSet<>(PsiTypes.primitiveTypeNames());
if (PsiUtil.isAvailable(JavaFeature.LVTI, expressionStatement)) {
targetKeywords.add(JavaKeywords.VAR);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, targetKeywords);
}
}
return null;
}
/**
* Tries to extend the old element to a keyword with "-".
*/
@NotNull
public static Pair<String, TextRange> tryExtendKeyword(@NotNull PsiElement old) {
if (PsiTreeUtil.nextVisibleLeaf(old) instanceof PsiJavaToken javaToken && javaToken.getTokenType() == JavaTokenType.MINUS) {
PsiElement secondPart = PsiTreeUtil.nextVisibleLeaf(javaToken);
if (secondPart instanceof PsiIdentifier || secondPart instanceof PsiKeyword) {
String newText = old.getText() + "-" + secondPart.getText();
TextRange newTextRange = new TextRange(old.getTextRange().getStartOffset(), secondPart.getTextRange().getEndOffset());
return new Pair<>(newText, newTextRange);
}
}
if (PsiTreeUtil.prevVisibleLeaf(old) instanceof PsiJavaToken javaToken &&
javaToken.getTokenType() == JavaTokenType.MINUS &&
PsiTreeUtil.prevVisibleLeaf(javaToken) instanceof PsiIdentifier identifier) {
String newText = identifier.getText() + "-" + old.getText();
TextRange newTextRange = new TextRange(identifier.getTextRange().getStartOffset(), old.getTextRange().getEndOffset());
return new Pair<>(newText, newTextRange);
}
return new Pair<>(old.getText(), old.getTextRange());
}
}
@@ -50,7 +50,6 @@ import java.util.function.Consumer;
import static com.intellij.java.codeserver.core.JavaPatternExhaustivenessUtil.checkRecordExhaustiveness;
import static com.intellij.java.codeserver.core.JavaPatternExhaustivenessUtil.findMissedClasses;
import static com.intellij.psi.util.PsiUtil.PRIMITIVE_TYPES;
import static com.intellij.util.ObjectUtils.tryCast;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElse;
@@ -335,7 +334,7 @@ public final class HighlightFixUtil {
public static void registerFixesForExpressionStatement(@NotNull Consumer<? super CommonIntentionAction> info,
@NotNull PsiElement statement) {
if (!(statement instanceof PsiExpressionStatement)) return;
if (!(statement.getParent() instanceof PsiCodeBlock block)) return;
if (!(statement.getParent() instanceof PsiCodeBlock block)) return;
PsiExpression expression = ((PsiExpressionStatement)statement).getExpression();
if (expression instanceof PsiAssignmentExpression) return;
PsiType type = expression.getType();
@@ -1143,69 +1142,6 @@ public final class HighlightFixUtil {
QuickFixFactory.getInstance().createSetVariableTypeFix(localVariable, type));
}
static @Nullable CommonIntentionAction createKeywordTypoFix(@Nullable PsiJavaCodeReferenceElement ref) {
if (ref == null) return null;
if (ref.isQualified()) return null;
if (ref.getParent() instanceof PsiTypeElement typeElement) {
//primitive keywords and var
PsiElement parent = typeElement.getParent();
if (parent instanceof PsiClass && typeElement.getNextSibling() instanceof PsiErrorElement) {
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, PRIMITIVE_TYPES);
}
if (!(parent instanceof PsiVariable variable &&
!(parent instanceof PsiParameter parameter && !(parameter.getParent() instanceof PsiParameterList)))) {
return null;
}
Set<String> targetKeywords = new HashSet<>(PRIMITIVE_TYPES);
PsiExpression initializer = variable.getInitializer();
if (initializer != null && initializer.getType() != null) {
PsiType initializerType = initializer.getType();
targetKeywords.removeIf(t -> {
PsiPrimitiveType targetType = null;
for (PsiPrimitiveType type : PsiTypes.primitiveTypes()) {
if (t.equals(type.getName())) {
targetType = type;
break;
}
}
if (targetType == null) return true;
return !TypeConversionUtil.isAssignable(targetType, initializerType);
});
}
if (parent instanceof PsiLocalVariable && PsiUtil.isAvailable(JavaFeature.LVTI, parent)) {
targetKeywords.add(JavaKeywords.VAR);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(typeElement, targetKeywords);
}
if (ref.getParent() instanceof PsiExpressionStatement expressionStatement) {
//primitive keywords and var
PsiElement[] children = expressionStatement.getChildren();
if (children.length == 2 && children[0] == ref && children[1] instanceof PsiErrorElement) {
Set<String> targetKeywords = new HashSet<>(PRIMITIVE_TYPES);
if (PsiUtil.isAvailable(JavaFeature.LVTI, expressionStatement)) {
targetKeywords.add(JavaKeywords.VAR);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, targetKeywords);
}
}
if (ref instanceof PsiReferenceExpression expression) {
//true, false, null
Set<String> targetKeywords = new HashSet<>();
PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
if (expectedType != null) {
if (TypeConversionUtil.isAssignable(expectedType, PsiTypes.booleanType())) {
targetKeywords.add(JavaKeywords.TRUE);
targetKeywords.add(JavaKeywords.FALSE);
}
if (expectedType instanceof PsiClassType) {
targetKeywords.add(JavaKeywords.NULL);
}
return QuickFixFactory.getInstance().createChangeToSimilarKeyword(ref, targetKeywords);
}
}
return null;
}
private static final class ReturnModel {
final PsiReturnStatement myStatement;
final PsiType myType;
@@ -13,7 +13,6 @@ import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.JavaElementType
import com.intellij.psi.util.InheritanceUtil
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.PsiUtil.PRIMITIVE_TYPES
import com.intellij.util.containers.addIfNotNull
@@ -95,7 +94,7 @@ private object TryWithResourcesPositionMatcher: LookupPositionMatcher {
private fun match(lookupElement: LookupElement): Boolean {
val obj = lookupElement.`object`
if (obj is PsiKeyword && obj.text in PRIMITIVE_TYPES) {
if (obj is PsiKeyword && obj.text in PsiTypes.primitiveTypeNames()) {
return true
}
val psiClass = obj as? PsiClass ?: return false
@@ -43,7 +43,6 @@ import static com.intellij.codeInsight.completion.JavaCompletionContributor.IN_C
import static com.intellij.openapi.util.Conditions.notInstanceOf;
import static com.intellij.patterns.PsiJavaPatterns.*;
import static com.intellij.psi.SyntaxTraverser.psiApi;
import static com.intellij.psi.util.PsiUtil.PRIMITIVE_TYPES;
public class JavaKeywordCompletion {
public static final ElementPattern<PsiElement> AFTER_DOT = psiElement().afterLeaf(".");
@@ -1216,7 +1215,7 @@ public class JavaKeywordCompletion {
boolean addAll = expected.isEmpty() || ContainerUtil.exists(expected, t ->
t.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) || t.equalsToText(CommonClassNames.JAVA_IO_SERIALIZABLE));
PsiElementFactory factory = JavaPsiFacade.getElementFactory(position.getProject());
for (String primitiveType : PRIMITIVE_TYPES) {
for (String primitiveType : PsiTypes.primitiveTypeNames()) {
PsiType array = factory.createTypeFromText(primitiveType + "[]", null);
if (addAll || expected.contains(array)) {
result.consume(PsiTypeLookupItem.createLookupItem(array, null));
@@ -1239,7 +1238,7 @@ public class JavaKeywordCompletion {
declaration ||
typeFragment ||
expressionPosition) && primitivesAreExpected(position)) {
for (String primitiveType : PRIMITIVE_TYPES) {
for (String primitiveType : PsiTypes.primitiveTypeNames()) {
if (!session.isKeywordAlreadyProcessed(primitiveType)) {
result.consume(BasicExpressionCompletionContributor.createKeywordLookupItem(position, primitiveType));
}
@@ -31,7 +31,6 @@ import java.util.function.Function;
import static com.intellij.patterns.PsiJavaPatterns.elementType;
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
import static com.intellij.patterns.StandardPatterns.or;
import static com.intellij.psi.util.PsiUtil.PRIMITIVE_TYPES;
public class PreferByKindWeigher extends LookupElementWeigher {
public static final Key<Boolean> INTRODUCED_VARIABLE = Key.create("INTRODUCED_VARIABLE");
@@ -357,7 +356,7 @@ public class PreferByKindWeigher extends LookupElementWeigher {
boolean expectsNotNull = ContainerUtil.exists(myExpectedTypes, PreferByKindWeigher::isEnumClass);
return expectsNotNull ? ThreeState.NO : ThreeState.YES;
}
if (PRIMITIVE_TYPES.contains(keyword) || JavaKeywords.VOID.equals(keyword)) {
if (PsiTypes.primitiveTypeNames().contains(keyword) || JavaKeywords.VOID.equals(keyword)) {
boolean inCallArg = psiElement().withParents(PsiReferenceExpression.class, PsiExpressionList.class).accepts(myPosition);
return inCallArg || isInMethodTypeArg(myPosition) ? ThreeState.NO : ThreeState.UNSURE;
}
@@ -16,6 +16,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import static com.intellij.codeInsight.daemon.impl.analysis.HighlightFixTypoUtil.tryExtendKeyword;
public class ChangeToSimilarKeywordFix extends PsiUpdateModCommandAction<PsiElement> {
@NotNull
@@ -28,7 +30,8 @@ public class ChangeToSimilarKeywordFix extends PsiUpdateModCommandAction<PsiElem
@Override
protected @Nullable Presentation getPresentation(@NotNull ActionContext context, @NotNull PsiElement element) {
return Presentation.of(QuickFixBundle.message("change.to.similar.keyword.fix.name", element.getText(), myKeyword));
return Presentation.of(QuickFixBundle.message("change.to.similar.keyword.fix.name",
tryExtendKeyword(element).first, myKeyword));
}
@Override
@@ -43,8 +46,9 @@ public class ChangeToSimilarKeywordFix extends PsiUpdateModCommandAction<PsiElem
PsiFile file = element.getContainingFile();
if (file == null) return;
Document document = file.getFileDocument();
TextRange textRange = element.getTextRange();
TextRange textRange = tryExtendKeyword(element).second;
document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myKeyword);
updater.moveCaretTo(textRange.getStartOffset() + myKeyword.length());
}
@@ -54,7 +58,8 @@ public class ChangeToSimilarKeywordFix extends PsiUpdateModCommandAction<PsiElem
@Nullable
public static ChangeToSimilarKeywordFix createFix(@Nullable PsiElement old, @NotNull Collection<@NotNull String> newKeywords) {
if (old == null || newKeywords.isEmpty()) return null;
String oldText = old.getText();
String oldText = tryExtendKeyword(old).first;
if (oldText.isEmpty()) return null;
int minDistance = Integer.MAX_VALUE;
String bestKeyword = null;
int maxLevenshtein;
@@ -2,10 +2,11 @@
package com.intellij.psi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.intellij.psi.PsiType.*;
@@ -23,6 +24,10 @@ public final class PsiTypes {
doubleType()
));
private static final Map<String, PsiPrimitiveType> PRIMITIVE_TYPES_BY_NAME =
Collections.unmodifiableMap(PRIMITIVE_TYPES.stream()
.collect(Collectors.toMap(PsiPrimitiveType::getName, Function.identity())));
/**
* Returns instance corresponding to {@code byte} type.
*/
@@ -94,6 +99,22 @@ public final class PsiTypes {
return PRIMITIVE_TYPES;
}
/**
* Returns a primitive type by its name.
* @param name name of a primitive type.
* @return primitive type instance or null if there is no such type.
*/
public static @Nullable PsiPrimitiveType primitiveTypeByName(@NotNull String name) {
return PRIMITIVE_TYPES_BY_NAME.get(name);
}
/**
* @return a set of names of primitive types.
*/
public static @NotNull Set<String> primitiveTypeNames() {
return PRIMITIVE_TYPES_BY_NAME.keySet();
}
/**
* Returns instance describing the type of {@code null} value.
*/
@@ -1538,14 +1538,6 @@ public final class PsiUtil extends PsiUtilCore {
return false;
}
@ApiStatus.Internal
public static final Set<String> PRIMITIVE_TYPES = Collections.unmodifiableSet(ContainerUtil.newLinkedHashSet(
SHORT, BOOLEAN,
DOUBLE, LONG,
INT, FLOAT,
CHAR, BYTE
));
private static final Set<String> KEYWORDS = Collections.unmodifiableSet(
ContainerUtil.newHashSet(ABSTRACT, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CLASS, CONST, CONTINUE, DEFAULT, DO, DOUBLE, ELSE, EXTENDS,
FALSE, FINAL, FINALLY, FLOAT, FOR, GOTO, IF, IMPLEMENTS, IMPORT, INSTANCEOF, INT, INTERFACE, LONG, NATIVE,
@@ -1300,8 +1300,7 @@ public final class TypeConversionUtil {
private static final Set<String> PRIMITIVE_WRAPPER_FQNS = Collections.unmodifiableSet(
ContainerUtil.newHashSet(JAVA_LANG_BYTE, JAVA_LANG_CHARACTER, JAVA_LANG_DOUBLE, JAVA_LANG_FLOAT, JAVA_LANG_LONG, JAVA_LANG_INTEGER,
JAVA_LANG_SHORT,
JAVA_LANG_BOOLEAN));
JAVA_LANG_SHORT, JAVA_LANG_BOOLEAN));
private static final Set<String> PRIMITIVE_WRAPPER_SIMPLE_NAMES =
ContainerUtil.map2Set(PRIMITIVE_WRAPPER_FQNS, StringUtil::getShortName);
@@ -0,0 +1,9 @@
// "Change 'breal' to 'break'" "true-preview"
public class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
break;
}
}
}
@@ -0,0 +1,9 @@
// "Change 'breal' to 'break'" "true-preview"
public class Test {
public static void main(String[] args) {
switch (args.length) {
case 0:
break
}
}
}
@@ -0,0 +1,2 @@
// "Change 'clss' to 'class'" "true-preview"
class
@@ -0,0 +1,6 @@
// "Change 'extnd' to 'extends'" "true-preview"
class Test extends Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extend' to 'extends'" "true-preview"
class Test implements Runnable extends {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extend' to 'extends'" "true-preview"
class Test implements Runnable extends Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extnd' to 'extends'" "true-preview"
class Test extends {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,4 @@
// "Change 'clss' to 'class'" "true-preview"
class Test {
}
@@ -0,0 +1,6 @@
// "Change 'implement' to 'implements'" "true-preview"
class Test implements Runnable extends AA {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'implemnt' to 'implements'" "true-preview"
class Test extends Runnable implements Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'clas' to 'class'" "true-preview"
class A {
class B{
}
}
@@ -0,0 +1,4 @@
// "Change 'clas' to 'class'" "true-preview"
class A {
class
}
@@ -0,0 +1,3 @@
// "Change 'clas' to 'class'" "true-preview"
private class A {
}
@@ -0,0 +1,2 @@
// "Change 'clas' to 'class'" "true-preview"
private class
@@ -0,0 +1,8 @@
// "Change 'continu' to 'continue'" "true-preview"
public class Test {
public static void test(List<String> list) {
while (true) {
continue;
}
}
}
@@ -0,0 +1,5 @@
// "Change 'defult' to 'default'" "true-preview"
public interface A {
default void a();
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1:
System.out.println();
break;
default
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1:
System.out.println();
break;
default:
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1->{
System.out.println();
}
default
}
}
}
@@ -0,0 +1,13 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1->{
System.out.println();
}
default->{
}
}
}
}
@@ -0,0 +1,13 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
return switch (1) {
case 1->{
System.out.println();
}
default->{
}
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
return switch (1) {
case 1:
System.out.println();
break;
default:
}
}
}
@@ -0,0 +1,4 @@
// "Change 'implement' to 'implements'" "true-preview"
enum A implements Exception{
}
@@ -0,0 +1,2 @@
// "Change 'enm' to 'enum'" "true-preview"
public enum
@@ -0,0 +1,3 @@
// "Change 'fnal' to 'final'" "true-preview"
public final class {
}
@@ -0,0 +1,6 @@
// "Change 'fnal' to 'final'" "true-preview"
class A{
static final public class B {
}
}
@@ -0,0 +1,4 @@
// "Change 'fnal' to 'final'" "true-preview"
final public class {
}
@@ -0,0 +1,4 @@
// "Change 'extend' to 'extends'" "true-preview"
interface A extends Exception{
}
@@ -0,0 +1,2 @@
// "Change 'inteerface' to 'interface'" "true-preview"
public interface
@@ -0,0 +1,4 @@
// "Change 'non-seled' to 'non-sealed'" "true-preview"
public non-sealed interface A {
}
@@ -0,0 +1,4 @@
// "Change 'non-seled' to 'non-sealed'" "true-preview"
public non-sealed interface A {
}
@@ -0,0 +1,4 @@
// "Change 'extend' to 'extends'" "true-preview"
record A extend<caret> Exception{
}
@@ -0,0 +1,4 @@
// "Change 'implement' to 'implements'" "true-preview"
record A implements Exception{
}
@@ -0,0 +1,2 @@
// "Change 'recort' to 'record'" "true-preview"
public record
@@ -0,0 +1,4 @@
// "Change 'seled' to 'sealed'" "true-preview"
public sealed interface A {
}
@@ -0,0 +1,6 @@
// "Change 'switc' to 'switch'" "true-preview"
class Test {
public static void test(List<String> list) throws Exception {
switch()
}
}
@@ -0,0 +1,6 @@
// "Change 'switc' to 'switch'" "true-preview"
class Test {
public static void test(List<String> list) throws Exception {
System.out.println(switch(){});
}
}
@@ -0,0 +1,8 @@
// "Change 'switc' to 'switch'" "true-preview"
class Test {
public static int test(List<String> list) throws Exception {
return switch (list){
}
}
}
@@ -0,0 +1,6 @@
// "Change 'switc' to 'switch'" "true-preview"
class Test {
public static void test(List<String> list) throws Exception {
switch
}
}
@@ -0,0 +1,6 @@
// "Change 'synchronize' to 'synchronized'" "true-preview"
public class Test {
public static void test(List<String> list) {
synchronized
}
}
@@ -0,0 +1,6 @@
// "Change 'synchronize' to 'synchronized'" "true-preview"
public class Test {
public static void test(List<String> list) {
synchronized(this){}
}
}
@@ -0,0 +1,6 @@
// "Change 'synchronize' to 'synchronized'" "true-preview"
public class Test {
public static void test(List<String> list) {
synchronized()
}
}
@@ -0,0 +1,6 @@
// "Change 'thrws' to 'throws'" "true-preview"
public class Test {
public static void test(List<String> list) throws {
}
}
@@ -0,0 +1,6 @@
// "Change 'thrws' to 'throws'" "true-preview"
public class Test {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,3 @@
// "Change 'thrws' to 'throws'" "true-preview"
public class Test {
public static void test(List<String> list) throws Exception
@@ -0,0 +1,11 @@
// "Change 'catc' to 'catch'" "true-preview"
public class Test {
public static void test(List<String> list) {
try{
}
catch(){
}
}
}
@@ -0,0 +1,9 @@
// "Change 'catc' to 'catch'" "true-preview"
public class Test {
public static void test(List<String> list) {
try{
}
catch
}
}
@@ -0,0 +1,11 @@
// "Change 'finly' to 'finally'" "true-preview"
public class Test {
public static void test(List<String> list) {
try{
}
finally{
}
}
}
@@ -0,0 +1,3 @@
// "Change 'publi' to 'public'" "true-preview"
public class {
}
@@ -0,0 +1,4 @@
// "Change 'publi' to 'public'" "true-preview"
public class Test {
}
@@ -0,0 +1,4 @@
// "Change 'publi' to 'public'" "true-preview"
public class A{
public Integer a(){}
}
@@ -0,0 +1,6 @@
// "Change 'publi' to 'public'" "true-preview"
public class A{
public class {
}
}
@@ -0,0 +1,4 @@
// "Change 'publi' to 'public'" "true-preview"
public class A{
public Integer a;
}
@@ -0,0 +1,4 @@
// "Change 'publi' to 'public'" "true-preview"
public class A{
public
}
@@ -0,0 +1,2 @@
// "Change 'publi' to 'public'" "true-preview"
public
@@ -0,0 +1,4 @@
// "Change 'publi' to 'public'" "true-preview"
public class A{
public t
}
@@ -0,0 +1,5 @@
// "Change 'volitle' to 'volatile'" "true-preview"
class A {
private volatile String a = "1";
}
@@ -0,0 +1,9 @@
// "Change 'breal' to 'break'" "true-preview"
public class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
breal<caret>;
}
}
}
@@ -0,0 +1,9 @@
// "Change 'breal' to 'break'" "true-preview"
public class Test {
public static void main(String[] args) {
switch (args.length) {
case 0:
breal<caret>
}
}
}
@@ -0,0 +1,2 @@
// "Change 'clss' to 'class'" "true-preview"
clss<caret>
@@ -0,0 +1,6 @@
// "Change 'extnd' to 'extends'" "true-preview"
class Test extnd<caret> Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extend' to 'extends'" "false"
class Test extends Runnable extend<caret> Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extend' to 'extends'" "true-preview"
class Test implements Runnable extend<caret> {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extend' to 'extends'" "true-preview"
class Test implements Runnable extend<caret> Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'extnd' to 'extends'" "true-preview"
class Test extnd<caret> {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,4 @@
// "Change 'clss' to 'class'" "true-preview"
clss<caret> Test {
}
@@ -0,0 +1,6 @@
// "Change 'implement' to 'implements'" "true-preview"
class Test implement<caret> Runnable extends AA {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'implemnt' to 'implements'" "true-preview"
class Test extends Runnable implemnt<caret> Runnable {
public static void test(List<String> list) throws Exception {
}
}
@@ -0,0 +1,6 @@
// "Change 'clas' to 'class'" "true-preview"
class A {
clas<caret> B{
}
}
@@ -0,0 +1,4 @@
// "Change 'clas' to 'class'" "true-preview"
class A {
clas<caret>
}
@@ -0,0 +1,3 @@
// "Change 'clas' to 'class'" "true-preview"
private clas<caret> A {
}
@@ -0,0 +1,2 @@
// "Change 'clas' to 'class'" "true-preview"
private clas<caret>
@@ -0,0 +1,8 @@
// "Change 'continu' to 'continue'" "true-preview"
public class Test {
public static void test(List<String> list) {
while (true) {
continu<caret>;
}
}
}
@@ -0,0 +1,8 @@
// "Change 'continu' to 'continue'" "false"
public class Test {
public static void test(List<String> list) {
while (true) {
}
continu<caret>;
}
}
@@ -0,0 +1,5 @@
// "Change 'defult' to 'default'" "false"
public class A {
defult<caret> void a();
}
@@ -0,0 +1,5 @@
// "Change 'defult' to 'default'" "false"
public interface A {
defult<caret> static void a()
}
@@ -0,0 +1,5 @@
// "Change 'defult' to 'default'" "true-preview"
public interface A {
defult<caret> void a();
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1:
System.out.println();
break;
defaul<caret>
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1:
System.out.println();
break;
defaul<caret>:
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1->{
System.out.println();
}
defaul<caret>
}
}
}
@@ -0,0 +1,13 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
switch (1) {
case 1->{
System.out.println();
}
defaul<caret>->{
}
}
}
}
@@ -0,0 +1,13 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
return switch (1) {
case 1->{
System.out.println();
}
defaul<caret>->{
}
}
}
}
@@ -0,0 +1,11 @@
// "Change 'defaul' to 'default'" "true-preview"
public class Test {
public static void test(List<String> list) {
return switch (1) {
case 1:
System.out.println();
break;
defaul<caret>:
}
}
}
@@ -0,0 +1,4 @@
// "Change 'extend' to 'extends'" "false"
enum A extend<caret> Exception{
}
@@ -0,0 +1,4 @@
// "Change 'implement' to 'implements'" "true-preview"
enum A implement<caret> Exception{
}
@@ -0,0 +1,2 @@
// "Change 'enm' to 'enum'" "true-preview"
public enm<caret>
@@ -0,0 +1,3 @@
// "Change 'fnal' to 'final'" "true-preview"
public fnal<caret> class {
}
@@ -0,0 +1,6 @@
// "Change 'fnal' to 'final'" "true-preview"
class A{
static fnal<caret> public class B {
}
}
@@ -0,0 +1,4 @@
// "Change 'fnal' to 'final'" "true-preview"
fnal<caret> public class {
}
@@ -0,0 +1,4 @@
// "Change 'extend' to 'extends'" "true-preview"
interface A extend<caret> Exception{
}

Some files were not shown because too many files have changed in this diff Show More