fix override modifier when method overrides method only from java.lang.Object

This commit is contained in:
Sergey Ignatov
2011-11-30 14:11:59 +04:00
parent bcd0618fb4
commit 03d3ac3502
5 changed files with 148 additions and 1 deletions
+12 -1
View File
@@ -292,7 +292,7 @@ public class Converter {
final List<Element> typeParameters = elementsToElementList(method.getTypeParameters());
final Set<String> 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;
@@ -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();
}
}
@@ -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()
}
}
@@ -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();
}
}
@@ -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()
}
}