Bug 543073 - The CompilationUnitSorter.sort() throws on level = 11 in
4.10
Change-Id: I9d59929fa2fee1c3b8dc47322233dd38bf74313b
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
index 679e6a0..5a41713 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SortCompilationUnitElementsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1920,6 +1920,32 @@
deleteFile("/P/src/X.java");
}
}
+@SuppressWarnings("deprecation")
+public void testBug543073_001() throws CoreException {
+ try {
+ this.createFile(
+ "/P/src/X.java",
+ "public enum X {\n" +
+ " Z, A, C, B;\n" +
+ "}"
+ );
+ String expectedResult =
+ "public enum X {\n" +
+ " Z, A, C, B;\n" +
+ "}";
+ sortUnit(AST_INTERNAL_JLS10, this.getCompilationUnit("/P/src/X.java"), expectedResult, false, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ BodyDeclaration bodyDeclaration1 = (BodyDeclaration) o1;
+ BodyDeclaration bodyDeclaration2 = (BodyDeclaration) o2;
+ final int sourceStart1 = ((Integer) bodyDeclaration1.getProperty(CompilationUnitSorter.RELATIVE_ORDER)).intValue();
+ final int sourceStart2 = ((Integer) bodyDeclaration2.getProperty(CompilationUnitSorter.RELATIVE_ORDER)).intValue();
+ return sourceStart1 - sourceStart2;
+ }
+ });
+ } finally {
+ deleteFile("/P/src/X.java");
+ }
+}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113722
public void test030() throws CoreException {
try {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java
index c4a9429..19b2f07 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/CompilationUnitSorter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -57,6 +57,9 @@
case AST.JLS8 :
case AST.JLS9 :
case AST.JLS10 :
+ case AST.JLS11 :
+ case AST.JLS12 :
+ case AST.JLS13 :
break;
default :
throw new IllegalArgumentException();