omit stubs for the overriding methods with wider return type than that of their supers (yes, this happens in Groovy) (IDEA-63687)

This commit is contained in:
peter
2011-01-10 01:21:17 +03:00
parent ac8046097d
commit 0ca3f0361f
4 changed files with 77 additions and 4 deletions
@@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.compiler.generator;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.compiler.impl.CompilerUtil;
import com.intellij.javaee.model.annotations.AnnotationModelUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.diagnostic.Logger;
@@ -63,7 +62,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDef
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
import java.io.File;
import java.io.IOException;
@@ -287,7 +285,7 @@ public class GroovyToJavaGenerator {
private void writeAllMethods(StringBuffer text, Collection<PsiMethod> methods, PsiClass aClass) {
Set<MethodSignature> methodSignatures = new HashSet<MethodSignature>();
for (PsiMethod method : methods) {
if (LightMethodBuilder.isLightMethod(method, GrClassImplUtil.SYNTHETIC_METHOD_IMPLEMENTATION)) {
if (!shouldBeGenerated(method)) {
continue;
}
@@ -327,6 +325,19 @@ public class GroovyToJavaGenerator {
}
}
private static boolean shouldBeGenerated(PsiMethod method) {
for (PsiMethod psiMethod : method.findSuperMethods()) {
if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
final PsiType type = method.getReturnType();
final PsiType superType = psiMethod.getReturnType();
if (type != null && superType != null && !superType.isAssignableFrom(type)) {
return false;
}
}
}
return true;
}
private Collection<PsiMethod> collectMethods(PsiClass typeDefinition, boolean classDef) {
Collection<PsiMethod> methods = new LinkedHashSet<PsiMethod>();
ContainerUtil.addAll(methods, typeDefinition.getMethods());
@@ -60,7 +60,6 @@ public class GrClassImplUtil {
};
public static final String GROOVY_OBJECT_SUPPORT = "groovy.lang.GroovyObjectSupport";
public static final String SYNTHETIC_METHOD_IMPLEMENTATION = "GroovySyntheticMethodImplementation";
private GrClassImplUtil() {
}
@@ -56,6 +56,7 @@ public void testArrayType1() throws Throwable { doTest(); }
public void testSynchronizedProperty() throws Throwable { doTest(); }
public void testVarargs() throws Throwable { doTest(); }
public void testThrowsCheckedException() throws Throwable { doTest(); }
public void testSubclassProperty() throws Throwable { doTest(); }
public void testCheckedExceptionInConstructorDelegate() throws Throwable {
myFixture.addClass("package foo;" +
@@ -0,0 +1,62 @@
class Super {
String getFoo() {}
}
class Sub extends Super {
def foo
}
-----
public class Super extends groovy.lang.GroovyObjectSupport implements groovy.lang.GroovyObject {
public java.lang.String getFoo() {
return null;
}
public groovy.lang.MetaClass getMetaClass() {
return null;
}
public void setMetaClass(groovy.lang.MetaClass mc) {
return ;
}
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) {
return null;
}
public java.lang.Object getProperty(java.lang.String propertyName) {
return null;
}
public void setProperty(java.lang.String propertyName, java.lang.Object newValue) {
return ;
}
}
---
public class Sub extends Super implements groovy.lang.GroovyObject {
public void setFoo(java.lang.Object foo) {
return ;
}
public groovy.lang.MetaClass getMetaClass() {
return null;
}
public void setMetaClass(groovy.lang.MetaClass mc) {
return ;
}
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) {
return null;
}
public java.lang.Object getProperty(java.lang.String propertyName) {
return null;
}
public void setProperty(java.lang.String propertyName, java.lang.Object newValue) {
return ;
}
private java.lang.Object foo = null;
}
---