From 03d3ac350272f6f8680c60cf7006cdaacf18cc7e Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Wed, 30 Nov 2011 14:11:59 +0400 Subject: [PATCH] fix override modifier when method overrides method only from java.lang.Object --- src/org/jetbrains/jet/j2k/Converter.java | 13 ++++- .../file/extendsBaseWhichExtendsObject.jav | 55 +++++++++++++++++++ .../file/extendsBaseWhichExtendsObject.kt | 35 ++++++++++++ testData/ast/function/file/overrideObject.jav | 28 ++++++++++ testData/ast/function/file/overrideObject.kt | 18 ++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 testData/ast/function/file/extendsBaseWhichExtendsObject.jav create mode 100644 testData/ast/function/file/extendsBaseWhichExtendsObject.kt create mode 100644 testData/ast/function/file/overrideObject.jav create mode 100644 testData/ast/function/file/overrideObject.kt diff --git a/src/org/jetbrains/jet/j2k/Converter.java b/src/org/jetbrains/jet/j2k/Converter.java index 9ac7fb2082f..e33682d8969 100644 --- a/src/org/jetbrains/jet/j2k/Converter.java +++ b/src/org/jetbrains/jet/j2k/Converter.java @@ -292,7 +292,7 @@ public class Converter { final List typeParameters = elementsToElementList(method.getTypeParameters()); final Set modifiers = modifiersListToModifiersSet(method.getModifierList()); - if (method.getHierarchicalMethodSignature().getSuperSignatures().size() > 0) + if (isOverrideAnyMethodExceptMethodsFromObject(method)) modifiers.add(Modifier.OVERRIDE); if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface()) modifiers.remove(Modifier.ABSTRACT); @@ -324,6 +324,17 @@ public class Converter { ); } + private static boolean isOverrideAnyMethodExceptMethodsFromObject(@NotNull PsiMethod method) { + int counter = 0; + for (HierarchicalMethodSignature s : method.getHierarchicalMethodSignature().getSuperSignatures()) { + PsiClass containingClass = s.getMethod().getContainingClass(); + String qualifiedName = containingClass != null ? containingClass.getQualifiedName() : ""; + if (qualifiedName != null && !qualifiedName.equals("java.lang.Object")) + counter++; + } + return counter > 0; + } + @NotNull public static Block blockToBlock(@Nullable PsiCodeBlock block, boolean notEmpty) { if (block == null) return Block.EMPTY_BLOCK; diff --git a/testData/ast/function/file/extendsBaseWhichExtendsObject.jav b/testData/ast/function/file/extendsBaseWhichExtendsObject.jav new file mode 100644 index 00000000000..b72fd76ec71 --- /dev/null +++ b/testData/ast/function/file/extendsBaseWhichExtendsObject.jav @@ -0,0 +1,55 @@ +package test; + +class Test extends Base { + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public String toString() { + return super.toString(); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + } +} + +class Base { + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public String toString() { + return super.toString(); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + } +} \ No newline at end of file diff --git a/testData/ast/function/file/extendsBaseWhichExtendsObject.kt b/testData/ast/function/file/extendsBaseWhichExtendsObject.kt new file mode 100644 index 00000000000..c5f6ebe3a49 --- /dev/null +++ b/testData/ast/function/file/extendsBaseWhichExtendsObject.kt @@ -0,0 +1,35 @@ +namespace test +open class Test() : Base() { +override public fun hashCode() : Int { +return super.hashCode() +} +override public fun equals(o : Any?) : Boolean { +return super.equals(o) +} +override protected fun clone() : Any? { +return super.clone() +} +override public fun toString() : String? { +return super.toString() +} +override protected fun finalize() : Unit { +super.finalize() +} +} +open class Base() { +open public fun hashCode() : Int { +return super.hashCode() +} +open public fun equals(o : Any?) : Boolean { +return super.equals(o) +} +open protected fun clone() : Any? { +return super.clone() +} +open public fun toString() : String? { +return super.toString() +} +open protected fun finalize() : Unit { +super.finalize() +} +} \ No newline at end of file diff --git a/testData/ast/function/file/overrideObject.jav b/testData/ast/function/file/overrideObject.jav new file mode 100644 index 00000000000..0538508c9b8 --- /dev/null +++ b/testData/ast/function/file/overrideObject.jav @@ -0,0 +1,28 @@ +package test; + +class Test { + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public String toString() { + return super.toString(); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + } +} \ No newline at end of file diff --git a/testData/ast/function/file/overrideObject.kt b/testData/ast/function/file/overrideObject.kt new file mode 100644 index 00000000000..b60bac09b96 --- /dev/null +++ b/testData/ast/function/file/overrideObject.kt @@ -0,0 +1,18 @@ +namespace test +open class Test() { +open public fun hashCode() : Int { +return super.hashCode() +} +open public fun equals(o : Any?) : Boolean { +return super.equals(o) +} +open protected fun clone() : Any? { +return super.clone() +} +open public fun toString() : String? { +return super.toString() +} +open protected fun finalize() : Unit { +super.finalize() +} +} \ No newline at end of file