List of usage examples for org.eclipse.jdt.internal.core.util Util sort
public static void sort(String[] strings)
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private boolean hasJavaLikeNamesChanged() { char[][] currentNames = com.codenvy.ide.ext.java.server.internal.core.search.Util.getJavaLikeExtensions(); int current = currentNames.length; char[][] prevNames = readJavaLikeNamesFile(); if (prevNames == null) { if (VERBOSE && current != 1) Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$ System.err);//w ww . j av a 2s . c o m return (current != 1); //Ignore if only java } int prev = prevNames.length; if (current != prev) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } if (current > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current); Util.sort(currentNames); } // The JavaLikeNames would have been sorted before getting stored in the file, // hence just do a direct compare. for (int i = 0; i < current; i++) { if (!CharOperation.equals(currentNames[i], prevNames[i])) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeJavaLikeNamesFile() { BufferedWriter writer = null; String pathName = getJavaPluginWorkingLocation().toOSString(); try {/*from ww w .jav a 2s . c om*/ char[][] currentNames = com.codenvy.ide.ext.java.server.internal.core.search.Util .getJavaLikeExtensions(); int length = currentNames.length; if (length > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[length][], 0, length); Util.sort(currentNames); } File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); //$NON-NLS-1$ writer = new BufferedWriter(new FileWriter(javaLikeNamesFile)); for (int i = 0; i < length - 1; i++) { writer.write(currentNames[i]); writer.write('\n'); } if (length > 0) writer.write(currentNames[length - 1]); } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write javaLikeNames file", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
public String toString() { StringBuffer result = new StringBuffer("JavaSearchScope on "); //$NON-NLS-1$ if (this.elements != null) { result.append("["); //$NON-NLS-1$ for (int i = 0, length = this.elements.size(); i < length; i++) { JavaElement element = (JavaElement) this.elements.get(i); result.append("\n\t"); //$NON-NLS-1$ result.append(element.toStringWithAncestors()); }/*w ww.j a v a 2s . c om*/ result.append("\n]"); //$NON-NLS-1$ } else { if (this.pathsCount == 0) { result.append("[empty scope]"); //$NON-NLS-1$ } else { result.append("["); //$NON-NLS-1$ String[] paths = new String[this.relativePaths.length]; int index = 0; for (int i = 0; i < this.relativePaths.length; i++) { String path = this.relativePaths[i]; if (path == null) continue; String containerPath; if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) { Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i])); containerPath = ((IFolder) target).getLocation().toOSString(); } else { containerPath = this.containerPaths[i]; } if (path.length() > 0) { paths[index++] = containerPath + '/' + path; } else { paths[index++] = containerPath; } } System.arraycopy(paths, 0, paths = new String[index], 0, index); Util.sort(paths); for (int i = 0; i < index; i++) { result.append("\n\t"); //$NON-NLS-1$ result.append(paths[i]); } result.append("\n]"); //$NON-NLS-1$ } } return result.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.SuperTypeNamesCollector.java
License:Open Source License
public char[][][] collect() throws JavaModelException { if (this.type != null) { // Collect the paths of the cus that are in the hierarchy of the given type this.result = new char[1][][]; this.resultIndex = 0; JavaProject javaProject = (JavaProject) this.type.getJavaProject(); this.locator.initialize(javaProject, 0); try {/* w ww .j av a2s . c o m*/ if (this.type.isBinary()) { BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null); if (binding != null) collectSuperTypeNames(binding, null); } else { ICompilationUnit unit = this.type.getCompilationUnit(); SourceType sourceType = (SourceType) this.type; boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null; CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember); if (parsedUnit != null) { TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type); if (typeDecl != null && typeDecl.binding != null) collectSuperTypeNames(typeDecl.binding, null); } } } catch (AbortCompilation e) { // problem with classpath: report inaccurate matches return null; } if (this.result.length > this.resultIndex) System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex); return this.result; } // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName String[] paths = getPathsOfDeclaringType(); if (paths == null) return null; // Create bindings from source types and binary types and collect super type names of the type declaration // that match the given declaring type Util.sort(paths); // sort by projects JavaProject previousProject = null; this.result = new char[1][][]; this.samePackageSuperTypeName = new char[1][][]; this.resultIndex = 0; for (int i = 0, length = paths.length; i < length; i++) { try { //todo Openable Openable openable = null;//this.locator.handleFactory.createOpenable(paths[i], this.locator.scope); if (openable == null) continue; // outside classpath IJavaProject project = openable.getJavaProject(); if (!project.equals(previousProject)) { previousProject = (JavaProject) project; this.locator.initialize(previousProject, 0); } if (openable instanceof ICompilationUnit) { ICompilationUnit unit = (ICompilationUnit) openable; CompilationUnitDeclaration parsedUnit = buildBindings(unit, true /*only top level and member types are visible to the focus type*/); if (parsedUnit != null) parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope); } else if (openable instanceof IClassFile) { IClassFile classFile = (IClassFile) openable; BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null); if (matches(binding)) collectSuperTypeNames(binding, binding.compoundName); } } catch (AbortCompilation e) { // ignore: continue with next element } catch (JavaModelException e) { // ignore: continue with next element } } if (this.result.length > this.resultIndex) System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex); return this.result; }
From source file:org.eclipse.che.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
private boolean hasJavaLikeNamesChanged() { char[][] currentNames = org.eclipse.che.jdt.internal.core.search.Util.getJavaLikeExtensions(); int current = currentNames.length; char[][] prevNames = readJavaLikeNamesFile(); if (prevNames == null) { if (VERBOSE && current != 1) Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$ System.err);//w w w . j a va 2 s . c o m return (current != 1); //Ignore if only java } int prev = prevNames.length; if (current != prev) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } if (current > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current); Util.sort(currentNames); } // The JavaLikeNames would have been sorted before getting stored in the file, // hence just do a direct compare. for (int i = 0; i < current; i++) { if (!CharOperation.equals(currentNames[i], prevNames[i])) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } } return false; }
From source file:org.eclipse.che.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeJavaLikeNamesFile() { BufferedWriter writer = null; String pathName = getJavaPluginWorkingLocation().toOSString(); try {//from w ww . ja va 2s . c o m char[][] currentNames = org.eclipse.che.jdt.internal.core.search.Util.getJavaLikeExtensions(); int length = currentNames.length; if (length > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[length][], 0, length); Util.sort(currentNames); } File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); //$NON-NLS-1$ writer = new BufferedWriter(new FileWriter(javaLikeNamesFile)); for (int i = 0; i < length - 1; i++) { writer.write(currentNames[i]); writer.write('\n'); } if (length > 0) writer.write(currentNames[length - 1]); } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write javaLikeNames file", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:org.eclipse.che.jdt.internal.core.search.matching.SuperTypeNamesCollector.java
License:Open Source License
public char[][][] collect() throws JavaModelException { if (this.type != null) { // Collect the paths of the cus that are in the hierarchy of the given type this.result = new char[1][][]; this.resultIndex = 0; JavaProject javaProject = (JavaProject) this.type.getJavaProject(); this.locator.initialize(javaProject, 0); try {/*ww w .j a v a 2 s. c o m*/ if (this.type.isBinary()) { BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null); if (binding != null) collectSuperTypeNames(binding, null); } else { ICompilationUnit unit = this.type.getCompilationUnit(); SourceType sourceType = (SourceType) this.type; boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null; CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember); if (parsedUnit != null) { TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type); if (typeDecl != null && typeDecl.binding != null) collectSuperTypeNames(typeDecl.binding, null); } } } catch (AbortCompilation e) { // problem with classpath: report inaccurate matches return null; } if (this.result.length > this.resultIndex) System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex); return this.result; } // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName String[] paths = getPathsOfDeclaringType(); if (paths == null) return null; // Create bindings from source types and binary types and collect super type names of the type declaration // that match the given declaring type Util.sort(paths); // sort by projects JavaProject previousProject = null; this.result = new char[1][][]; this.samePackageSuperTypeName = new char[1][][]; this.resultIndex = 0; for (int i = 0, length = paths.length; i < length; i++) { try { Openable openable = this.locator.handleFactory.createOpenable(paths[i], this.locator.scope); if (openable == null) continue; // outside classpath IJavaProject project = openable.getJavaProject(); if (!project.equals(previousProject)) { previousProject = (JavaProject) project; this.locator.initialize(previousProject, 0); } if (openable instanceof ICompilationUnit) { ICompilationUnit unit = (ICompilationUnit) openable; CompilationUnitDeclaration parsedUnit = buildBindings(unit, true /*only top level and member types are visible to the focus type*/); if (parsedUnit != null) parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope); } else if (openable instanceof IClassFile) { IClassFile classFile = (IClassFile) openable; BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null); if (matches(binding)) collectSuperTypeNames(binding, binding.compoundName); } } catch (AbortCompilation e) { // ignore: continue with next element } catch (JavaModelException e) { // ignore: continue with next element } } if (this.result.length > this.resultIndex) System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex); return this.result; }
From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
private boolean hasJavaLikeNamesChanged() { char[][] currentNames = Util.getJavaLikeExtensions(); int current = currentNames.length; char[][] prevNames = readJavaLikeNamesFile(); if (prevNames == null) { if (VERBOSE && current != 1) Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$ System.err);/*from ww w. j a v a 2 s . c om*/ return (current != 1); //Ignore if only java } int prev = prevNames.length; if (current != prev) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } if (current > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current); Util.sort(currentNames); } // The JavaLikeNames would have been sorted before getting stored in the file, // hence just do a direct compare. for (int i = 0; i < current; i++) { if (!CharOperation.equals(currentNames[i], prevNames[i])) { if (VERBOSE) Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$ return true; } } return false; }
From source file:org.eclipse.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void writeJavaLikeNamesFile() { BufferedWriter writer = null; String pathName = getJavaPluginWorkingLocation().toOSString(); try {/*from ww w . j a v a2 s. c o m*/ char[][] currentNames = Util.getJavaLikeExtensions(); int length = currentNames.length; if (length > 1) { // Sort the current java like names. // Copy the array to avoid modifying the Util static variable System.arraycopy(currentNames, 0, currentNames = new char[length][], 0, length); Util.sort(currentNames); } File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); //$NON-NLS-1$ writer = new BufferedWriter(new FileWriter(javaLikeNamesFile)); for (int i = 0; i < length - 1; i++) { writer.write(currentNames[i]); writer.write('\n'); } if (length > 0) writer.write(currentNames[length - 1]); } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to write javaLikeNames file", System.err); //$NON-NLS-1$ } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // ignore } } } }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
protected void assertSortedStringsEqual(String message, String expected, String[] strings) { Util.sort(strings); assertStringsEqual(message, expected, strings); }