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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/hierarchy/IndexBasedHierarchyBuilder.java (-15 / +33 lines)
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
25
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
26
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
26
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
27
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
27
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
28
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
28
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
29
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
29
import org.eclipse.jdt.internal.core.*;
30
import org.eclipse.jdt.internal.core.*;
30
import org.eclipse.jdt.internal.core.search.IndexQueryRequestor;
31
import org.eclipse.jdt.internal.core.search.IndexQueryRequestor;
Lines 137-149 Link Here
137
	}
138
	}
138
}
139
}
139
private void buildForProject(JavaProject project, ArrayList potentialSubtypes, org.eclipse.jdt.core.ICompilationUnit[] workingCopies, HashSet localTypes, IProgressMonitor monitor) throws JavaModelException {
140
private void buildForProject(JavaProject project, ArrayList potentialSubtypes, org.eclipse.jdt.core.ICompilationUnit[] workingCopies, HashSet localTypes, IProgressMonitor monitor) throws JavaModelException {
140
	// copy vectors into arrays
141
	int openablesLength = potentialSubtypes.size();
142
	Openable[] openables = new Openable[openablesLength];
143
	potentialSubtypes.toArray(openables);
144
145
	// resolve
141
	// resolve
142
	int openablesLength = potentialSubtypes.size();
146
	if (openablesLength > 0) {
143
	if (openablesLength > 0) {
144
		// copy vectors into arrays
145
		Openable[] openables = new Openable[openablesLength];
146
		potentialSubtypes.toArray(openables);
147
148
		// sort in the order of roots and in reverse alphabetical order for .class file
149
		// since requesting top level types in the process of caching an enclosing type is
150
		// not supported by the lookup environment
151
		IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
152
		int rootsLength = roots.length;
153
		final HashtableOfObjectToInt indexes = new HashtableOfObjectToInt(openablesLength);
154
		for (int i = 0; i < openablesLength; i++) {
155
			IJavaElement root = openables[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
156
			int index;
157
			for (index = 0; index < rootsLength; index++) {
158
				if (roots[index].equals(root))
159
					break;
160
			}		
161
			indexes.put(openables[i], index);
162
		}
163
		Util.sort(openables, new Util.Comparer() {
164
			public int compare(Object a, Object b) {
165
				int aIndex = indexes.get(a);
166
				int bIndex = indexes.get(b);
167
				if (aIndex < bIndex)
168
					return -1;
169
				else if (aIndex > bIndex)
170
					return 1;
171
				return ((Openable) b).getElementName().compareTo(((Openable) a).getElementName());
172
			}
173
		});
174
		
147
		IType focusType = this.getType();
175
		IType focusType = this.getType();
148
		boolean inProjectOfFocusType = focusType != null && focusType.getJavaProject().equals(project);
176
		boolean inProjectOfFocusType = focusType != null && focusType.getJavaProject().equals(project);
149
		org.eclipse.jdt.core.ICompilationUnit[] unitsToLookInside = null;
177
		org.eclipse.jdt.core.ICompilationUnit[] unitsToLookInside = null;
Lines 240-256 Link Here
240
		length++;
268
		length++;
241
	}
269
	}
242
	
270
	
243
	// sort by projects
244
	/*
245
	 * NOTE: To workaround pb with hierarchy resolver that requests top  
246
	 * level types in the process of caching an enclosing type, this needs to
247
	 * be sorted in reverse alphabetical order so that top level types are cached
248
	 * before their inner types.
249
	 */
250
	org.eclipse.jdt.internal.core.util.Util.sortReverseOrder(allPotentialSubTypes);
251
	
252
	ArrayList potentialSubtypes = new ArrayList();
271
	ArrayList potentialSubtypes = new ArrayList();
253
254
	try {
272
	try {
255
		// create element infos for subtypes
273
		// create element infos for subtypes
256
		HandleFactory factory = new HandleFactory();
274
		HandleFactory factory = new HandleFactory();
(-)model/org/eclipse/jdt/internal/core/util/Util.java (-79 lines)
Lines 1616-1654 Link Here
1616
	}
1616
	}
1617
1617
1618
	/**
1618
	/**
1619
	 * Sort the objects in the given collection using the given sort order.
1620
	 */
1621
	private static void quickSort(Object[] sortedCollection, int left, int right, int[] sortOrder) {
1622
		int original_left = left;
1623
		int original_right = right;
1624
		int mid = sortOrder[ (left + right) / 2];
1625
		do {
1626
			while (sortOrder[left] < mid) {
1627
				left++;
1628
			}
1629
			while (mid < sortOrder[right]) {
1630
				right--;
1631
			}
1632
			if (left <= right) {
1633
				Object tmp = sortedCollection[left];
1634
				sortedCollection[left] = sortedCollection[right];
1635
				sortedCollection[right] = tmp;
1636
				int tmp2 = sortOrder[left];
1637
				sortOrder[left] = sortOrder[right];
1638
				sortOrder[right] = tmp2;
1639
				left++;
1640
				right--;
1641
			}
1642
		} while (left <= right);
1643
		if (original_left < right) {
1644
			quickSort(sortedCollection, original_left, right, sortOrder);
1645
		}
1646
		if (left < original_right) {
1647
			quickSort(sortedCollection, left, original_right, sortOrder);
1648
		}
1649
	}
1650
1651
	/**
1652
	 * Sort the strings in the given collection.
1619
	 * Sort the strings in the given collection.
1653
	 */
1620
	 */
1654
	private static void quickSort(String[] sortedCollection, int left, int right) {
1621
	private static void quickSort(String[] sortedCollection, int left, int right) {
Lines 1679-1713 Link Here
1679
	}
1646
	}
1680
1647
1681
	/**
1648
	/**
1682
	 * Sort the strings in the given collection in reverse alphabetical order.
1683
	 */
1684
	private static void quickSortReverse(String[] sortedCollection, int left, int right) {
1685
		int original_left = left;
1686
		int original_right = right;
1687
		String mid = sortedCollection[ (left + right) / 2];
1688
		do {
1689
			while (sortedCollection[left].compareTo(mid) > 0) {
1690
				left++;
1691
			}
1692
			while (mid.compareTo(sortedCollection[right]) > 0) {
1693
				right--;
1694
			}
1695
			if (left <= right) {
1696
				String tmp = sortedCollection[left];
1697
				sortedCollection[left] = sortedCollection[right];
1698
				sortedCollection[right] = tmp;
1699
				left++;
1700
				right--;
1701
			}
1702
		} while (left <= right);
1703
		if (original_left < right) {
1704
			quickSortReverse(sortedCollection, original_left, right);
1705
		}
1706
		if (left < original_right) {
1707
			quickSortReverse(sortedCollection, left, original_right);
1708
		}
1709
	}
1710
	/**
1711
	 * Reads in a string from the specified data input stream. The 
1649
	 * Reads in a string from the specified data input stream. The 
1712
	 * string has been encoded using a modified UTF-8 format. 
1650
	 * string has been encoded using a modified UTF-8 format. 
1713
	 * <p>
1651
	 * <p>
Lines 1923-1936 Link Here
1923
	}
1861
	}
1924
1862
1925
	/**
1863
	/**
1926
	 * Sorts an array of objects in place, using the sort order given for each item.
1927
	 */
1928
	public static void sort(Object[] objects, int[] sortOrder) {
1929
		if (objects.length > 1)
1930
			quickSort(objects, 0, objects.length - 1, sortOrder);
1931
	}
1932
1933
	/**
1934
	 * Sorts an array of strings in place using quicksort.
1864
	 * Sorts an array of strings in place using quicksort.
1935
	 */
1865
	 */
1936
	public static void sort(String[] strings) {
1866
	public static void sort(String[] strings) {
Lines 1991-2005 Link Here
1991
		return copy;
1921
		return copy;
1992
	}
1922
	}
1993
1923
1994
	/**
1995
	 * Sorts an array of strings in place using quicksort
1996
	 * in reverse alphabetical order.
1997
	 */
1998
	public static void sortReverseOrder(String[] strings) {
1999
		if (strings.length > 1)
2000
			quickSortReverse(strings, 0, strings.length - 1);
2001
	}
2002
	
2003
	/*
1924
	/*
2004
	 * Returns whether the given compound name starts with the given prefix.
1925
	 * Returns whether the given compound name starts with the given prefix.
2005
	 * Returns true if the n first elements of the prefix are equals and the last element of the 
1926
	 * Returns true if the n first elements of the prefix are equals and the last element of the 

Return to bug 139555