[java] nullability annotation copying logic restored; test added (IDEA-CR-6810)

This commit is contained in:
Roman Shevchenko
2015-11-24 11:42:14 +01:00
parent e4bde377a9
commit eb5890cc8f
5 changed files with 36 additions and 9 deletions
@@ -194,7 +194,10 @@ public final class FieldFromParameterUtils {
modifierList.setModifierProperty(PsiModifier.STATIC, isStatic);
modifierList.setModifierProperty(PsiModifier.FINAL, isFinal);
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(parameter, field);
NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
if (manager.copyNullableAnnotation(parameter, field) == null && isFinal) {
manager.copyNotNullAnnotation(parameter, field);
}
PsiCodeBlock methodBody = method.getBody();
if (methodBody == null) return;
@@ -142,6 +142,11 @@ public abstract class NullableNotNullManager implements PersistentStateComponent
return copyAnnotation(getNotNullAnnotation(original, false), generated);
}
@Nullable
public PsiAnnotation copyNullableAnnotation(@NotNull PsiModifierListOwner original, @NotNull PsiModifierListOwner generated) {
return copyAnnotation(getNullableAnnotation(original, false), generated);
}
@Nullable
public PsiAnnotation copyNullableOrNotNullAnnotation(@NotNull PsiModifierListOwner original, @NotNull PsiModifierListOwner generated) {
PsiAnnotation annotation = getNullableAnnotation(original, false);
@@ -0,0 +1,11 @@
// "Create field for parameter 'name'" "true"
import org.jetbrains.annotations.NotNull;
class Test {
private String myName;
void f(@NotNull String name) {
myName = name;
}
}
@@ -0,0 +1,8 @@
// "Create field for parameter 'name'" "true"
import org.jetbrains.annotations.NotNull;
class Test {
void f(@NotNull String <caret>name) {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
/**
@@ -26,21 +25,22 @@ public class CreateFieldFromParameterTest extends LightIntentionActionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.FIELD_NAME_PREFIX = "my";
CodeStyleSettingsManager.getSettings(getProject()).FIELD_NAME_PREFIX = "my";
}
@Override
protected void tearDown() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.FIELD_NAME_PREFIX = "";
CodeStyleSettingsManager.getSettings(getProject()).FIELD_NAME_PREFIX = "";
//noinspection SuperTearDownInFinally
super.tearDown();
}
public void test() throws Exception { doAllTests(); }
public void test() {
doAllTests();
}
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromParameter";
}
}
}