IDEA-179871 Automatically use nullable annotations in constructor generation

This commit is contained in:
peter
2018-01-08 20:50:57 +01:00
parent 0d68a7724a
commit 9d1de0c271
4 changed files with 19 additions and 1 deletions

View File

@@ -275,7 +275,7 @@ public class GenerateConstructorHandler extends GenerateMembersHandlerBase {
parmName = javaStyle.suggestUniqueVariableName(parmName, dummyConstructor, true);
PsiParameter parm = factory.createParameter(parmName, field.getType(), aClass);
NullableNotNullManager.getInstance(project).copyNotNullAnnotation(field, parm);
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, parm);
if (constructor.isVarArgs()) {
final PsiParameterList parameterList = constructor.getParameterList();

View File

@@ -0,0 +1,9 @@
import org.jetbrains.annotations.Nullable;
class C {
private @Nullable String s;
public C(@Nullable String s) {
this.s = s;
}
}

View File

@@ -0,0 +1,7 @@
import org.jetbrains.annotations.Nullable;
class C {
private @Nullable String s;
<caret>
}

View File

@@ -92,6 +92,8 @@ public class GenerateConstructorTest extends LightCodeInsightFixtureTestCase {
doTest();
}
public void testNullableField() { doTest(); }
private void doTest() {
doTest(false);
}