use of com.intellij.util.indexing.FileBasedIndex 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.util.indexing.FileBasedIndex in project intellij-community by JetBrains.
the class AntHectorConfigurable method createComponent.
public JComponent createComponent() {
final JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(IdeBorderFactory.createTitledBorder("File Context", false));
myCombo = new ComboBox();
myCombo.putClientProperty(CONTEXTS_COMBO_KEY, Boolean.TRUE);
panel.add(new JLabel("Included into:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(5, 0), 0, 0));
panel.add(myCombo, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(5, 5, 5, 0), 0, 0));
final PsiManager psiManager = PsiManager.getInstance(myProject);
final FileBasedIndex fbi = FileBasedIndex.getInstance();
final Collection<VirtualFile> antFiles = fbi.getContainingFiles(AntImportsIndex.INDEX_NAME, AntImportsIndex.ANT_FILES_WITH_IMPORTS_KEY, myFileFilter);
for (VirtualFile file : antFiles) {
final PsiFile psiFile = psiManager.findFile(file);
if (!(psiFile instanceof XmlFile)) {
continue;
}
final XmlFile xmlFile = (XmlFile) psiFile;
if (!xmlFile.equals(myFile) && AntDomFileDescription.isAntFile(xmlFile)) {
final String path = PathUtil.getLocalPath(file);
final XmlFile previous = myPathToFileMap.put(path, xmlFile);
assert previous == null;
}
}
final List<String> paths = new ArrayList<>(myPathToFileMap.keySet());
Collections.sort(paths, (o1, o2) -> o1.compareTo(o2));
myCombo.addItem(NONE);
for (String path : paths) {
myCombo.addItem(path);
}
final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(myProject);
final XmlFile currentContext = antConfig.getContextFile(myFile);
if (currentContext != null) {
final VirtualFile vFile = currentContext.getVirtualFile();
assert vFile != null;
final String path = PathUtil.getLocalPath(vFile);
if (!FileUtil.pathsEqual(path, myLocalPath)) {
myOriginalContext = path;
}
}
myCombo.setSelectedItem(myOriginalContext);
return panel;
}
use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.
the class AngularIndexUtil method multiResolveAngularNamedDefinitionIndex.
public static ResolveResult[] multiResolveAngularNamedDefinitionIndex(@NotNull final Project project, @NotNull final ID<String, AngularNamedItemDefinition> INDEX, @NotNull final String id, @NotNull final Condition<VirtualFile> filter, boolean dirtyResolve) {
final FileBasedIndex instance = FileBasedIndex.getInstance();
Collection<VirtualFile> files = instance.getContainingFiles(INDEX, id, GlobalSearchScope.allScope(project));
if (files.isEmpty())
return ResolveResult.EMPTY_ARRAY;
final List<VirtualFile> filtered = ContainerUtil.filter(files, filter);
if (filtered.isEmpty()) {
if (!dirtyResolve)
return ResolveResult.EMPTY_ARRAY;
} else {
files = filtered;
}
final List<JSImplicitElement> elements = new ArrayList<>();
for (VirtualFile file : files) {
final List<AngularNamedItemDefinition> values = instance.getValues(INDEX, id, GlobalSearchScope.fileScope(project, file));
for (AngularNamedItemDefinition value : values) {
JSQualifiedNameImpl qName = JSQualifiedNameImpl.fromQualifiedName(id);
JSImplicitElementImpl.Builder elementBuilder = new JSImplicitElementImpl.Builder(qName, null);
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
elements.add(new JSOffsetBasedImplicitElement(elementBuilder, (int) value.getStartOffset(), psiFile));
}
}
}
final List<ResolveResult> list = ContainerUtil.map(elements, JS_IMPLICIT_TO_RESOLVE_RESULT);
return list.toArray(new ResolveResult[list.size()]);
}
use of com.intellij.util.indexing.FileBasedIndex in project intellij-community by JetBrains.
the class FrameworkDetectionManager method doRunDetection.
private void doRunDetection() {
Set<Integer> detectorsToProcess;
synchronized (myLock) {
detectorsToProcess = new HashSet<>(myDetectorsToProcess);
detectorsToProcess.addAll(myDetectorsToProcess);
myDetectorsToProcess.clear();
}
if (detectorsToProcess.isEmpty())
return;
if (LOG.isDebugEnabled()) {
LOG.debug("Starting framework detectors: " + detectorsToProcess);
}
final FileBasedIndex index = FileBasedIndex.getInstance();
List<DetectedFrameworkDescription> newDescriptions = new ArrayList<>();
List<DetectedFrameworkDescription> oldDescriptions = new ArrayList<>();
final DetectionExcludesConfiguration excludesConfiguration = DetectionExcludesConfiguration.getInstance(myProject);
for (Integer id : detectorsToProcess) {
final List<? extends DetectedFrameworkDescription> frameworks = runDetector(id, index, excludesConfiguration, true);
oldDescriptions.addAll(frameworks);
final Collection<? extends DetectedFrameworkDescription> updated = myDetectedFrameworksData.updateFrameworksList(id, frameworks);
newDescriptions.addAll(updated);
oldDescriptions.removeAll(updated);
if (LOG.isDebugEnabled()) {
LOG.debug(frameworks.size() + " frameworks detected, " + updated.size() + " changed");
}
}
Set<String> frameworkNames = new HashSet<>();
for (final DetectedFrameworkDescription description : FrameworkDetectionUtil.removeDisabled(newDescriptions, oldDescriptions)) {
frameworkNames.add(description.getDetector().getFrameworkType().getPresentableName());
}
if (!frameworkNames.isEmpty()) {
String names = StringUtil.join(frameworkNames, ", ");
final String text = ProjectBundle.message("framework.detected.info.text", names, frameworkNames.size());
FRAMEWORK_DETECTION_NOTIFICATION.createNotification("Frameworks detected", text, NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
showSetupFrameworksDialog(notification);
}
}
}).notify(myProject);
}
}
use of com.intellij.util.indexing.FileBasedIndex in project intellij-plugins by JetBrains.
the class AngularJavaScriptCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (AngularJSCompletionContributor.getElementLanguage(parameters).isKindOf(JavascriptLanguage.INSTANCE)) {
PsiElement originalPosition = parameters.getOriginalPosition();
if (originalPosition == null)
return;
final Project project = originalPosition.getProject();
if (AngularJSReferencesContributor.UI_VIEW_PATTERN.accepts(originalPosition)) {
final FileBasedIndex instance = FileBasedIndex.getInstance();
final Collection<String> keys = instance.getAllKeys(AngularUiRouterViewsIndex.UI_ROUTER_VIEWS_CACHE_INDEX, project);
addCompletionVariants(result, keys, " (angular-ui-router ui-view)");
} else {
originalPosition = originalPosition instanceof LeafPsiElement && ((LeafPsiElement) originalPosition).getElementType() == JSTokenTypes.STRING_LITERAL ? originalPosition.getParent() : originalPosition;
if (AngularJSReferencesContributor.MODULE_PATTERN.accepts(originalPosition) || AngularJSReferencesContributor.MODULE_DEPENDENCY_PATTERN.accepts(originalPosition)) {
final Collection<String> keys = AngularIndexUtil.getAllKeys(AngularModuleIndex.KEY, project);
addCompletionVariants(result, keys, " (AngularJS module)");
}
}
}
}
Aggregations