Search in sources :

Example 16 with NullableFunction

use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.

the class XsltIncludeIndex method _process.

private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file -> psiManager.findFile(file));
    for (final PsiFile psiFile : psiFiles) {
        if (XsltSupport.isXsltFile(psiFile)) {
            if (!processor.process((XmlFile) psiFile)) {
                return false;
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileIncludeManager(com.intellij.psi.impl.include.FileIncludeManager) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XsltSupport(org.intellij.lang.xpath.xslt.XsltSupport) NullableFunction(com.intellij.util.NullableFunction) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiManager(com.intellij.psi.PsiManager) Nullable(org.jetbrains.annotations.Nullable) Comparing(com.intellij.openapi.util.Comparing) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 17 with NullableFunction

use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.

the class GotoPropertyDeclarationsProvider method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
    final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
    if (!(editor instanceof ResourceBundleEditor)) {
        return Collections.emptyList();
    }
    final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) editor;
    final Collection<ResourceBundleEditorViewElement> elements = resourceBundleEditor.getSelectedElements();
    if (elements.size() != 1) {
        return Collections.emptyList();
    }
    final IProperty[] properties = ContainerUtil.getFirstItem(elements).getProperties();
    if (properties == null || properties.length != 1 || !(properties[0] instanceof Property)) {
        return Collections.emptyList();
    }
    final IProperty property = properties[0];
    final String propertyKey = property.getKey();
    final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(property.getPsiElement().getContainingFile());
    assert file != null;
    final ResourceBundle resourceBundle = file.getResourceBundle();
    return ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(), (NullableFunction<PropertiesFile, GotoRelatedItem>) f -> {
        final IProperty foundProperty = f.findPropertyByKey(propertyKey);
        return foundProperty == null ? null : new GotoRelatedItem(foundProperty.getPsiElement(), "Property Declarations");
    });
}
Also used : Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) DataContext(com.intellij.openapi.actionSystem.DataContext) Collection(java.util.Collection) NullableFunction(com.intellij.util.NullableFunction) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileEditor(com.intellij.openapi.fileEditor.FileEditor) GotoRelatedProvider(com.intellij.navigation.GotoRelatedProvider) List(java.util.List) IProperty(com.intellij.lang.properties.IProperty) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) ResourceBundle(com.intellij.lang.properties.ResourceBundle) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileEditor(com.intellij.openapi.fileEditor.FileEditor) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with NullableFunction

use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.

the class TemplateListPanel method createTable.

private JPanel createTable() {
    myTreeRoot = new CheckedTreeNode(null);
    myTree = new LiveTemplateTree(new CheckboxTree.CheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(final JTree tree, Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
            if (!(value instanceof DefaultMutableTreeNode))
                return;
            value = ((DefaultMutableTreeNode) value).getUserObject();
            if (value instanceof TemplateImpl) {
                TemplateImpl template = (TemplateImpl) value;
                TemplateImpl defaultTemplate = TemplateSettings.getInstance().getDefaultTemplate(template);
                Color fgColor = defaultTemplate != null && templatesDiffer(template, defaultTemplate) ? JBColor.BLUE : null;
                getTextRenderer().append(template.getKey(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, fgColor));
                String description = template.getDescription();
                if (StringUtil.isNotEmpty(description)) {
                    getTextRenderer().append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
                }
            } else if (value instanceof TemplateGroup) {
                getTextRenderer().append(((TemplateGroup) value).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
            }
        }
    }, myTreeRoot, this);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(@NotNull final TreeSelectionEvent e) {
            TemplateSettings templateSettings = TemplateSettings.getInstance();
            TemplateImpl template = getTemplate(getSingleSelectedIndex());
            if (template != null) {
                templateSettings.setLastSelectedTemplate(template.getGroupName(), template.getKey());
            } else {
                templateSettings.setLastSelectedTemplate(null, null);
                showEmptyCard();
            }
            if (myUpdateNeeded) {
                myAlarm.cancelAllRequests();
                myAlarm.addRequest(() -> updateTemplateDetails(false, false), 100);
            }
        }
    });
    myTree.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(@Nullable ActionEvent event) {
            myCurrentTemplateEditor.focusKey();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
    installPopup();
    DnDSupport.createBuilder(myTree).setBeanProvider((NullableFunction<DnDActionInfo, DnDDragStartBean>) dnDActionInfo -> {
        Point point = dnDActionInfo.getPoint();
        if (myTree.getPathForLocation(point.x, point.y) == null)
            return null;
        Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
        return !templates.isEmpty() ? new DnDDragStartBean(templates) : null;
    }).setDisposableParent(this).setTargetChecker(new DnDTargetChecker() {

        @Override
        public boolean update(DnDEvent event) {
            @SuppressWarnings("unchecked") Set<String> oldGroupNames = getAllGroups((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject());
            TemplateGroup group = getDropGroup(event);
            boolean differentGroup = group != null && !oldGroupNames.contains(group.getName());
            event.setDropPossible(differentGroup, "");
            return true;
        }
    }).setDropHandler(new DnDDropHandler() {

        @Override
        public void drop(DnDEvent event) {
            //noinspection unchecked
            moveTemplates((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject(), ObjectUtils.assertNotNull(getDropGroup(event)).getName());
        }
    }).setImageProvider((NullableFunction<DnDActionInfo, DnDImage>) dnDActionInfo -> {
        Point point = dnDActionInfo.getPoint();
        TreePath path = myTree.getPathForLocation(point.x, point.y);
        return path == null ? null : new DnDImage(DnDAwareTree.getDragImage(myTree, path, point).first);
    }).install();
    if (myTemplateGroups.size() > 0) {
        myTree.setSelectionInterval(0, 0);
    }
    return initToolbar().createPanel();
}
Also used : ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) NullableFunction(com.intellij.util.NullableFunction) ActionListener(java.awt.event.ActionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 19 with NullableFunction

use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.

the class RelaxIncludeIndex method processRelatedFiles.

private static boolean processRelatedFiles(PsiFile file, VirtualFile[] files, PsiElementProcessor<XmlFile> processor) {
    Project project = file.getProject();
    final PsiManager psiManager = PsiManager.getInstance(project);
    final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file1 -> psiManager.findFile(file1));
    for (final PsiFile psiFile : psiFiles) {
        if (!processFile(psiFile, processor)) {
            return false;
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileIncludeManager(com.intellij.psi.impl.include.FileIncludeManager) RncFileType(org.intellij.plugins.relaxNG.compact.RncFileType) XmlFileType(com.intellij.ide.highlighter.XmlFileType) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullableFunction(com.intellij.util.NullableFunction) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) FileType(com.intellij.openapi.fileTypes.FileType) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiManager(com.intellij.psi.PsiManager) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DomManager(com.intellij.util.xml.DomManager) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Aggregations

NullableFunction (com.intellij.util.NullableFunction)19 NotNull (org.jetbrains.annotations.NotNull)17 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Nullable (org.jetbrains.annotations.Nullable)13 List (java.util.List)12 Project (com.intellij.openapi.project.Project)11 StringUtil (com.intellij.openapi.util.text.StringUtil)7 Logger (com.intellij.openapi.diagnostic.Logger)6 java.util (java.util)6 Collections (java.util.Collections)6 Comparing (com.intellij.openapi.util.Comparing)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 com.intellij.psi (com.intellij.psi)5 java.awt (java.awt)5 javax.swing (javax.swing)5 ArrayList (java.util.ArrayList)4 Extensions (com.intellij.openapi.extensions.Extensions)3 Ref (com.intellij.openapi.util.Ref)3 PsiFile (com.intellij.psi.PsiFile)3 ActionEvent (java.awt.event.ActionEvent)3