mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: use target class context to check nullability
This commit is contained in:
+1
-1
@@ -630,7 +630,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
|
||||
private Nullness initNullness() {
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(myElements[0]) || PsiUtil.resolveClassInType(myReturnType) == null) return null;
|
||||
final PsiMethod emptyMethod = generateEmptyMethod(getThrownExceptions(), isStatic(), "name");
|
||||
final PsiMethod emptyMethod = (PsiMethod)myTargetClass.copy().add(generateEmptyMethod(getThrownExceptions(), isStatic(), "name"));
|
||||
prepareMethodBody(emptyMethod, false);
|
||||
final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
|
||||
final PsiClass nullableAnnotationClass = JavaPsiFacade.getInstance(myProject)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class X {
|
||||
public static String main(String[] args) {
|
||||
<selection>System.out.println();
|
||||
return f();
|
||||
</selection>
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String f() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class X {
|
||||
public static String main(String[] args) {
|
||||
return newMethod();
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String newMethod() {
|
||||
System.out.println();
|
||||
return f();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String f() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -698,6 +698,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testInferredNotNull() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCantPassFieldAsParameter() throws Exception {
|
||||
try {
|
||||
doTestPassFieldsAsParams();
|
||||
|
||||
Reference in New Issue
Block a user