use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class MoveCuUpdateCreator method getReferences.
private static SearchResultGroup[] getReferences(ICompilationUnit unit, IProgressMonitor pm, RefactoringStatus status) throws CoreException {
final SearchPattern pattern = RefactoringSearchEngine.createOrPattern(unit.getTypes(), IJavaSearchConstants.REFERENCES);
if (pattern != null) {
String binaryRefsDescription = Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description, BasicElementLabels.getFileName(unit));
ReferencesInBinaryContext binaryRefs = new ReferencesInBinaryContext(binaryRefsDescription);
Collector requestor = new Collector(((IPackageFragment) unit.getParent()), binaryRefs);
IJavaSearchScope scope = RefactoringScopeFactory.create(unit, true, false);
SearchResultGroup[] result = RefactoringSearchEngine.search(pattern, scope, requestor, new SubProgressMonitor(pm, 1), status);
binaryRefs.addErrorIfNecessary(status);
return result;
}
return new SearchResultGroup[] {};
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project che by eclipse.
the class RenameTypeProcessor method checkConflictingTypes.
private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
IJavaSearchScope scope = RefactoringScopeFactory.create(fType);
SearchPattern pattern = SearchPattern.createPattern(getNewElementName(), IJavaSearchConstants.TYPE, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
ICompilationUnit[] cusWithReferencesToConflictingTypes = RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
if (cusWithReferencesToConflictingTypes.length == 0)
return result;
ICompilationUnit[] cusWithReferencesToRenamedType = getCus(fReferences);
Set<ICompilationUnit> conflicts = getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
if (cusWithReferencesToConflictingTypes.length > 0) {
cus: for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
String packageName = fType.getPackageFragment().getElementName();
if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
boolean hasOnDemandImport = false;
IImportDeclaration[] imports = cu.getImports();
for (IImportDeclaration importDecl : imports) {
if (importDecl.isOnDemand()) {
hasOnDemandImport = true;
} else {
String importName = importDecl.getElementName();
int packageLength = importName.length() - getNewElementName().length() - 1;
if (packageLength > 0 && importName.endsWith(getNewElementName()) && importName.charAt(packageLength) == '.') {
// explicit import from another package => no problem
continue cus;
}
}
}
if (hasOnDemandImport) {
// the renamed type in the same package will shadow the *-imported type
conflicts.add(cu);
}
}
}
}
for (ICompilationUnit conflict : conflicts) {
RefactoringStatusContext context = JavaStatusContext.create(conflict);
String message = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_another_type, new String[] { getNewElementLabel(), BasicElementLabels.getFileName(conflict) });
result.addError(message, context);
}
return result;
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.
the class PkgPatternsProposalProvider method doGenerateProposals.
@Override
protected Collection<? extends IContentProposal> doGenerateProposals(String contents, int position) {
String prefix = contents.substring(0, position);
final int replaceFromPos;
if (prefix.startsWith("!")) {
//$NON-NLS-1$
prefix = prefix.substring(1);
replaceFromPos = 1;
} else {
replaceFromPos = 0;
}
Comparator<PkgPatternProposal> comparator = new Comparator<PkgPatternProposal>() {
public int compare(PkgPatternProposal o1, PkgPatternProposal o2) {
int result = o1.getPackageFragment().getElementName().compareTo(o2.getPackageFragment().getElementName());
if (result == 0) {
result = Boolean.valueOf(o1.isWildcard()).compareTo(Boolean.valueOf(o2.isWildcard()));
}
return result;
}
};
final TreeSet<PkgPatternProposal> result = new TreeSet<PkgPatternProposal>(comparator);
final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() });
final SearchPattern pattern = SearchPattern.createPattern("*" + prefix + "*", IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
final SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IPackageFragment pkg = (IPackageFragment) match.getElement();
// "java." since these cannot be imported
if (pkg.isDefaultPackage() || pkg.getElementName().startsWith("java."))
return;
result.add(new PkgPatternProposal(pkg, false, replaceFromPos));
result.add(new PkgPatternProposal(pkg, true, replaceFromPos));
}
};
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
IRunnableContext runContext = searchContext.getRunContext();
if (runContext != null) {
runContext.run(false, false, runnable);
} else {
runnable.run(new NullProgressMonitor());
}
return result;
} catch (InvocationTargetException e) {
logger.logError("Error searching for packages.", e);
return Collections.emptyList();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return Collections.emptyList();
}
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.
the class PrivatePackagesPart method doAddPackages.
private void doAddPackages() {
// Prepare the exclusion list based on existing private packages
final Set<String> packageNameSet = new HashSet<String>(packages);
// Create a filter from the exclusion list and packages matching
// "java.*", which must not be included in a bundle
IPackageFilter filter = new IPackageFilter() {
@Override
public boolean select(String packageName) {
return !packageName.equals("java") && !packageName.startsWith("java.") && !packageNameSet.contains(packageName);
}
};
IFormPage page = (IFormPage) getManagedForm().getContainer();
IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
// Prepare the package lister from the Java project
IJavaProject javaProject = getJavaProject();
if (javaProject == null) {
MessageDialog.openError(getSection().getShell(), "Error", "Cannot add packages: unable to find a Java project associated with the editor input.");
return;
}
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
JavaSearchScopePackageLister packageLister = new JavaSearchScopePackageLister(searchScope, window);
// Create and open the dialog
PackageSelectionDialog dialog = new PackageSelectionDialog(getSection().getShell(), packageLister, filter, "Select new packages to include in the bundle.");
dialog.setSourceOnly(true);
dialog.setMultipleSelection(true);
if (dialog.open() == Window.OK) {
Object[] results = dialog.getResult();
List<String> added = new LinkedList<String>();
// Select the results
for (Object result : results) {
String newPackageName = (String) result;
if (packages.add(newPackageName)) {
added.add(newPackageName);
}
}
// Update the model and view
if (!added.isEmpty()) {
viewer.add(added.toArray());
markDirty();
}
}
}
use of org.eclipse.jdt.core.search.IJavaSearchScope in project bndtools by bndtools.
the class TestSuiteLabelProvider method doAdd.
void doAdd() {
// Prepare the exclusion list based on existing test cases
final Set<String> testSuitesSet = new HashSet<String>(testSuites);
// Create a filter from the exclusion list
ITestCaseFilter filter = new ITestCaseFilter() {
@Override
public boolean select(String testCaseName) {
return !testSuitesSet.contains(testCaseName);
}
};
IFormPage page = (IFormPage) getManagedForm().getContainer();
IWorkbenchWindow window = page.getEditorSite().getWorkbenchWindow();
// Prepare the package lister from the Java project
IJavaProject javaProject = getJavaProject();
if (javaProject == null) {
MessageDialog.openError(getSection().getShell(), "Error", "Cannot add test cases: unable to find a Java project associated with the editor input.");
return;
}
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
JavaSearchScopeTestCaseLister testCaseLister = new JavaSearchScopeTestCaseLister(searchScope, window);
// Create and open the dialog
TestCaseSelectionDialog dialog = new TestCaseSelectionDialog(getSection().getShell(), testCaseLister, filter, Messages.TestSuitesPart_title);
dialog.setSourceOnly(true);
dialog.setMultipleSelection(true);
if (dialog.open() == Window.OK) {
Object[] results = dialog.getResult();
List<String> added = new LinkedList<String>();
// Select the results
for (Object result : results) {
String newTestSuites = (String) result;
if (testSuites.add(newTestSuites)) {
added.add(newTestSuites);
}
}
// Update the model and view
if (!added.isEmpty()) {
viewer.add(added.toArray());
markDirty();
}
}
}
Aggregations