use of com.intellij.psi.search.EverythingGlobalScope in project android-butterknife-zelezny by avast.
the class Utils method resolveLayoutResourceFile.
private static PsiFile resolveLayoutResourceFile(PsiElement element, Project project, String name) {
// restricting the search to the current module - searching the whole project could return wrong layouts
Module module = ModuleUtil.findModuleForPsiElement(element);
PsiFile[] files = null;
if (module != null) {
// first omit libraries, it might cause issues like (#103)
GlobalSearchScope moduleScope = module.getModuleWithDependenciesScope();
files = FilenameIndex.getFilesByName(project, name, moduleScope);
if (files == null || files.length <= 0) {
// now let's do a fallback including the libraries
moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false);
files = FilenameIndex.getFilesByName(project, name, moduleScope);
}
}
if (files == null || files.length <= 0) {
// fallback to search through the whole project
// useful when the project is not properly configured - when the resource directory is not configured
files = FilenameIndex.getFilesByName(project, name, new EverythingGlobalScope(project));
if (files.length <= 0) {
//no matching files
return null;
}
}
// we need to resolve R class properly and find the proper layout for the R class
for (PsiFile file : files) {
log.info("Resolved layout resource file for name [" + name + "]: " + file.getVirtualFile());
}
return files[0];
}
use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.
the class DefaultXmlTagNameProvider method getRootTagsVariants.
private static List<LookupElement> getRootTagsVariants(final XmlTag tag, final List<LookupElement> elements) {
elements.add(LookupElementBuilder.create("?xml version=\"1.0\" encoding=\"\" ?>").withPresentableText("<?xml version=\"1.0\" encoding=\"\" ?>").withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
int offset = context.getEditor().getCaretModel().getOffset();
context.getEditor().getCaretModel().moveToOffset(offset - 4);
AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
}
}));
final FileBasedIndex fbi = FileBasedIndex.getInstance();
Collection<String> result = new ArrayList<>();
Processor<String> processor = Processors.cancelableCollectProcessor(result);
fbi.processAllKeys(XmlNamespaceIndex.NAME, processor, tag.getProject());
final GlobalSearchScope scope = new EverythingGlobalScope();
for (final String ns : result) {
if (ns.startsWith("file://"))
continue;
fbi.processValues(XmlNamespaceIndex.NAME, ns, null, new FileBasedIndex.ValueProcessor<XsdNamespaceBuilder>() {
@Override
public boolean process(final VirtualFile file, XsdNamespaceBuilder value) {
List<String> tags = value.getRootTags();
for (String s : tags) {
elements.add(LookupElementBuilder.create(s).withTypeText(ns).withInsertHandler(new XmlTagInsertHandler() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = context.getDocument();
final int caretOffset = editor.getCaretModel().getOffset();
final RangeMarker caretMarker = document.createRangeMarker(caretOffset, caretOffset);
caretMarker.setGreedyToRight(true);
XmlFile psiFile = (XmlFile) context.getFile();
boolean incomplete = XmlUtil.getTokenOfType(tag, XmlTokenType.XML_TAG_END) == null && XmlUtil.getTokenOfType(tag, XmlTokenType.XML_EMPTY_ELEMENT_END) == null;
XmlNamespaceHelper.getHelper(psiFile).insertNamespaceDeclaration(psiFile, editor, Collections.singleton(ns), null, null);
editor.getCaretModel().moveToOffset(caretMarker.getEndOffset());
XmlTag rootTag = psiFile.getRootTag();
if (incomplete) {
XmlToken token = XmlUtil.getTokenOfType(rootTag, XmlTokenType.XML_EMPTY_ELEMENT_END);
// remove tag end added by smart attribute adder :(
if (token != null)
token.delete();
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(document);
super.handleInsert(context, item);
}
}
}));
}
return true;
}
}, scope);
}
return elements;
}
use of com.intellij.psi.search.EverythingGlobalScope in project kotlin by JetBrains.
the class SourceNavigationHelper method createLibraryOrSourcesScope.
@NotNull
private static GlobalSearchScope createLibraryOrSourcesScope(@NotNull KtNamedDeclaration declaration, @NotNull NavigationKind navigationKind) {
KtFile containingFile = declaration.getContainingKtFile();
VirtualFile libraryFile = containingFile.getVirtualFile();
if (libraryFile == null)
return GlobalSearchScope.EMPTY_SCOPE;
boolean includeLibrarySources = navigationKind == NavigationKind.CLASS_FILES_TO_SOURCES;
if (ProjectRootsUtil.isInContent(declaration, false, includeLibrarySources, !includeLibrarySources, true)) {
return GlobalSearchScope.EMPTY_SCOPE;
}
Project project = declaration.getProject();
return includeLibrarySources ? KotlinSourceFilterScope.librarySources(new EverythingGlobalScope(project), project) : KotlinSourceFilterScope.libraryClassFiles(new EverythingGlobalScope(project), project);
}
use of com.intellij.psi.search.EverythingGlobalScope in project intellij-community by JetBrains.
the class JavaDocInfoGenerator method elementHasSourceCode.
private boolean elementHasSourceCode() {
PsiFileSystemItem[] items;
if (myElement instanceof PsiDirectory) {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) myElement);
if (aPackage == null)
return false;
items = aPackage.getDirectories(new EverythingGlobalScope(myProject));
} else if (myElement instanceof PsiPackage) {
items = ((PsiPackage) myElement).getDirectories(new EverythingGlobalScope(myProject));
} else {
PsiFile containingFile = myElement.getNavigationElement().getContainingFile();
if (containingFile == null)
return false;
items = new PsiFileSystemItem[] { containingFile };
}
ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
for (PsiFileSystemItem item : items) {
VirtualFile file = item.getVirtualFile();
if (file != null && projectFileIndex.isInSource(file))
return true;
}
return false;
}
use of com.intellij.psi.search.EverythingGlobalScope in project android-butterknife-zelezny by avast.
the class InjectWriter method generateInjects.
protected void generateInjects(@NotNull IButterKnife butterKnife) {
PsiClass activityClass = JavaPsiFacade.getInstance(mProject).findClass("android.app.Activity", new EverythingGlobalScope(mProject));
PsiClass fragmentClass = JavaPsiFacade.getInstance(mProject).findClass("android.app.Fragment", new EverythingGlobalScope(mProject));
PsiClass supportFragmentClass = JavaPsiFacade.getInstance(mProject).findClass("android.support.v4.app.Fragment", new EverythingGlobalScope(mProject));
// Check for Activity class
if (activityClass != null && mClass.isInheritor(activityClass, true)) {
generateActivityBind(butterKnife);
// Check for Fragment class
} else if ((fragmentClass != null && mClass.isInheritor(fragmentClass, true)) || (supportFragmentClass != null && mClass.isInheritor(supportFragmentClass, true))) {
generateFragmentBindAndUnbind(butterKnife);
}
}
Aggregations