From 997f409e1a78ae5afb042299ec29a9722dc22ec2 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 25 May 2012 12:41:49 +0400 Subject: [PATCH] method type params should be excluded from signature when overriding from raw type (IDEA-67585;IDEA-67582) --- .../generation/OverrideImplementUtil.java | 16 +++++++++++- .../overrideImplement/afterRawSuper.java | 25 ++++++++++++++++++ ...afterSubstituteBoundInMethodTypeParam.java | 26 +++++++++++++++++++ .../overrideImplement/beforeRawSuper.java | 24 +++++++++++++++++ ...eforeSubstituteBoundInMethodTypeParam.java | 22 ++++++++++++++++ .../codeInsight/OverrideImplementTest.java | 2 ++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/overrideImplement/afterRawSuper.java create mode 100644 java/java-tests/testData/codeInsight/overrideImplement/afterSubstituteBoundInMethodTypeParam.java create mode 100644 java/java-tests/testData/codeInsight/overrideImplement/beforeRawSuper.java create mode 100644 java/java-tests/testData/codeInsight/overrideImplement/beforeSubstituteBoundInMethodTypeParam.java diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java index 6a52ec171673..f9314080f647 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/OverrideImplementUtil.java @@ -263,7 +263,7 @@ public class OverrideImplementUtil { } if (results.isEmpty()) { PsiMethod method1 = GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass); - + PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); PsiMethod result = (PsiMethod)factory.createClass("Dummy").add(method1); if (result instanceof PsiAnnotationMethod) { @@ -304,6 +304,20 @@ public class OverrideImplementUtil { } } + //method type params are not allowed when overriding from raw type + final PsiTypeParameterList list = result.getTypeParameterList(); + if (list != null) { + final PsiClass containingClass = method.getContainingClass(); + if (containingClass != null) { + for (PsiClassType classType : aClass.getSuperTypes()) { + if (InheritanceUtil.isInheritorOrSelf(PsiUtil.resolveClassInType(classType), containingClass, true) && classType.isRaw()) { + list.replace(JavaPsiFacade.getElementFactory(aClass.getProject()).createTypeParameterList()); + break; + } + } + } + } + annotateOnOverrideImplement(result, aClass, method, insertOverrideIfPossible); if (CodeStyleSettingsManager.getSettings(aClass.getProject()).REPEAT_SYNCHRONIZED && method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { diff --git a/java/java-tests/testData/codeInsight/overrideImplement/afterRawSuper.java b/java/java-tests/testData/codeInsight/overrideImplement/afterRawSuper.java new file mode 100644 index 000000000000..95912a1bd1da --- /dev/null +++ b/java/java-tests/testData/codeInsight/overrideImplement/afterRawSuper.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +interface A { + void foo(); + } + + class B implements A + { + public void foo() { + //To change body of implemented methods use File | Settings | File Templates. + } + } diff --git a/java/java-tests/testData/codeInsight/overrideImplement/afterSubstituteBoundInMethodTypeParam.java b/java/java-tests/testData/codeInsight/overrideImplement/afterSubstituteBoundInMethodTypeParam.java new file mode 100644 index 000000000000..47816c480dca --- /dev/null +++ b/java/java-tests/testData/codeInsight/overrideImplement/afterSubstituteBoundInMethodTypeParam.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +abstract class A { + abstract void foo(S s); + } + + class B extends A{ // Implement methods + + @Override + void foo(S s) { + //To change body of implemented methods use File | Settings | File Templates. + } + } diff --git a/java/java-tests/testData/codeInsight/overrideImplement/beforeRawSuper.java b/java/java-tests/testData/codeInsight/overrideImplement/beforeRawSuper.java new file mode 100644 index 000000000000..aefe95c86643 --- /dev/null +++ b/java/java-tests/testData/codeInsight/overrideImplement/beforeRawSuper.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +interface A { + void foo(); + } + + class B implements A + { + + + } diff --git a/java/java-tests/testData/codeInsight/overrideImplement/beforeSubstituteBoundInMethodTypeParam.java b/java/java-tests/testData/codeInsight/overrideImplement/beforeSubstituteBoundInMethodTypeParam.java new file mode 100644 index 000000000000..0cccda1cebde --- /dev/null +++ b/java/java-tests/testData/codeInsight/overrideImplement/beforeSubstituteBoundInMethodTypeParam.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2012 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +abstract class A { + abstract void foo(S s); + } + + class B extends A{ // Implement methods + + } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/OverrideImplementTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/OverrideImplementTest.java index 3d0a160e8094..5a4b795126df 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/OverrideImplementTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/OverrideImplementTest.java @@ -37,6 +37,8 @@ public class OverrideImplementTest extends LightCodeInsightTestCase { public void testWildcard() throws Exception { doTest(false); } public void testTypeParam() throws Exception { doTest(false); } public void testInterfaceAndAbstractClass() throws Exception { doTest(false); } + public void testRawSuper() throws Exception { doTest(false); } + public void testSubstituteBoundInMethodTypeParam() throws Exception { doTest(false); } public void testLongFinalParameterList() throws Exception { CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();