mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
completion: infer Throwable for thrown bounds in completion so more candidates would be applicable (IDEA-162710)
This commit is contained in:
+5
@@ -48,6 +48,11 @@ public class CompletionParameterTypeInferencePolicy extends ProcessCandidatePara
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inferRuntimeExceptionForThrownBoundWithNoConstraints() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType adjustInferredType(PsiManager manager, PsiType guess, ConstraintType constraintType) {
|
||||
if (guess != null && !(guess instanceof PsiWildcardType)) {
|
||||
|
||||
+4
@@ -33,6 +33,10 @@ public abstract class ParameterTypeInferencePolicy {
|
||||
|
||||
public abstract Pair<PsiType, ConstraintType> getInferredTypeWithNoConstraint(PsiManager manager, PsiType superType);
|
||||
|
||||
public boolean inferRuntimeExceptionForThrownBoundWithNoConstraints() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract PsiType adjustInferredType(PsiManager manager, PsiType guess, ConstraintType second);
|
||||
|
||||
public boolean isVarargsIgnored() {
|
||||
|
||||
+1
-1
@@ -1259,7 +1259,7 @@ public class InferenceSession {
|
||||
}
|
||||
|
||||
if (type == PsiType.NULL) {
|
||||
if (var.isThrownBound() && isThrowable(var.getBounds(InferenceBound.UPPER))) {
|
||||
if (var.isThrownBound() && myPolicy.inferRuntimeExceptionForThrownBoundWithNoConstraints() && isThrowable(var.getBounds(InferenceBound.UPPER))) {
|
||||
type = PsiType.getJavaLangRuntimeException(myManager, GlobalSearchScope.allScope(myManager.getProject()));
|
||||
}
|
||||
else {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.io.IOException;
|
||||
import java.util.function.Function;
|
||||
|
||||
class LocalDateTime {}
|
||||
class Launcher {
|
||||
public static final Function<LocalDateTime, IOException> TO_STRING = (message) -> new IOException(message.toString());
|
||||
|
||||
public static void main(String[] args) throws Throwable{
|
||||
throwException(new LocalDateTime(), TO_STRING);
|
||||
}
|
||||
|
||||
public static <Ex extends Throwable> void throwException(LocalDateTime str, Function<LocalDateTime, Ex> exceptionBuilder) throws Ex {
|
||||
throw exceptionBuilder.apply(str);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.io.IOException;
|
||||
import java.util.function.Function;
|
||||
|
||||
class LocalDateTime {}
|
||||
class Launcher {
|
||||
public static final Function<LocalDateTime, IOException> TO_STRING = (message) -> new IOException(message.toString());
|
||||
|
||||
public static void main(String[] args) throws Throwable{
|
||||
throwException(new LocalDateTime(), TO<caret>);
|
||||
}
|
||||
|
||||
public static <Ex extends Throwable> void throwException(LocalDateTime str, Function<LocalDateTime, Ex> exceptionBuilder) throws Ex {
|
||||
throw exceptionBuilder.apply(str);
|
||||
}
|
||||
}
|
||||
+6
@@ -177,6 +177,12 @@ public void testConvertToObjectStream() {
|
||||
checkResultByFile("/" + getTestName(false) + "-out.java");
|
||||
}
|
||||
|
||||
public void testInferThrowableBoundInCompletion() {
|
||||
configureByTestName();
|
||||
myFixture.complete(CompletionType.SMART, 1);
|
||||
checkResultByFile("/" + getTestName(false) + "-out.java");
|
||||
}
|
||||
|
||||
public void testInsideNewExpressionWithDiamondAndOverloadConstructors() throws Exception {
|
||||
configureByTestName();
|
||||
myFixture.complete(CompletionType.SMART, 1);
|
||||
|
||||
Reference in New Issue
Block a user