mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[java] Preserve type annotations when generating getters and setters
Fixes IDEA-196894 Generating accessors should insert nullability annotations automatically when corresponding fields have them GitOrigin-RevId: a24d1288e4b3c82f0baa6216b6d84e9b5da29b76
This commit is contained in:
committed by
intellij-monorepo-bot
parent
db04ce1b62
commit
8aff1fed71
@@ -167,7 +167,9 @@ public class GenerateGetterSetterTest extends LightJavaCodeInsightFixtureTestCas
|
||||
}
|
||||
|
||||
public void testNullableStuff() {
|
||||
myFixture.addClass("package org.jetbrains.annotations;\n" + "public @interface NotNull {}");
|
||||
myFixture.addClass("""
|
||||
package org.jetbrains.annotations;
|
||||
public @interface NotNull {}""");
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
@org.jetbrains.annotations.NotNull
|
||||
@@ -197,6 +199,42 @@ public class GenerateGetterSetterTest extends LightJavaCodeInsightFixtureTestCas
|
||||
""");
|
||||
}
|
||||
|
||||
public void testNullableStuffTypeUse() {
|
||||
myFixture.addClass("""
|
||||
package org.jetbrains.annotations;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface NotNull {}""");
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
@org.jetbrains.annotations.NotNull
|
||||
private String myName;
|
||||
|
||||
<caret>
|
||||
}
|
||||
""");
|
||||
generateGetter();
|
||||
generateSetter();
|
||||
myFixture.checkResult("""
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class Foo {
|
||||
@org.jetbrains.annotations.NotNull
|
||||
private String myName;
|
||||
|
||||
public void setMyName(@NotNull String myName) {
|
||||
this.myName = myName;
|
||||
}
|
||||
|
||||
public @NotNull String getMyName() {
|
||||
return myName;
|
||||
}
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
public void testLombokGeneratedFieldsWithoutContainingFile() {
|
||||
ServiceContainerUtil.registerExtension(ApplicationManager.getApplication(), GenerateAccessorProviderRegistrar.EP_NAME,
|
||||
new NotNullFunction<PsiClass, Collection<EncapsulatableClassMember>>() {
|
||||
|
||||
@@ -167,7 +167,7 @@ public final class ElementFactory {
|
||||
// type names
|
||||
element.setTypeName(PsiAdapter.getTypeClassName(type));
|
||||
element.setTypeQualifiedName(PsiAdapter.getTypeQualifiedClassName(type));
|
||||
element.setType(type.getCanonicalText());
|
||||
element.setType(type.getCanonicalText(true));
|
||||
|
||||
// arrays, collections and maps types
|
||||
if (PsiAdapter.isObjectArrayType(type)) {
|
||||
|
||||
Reference in New Issue
Block a user