diff --git a/java/codeserver/highlighting/resources/messages/JavaCompilationErrorBundle.properties b/java/codeserver/highlighting/resources/messages/JavaCompilationErrorBundle.properties index edd4a3aa9d1a..f0c1ae4a3546 100644 --- a/java/codeserver/highlighting/resources/messages/JavaCompilationErrorBundle.properties +++ b/java/codeserver/highlighting/resources/messages/JavaCompilationErrorBundle.properties @@ -171,6 +171,7 @@ method.inheritance.clash.unrelated.return.types={0}; methods have unrelated retu method.inheritance.clash.incompatible.return.types={0}; attempting to use incompatible return type method.inheritance.clash.does.not.throw={0}; overridden method does not throw ''{1}'' method.no.parameter.list=Parameter list expected +method.missing.return.type=Invalid method declaration; return type required clash.methods.message=''{0}'' clashes with ''{1}'' clash.methods.message.show.classes=''{0}'' in ''{2}'' clashes with ''{1}'' in ''{3}'' @@ -322,3 +323,11 @@ unnamed.method.parameter.not.allowed=Unnamed method parameter is not allowed unnamed.variable.not.allowed.in.this.context=Unnamed variable declaration is not allowed in this context unnamed.variable.brackets=Brackets are not allowed after an unnamed variable declaration unnamed.variable.without.initializer=Unnamed variable declaration must have an initializer + +return.outside.switch.expression=Return outside of enclosing switch expression +return.compact.constructor='return' statement is not allowed in compact constructor +return.outside.method=Return outside method +return.before.explicit.constructor.call='return' not allowed before ''{0}'' call +return.value.missing=Missing return value +return.from.void.method=Cannot return a value from a method with void result type +return.from.constructor=Cannot return a value from a constructor diff --git a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/JavaErrorVisitor.java b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/JavaErrorVisitor.java index fa2090ae1c59..586c0368920b 100644 --- a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/JavaErrorVisitor.java +++ b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/JavaErrorVisitor.java @@ -382,6 +382,26 @@ final class JavaErrorVisitor extends JavaElementVisitor { if (!hasErrorResults()) visitExpression(expression); } + @Override + public void visitReturnStatement(@NotNull PsiReturnStatement statement) { + super.visitReturnStatement(statement); + if (!hasErrorResults()) myStatementChecker.checkReturnStatement(statement); + } + + @Override + public void visitReferenceParameterList(@NotNull PsiReferenceParameterList list) { + super.visitReferenceParameterList(list); + if (list.getTextLength() == 0) return; + checkFeature(list, JavaFeature.GENERICS); + if (!hasErrorResults()) { + for (PsiTypeElement typeElement : list.getTypeParameterElements()) { + if (typeElement.getType() instanceof PsiDiamondType) { + checkFeature(list, JavaFeature.DIAMOND_TYPES); + } + } + } + } + @Override public void visitIdentifier(@NotNull PsiIdentifier identifier) { PsiElement parent = identifier.getParent(); @@ -405,6 +425,9 @@ final class JavaErrorVisitor extends JavaElementVisitor { } else if (parent instanceof PsiMethod method) { myClassChecker.checkImplicitClassMember(method); + if (method.isConstructor()) { + myMethodChecker.checkConstructorName(method); + } } myExpressionChecker.checkUnderscore(identifier); } diff --git a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/MethodChecker.java b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/MethodChecker.java index 38558030098c..0a1cbf13a593 100644 --- a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/MethodChecker.java +++ b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/MethodChecker.java @@ -6,6 +6,7 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil; import com.intellij.java.codeserver.highlighting.errors.JavaErrorKinds; import com.intellij.java.codeserver.highlighting.errors.JavaIncompatibleTypeErrorContext; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.TextRange; import com.intellij.pom.java.JavaFeature; import com.intellij.pom.java.LanguageLevel; @@ -400,6 +401,16 @@ final class MethodChecker { } } + void checkConstructorName(PsiMethod method) { + PsiClass aClass = method.getContainingClass(); + if (aClass != null) { + String className = aClass instanceof PsiAnonymousClass ? null : aClass.getName(); + if (className == null || !Comparing.strEqual(method.getName(), className)) { + myVisitor.report(JavaErrorKinds.METHOD_MISSING_RETURN_TYPE.create(method, className)); + } + } + } + static @Nullable TextRange getCStyleDeclarationRange(@NotNull PsiVariable variable) { PsiIdentifier identifier = variable.getNameIdentifier(); TextRange range = null; diff --git a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/StatementChecker.java b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/StatementChecker.java index 342ff9ff14a8..f559302f3465 100644 --- a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/StatementChecker.java +++ b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/StatementChecker.java @@ -6,11 +6,12 @@ import com.intellij.java.codeserver.highlighting.errors.JavaErrorKinds; import com.intellij.java.codeserver.highlighting.errors.JavaIncompatibleTypeErrorContext; import com.intellij.pom.java.JavaFeature; import com.intellij.psi.*; -import com.intellij.psi.util.InheritanceUtil; -import com.intellij.psi.util.PsiUtil; -import com.intellij.psi.util.TypeConversionUtil; +import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.util.*; +import com.intellij.refactoring.util.RefactoringChangeUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtilRt; +import com.intellij.util.JavaPsiConstructorUtil; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,6 +21,8 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import static com.intellij.util.ObjectUtils.tryCast; + final class StatementChecker { private final @NotNull JavaErrorVisitor myVisitor; @@ -198,4 +201,61 @@ final class StatementChecker { PsiClass upperCatchClass = PsiUtil.resolveClassInType(upperCatchType); return upperCatchClass != null && InheritanceUtil.isInheritorOrSelf(catchClass, upperCatchClass, true); } + + void checkReturnStatement(@NotNull PsiReturnStatement statement) { + if (myVisitor.isApplicable(JavaFeature.ENHANCED_SWITCH) && PsiImplUtil.findEnclosingSwitchExpression(statement) != null) { + myVisitor.report(JavaErrorKinds.RETURN_OUTSIDE_SWITCH_EXPRESSION.create(statement)); + return; + } + PsiElement parent = PsiTreeUtil.getParentOfType(statement, PsiFile.class, PsiClassInitializer.class, + PsiLambdaExpression.class, PsiMethod.class); + if (parent instanceof PsiMethod method) { + if (JavaPsiRecordUtil.isCompactConstructor(method)) { + myVisitor.report(JavaErrorKinds.RETURN_COMPACT_CONSTRUCTOR.create(statement)); + return; + } + if (method.isConstructor()) { + PsiMethodCallExpression constructorCall = JavaPsiConstructorUtil.findThisOrSuperCallInConstructor(method); + if (constructorCall != null && statement.getTextOffset() < constructorCall.getTextOffset()) { + myVisitor.report(JavaErrorKinds.RETURN_BEFORE_EXPLICIT_CONSTRUCTOR_CALL.create(statement, constructorCall)); + return; + } + } + } + if (parent != null) { + checkReturnStatementType(statement, parent); + } + } + + void checkReturnStatementType(@NotNull PsiReturnStatement statement, @NotNull PsiElement parent) { + if (parent instanceof PsiCodeFragment || parent instanceof PsiLambdaExpression) return; + PsiMethod method = tryCast(parent, PsiMethod.class); + if (method == null && !(parent instanceof ServerPageFile)) { + myVisitor.report(JavaErrorKinds.RETURN_OUTSIDE_METHOD.create(statement)); + return; + } + PsiType returnType = method != null ? method.getReturnType() : null/*JSP page returns void*/; + boolean isMethodVoid = returnType == null || PsiTypes.voidType().equals(returnType); + PsiExpression returnValue = statement.getReturnValue(); + if (returnValue != null) { + PsiType valueType = RefactoringChangeUtil.getTypeByExpression(returnValue); + if (isMethodVoid) { + boolean constructor = method != null && method.isConstructor(); + if (constructor) { + PsiClass containingClass = method.getContainingClass(); + if (containingClass != null && !method.getName().equals(containingClass.getName())) { + return; + } + } + var kind = constructor ? JavaErrorKinds.RETURN_FROM_CONSTRUCTOR : JavaErrorKinds.RETURN_FROM_VOID_METHOD; + myVisitor.report(kind.create(statement, method)); + } + else { + myVisitor.myExpressionChecker.checkAssignability(returnType, valueType, returnValue, returnValue); + } + } + else if (!isMethodVoid && !PsiTreeUtil.hasErrorElements(statement)) { + myVisitor.report(JavaErrorKinds.RETURN_VALUE_MISSING.create(statement, method)); + } + } } diff --git a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/errors/JavaErrorKinds.java b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/errors/JavaErrorKinds.java index bfd58c74db50..84a0a330eb52 100644 --- a/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/errors/JavaErrorKinds.java +++ b/java/codeserver/highlighting/src/com/intellij/java/codeserver/highlighting/errors/JavaErrorKinds.java @@ -559,6 +559,9 @@ public final class JavaErrorKinds { .withRawDescription((cls, ctx) -> message("method.inheritance.clash.does.not.throw", formatClashMethodMessage(ctx.method(), ctx.superMethod(), true), formatType(ctx.exceptionType()))); + public static final Parameterized METHOD_MISSING_RETURN_TYPE = + parameterized(PsiMethod.class, String.class, "method.missing.return.type") + .withAnchor((method, className) -> requireNonNullElse(method.getNameIdentifier(), method)); public static final Parameterized CONSTRUCTOR_AMBIGUOUS_IMPLICIT_CALL = parameterized(PsiMember.class, AmbiguousImplicitConstructorCallContext.class, "constructor.ambiguous.implicit.call") @@ -914,6 +917,22 @@ public final class JavaErrorKinds { public static final Simple UNNAMED_VARIABLE_NOT_ALLOWED_IN_THIS_CONTEXT = error(PsiVariable.class, "unnamed.variable.not.allowed.in.this.context") .withRange(var -> TextRange.create(0, requireNonNull(var.getNameIdentifier()).getTextRangeInParent().getEndOffset())); + + public static final Simple RETURN_OUTSIDE_SWITCH_EXPRESSION = + error(PsiReturnStatement.class, "return.outside.switch.expression"); + public static final Simple RETURN_COMPACT_CONSTRUCTOR = + error(PsiReturnStatement.class, "return.compact.constructor"); + public static final Simple RETURN_OUTSIDE_METHOD = + error(PsiReturnStatement.class, "return.outside.method"); + public static final Parameterized RETURN_VALUE_MISSING = + parameterized(PsiReturnStatement.class, PsiMethod.class, "return.value.missing"); + public static final Parameterized RETURN_FROM_CONSTRUCTOR = + parameterized(PsiReturnStatement.class, PsiMethod.class, "return.from.constructor"); + public static final Parameterized RETURN_FROM_VOID_METHOD = + parameterized(PsiReturnStatement.class, PsiMethod.class, "return.from.void.method"); + public static final Parameterized RETURN_BEFORE_EXPLICIT_CONSTRUCTOR_CALL = + parameterized(PsiReturnStatement.class, PsiMethodCallExpression.class, "return.before.explicit.constructor.call") + .withRawDescription((psi, call) -> message("return.before.explicit.constructor.call", call.getMethodExpression().getText() + "()")); private static @NotNull Simple error( @NotNull @PropertyKey(resourceBundle = JavaCompilationErrorBundle.BUNDLE) String key) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java index 172c171bcc21..37dd8e7996db 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java @@ -310,8 +310,9 @@ public final class HighlightFixUtil { } static void registerChangeParameterClassFix(@NotNull PsiType lType, - @NotNull PsiType rType, + @Nullable PsiType rType, @NotNull Consumer info) { + if (rType == null) return; IntentionAction action = getChangeParameterClassFix(lType, rType); if (action != null) { info.accept(action); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index a26d95790c26..1d357eed2b41 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -557,25 +557,6 @@ public final class HighlightMethodUtil { return errorResult; } - static HighlightInfo.Builder checkConstructorName(@NotNull PsiMethod method) { - PsiClass aClass = method.getContainingClass(); - if (aClass != null) { - String className = aClass instanceof PsiAnonymousClass ? null : aClass.getName(); - if (className == null || !Comparing.strEqual(method.getName(), className)) { - PsiElement element = ObjectUtils.notNull(method.getNameIdentifier(), method); - String description = JavaErrorBundle.message("missing.return.type"); - HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description); - if (className != null) { - IntentionAction action = QuickFixFactory.getInstance().createRenameElementFix(method, className); - info.registerFix(action, null, null, null, null); - } - return info; - } - } - - return null; - } - static HighlightInfo.Builder checkConstructorHandleSuperClassExceptions(@NotNull PsiMethod method) { if (!method.isConstructor()) { return null; @@ -621,17 +602,19 @@ public final class HighlightMethodUtil { return builder.toString(); } - static PsiType determineReturnType(@NotNull PsiMethod method) { - PsiManager manager = method.getManager(); - PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements(method); - if (returnStatements.length == 0) return PsiTypes.voidType(); - PsiType expectedType = null; - for (PsiReturnStatement returnStatement : returnStatements) { - ReturnModel returnModel = ReturnModel.create(returnStatement); - if (returnModel == null) return null; - expectedType = lub(expectedType, returnModel.myLeastType, returnModel.myType, method, manager); - } - return expectedType; + static @Nullable PsiType determineReturnType(@NotNull PsiMethod method) { + return CachedValuesManager.getCachedValue(method, () -> { + PsiManager manager = method.getManager(); + PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements(method); + if (returnStatements.length == 0) return CachedValueProvider.Result.create(PsiTypes.voidType(), method); + PsiType expectedType = null; + for (PsiReturnStatement returnStatement : returnStatements) { + ReturnModel returnModel = ReturnModel.create(returnStatement); + if (returnModel == null) return CachedValueProvider.Result.create(null, method); + expectedType = lub(expectedType, returnModel.myLeastType, returnModel.myType, method, manager); + } + return CachedValueProvider.Result.create(expectedType, method); + }); } private static @NotNull PsiType lub(@Nullable PsiType currentType, diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 2ac74cc845e0..5684cb9dc08a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -47,7 +47,6 @@ import com.intellij.psi.scope.util.PsiScopesUtil; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.*; -import com.intellij.refactoring.util.RefactoringChangeUtil; import com.intellij.ui.ColorUtil; import com.intellij.ui.NewUI; import com.intellij.util.ArrayUtilRt; @@ -411,81 +410,6 @@ public final class HighlightUtil { return fix -> highlightInfo.registerFix(fix.asIntention(), null, null, null, null); } - static HighlightInfo.Builder checkReturnFromSwitchExpr(@NotNull PsiReturnStatement statement) { - if (PsiImplUtil.findEnclosingSwitchExpression(statement) != null) { - String message = JavaErrorBundle.message("return.outside.switch.expr"); - HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message); - if (statement.getReturnValue() != null) { - var action = new ReplaceWithYieldFix(statement); - info.registerFix(action, null, null, null, null); - } - return info; - } - - return null; - } - - static HighlightInfo.Builder checkReturnStatementType(@NotNull PsiReturnStatement statement, @NotNull PsiElement parent) { - if (parent instanceof PsiCodeFragment || parent instanceof PsiLambdaExpression) { - return null; - } - PsiMethod method = tryCast(parent, PsiMethod.class); - String description; - HighlightInfo.Builder errorResult; - if (method == null && !(parent instanceof ServerPageFile)) { - description = JavaErrorBundle.message("return.outside.method"); - errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(description); - } - else { - PsiType returnType = method != null ? method.getReturnType() : null/*JSP page returns void*/; - boolean isMethodVoid = returnType == null || PsiTypes.voidType().equals(returnType); - PsiExpression returnValue = statement.getReturnValue(); - if (returnValue != null) { - PsiType valueType = RefactoringChangeUtil.getTypeByExpression(returnValue); - if (isMethodVoid) { - boolean constructor = method != null && method.isConstructor(); - if (constructor) { - PsiClass containingClass = method.getContainingClass(); - if (containingClass != null && !method.getName().equals(containingClass.getName())) { - return null; - } - } - description = JavaErrorBundle.message(constructor ? "return.from.constructor" : "return.from.void.method"); - errorResult = - HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(description); - if (method != null && valueType != null && method.getBody() != null) { - IntentionAction action1 = getFixFactory().createDeleteReturnFix(method, statement); - errorResult.registerFix(action1, null, null, null, null); - IntentionAction action = getFixFactory().createMethodReturnFix(method, valueType, true); - errorResult.registerFix(action, null, null, null, null); - } - } - else { - TextRange textRange = statement.getTextRange(); - errorResult = checkAssignability(returnType, valueType, returnValue, textRange, returnValue.getStartOffsetInParent()); - if (errorResult != null && valueType != null) { - if (!PsiTypes.voidType().equals(valueType)) { - IntentionAction action = getFixFactory().createMethodReturnFix(method, valueType, true); - errorResult.registerFix(action, null, null, null, null); - } - HighlightFixUtil.registerChangeParameterClassFix(returnType, valueType, asConsumer(errorResult)); - } - } - } - else if (!isMethodVoid && !PsiTreeUtil.hasErrorElements(statement)) { - description = JavaErrorBundle.message("missing.return.value"); - errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(description) - .navigationShift(PsiKeyword.RETURN.length()); - IntentionAction action = getFixFactory().createMethodReturnFix(method, PsiTypes.voidType(), true); - errorResult.registerFix(action, null, null, null, null); - } - else { - errorResult = null; - } - } - return errorResult; - } - static void registerReturnTypeFixes(@NotNull HighlightInfo.Builder info, @NotNull PsiMethod method, @NotNull PsiType expectedReturnType) { IntentionAction action = getFixFactory().createMethodReturnFix(method, expectedReturnType, true, true); info.registerFix(action, null, null, null, null); @@ -823,8 +747,8 @@ public final class HighlightUtil { boolean allowedError = false; if (statement instanceof PsiExpressionStatement) { PsiElement[] children = statement.getChildren(); - if (children[0] instanceof PsiExpression && children[1] instanceof PsiErrorElement && - ((PsiErrorElement)children[1]).getErrorDescription().equals(JavaPsiBundle.message("expected.semicolon"))) { + if (children[0] instanceof PsiExpression && children[1] instanceof PsiErrorElement errorElement && + errorElement.getErrorDescription().equals(JavaPsiBundle.message("expected.semicolon"))) { allowedError = true; anchor = children[0]; } diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 76224b54cbce..56a2cce887c7 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -33,7 +33,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.JavaVersionService; import com.intellij.openapi.util.NlsContexts; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.HtmlChunk; import com.intellij.pom.java.JavaFeature; @@ -49,7 +48,6 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.*; import com.intellij.ui.ColorUtil; import com.intellij.ui.NewUI; -import com.intellij.util.JavaPsiConstructorUtil; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBUI; @@ -92,14 +90,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh // map codeBlock->List of PsiReferenceExpression of extra initialization of final variable private final Map> myFinalVarProblems = new HashMap<>(); - private final Map> mySingleImportedClasses = new HashMap<>(); - private final Map> mySingleImportedFields = new HashMap<>(); private final @NotNull Consumer myErrorSink = builder -> add(builder); private final Set myOverrideEquivalentMethodsVisitedClasses = new HashSet<>(); // stored "clashing signatures" errors for the method (if the key is a PsiModifierList of the method), or the class (if the key is a PsiModifierList of the class) private final Map myOverrideEquivalentMethodsErrors = new HashMap<>(); - private final Map myExpectedReturnTypes = new HashMap<>(); private final Function mySurroundingConstructor = entry -> findSurroundingConstructor(entry); private final Map myInsideConstructorOfClassCache = new HashMap<>(); // null value means "cached but no corresponding ctr found" private boolean myHasError; // true if myHolder.add() was called with HighlightInfo of >=ERROR severity. On each .visit(PsiElement) call this flag is reset. Useful to determine whether the error was already reported while visiting this PsiElement. @@ -193,8 +188,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh finally { myUninitializedVarProblems.clear(); myFinalVarProblems.clear(); - mySingleImportedClasses.clear(); - mySingleImportedFields.clear(); myJavaModule = null; myFile = null; myHolder = null; @@ -202,7 +195,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh myPreviewFeatureVisitor = null; myOverrideEquivalentMethodsVisitedClasses.clear(); myOverrideEquivalentMethodsErrors.clear(); - myExpectedReturnTypes.clear(); myInsideConstructorOfClassCache.clear(); } @@ -576,16 +568,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh } } else if (parent instanceof PsiMethod method) { - if (method.isConstructor()) { - HighlightInfo.Builder info = HighlightMethodUtil.checkConstructorName(method); - if (info != null) { - PsiType expectedType = myExpectedReturnTypes.computeIfAbsent(method, HighlightMethodUtil::determineReturnType); - if (expectedType != null) { - HighlightUtil.registerReturnTypeFixes(info, method, expectedType); - } - } - add(info); - } PsiClass aClass = method.getContainingClass(); if (aClass != null) { add(GenericsHighlightUtil.checkDefaultMethodOverridesMemberOfJavaLangObject(myLanguageLevel, aClass, method, identifier)); @@ -597,6 +579,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitImportStatement(@NotNull PsiImportStatement statement) { + super.visitImportStatement(statement); if (!hasErrorResults()) { PreviewFeatureUtil.checkPreviewFeature(statement, myPreviewFeatureVisitor); } @@ -687,7 +670,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitNewExpression(@NotNull PsiNewExpression expression) { - PsiType type = expression.getType(); if (!hasErrorResults()) add(GenericsHighlightUtil.checkTypeParameterInstantiation(expression)); if (!hasErrorResults()) visitExpression(expression); @@ -1144,58 +1126,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh @Override public void visitReferenceParameterList(@NotNull PsiReferenceParameterList list) { + super.visitReferenceParameterList(list); if (list.getTextLength() == 0) return; - add(checkFeature(list, JavaFeature.GENERICS)); if (!hasErrorResults()) add(GenericsHighlightUtil.checkParametersAllowed(list)); if (!hasErrorResults()) add(GenericsHighlightUtil.checkParametersOnRaw(list, myLanguageLevel)); - if (!hasErrorResults()) { - for (PsiTypeElement typeElement : list.getTypeParameterElements()) { - if (typeElement.getType() instanceof PsiDiamondType) { - add(checkFeature(list, JavaFeature.DIAMOND_TYPES)); - } - } - } - } - - @Override - public void visitReturnStatement(@NotNull PsiReturnStatement statement) { - super.visitStatement(statement); - if (!hasErrorResults() && PsiUtil.isAvailable(JavaFeature.ENHANCED_SWITCH, myFile)) { - add(HighlightUtil.checkReturnFromSwitchExpr(statement)); - } - if (!hasErrorResults()) { - try { - PsiElement parent = PsiTreeUtil.getParentOfType(statement, PsiFile.class, PsiClassInitializer.class, - PsiLambdaExpression.class, PsiMethod.class); - if (parent instanceof PsiMethod method ) { - if (JavaPsiRecordUtil.isCompactConstructor(method)) { - add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement) - .descriptionAndTooltip(JavaErrorBundle.message("record.compact.constructor.return"))); - } - else if (method.isConstructor()) { - PsiMethodCallExpression constructorCall = JavaPsiConstructorUtil.findThisOrSuperCallInConstructor(method); - if (constructorCall != null && statement.getTextOffset() < constructorCall.getTextOffset()) { - add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement) - .descriptionAndTooltip(JavaErrorBundle.message("return.statement.not.allowed.before.explicit.constructor.call", - constructorCall.getMethodExpression().getText() + "()"))); - } - } - } - if (!hasErrorResults() && parent != null) { - HighlightInfo.Builder info = HighlightUtil.checkReturnStatementType(statement, parent); - if (info != null && parent instanceof PsiMethod method) { - PsiType expectedType = myExpectedReturnTypes.computeIfAbsent(method, HighlightMethodUtil::determineReturnType); - if (expectedType != null && !PsiTypes.voidType().equals(expectedType)) { - HighlightUtil.registerReturnTypeFixes(info, method, expectedType); - } - } - add(info); - } - } - catch (IndexNotReadyException ignore) { - } - } } @Override diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaErrorFixProvider.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaErrorFixProvider.java index d22556c5213a..43e6cf196880 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaErrorFixProvider.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaErrorFixProvider.java @@ -31,6 +31,7 @@ import com.intellij.psi.impl.light.LightRecordMethod; import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.util.*; +import com.intellij.refactoring.util.RefactoringChangeUtil; import com.intellij.util.VisibilityUtil; import com.intellij.util.containers.ContainerUtil; import com.siyeh.ig.psiutils.TypeUtils; @@ -110,6 +111,7 @@ final class JavaErrorFixProvider { createMethodFixes(); createExpressionFixes(); createVariableFixes(); + createStatementFixes(); createExceptionFixes(); createGenericFixes(); createRecordFixes(); @@ -119,6 +121,34 @@ final class JavaErrorFixProvider { createReceiverParameterFixes(); } + private void createStatementFixes() { + fix(RETURN_OUTSIDE_SWITCH_EXPRESSION, error -> error.psi().getReturnValue() != null ? new ReplaceWithYieldFix(error.psi()) : null); + fixes(RETURN_VALUE_MISSING, (error, sink) -> { + PsiMethod method = error.context(); + sink.accept(myFactory.createMethodReturnFix(method, PsiTypes.voidType(), true)); + PsiType expectedType = HighlightMethodUtil.determineReturnType(method); + if (expectedType != null && !PsiTypes.voidType().equals(expectedType)) { + sink.accept(myFactory.createMethodReturnFix(method, expectedType, true, true)); + } + }); + JavaFixesPusher fixReturnFromVoid = (error, sink) -> { + PsiMethod method = error.context(); + if (method != null && method.getBody() != null) { + PsiType valueType = RefactoringChangeUtil.getTypeByExpression(requireNonNull(error.psi().getReturnValue())); + if (valueType != null) { + sink.accept(myFactory.createDeleteReturnFix(method, error.psi())); + sink.accept(myFactory.createMethodReturnFix(method, valueType, true)); + } + PsiType expectedType = HighlightMethodUtil.determineReturnType(method); + if (expectedType != null && !PsiTypes.voidType().equals(expectedType) && !expectedType.equals(valueType)) { + sink.accept(myFactory.createMethodReturnFix(method, expectedType, true, true)); + } + } + }; + fixes(RETURN_FROM_CONSTRUCTOR, fixReturnFromVoid); + fixes(RETURN_FROM_VOID_METHOD, fixReturnFromVoid); + } + private void createMethodFixes() { JavaFixProvider addBody = error -> myFactory.createAddMethodBodyFix(error.psi()); fix(METHOD_DEFAULT_SHOULD_HAVE_BODY, addBody); @@ -176,6 +206,17 @@ final class JavaErrorFixProvider { } }); fix(VARARG_CSTYLE_DECLARATION, error -> new NormalizeBracketsFix(error.psi())); + fixes(METHOD_MISSING_RETURN_TYPE, (error, sink) -> { + String className = error.context(); + PsiMethod method = error.psi(); + if (className != null) { + sink.accept(myFactory.createRenameElementFix(method, className)); + } + PsiType expectedType = HighlightMethodUtil.determineReturnType(method); + if (expectedType != null) { + sink.accept(myFactory.createMethodReturnFix(method, expectedType, true, true)); + } + }); } private void createExceptionFixes() { @@ -424,9 +465,13 @@ final class JavaErrorFixProvider { PsiType sameType = JavaHighlightUtil.sameType(initializerList.getInitializers()); sink.accept(sameType == null ? null : VariableArrayTypeFix.createFix(initializerList, sameType)); } - else if (parent instanceof PsiReturnStatement && rType != null) { - if (PsiTreeUtil.getParentOfType(parent, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiMethod containingMethod) { - sink.accept(myFactory.createMethodReturnFix(containingMethod, rType, true, true)); + else if (parent instanceof PsiReturnStatement && rType != null && !PsiTypes.voidType().equals(rType)) { + if (PsiTreeUtil.getParentOfType(parent, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiMethod method) { + sink.accept(myFactory.createMethodReturnFix(method, rType, true, true)); + PsiType expectedType = HighlightMethodUtil.determineReturnType(method); + if (expectedType != null && !PsiTypes.voidType().equals(expectedType) && !expectedType.equals(rType)) { + sink.accept(myFactory.createMethodReturnFix(method, expectedType, true, true)); + } } } else if (parent instanceof PsiLocalVariable var && rType != null) { @@ -445,6 +490,7 @@ final class JavaErrorFixProvider { if (anchor instanceof PsiParameter parameter && parent instanceof PsiForeachStatement forEach) { HighlightFixUtil.registerChangeVariableTypeFixes(parameter, rType, forEach.getIteratedValue(), sink); } + HighlightFixUtil.registerChangeParameterClassFix(lType, rType, sink); }); fixes(CALL_TYPE_INFERENCE_ERROR, (error, sink) -> { if (error.psi() instanceof PsiMethodCallExpression callExpression) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ClassLiteral.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ClassLiteral.java index 659f721faa69..da090d148752 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ClassLiteral.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/ClassLiteral.java @@ -17,12 +17,12 @@ class Foo { public static Class> fFoo(final Foo foo) { Class> fooClass = foo.getClass(); fooClass = foo.getClass(); - return foo.getClass(); + return foo.getClass(); } public static Class> fFoo1(final Foo foo) { Class> fooClass = foo.getClass(); fooClass = foo.getClass(); - return foo.getClass(); + return foo.getClass(); } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/UncheckedWarning.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/UncheckedWarning.java index d7b9878d2412..cb0ad373263f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/UncheckedWarning.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/UncheckedWarning.java @@ -7,6 +7,6 @@ class Test { } public List transform(List> result) { - return result; + return result; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FailedInferenceWithBoxing.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FailedInferenceWithBoxing.java index c28bc6b040b9..d0093f701005 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FailedInferenceWithBoxing.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/FailedInferenceWithBoxing.java @@ -3,7 +3,7 @@ class Test { return null; } public boolean test() { - return doStuff(); + return doStuff(); } public Boolean test1() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA128159.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA128159.java index 14afacc41dff..2214c8eed4ba 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA128159.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA128159.java @@ -1,7 +1,7 @@ class Bug { static A test(A[] as) { for (B b : as) { - return b; + return b; } return null; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA57411.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA57411.java index 0ca6f6ee8f86..c155119ac8d4 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA57411.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEA57411.java @@ -13,6 +13,6 @@ class B extends A { class C extends B { @Override T foo(T x, String y) { - return super.foo(x, y); + return super.foo(x, y); } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java index f4e5c5364963..fe30ca527b4d 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java @@ -23,7 +23,7 @@ class LimitedPool { storage[index] = factory.create(); } - return storage; + return storage; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java index 7c1f25042a92..0566f65816d0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java @@ -78,7 +78,7 @@ class d { class e { String foo () { MyList myList = new MyList(); - return myList.get(0); + return myList.get(0); } static class MyList<T> extends ArrayList{ @@ -130,7 +130,7 @@ class A111 { String g(A111 a) { //noinspection unchecked - return a.f(""); + return a.f(""); } } @@ -152,7 +152,7 @@ class Test1 { X x; java.util.ArrayList foo = new java.util.ArrayList(); public static Number foo() { - return new Test1().foo.get(0); + return new Test1().foo.get(0); } } //end of IDEADEV-26163 diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ErasureOfReturnTypeOfNonGenericMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ErasureOfReturnTypeOfNonGenericMethod.java index e760794e35be..a226ec360b00 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ErasureOfReturnTypeOfNonGenericMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/ErasureOfReturnTypeOfNonGenericMethod.java @@ -5,7 +5,7 @@ import java.util.stream.Stream; class Test { public static List sort(Comparator comp, Stream stream) { - return stream.sorted(comp).collect(Collectors.toList()); + return stream.sorted(comp).collect(Collectors.toList()); } //accept unbounded wildcards diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA57411.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA57411.java index 89aea4a65223..ebcd696f3d6b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA57411.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA57411.java @@ -13,6 +13,6 @@ class B extends A { class C extends B { @Override T foo(T x, String y) { - return super.foo(x, y); + return super.foo(x, y); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEADEV13011.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEADEV13011.java index 77b1de425025..10c82c1e5043 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEADEV13011.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEADEV13011.java @@ -23,7 +23,7 @@ class LimitedPool { storage[index] = factory.create(); } - return storage; + return storage; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Raw.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Raw.java index 9b8794b88be0..d8f6f4aeac49 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Raw.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/Raw.java @@ -89,7 +89,7 @@ class d { class e { String foo () { MyList myList = new MyList(); - return myList.get(0); + return myList.get(0); } static class MyList<T> extends ArrayList{ @@ -141,7 +141,7 @@ class A111 { String g(A111 a) { //noinspection unchecked - return a.f(""); + return a.f(""); } } @@ -163,7 +163,7 @@ class Test1 { X x; java.util.ArrayList foo = new java.util.ArrayList(); public static Number foo() { - return new Test1().foo.get(0); + return new Test1().foo.get(0); } } //end of IDEADEV-26163 diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsInnerClassHighlighting/GenericToRawAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsInnerClassHighlighting/GenericToRawAssignment.java index a879d5975dc6..6d8802a50854 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsInnerClassHighlighting/GenericToRawAssignment.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsInnerClassHighlighting/GenericToRawAssignment.java @@ -1,7 +1,7 @@ class Outer { class Inner { } Foo m(Foo.Inner> foo) { - return foo; + return foo; } } class Foo {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/ErasureOfReturnTypeIffUncheckedConversionWasNecessaryDuringApplicabilityCheckOnly.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/ErasureOfReturnTypeIffUncheckedConversionWasNecessaryDuringApplicabilityCheckOnly.java index 5d45aa6ae834..f8d3b8ddb98a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/ErasureOfReturnTypeIffUncheckedConversionWasNecessaryDuringApplicabilityCheckOnly.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/ErasureOfReturnTypeIffUncheckedConversionWasNecessaryDuringApplicabilityCheckOnly.java @@ -3,10 +3,10 @@ import java.util.stream.Collectors; class Test { private static List test(List list) { - return list.stream().flatMap(List::stream).collect(Collectors.toList()); + return list.stream().flatMap(List::stream).collect(Collectors.toList()); } private static List test1(List list) { - return list.stream().flatMap(l -> l.stream()).collect(Collectors.toList()); + return list.stream().flatMap(l -> l.stream()).collect(Collectors.toList()); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java index edf19b8e7337..5d5d09ddf30a 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/ExtensionMethods.java @@ -26,7 +26,7 @@ class C { super.m(); System.out.println(I.super.i); - System.out.println(super.i); + System.out.println(super.i); } void ma(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/StaticMethodAccessibleThroughInheritance.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/StaticMethodAccessibleThroughInheritance.java index e626370810ef..a7a089fd3f26 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/StaticMethodAccessibleThroughInheritance.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/interfaceMethods/StaticMethodAccessibleThroughInheritance.java @@ -1,4 +1,4 @@ -import static p.Foo.FooEx.foo; +import static p.Foo.FooEx.foo; class FooImpl { public void baz() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CapturedWildcardNotOpenedDuringInference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CapturedWildcardNotOpenedDuringInference.java index b69d4bd0eb65..57119cb3ec70 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CapturedWildcardNotOpenedDuringInference.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/CapturedWildcardNotOpenedDuringInference.java @@ -12,9 +12,9 @@ interface Foo { class Bar { Foo> transform(final Foo foo) { - return foo + return foo .map(v2 -> tuple(v2)) - .onClose(); + .onClose(); } static List tuple(T2 v2) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after10.java index def79e6a6136..b841f02d46e5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after10.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'Callable'" "true" +// "Make 'call()' return 'Callable' or ancestor" "true" public class a extends Callable { public Callable call() { return new Callable(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after11.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after11.java index 336eab097583..0cfd48d9ee64 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after11.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after11.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'Callable'" "true" +// "Make 'call()' return 'Callable' or ancestor" "true" public class a extends CallableEx { public Callable call() { return new Callable(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after3.java index e6afe94bb080..3ca08d96d567 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after3.java @@ -1,4 +1,4 @@ -// "Make 'f()' return 'java.lang.String'" "true-preview" +// "Make 'f()' return 'java.lang.String' or ancestor" "true-preview" class a { String f() { return ""; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after6.java index 357de3c1c348..f5bb2a7e3cf1 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after6.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'java.lang.Integer'" "true" +// "Make 'call()' return 'java.lang.Integer' or ancestor" "true" public class a { String f() { return new Callable() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after7.java index a2b00e9d101a..45ea620208e2 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after7.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/after7.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'java.lang.Integer'" "true" +// "Make 'call()' return 'java.lang.Integer' or ancestor" "true" public class a implements Callable { public Integer call() { return new Integer(0); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/afterBrokenControlFlow.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/afterBrokenControlFlow.java index 836037ad54eb..664061707683 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/afterBrokenControlFlow.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/afterBrokenControlFlow.java @@ -1,4 +1,4 @@ -// "Make 'getDrawerAppsList()' return 'java.util.ArrayList'" "true-preview" +// "Make 'getDrawerAppsList()' return 'java.util.ArrayList' or ancestor" "true-preview" import java.util.*; class Test { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before10.java index cfd74a8873fb..4ef5b5ba8983 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before10.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before10.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'Callable'" "true" +// "Make 'call()' return 'Callable' or ancestor" "true" public class a extends Callable { public Callable call() { return new Callableger>(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before11.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before11.java index 3e6425103722..bca509039fe0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before11.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before11.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'Callable'" "true" +// "Make 'call()' return 'Callable' or ancestor" "true" public class a extends CallableEx { public Callable call() { return new Callableger>(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before3.java index c81499a5ba23..e02e9dfa4cd0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before3.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before3.java @@ -1,4 +1,4 @@ -// "Make 'f()' return 'java.lang.String'" "true-preview" +// "Make 'f()' return 'java.lang.String' or ancestor" "true-preview" class a { int f() { return ""; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before6.java index 59e7831b6f3c..6a4e814d0d90 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before6.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before6.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'java.lang.Integer'" "true" +// "Make 'call()' return 'java.lang.Integer' or ancestor" "true" public class a { String f() { return new Callable() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before7.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before7.java index e01c107fc905..56258665d8c7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before7.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/before7.java @@ -1,4 +1,4 @@ -// "Make 'call()' return 'java.lang.Integer'" "true" +// "Make 'call()' return 'java.lang.Integer' or ancestor" "true" public class a implements Callable { public String call() { return new Integer(0); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/beforeBrokenControlFlow.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/beforeBrokenControlFlow.java index e7b1fc929dc1..a92503542d66 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/beforeBrokenControlFlow.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn/beforeBrokenControlFlow.java @@ -1,4 +1,4 @@ -// "Make 'getDrawerAppsList()' return 'java.util.ArrayList'" "true-preview" +// "Make 'getDrawerAppsList()' return 'java.util.ArrayList' or ancestor" "true-preview" import java.util.*; class Test { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/afterMultipleParameters.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/afterMultipleParameters.java index 7c1b56f943a3..a135b5e24858 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/afterMultipleParameters.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/afterMultipleParameters.java @@ -1,4 +1,4 @@ -// "Make 'foo()' return 'java.util.List'" "true" +// "Make 'foo()' return 'java.util.List' or ancestor" "true" import java.util.List; interface Main { List foo(); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/beforeMultipleParameters.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/beforeMultipleParameters.java index 69bf4b86def9..b49c1d1d08e7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/beforeMultipleParameters.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturn8/beforeMultipleParameters.java @@ -1,4 +1,4 @@ -// "Make 'foo()' return 'java.util.List'" "true" +// "Make 'foo()' return 'java.util.List' or ancestor" "true" import java.util.List; interface Main { List foo(); diff --git a/java/java-tests/testData/ig/com/siyeh/igfixes/junit/simplifiable_junit_assertion/TrueToArrayEquals.java b/java/java-tests/testData/ig/com/siyeh/igfixes/junit/simplifiable_junit_assertion/TrueToArrayEquals.java index 9199a2821bbf..f68d4d243d86 100644 --- a/java/java-tests/testData/ig/com/siyeh/igfixes/junit/simplifiable_junit_assertion/TrueToArrayEquals.java +++ b/java/java-tests/testData/ig/com/siyeh/igfixes/junit/simplifiable_junit_assertion/TrueToArrayEquals.java @@ -8,6 +8,6 @@ class ObjectEqualsToEquals { assertTrue(Arrays.equals(getFoo(), getBar())); } - int[] getFoo() { return "foo"; } - int[] getBar() { return "foo"; } + int[] getFoo() { return "foo"; } + int[] getBar() { return "foo"; } } \ No newline at end of file