mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-122133 (type annotations skipped from copying into generated parameter)
This commit is contained in:
@@ -34,6 +34,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.light.LightTypeElement;
|
||||
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
@@ -550,17 +551,14 @@ public class GenerateMembersUtil {
|
||||
PsiModifierList targetModifierList = targetParam.getModifierList();
|
||||
|
||||
if (sourceModifierList != null && targetModifierList != null) {
|
||||
if (sourceParam.getLanguage() == targetParam.getLanguage()) {
|
||||
targetModifierList = (PsiModifierList)targetModifierList.replace(sourceModifierList);
|
||||
}
|
||||
else {
|
||||
JVMElementFactory factory = JVMElementFactories.requireFactory(targetParam.getLanguage(), targetParam.getProject());
|
||||
for (PsiAnnotation annotation : sourceModifierList.getAnnotations()) {
|
||||
JVMElementFactory factory = JVMElementFactories.requireFactory(targetParam.getLanguage(), targetParam.getProject());
|
||||
for (PsiAnnotation annotation : sourceModifierList.getAnnotations()) {
|
||||
if (!PsiImplUtil.isTypeAnnotation(annotation)) {
|
||||
targetModifierList.add(factory.createAnnotationFromText(annotation.getText(), sourceParam));
|
||||
}
|
||||
for (@PsiModifier.ModifierConstant String m : PsiModifier.MODIFIERS) {
|
||||
targetModifierList.setModifierProperty(m, sourceParam.hasModifierProperty(m));
|
||||
}
|
||||
}
|
||||
for (@PsiModifier.ModifierConstant String m : PsiModifier.MODIFIERS) {
|
||||
targetModifierList.setModifierProperty(m, sourceParam.hasModifierProperty(m));
|
||||
}
|
||||
|
||||
filterAnnotations(sourceModifierList.getProject(), targetModifierList, targetModifierList.getResolveScope());
|
||||
@@ -568,13 +566,13 @@ public class GenerateMembersUtil {
|
||||
}
|
||||
|
||||
private static void filterAnnotations(Project project, PsiModifierList modifierList, GlobalSearchScope moduleScope) {
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
|
||||
final Set<String> toRemove = new HashSet<String>();
|
||||
Set<String> toRemove = new HashSet<String>();
|
||||
JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
|
||||
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
|
||||
final String qualifiedName = annotation.getQualifiedName();
|
||||
String qualifiedName = annotation.getQualifiedName();
|
||||
if (qualifiedName != null) {
|
||||
for (OverrideImplementsAnnotationsHandler handler : Extensions.getExtensions(OverrideImplementsAnnotationsHandler.EP_NAME)) {
|
||||
final String[] annotations2Remove = handler.annotationsToRemove(project, qualifiedName);
|
||||
String[] annotations2Remove = handler.annotationsToRemove(project, qualifiedName);
|
||||
Collections.addAll(toRemove, annotations2Remove);
|
||||
if (moduleScope != null && psiFacade.findClass(qualifiedName, moduleScope) == null) {
|
||||
toRemove.add(qualifiedName);
|
||||
@@ -583,14 +581,13 @@ public class GenerateMembersUtil {
|
||||
}
|
||||
}
|
||||
for (String fqn : toRemove) {
|
||||
final PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqn);
|
||||
PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqn);
|
||||
if (psiAnnotation != null) {
|
||||
psiAnnotation.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//java bean getters/setters
|
||||
public static PsiMethod generateSimpleGetterPrototype(@NotNull PsiField field) {
|
||||
return generatePrototype(field, PropertyUtil.generateGetterPrototype(field));
|
||||
|
||||
+4
-2
@@ -268,13 +268,15 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
|
||||
JavaResolveResult[] results = PsiImplUtil.multiResolveImpl(containingFile.getProject(), containingFile, this, false, OurGenericsResolver.INSTANCE);
|
||||
PsiElement target = results.length == 1 ? results[0].getElement() : null;
|
||||
if (target instanceof PsiClass) {
|
||||
PsiClass aClass = (PsiClass)target;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
PsiClass aClass = (PsiClass)target;
|
||||
PsiElement qualifier = getQualifier();
|
||||
|
||||
String prefix = null;
|
||||
if (qualifier instanceof PsiJavaCodeReferenceElementImpl) {
|
||||
prefix = ((PsiJavaCodeReferenceElementImpl)qualifier).getCanonicalText(annotated, null, containingFile);
|
||||
prefix = ((PsiJavaCodeReferenceElementImpl)qualifier).getCanonicalText(annotated, annotations, containingFile);
|
||||
annotations = null;
|
||||
}
|
||||
else {
|
||||
String fqn = aClass.getQualifiedName();
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
// "Implement methods" "true"
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@interface TA { int value() default 0; }
|
||||
|
||||
interface I {
|
||||
@TA List<@TA String> i(@TA int p1, @TA(1) int @TA(2) [] p2 @TA(3) []) throws @TA IllegalArgumentException;
|
||||
}
|
||||
|
||||
class C implements I {
|
||||
@Override
|
||||
public @TA List<@TA String> i(@TA int p1, @TA(1) int @TA(2) [] @TA(3) [] p2) throws @TA IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// "Implement methods" "true"
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@interface TA { int value() default 0; }
|
||||
|
||||
interface I {
|
||||
@TA List<@TA String> i(@TA int p1, @TA(1) int @TA(2) [] p2 @TA(3) []) throws @TA IllegalArgumentException;
|
||||
}
|
||||
|
||||
<caret>class C implements I {
|
||||
}
|
||||
@@ -101,6 +101,40 @@ class Test implements A {
|
||||
"""
|
||||
}
|
||||
|
||||
public void testTypeAnnotationsInImplementedMethod() {
|
||||
myFixture.addClass """\
|
||||
import java.lang.annotation.*;
|
||||
@Target(ElementType.TYPE_USE)
|
||||
public @interface TA { }""".stripIndent()
|
||||
|
||||
myFixture.configureByText "test.java", """\
|
||||
import java.util.*;
|
||||
|
||||
interface I {
|
||||
@TA List<@TA String> i(@TA String p1, @TA(1) int @TA(2) [] p2 @TA(3) []) throws @TA IllegalArgumentException;
|
||||
}
|
||||
|
||||
class C implements I {
|
||||
<caret>
|
||||
}""".stripIndent()
|
||||
|
||||
invokeAction(true)
|
||||
|
||||
myFixture.checkResult """\
|
||||
import java.util.*;
|
||||
|
||||
interface I {
|
||||
@TA List<@TA String> i(@TA String p1, @TA(1) int @TA(2) [] p2 @TA(3) []) throws @TA IllegalArgumentException;
|
||||
}
|
||||
|
||||
class C implements I {
|
||||
@Override
|
||||
public @TA List<@TA String> i(@TA String p1, @TA(1) int @TA(2) [] @TA(3) [] p2) throws @TA IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
}""".stripIndent()
|
||||
}
|
||||
|
||||
private void doTest(boolean toImplement) {
|
||||
String name = getTestName(false)
|
||||
myFixture.configureByFile("before${name}.java")
|
||||
|
||||
@@ -24,7 +24,7 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
private PsiElementFactory factory
|
||||
private PsiElement context
|
||||
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
super.setUp()
|
||||
|
||||
factory = myFixture.javaFacade.elementFactory
|
||||
@@ -36,6 +36,10 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
@interface A { }
|
||||
@Target(ElementType.TYPE_USE) @interface TA { int value() default 42; }
|
||||
|
||||
class O {
|
||||
class I { }
|
||||
}
|
||||
|
||||
class E1 extends Exception { }
|
||||
class E2 extends Exception { }""".stripIndent())
|
||||
}
|
||||
@@ -56,6 +60,14 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
doTest("@A java.lang.@TA(1) String s", "java.lang.@pkg.TA(1) String", "java.lang.String")
|
||||
}
|
||||
|
||||
public void testQualifiedPackageClassReferenceType() {
|
||||
doTest("@A @TA java.lang.String s", "java.lang.String", "java.lang.String") // packages cannot have type annotations
|
||||
}
|
||||
|
||||
public void testPartiallyQualifiedClassReferenceType() {
|
||||
doTest("@TA(1) O.@TA(2) I i", "pkg.@pkg.TA(1) O.@pkg.TA(2) I", "pkg.O.I")
|
||||
}
|
||||
|
||||
public void testCStyleArrayType() {
|
||||
doTest("@A @TA(1) String @TA(2) [] f @TA(3) []", "java.lang.@pkg.TA(1) String @pkg.TA(2) [] @pkg.TA(3) []", "java.lang.String[][]")
|
||||
}
|
||||
@@ -90,4 +102,4 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
assert type.getCanonicalText(true) == annotated
|
||||
assert type.getCanonicalText(false) == canonical
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user