mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
HighlightVisitorImpl: add standard quick-fixes for lambda return value
This commit is contained in:
+13
@@ -1479,6 +1479,19 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
static void addLambdaReturnTypeFixes(HighlightInfo info, PsiLambdaExpression lambda, PsiExpression expression) {
|
||||
PsiType type = LambdaUtil.getFunctionalInterfaceReturnType(lambda);
|
||||
if (type != null) {
|
||||
PsiType exprType = expression.getType();
|
||||
if (exprType != null && TypeConversionUtil.areTypesConvertible(exprType, type)) {
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createAddTypeCastFix(type, expression));
|
||||
}
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createWrapWithOptionalFix(type, expression));
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createWrapExpressionFix(type, expression));
|
||||
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createWrapWithAdapterFix(type, expression));
|
||||
}
|
||||
}
|
||||
|
||||
private enum SelectorKind { INT, ENUM, STRING }
|
||||
|
||||
private static SelectorKind getSwitchSelectorKind(@NotNull PsiType type) {
|
||||
|
||||
+4
@@ -376,6 +376,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
.range(entry.getKey())
|
||||
.descriptionAndTooltip(entry.getValue()).create();
|
||||
QuickFixAction.registerQuickFixAction(info, AdjustFunctionContextFix.createFix(entry.getKey()));
|
||||
if (entry.getKey() instanceof PsiExpression) {
|
||||
PsiExpression expr = (PsiExpression)entry.getKey();
|
||||
HighlightUtil.addLambdaReturnTypeFixes(info, expression, expr);
|
||||
}
|
||||
myHolder.add(info);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Cast to 'int'" "true"
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
IntSupplier i = () -> (int) Math.PI;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Cast to 'int'" "true"
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
IntSupplier i = () -> Math.<caret>PI;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Wrap using 'Math.toIntExact()'" "true"
|
||||
import java.util.function.*;
|
||||
|
||||
public class Test {
|
||||
|
||||
void m() {
|
||||
|
||||
LongToIntFunction fn = x -> {
|
||||
if(x > 0) {
|
||||
return Math.toIntExact(x * 2);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Wrap using 'Math.toIntExact()'" "true"
|
||||
import java.util.function.*;
|
||||
|
||||
public class Test {
|
||||
|
||||
void m() {
|
||||
|
||||
LongToIntFunction fn = x -> {
|
||||
if(x > 0) {
|
||||
return x<caret>*2;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user