IDEA-119272 Groovy: don't duplicate @Nullable in implemented methods

This commit is contained in:
Max Medvedev
2014-01-13 16:17:32 +04:00
parent 8aa8ca5de2
commit b1d9f99774
3 changed files with 53 additions and 16 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -94,18 +94,19 @@ public class GroovyOverrideImplementUtil {
GrParameter[] parameters = result.getParameters();
for (int i = 0; i < parameters.length; i++) {
GrParameter parameter = parameters[i];
final PsiParameter original = originalParams[i];
PsiParameter original = originalParams[i];
for (PsiAnnotation annotation : original.getModifierList().getAnnotations()) {
final GrModifierList modifierList = parameter.getModifierList();
String qname = annotation.getQualifiedName();
if (annotation instanceof GrAnnotation) {
modifierList.add(annotation);
}
else {
modifierList.add(factory.createAnnotationFromText(annotation.getText()));
if (qname != null && modifierList.findAnnotation(qname) == null) {
if (annotation instanceof GrAnnotation) {
modifierList.add(annotation);
}
else {
modifierList.add(factory.createAnnotationFromText(annotation.getText()));
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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,6 +16,7 @@
package org.jetbrains.plugins.groovy.overrideImplement;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.generation.OverrideImplementExploreUtil;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.codeInsight.hint.HintManager;
import com.intellij.lang.LanguageCodeInsightActionHandler;
@@ -40,7 +41,7 @@ public class GroovyOverrideMethodsHandler implements LanguageCodeInsightActionHa
PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
if (aClass == null) return;
if (OverrideImplementUtil.getMethodSignaturesToOverride(aClass).isEmpty()) {
if (OverrideImplementExploreUtil.getMethodSignaturesToOverride(aClass).isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "No methods to override have been found");
return;
}
@@ -100,7 +100,7 @@ class Test<T> extends Base<T> {
}
void testTrhowsList() {
myFixture.configureByText('a.groovy', '''\
assertImplement('''\
class X implements I {
<caret>
}
@@ -108,11 +108,7 @@ class X implements I {
interface I {
void foo() throws RuntimeException
}
''')
generateImplementation(findMethod('I', 'foo'))
myFixture.checkResult('''\
''', 'I', 'foo', '''\
class X implements I {
@Override
@@ -127,6 +123,12 @@ interface I {
''')
}
private void assertImplement(String textBefore, String clazz, String name, String textAfter) {
myFixture.configureByText('a.groovy', textBefore)
generateImplementation(findMethod(clazz, name))
myFixture.checkResult(textAfter)
}
void testThrowsListWithImport() {
myFixture.addClass('''\
package pack;
@@ -162,6 +164,39 @@ class X implements I {
''')
}
void testNullableParameter() {
myFixture.addClass('''
package org.jetbrains.annotations;
public @interface Nullable{}
''')
assertImplement('''
import org.jetbrains.annotations.Nullable
class Inheritor implements I {
<caret>
}
interface I {
def foo(@Nullable p)
}
''', 'I', 'foo', '''
import org.jetbrains.annotations.Nullable
class Inheritor implements I {
@Override
def foo(@Nullable Object p) {
<caret>return null
}
}
interface I {
def foo(@Nullable p)
}
''')
}
public void _testImplementIntention() {
myFixture.configureByText('a.groovy', '''
class Base<E> {