use of org.eclipse.jdt.core.search.SearchParticipant in project che by eclipse.
the class RippleMethodFinder2 method findAllDeclarations.
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
fDeclarations = new ArrayList<IMethod>();
class MethodRequestor extends SearchRequestor {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
IMethod method = (IMethod) match.getElement();
boolean isBinary = method.isBinary();
if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) {
fDeclarations.add(method);
}
if (isBinary && fBinaryRefs != null) {
fDeclarationToMatch.put(method, match);
}
}
}
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants();
IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
MethodRequestor requestor = new MethodRequestor();
SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();
searchEngine.search(pattern, participants, scope, requestor, monitor);
}
use of org.eclipse.jdt.core.search.SearchParticipant in project che by eclipse.
the class IndexManager method addBinary.
/**
* Trigger addition of a resource to an index
* Note: the actual operation is performed in background
*/
public void addBinary(IFile resource, IPath containerPath) {
// if (JavaCore.getPlugin() == null) return;
SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
SearchDocument document = participant.getDocument(resource.getFullPath().toString());
IndexLocation indexLocation = computeIndexLocation(containerPath);
scheduleDocumentIndexing(document, containerPath, indexLocation, participant);
}
use of org.eclipse.jdt.core.search.SearchParticipant in project liferay-ide by liferay.
the class PortletURLHyperlinkDetector method _findPortletMethods.
private IMethod[] _findPortletMethods(IDocument document, String nameValue) {
IMethod[] retval = null;
IFile file = DOMUtils.getFile(document);
if ((file != null) && file.exists()) {
IJavaProject project = JavaCore.create(file.getProject());
if ((project != null) && project.exists()) {
try {
IType portlet = project.findType("javax.portlet.Portlet");
if (portlet != null) {
List<IMethod> methods = new ArrayList<>();
SearchRequestor requestor = new ActionMethodCollector(methods);
IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, portlet, true, false, null);
SearchPattern search = SearchPattern.createPattern(nameValue, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
SearchParticipant[] searchParticipant = { SearchEngine.getDefaultSearchParticipant() };
new SearchEngine().search(search, searchParticipant, scope, requestor, new NullProgressMonitor());
retval = methods.toArray(new IMethod[0]);
}
} catch (JavaModelException jme) {
} catch (CoreException ce) {
}
}
}
return retval;
}
use of org.eclipse.jdt.core.search.SearchParticipant in project xtext-eclipse by eclipse.
the class JdtTypeProvider method findSecondaryType.
/**
* Searches a secondary type with the given name and package.
*
* Secondary types are toplevel types with a name that does not match the name of the compilation unit.
* @since 2.9
*/
protected IType findSecondaryType(String packageName, final String typeName) throws JavaModelException {
IPackageFragmentRoot[] sourceFolders = getSourceFolders();
IndexManager indexManager = JavaModelManager.getIndexManager();
if (indexManager.awaitingJobsCount() > 0) {
// still indexing - don't enter a busy wait loop but ask the source folders directly
return findSecondaryTypeInSourceFolders(packageName, typeName, sourceFolders);
}
// code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes
// index is ready, query it for a secondary type
final TypeDeclarationPattern pattern = new TypeDeclarationPattern(packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray(), // top level type - no enclosing type names
CharOperation.NO_CHAR_CHAR, typeName.toCharArray(), IIndexConstants.SECONDARY_SUFFIX, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
// Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor
final HashSet<String> workingCopyPaths = new HashSet<String>();
String workingCopyPath = null;
ICompilationUnit[] copies = getWorkingCopies();
final int copiesLength = copies == null ? 0 : copies.length;
if (copies != null) {
if (copiesLength == 1) {
ICompilationUnit singleWC = copies[0];
if (singleWC.getPackageDeclaration(packageName).exists()) {
IType result = singleWC.getType(typeName);
if (result.exists()) {
return result;
}
}
workingCopyPath = copies[0].getPath().toString();
} else {
for (int i = 0; i < copiesLength; i++) {
ICompilationUnit workingCopy = copies[i];
if (workingCopy.getPackageDeclaration(packageName).exists()) {
IType result = workingCopy.getType(typeName);
if (result.exists()) {
return result;
}
}
workingCopyPaths.add(workingCopy.getPath().toString());
}
}
}
final String singleWkcpPath = workingCopyPath;
final Wrapper<IType> result = Wrapper.forType(IType.class);
IndexQueryRequestor searchRequestor = new IndexQueryRequestor() {
@Override
public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
// Filter unexpected types
switch(copiesLength) {
case 0:
break;
case 1:
if (singleWkcpPath == null) {
throw new IllegalStateException();
}
if (singleWkcpPath.equals(documentPath)) {
// filter out *the* working copy
return true;
}
break;
default:
if (workingCopyPaths.contains(documentPath)) {
// filter out working copies
return true;
}
break;
}
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath));
ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
IType type = unit.getType(typeName);
result.set(type);
return false;
}
};
try {
indexManager.performConcurrentJob(new PatternSearchJob(pattern, // Java search only
BasicSearchEngine.getDefaultSearchParticipant(), BasicSearchEngine.createJavaSearchScope(sourceFolders), searchRequestor), IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
} catch (OperationCanceledException oce) {
// do nothing
}
return result.get();
}
use of org.eclipse.jdt.core.search.SearchParticipant in project xtext-eclipse by eclipse.
the class ProjectAwareUniqueClassNameValidator method doCheckUniqueInProject.
public boolean doCheckUniqueInProject(QualifiedName name, JvmDeclaredType type) throws JavaModelException {
IJavaProject javaProject = javaProjectProvider.getJavaProject(type.eResource().getResourceSet());
getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS, outputConfigurationProvider.getOutputConfigurations(type.eResource()));
String packageName = type.getPackageName();
String typeName = type.getSimpleName();
IndexManager indexManager = JavaModelManager.getIndexManager();
List<IPackageFragmentRoot> sourceFolders = new ArrayList<>();
for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
sourceFolders.add(root);
}
}
if (sourceFolders.isEmpty() || indexManager.awaitingJobsCount() > 0) {
// still indexing - don't enter a busy wait loop but ask the source folders directly
SourceTraversal sourceTraversal = doCheckUniqueInProjectSource(packageName != null ? packageName : "", typeName, type, sourceFolders);
if (sourceTraversal == SourceTraversal.DUPLICATE) {
return false;
} else if (sourceTraversal == SourceTraversal.UNIQUE) {
return true;
}
}
Set<String> workingCopyPaths = new HashSet<>();
ICompilationUnit[] copies = getWorkingCopies(type);
if (copies != null) {
for (ICompilationUnit workingCopy : copies) {
IPath path = workingCopy.getPath();
if (javaProject.getPath().isPrefixOf(path) && !isDerived(workingCopy.getResource())) {
if (workingCopy.getPackageDeclaration(packageName).exists()) {
IType result = workingCopy.getType(typeName);
if (result.exists()) {
addIssue(type, workingCopy.getElementName());
return false;
}
}
workingCopyPaths.add(workingCopy.getPath().toString());
}
}
}
// The code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes
// The Index is ready, query it for a secondary type
char[] pkg = packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray();
TypeDeclarationPattern pattern = new //
TypeDeclarationPattern(//
pkg, // top level type - no enclosing type names
CharOperation.NO_CHAR_CHAR, //
typeName.toCharArray(), //
IIndexConstants.TYPE_SUFFIX, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
IndexQueryRequestor searchRequestor = new IndexQueryRequestor() {
@Override
public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
if (workingCopyPaths.contains(documentPath)) {
// filter out working copies
return true;
}
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath));
if (!isDerived(file) && file.exists()) {
addIssue(type, file.getName());
return false;
}
return true;
}
};
try {
// Java search only
SearchParticipant searchParticipant = BasicSearchEngine.getDefaultSearchParticipant();
IJavaSearchScope javaSearchScope = BasicSearchEngine.createJavaSearchScope(sourceFolders.toArray(new IJavaElement[0]));
PatternSearchJob patternSearchJob = new PatternSearchJob(pattern, searchParticipant, javaSearchScope, searchRequestor);
indexManager.performConcurrentJob(patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
return true;
} catch (Throwable OperationCanceledException) {
return false;
}
}
Aggregations