View | Details | Raw Unified | Return to bug 137744 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (+68 lines)
Lines 2095-2100 Link Here
2095
	"Syntax error, insert \"}\" to complete ClassBody\n" + 
2095
	"Syntax error, insert \"}\" to complete ClassBody\n" + 
2096
	"----------\n");
2096
	"----------\n");
2097
}
2097
}
2098
//	https://bugs.eclipse.org/bugs/show_bug.cgi?id=137744
2099
public void test064() {
2100
	Map options = this.getCompilerOptions();
2101
	if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) {
2102
		// ensure target is 1.1 for having default abstract methods involved
2103
		options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
2104
	}
2105
	this.runConformTest(
2106
			new String[] {
2107
				"X.java",
2108
				"public class X {\n" + 
2109
				"	public static void main(String[] args) {\n" + 
2110
				"		System.out.println(\"SUCCESS\");\n" + 
2111
				"		B a = new C();\n" + 
2112
				"		\n" + 
2113
				"		a.hasKursAt(1);\n" + 
2114
				"	}\n" + 
2115
				"\n" + 
2116
				"}",
2117
				"A.java",
2118
				"abstract public class A implements IA0 {\n" + 
2119
				"	int t;\n" + 
2120
				"	public A() {\n" + 
2121
				"	}\n" + 
2122
				"}",
2123
				"B.java",
2124
				"abstract public class B extends A implements IA3, IA1 {\n" + 
2125
				"	int a;\n" + 
2126
				"	public B() {\n" + 
2127
				"	}\n" + 
2128
				"	public void test() {	\n" + 
2129
				"	}\n" + 
2130
				"}",
2131
				"C.java",
2132
				"public class C extends B implements IA4, IA2{\n" + 
2133
				"	int c;\n" + 
2134
				"	public C() {\n" + 
2135
				"	}\n" + 
2136
				"	public boolean hasKursAt(int zeitpunkt) {\n" + 
2137
				"		return false;\n" + 
2138
				"	}\n" + 
2139
				"}",
2140
				"IA0.java",
2141
				"public interface IA0 {\n" + 
2142
				"	public void test();\n" + 
2143
				"}",
2144
				"IA1.java",
2145
				"public interface IA1 extends IA0 {\n" + 
2146
				"	public boolean hasKursAt(int zeitpunkt);\n" + 
2147
				"}",
2148
				"IA2.java",
2149
				"public interface IA2 extends IA0 {\n" + 
2150
				"	public boolean hasKursAt(int zeitpunkt);\n" + 
2151
				"}",
2152
				"IA3.java",
2153
				"public interface IA3 extends IA2 {\n" + 
2154
				"}",
2155
				"IA4.java",
2156
				"public interface IA4 extends IA3 {\n" + 
2157
				"}"
2158
			},
2159
			"SUCCESS",
2160
			null,
2161
			true,
2162
			null,
2163
			options,
2164
			null);
2165
}
2098
public static Class testClass() {	return LookupTest.class;
2166
public static Class testClass() {	return LookupTest.class;
2099
}
2167
}
2100
}
2168
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-21 / +35 lines)
Lines 63-82 Link Here
63
63
64
	computeId();
64
	computeId();
65
}
65
}
66
private void addDefaultAbstractMethod(MethodBinding abstractMethod) {
66
67
	MethodBinding defaultAbstract = new MethodBinding(
68
		abstractMethod.modifiers | ExtraCompilerModifiers.AccDefaultAbstract,
69
		abstractMethod.selector,
70
		abstractMethod.returnType,
71
		abstractMethod.parameters,
72
		abstractMethod.thrownExceptions,
73
		this);
74
75
	MethodBinding[] temp = new MethodBinding[this.methods.length + 1];
76
	System.arraycopy(this.methods, 0, temp, 0, this.methods.length);
77
	temp[this.methods.length] = defaultAbstract;
78
	this.methods = temp;
79
}
80
public void addDefaultAbstractMethods() {
67
public void addDefaultAbstractMethods() {
81
	if ((this.tagBits & TagBits.KnowsDefaultAbstractMethods) != 0) return;
68
	if ((this.tagBits & TagBits.KnowsDefaultAbstractMethods) != 0) return;
82
69
Lines 88-106 Link Here
88
		ReferenceBinding[][] interfacesToVisit = new ReferenceBinding[5][];
75
		ReferenceBinding[][] interfacesToVisit = new ReferenceBinding[5][];
89
		int lastPosition = 0;
76
		int lastPosition = 0;
90
		interfacesToVisit[lastPosition] = superInterfaces();
77
		interfacesToVisit[lastPosition] = superInterfaces();
91
		boolean hasAddedMethods = false;
78
		MethodBinding[] defaultAbstracts = null;
79
		int defaultAbstractsCount = 0;
92
		for (int i = 0; i <= lastPosition; i++) {
80
		for (int i = 0; i <= lastPosition; i++) {
93
			ReferenceBinding[] interfaces = interfacesToVisit[i];
81
			ReferenceBinding[] interfaces = interfacesToVisit[i];
94
			for (int j = 0, length = interfaces.length; j < length; j++) {
82
			for (int j = 0, length = interfaces.length; j < length; j++) {
95
				ReferenceBinding superType = interfaces[j];
83
				ReferenceBinding superType = interfaces[j];
96
				if (superType.isValidBinding()) {
84
				if (superType.isValidBinding()) {
97
					MethodBinding[] superMethods = superType.methods();
85
					MethodBinding[] superMethods = superType.methods();
98
					for (int m = superMethods.length; --m >= 0;) {
86
					nextAbstractMethod: for (int m = superMethods.length; --m >= 0;) {
99
						MethodBinding method = superMethods[m];
87
						MethodBinding method = superMethods[m];
100
						if (!implementsMethod(method)) {
88
						// explicitly implemented ?
101
							addDefaultAbstractMethod(method);
89
						if (implementsMethod(method)) {
102
							hasAddedMethods = true;
90
							continue nextAbstractMethod;
103
						}
91
						}
92
						if (defaultAbstractsCount == 0) {
93
							defaultAbstracts = new MethodBinding[5];
94
						} else {
95
							// already added as default abstract ?
96
							for(int k = 0; k < defaultAbstractsCount; k++) {
97
								MethodBinding alreadyAddedMethod = 	defaultAbstracts[k];
98
								if (CharOperation.equals(alreadyAddedMethod.selector, method.selector)
99
										&& alreadyAddedMethod.areParametersEqual(method)) {
100
									continue nextAbstractMethod;
101
								}
102
							}
103
						}
104
						MethodBinding defaultAbstract = new MethodBinding(
105
								method.modifiers | ExtraCompilerModifiers.AccDefaultAbstract,
106
								method.selector,
107
								method.returnType,
108
								method.parameters,
109
								method.thrownExceptions,
110
								this);
111
						if (defaultAbstractsCount == defaultAbstracts.length) {
112
							System.arraycopy(defaultAbstracts, 0, defaultAbstracts = new MethodBinding[2*defaultAbstractsCount], 0, defaultAbstractsCount);
113
						}
114
						defaultAbstracts[defaultAbstractsCount++] = defaultAbstract;
104
					}
115
					}
105
116
106
					ReferenceBinding[] itsInterfaces = superType.superInterfaces();
117
					ReferenceBinding[] itsInterfaces = superType.superInterfaces();
Lines 112-120 Link Here
112
				}
123
				}
113
			}
124
			}
114
		}
125
		}
115
		if (hasAddedMethods) {
126
		if (defaultAbstractsCount > 0) {
116
			// re-sort methods
117
			int length = this.methods.length;
127
			int length = this.methods.length;
128
			System.arraycopy(this.methods, 0, this.methods = new MethodBinding[length+defaultAbstractsCount], 0, length);
129
			System.arraycopy(defaultAbstracts, 0, this.methods, length, defaultAbstractsCount);
130
			// re-sort methods
131
			length = length+defaultAbstractsCount;
118
			if (length > 1) {
132
			if (length > 1) {
119
				ReferenceBinding.sortMethods(this.methods, 0, length - 1);
133
				ReferenceBinding.sortMethods(this.methods, 0, length - 1);
120
			}
134
			}

Return to bug 137744