### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v retrieving revision 1.46 diff -u -r1.46 LookupTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 8 Apr 2006 08:06:00 -0000 1.46 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 21 Apr 2006 10:20:05 -0000 @@ -2095,6 +2095,74 @@ "Syntax error, insert \"}\" to complete ClassBody\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=137744 +public void test064() { + Map options = this.getCompilerOptions(); + if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) { + // ensure target is 1.1 for having default abstract methods involved + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " B a = new C();\n" + + " \n" + + " a.hasKursAt(1);\n" + + " }\n" + + "\n" + + "}", + "A.java", + "abstract public class A implements IA0 {\n" + + " int t;\n" + + " public A() {\n" + + " }\n" + + "}", + "B.java", + "abstract public class B extends A implements IA3, IA1 {\n" + + " int a;\n" + + " public B() {\n" + + " }\n" + + " public void test() { \n" + + " }\n" + + "}", + "C.java", + "public class C extends B implements IA4, IA2{\n" + + " int c;\n" + + " public C() {\n" + + " }\n" + + " public boolean hasKursAt(int zeitpunkt) {\n" + + " return false;\n" + + " }\n" + + "}", + "IA0.java", + "public interface IA0 {\n" + + " public void test();\n" + + "}", + "IA1.java", + "public interface IA1 extends IA0 {\n" + + " public boolean hasKursAt(int zeitpunkt);\n" + + "}", + "IA2.java", + "public interface IA2 extends IA0 {\n" + + " public boolean hasKursAt(int zeitpunkt);\n" + + "}", + "IA3.java", + "public interface IA3 extends IA2 {\n" + + "}", + "IA4.java", + "public interface IA4 extends IA3 {\n" + + "}" + }, + "SUCCESS", + null, + true, + null, + options, + null); +} public static Class testClass() { return LookupTest.class; } } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v retrieving revision 1.132 diff -u -r1.132 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 10 Apr 2006 18:55:29 -0000 1.132 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 21 Apr 2006 10:20:07 -0000 @@ -63,20 +63,7 @@ computeId(); } -private void addDefaultAbstractMethod(MethodBinding abstractMethod) { - MethodBinding defaultAbstract = new MethodBinding( - abstractMethod.modifiers | ExtraCompilerModifiers.AccDefaultAbstract, - abstractMethod.selector, - abstractMethod.returnType, - abstractMethod.parameters, - abstractMethod.thrownExceptions, - this); - - MethodBinding[] temp = new MethodBinding[this.methods.length + 1]; - System.arraycopy(this.methods, 0, temp, 0, this.methods.length); - temp[this.methods.length] = defaultAbstract; - this.methods = temp; -} + public void addDefaultAbstractMethods() { if ((this.tagBits & TagBits.KnowsDefaultAbstractMethods) != 0) return; @@ -88,19 +75,43 @@ ReferenceBinding[][] interfacesToVisit = new ReferenceBinding[5][]; int lastPosition = 0; interfacesToVisit[lastPosition] = superInterfaces(); - boolean hasAddedMethods = false; + MethodBinding[] defaultAbstracts = null; + int defaultAbstractsCount = 0; for (int i = 0; i <= lastPosition; i++) { ReferenceBinding[] interfaces = interfacesToVisit[i]; for (int j = 0, length = interfaces.length; j < length; j++) { ReferenceBinding superType = interfaces[j]; if (superType.isValidBinding()) { MethodBinding[] superMethods = superType.methods(); - for (int m = superMethods.length; --m >= 0;) { + nextAbstractMethod: for (int m = superMethods.length; --m >= 0;) { MethodBinding method = superMethods[m]; - if (!implementsMethod(method)) { - addDefaultAbstractMethod(method); - hasAddedMethods = true; + // explicitly implemented ? + if (implementsMethod(method)) { + continue nextAbstractMethod; } + if (defaultAbstractsCount == 0) { + defaultAbstracts = new MethodBinding[5]; + } else { + // already added as default abstract ? + for(int k = 0; k < defaultAbstractsCount; k++) { + MethodBinding alreadyAddedMethod = defaultAbstracts[k]; + if (CharOperation.equals(alreadyAddedMethod.selector, method.selector) + && alreadyAddedMethod.areParametersEqual(method)) { + continue nextAbstractMethod; + } + } + } + MethodBinding defaultAbstract = new MethodBinding( + method.modifiers | ExtraCompilerModifiers.AccDefaultAbstract, + method.selector, + method.returnType, + method.parameters, + method.thrownExceptions, + this); + if (defaultAbstractsCount == defaultAbstracts.length) { + System.arraycopy(defaultAbstracts, 0, defaultAbstracts = new MethodBinding[2*defaultAbstractsCount], 0, defaultAbstractsCount); + } + defaultAbstracts[defaultAbstractsCount++] = defaultAbstract; } ReferenceBinding[] itsInterfaces = superType.superInterfaces(); @@ -112,9 +123,12 @@ } } } - if (hasAddedMethods) { - // re-sort methods + if (defaultAbstractsCount > 0) { int length = this.methods.length; + System.arraycopy(this.methods, 0, this.methods = new MethodBinding[length+defaultAbstractsCount], 0, length); + System.arraycopy(defaultAbstracts, 0, this.methods, length, defaultAbstractsCount); + // re-sort methods + length = length+defaultAbstractsCount; if (length > 1) { ReferenceBinding.sortMethods(this.methods, 0, length - 1); }