Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 297183
Collapse All | Expand All

(-)core extension/org/eclipse/jdt/internal/corext/util/MethodsSourcePositionComparator.java (-13 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
2
 * Copyright (c) 2009, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-46 Link Here
32
 * <li><code>m1</code> and <code>m2</code> are defined in the same type (<code>T</code> or any
32
 * <li><code>m1</code> and <code>m2</code> are defined in the same type (<code>T</code> or any
33
 * supertype of <code>T</code>), that type doesn't have a source attachment and name of
33
 * supertype of <code>T</code>), that type doesn't have a source attachment and name of
34
 * <code>m1</code> alphabetically precedes name of <code>m2</code></li>
34
 * <code>m1</code> alphabetically precedes name of <code>m2</code></li>
35
 * <li><code>m1</code> is defined in <code>T</code> and <code>m2</code> is defined in any supertype
35
 * 
36
 * <li><code>m2</code> is defined in <code>T</code> and <code>m1</code> is defined in any supertype
36
 * of <code>T</code></li>
37
 * of <code>T</code></li>
37
 * <li><code>m1</code> is defined in a superclass of <code>T</code> and <code>m2</code> is defined
38
 * <li><code>m2</code> is defined in a superclass of <code>T</code> and <code>m1</code> is defined
38
 * in a superinterface of <code>T</code></li>
39
 * in a superinterface of <code>T</code></li>
39
 * <li><code>m1</code> and <code>m2</code> are defined in different superclasses of <code>T</code>
40
 * <li><code>m1</code> and <code>m2</code> are defined in different superclasses of <code>T</code>
40
 * and a class which defines <code>m2</code> extends class which defines <code>m1</code>
41
 * and a class which defines <code>m1</code> extends class which defines <code>m2</code>
41
 * <li><code>m1</code> and <code>m2</code> are defined in different superinterfaces of
42
 * <li><code>m1</code> and <code>m2</code> are defined in different superinterfaces of
42
 * <code>T</code> and an interface which defines <code>m1</code> appears before an interface which
43
 * <code>T</code> and an interface which defines <code>m2</code> appears before an interface which
43
 * defines <code>m2</code> in <code>implements</code> clause of declaration of type <code>T</code></li>
44
 * defines <code>m1</code> in <code>implements</code> clause of declaration of type <code>T</code></li>
44
 * </ul>
45
 * </ul>
45
 */
46
 */
46
public class MethodsSourcePositionComparator implements Comparator {
47
public class MethodsSourcePositionComparator implements Comparator {
Lines 71-80 Link Here
71
		}
72
		}
72
73
73
		if (firstMethodType.equals(fTypeBinding)) {
74
		if (firstMethodType.equals(fTypeBinding)) {
74
			return -1;
75
			return 1;
75
		}
76
		}
76
		if (secondMethodType.equals(fTypeBinding)) {
77
		if (secondMethodType.equals(fTypeBinding)) {
77
			return 1;
78
			return -1;
78
		}
79
		}
79
80
80
		ITypeBinding type= fTypeBinding;
81
		ITypeBinding type= fTypeBinding;
Lines 89-110 Link Here
89
			count++;
90
			count++;
90
		}
91
		}
91
		if (firstCount != -1 && secondCount != -1) {
92
		if (firstCount != -1 && secondCount != -1) {
92
			return -(firstCount - secondCount);
93
			return (firstCount - secondCount);
93
		}
94
		}
94
		if (firstCount != -1 && secondCount == -1) {
95
		if (firstCount != -1 && secondCount == -1) {
95
			return -1;
96
			return 1;
96
		}
97
		}
97
		if (firstCount == -1 && secondCount != -1) {
98
		if (firstCount == -1 && secondCount != -1) {
98
			return 1;
99
			return -1;
99
		}
100
		}
100
101
101
		ITypeBinding[] interfaces= fTypeBinding.getInterfaces();
102
		ITypeBinding[] interfaces= fTypeBinding.getInterfaces();
102
		for (int i= 0; i < interfaces.length; i++) {
103
		for (int i= 0; i < interfaces.length; i++) {
103
			if (firstMethodType.equals(interfaces[i])) {
104
			if (firstMethodType.equals(interfaces[i])) {
104
				return -1;
105
				return 1;
105
			}
106
			}
106
			if (secondMethodType.equals(interfaces[i])) {
107
			if (secondMethodType.equals(interfaces[i])) {
107
				return 1;
108
				return -1;
108
			}
109
			}
109
		}
110
		}
110
		return 0;
111
		return 0;
(-)ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedMethodsTest.java (-2 / +46 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 51-56 Link Here
51
import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
51
import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
52
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
52
import org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType;
53
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
53
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
54
import org.eclipse.jdt.internal.corext.util.Strings;
54
55
55
import org.eclipse.jdt.ui.JavaUI;
56
import org.eclipse.jdt.ui.JavaUI;
56
import org.eclipse.jdt.ui.PreferenceConstants;
57
import org.eclipse.jdt.ui.PreferenceConstants;
Lines 236-247 Link Here
236
		testHelper(testClass);
237
		testHelper(testClass);
237
238
238
		IMethod[] methods= testClass.getMethods();
239
		IMethod[] methods= testClass.getMethods();
239
		checkMethods(new String[] { "b", "foo", "equals", "clone", "toString", "finalize", "hashCode" }, methods);
240
		checkMethodsInOrder(new String[] { "foo", "b", "clone", "equals", "finalize", "hashCode", "toString"}, methods);
240
241
241
		IImportDeclaration[] imports= cu.getImports();
242
		IImportDeclaration[] imports= cu.getImports();
242
		checkImports(new String[0], imports);
243
		checkImports(new String[0], imports);
243
	}
244
	}
244
245
246
	public void testBug297183() throws Exception {
247
		StringBuffer buf= new StringBuffer();
248
		buf.append("package ibm.util;\n");
249
		buf.append("interface Shape {\r\n");
250
		buf.append("  int getX();\r\n");
251
		buf.append("  int getY();\r\n");
252
		buf.append("  int getEdges();\r\n");
253
		buf.append("  int getArea();\r\n");
254
		buf.append("}\r\n");
255
		fPackage.createCompilationUnit("Shape.java", buf.toString(), false, null);
256
		
257
		buf= new StringBuffer();
258
		buf.append("package ibm.util;\n");
259
		buf.append("interface Circle extends Shape {\r\n");
260
		buf.append("  int getR();\r\n");
261
		buf.append("}\r\n");
262
		buf.append("\r\n");
263
		fPackage.createCompilationUnit("Circle.java", buf.toString(), false, null);
264
		
265
		buf= new StringBuffer();
266
		buf.append("package ibm.util;\n");
267
		buf.append("public class DefaultCircle implements Circle {\n");
268
		buf.append("}\n");
269
		ICompilationUnit cu= fPackage.getCompilationUnit("DefaultCircle.java");
270
		IType testClass= cu.createType(buf.toString(), null, true, null);
271
		
272
		testHelper(testClass, -1, false);
273
		
274
		IMethod[] methods= testClass.getMethods();
275
		checkMethodsInOrder(new String[] { "getX", "getY", "getEdges", "getArea", "getR"}, methods);
276
		
277
		IImportDeclaration[] imports= cu.getImports();
278
		checkImports(new String[0], imports);
279
	}
280
	
245
	public void testInsertAt() throws Exception {
281
	public void testInsertAt() throws Exception {
246
		fJavaProject= JavaProjectHelper.createJavaProject("DummyProject", "bin");
282
		fJavaProject= JavaProjectHelper.createJavaProject("DummyProject", "bin");
247
		assertNotNull(JavaProjectHelper.addRTJar(fJavaProject));
283
		assertNotNull(JavaProjectHelper.addRTJar(fJavaProject));
Lines 336-341 Link Here
336
		JavaModelUtil.reconcile(testClass.getCompilationUnit());
372
		JavaModelUtil.reconcile(testClass.getCompilationUnit());
337
	}
373
	}
338
374
375
	private void checkMethodsInOrder(String[] expected, IMethod[] methods) {
376
		String[] actualNames= new String[methods.length];
377
		for (int i= 0; i < actualNames.length; i++) {
378
			actualNames[i]= methods[i].getElementName();
379
		}
380
		assertEquals(Strings.concatenate(expected, ", "), Strings.concatenate(actualNames, ", "));
381
	}
382
	
339
	private void checkMethods(String[] expected, IMethod[] methods) {
383
	private void checkMethods(String[] expected, IMethod[] methods) {
340
		int nMethods= methods.length;
384
		int nMethods= methods.length;
341
		int nExpected= expected.length;
385
		int nExpected= expected.length;
(-)ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java (-6 / +6 lines)
Lines 2078-2091 Link Here
2078
		buf.append("import test2.InterImpl;\n");
2078
		buf.append("import test2.InterImpl;\n");
2079
		buf.append("public class E extends InterImpl {\n");
2079
		buf.append("public class E extends InterImpl {\n");
2080
		buf.append("\n");
2080
		buf.append("\n");
2081
		buf.append("    public int getCount(Object[] o) throws IOException {\n");
2082
		buf.append("        return 0;\n");
2083
		buf.append("    }\n");
2084
		buf.append("\n");
2081
		buf.append("    @Override\n");
2085
		buf.append("    @Override\n");
2082
		buf.append("    protected int[] getMusic() throws IOException {\n");
2086
		buf.append("    protected int[] getMusic() throws IOException {\n");
2083
		buf.append("        return null;\n");
2087
		buf.append("        return null;\n");
2084
		buf.append("    }\n");
2088
		buf.append("    }\n");
2085
		buf.append("\n");
2086
		buf.append("    public int getCount(Object[] o) throws IOException {\n");
2087
		buf.append("        return 0;\n");
2088
		buf.append("    }\n");
2089
		buf.append("}\n");
2089
		buf.append("}\n");
2090
		String expected2= buf.toString();
2090
		String expected2= buf.toString();
2091
2091
Lines 2598-2609 Link Here
2598
		buf.append("package test;\n");
2598
		buf.append("package test;\n");
2599
		buf.append("enum TestEnum implements Runnable {\n");
2599
		buf.append("enum TestEnum implements Runnable {\n");
2600
		buf.append("    A {\n");
2600
		buf.append("    A {\n");
2601
		buf.append("        public void run() {\n");
2602
		buf.append("        }\n");
2601
		buf.append("        @Override\n");
2603
		buf.append("        @Override\n");
2602
		buf.append("        public boolean foo() {\n");
2604
		buf.append("        public boolean foo() {\n");
2603
		buf.append("            return false;\n");
2605
		buf.append("            return false;\n");
2604
		buf.append("        }\n");
2606
		buf.append("        }\n");
2605
		buf.append("        public void run() {\n");
2606
		buf.append("        }\n");
2607
		buf.append("    };\n");
2607
		buf.append("    };\n");
2608
		buf.append("    public abstract boolean foo();\n");
2608
		buf.append("    public abstract boolean foo();\n");
2609
		buf.append("}\n");
2609
		buf.append("}\n");

Return to bug 297183