Search in sources :

Example 36 with Condition

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

the class CollectHighlightsUtil method getElementsToHighlight.

@NotNull
private static List<PsiElement> getElementsToHighlight(@NotNull PsiElement parent, final int startOffset, final int endOffset) {
    final List<PsiElement> result = new ArrayList<>();
    final int currentOffset = parent.getTextRange().getStartOffset();
    final Condition<PsiElement>[] filters = Extensions.getExtensions(EP_NAME);
    int offset = currentOffset;
    final TIntStack starts = new TIntStack(STARTING_TREE_HEIGHT);
    final Stack<PsiElement> elements = new Stack<>(STARTING_TREE_HEIGHT);
    final Stack<PsiElement> children = new Stack<>(STARTING_TREE_HEIGHT);
    PsiElement element = parent;
    PsiElement child = PsiUtilCore.NULL_PSI_ELEMENT;
    while (true) {
        ProgressIndicatorProvider.checkCanceled();
        for (Condition<PsiElement> filter : filters) {
            if (!filter.value(element)) {
                assert child == PsiUtilCore.NULL_PSI_ELEMENT;
                // do not want to process children
                child = null;
                break;
            }
        }
        boolean startChildrenVisiting;
        if (child == PsiUtilCore.NULL_PSI_ELEMENT) {
            startChildrenVisiting = true;
            child = element.getFirstChild();
        } else {
            startChildrenVisiting = false;
        }
        if (child == null) {
            if (startChildrenVisiting) {
                // leaf element
                offset += element.getTextLength();
            }
            if (elements.isEmpty())
                break;
            int start = starts.pop();
            if (startOffset <= start && offset <= endOffset) {
                assert element != null;
                assert element != PsiUtilCore.NULL_PSI_ELEMENT;
                result.add(element);
            }
            element = elements.pop();
            child = children.pop();
        } else {
            // composite element
            if (offset > endOffset)
                break;
            children.push(child.getNextSibling());
            starts.push(offset);
            assert element != null;
            assert element != PsiUtilCore.NULL_PSI_ELEMENT;
            elements.push(element);
            element = child;
            child = PsiUtilCore.NULL_PSI_ELEMENT;
        }
    }
    return result;
}
Also used : Condition(com.intellij.openapi.util.Condition) ArrayList(java.util.ArrayList) TIntStack(gnu.trove.TIntStack) PsiElement(com.intellij.psi.PsiElement) TIntStack(gnu.trove.TIntStack) Stack(com.intellij.util.containers.Stack) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with Condition

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

the class JdkComboBox method setSetupButton.

public void setSetupButton(final JButton setUpButton, @Nullable final Project project, final ProjectSdksModel jdksModel, final JdkComboBoxItem firstItem, @Nullable final Condition<Sdk> additionalSetup, final String actionGroupTitle) {
    mySetUpButton = setUpButton;
    mySetUpButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultActionGroup group = new DefaultActionGroup();
            jdksModel.createAddActions(group, JdkComboBox.this, getSelectedJdk(), jdk -> {
                if (project != null) {
                    final JdkListConfigurable configurable = JdkListConfigurable.getInstance(project);
                    configurable.addJdkNode(jdk, false);
                }
                reloadModel(new ActualJdkComboBoxItem(jdk), project);
                setSelectedJdk(jdk);
                if (additionalSetup != null) {
                    if (additionalSetup.value(jdk)) {
                        setSelectedJdk(firstItem.getJdk());
                    }
                }
            }, myCreationFilter);
            final DataContext dataContext = DataManager.getInstance().getDataContext(JdkComboBox.this);
            if (group.getChildrenCount() > 1) {
                JBPopupFactory.getInstance().createActionGroupPopup(actionGroupTitle, group, dataContext, JBPopupFactory.ActionSelectionAid.MNEMONICS, false).showUnderneathOf(setUpButton);
            } else {
                final AnActionEvent event = new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0);
                group.getChildren(event)[0].actionPerformed(event);
            }
        }
    });
}
Also used : Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBUI(com.intellij.util.ui.JBUI) ComboBoxWithWidePopup(com.intellij.openapi.ui.ComboBoxWithWidePopup) Project(com.intellij.openapi.project.Project) Conditions(com.intellij.openapi.util.Conditions) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) DataManager(com.intellij.ide.DataManager) JdkListConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable) ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) EmptyIcon(com.intellij.util.ui.EmptyIcon) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) ScreenUtil(com.intellij.ui.ScreenUtil) ActionEvent(java.awt.event.ActionEvent) Sdk(com.intellij.openapi.projectRoots.Sdk) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) OrderEntryAppearanceService(com.intellij.openapi.roots.ui.OrderEntryAppearanceService) SdkType(com.intellij.openapi.projectRoots.SdkType) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) ActionListener(java.awt.event.ActionListener) JdkListConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.JdkListConfigurable) ActionEvent(java.awt.event.ActionEvent)

Example 38 with Condition

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

the class ExtractSuperClassUtil method createExtendingReference.

public static PsiJavaCodeReferenceElement createExtendingReference(final PsiClass superClass, final PsiClass derivedClass, final MemberInfo[] selectedMembers) throws IncorrectOperationException {
    final PsiManager manager = derivedClass.getManager();
    Set<PsiElement> movedElements = new com.intellij.util.containers.HashSet<>();
    for (final MemberInfo info : selectedMembers) {
        movedElements.add(info.getMember());
    }
    final Condition<PsiTypeParameter> filter = parameter -> findTypeParameterInDerived(derivedClass, parameter.getName()) == parameter;
    final PsiTypeParameterList typeParameterList = RefactoringUtil.createTypeParameterListWithUsedTypeParameters(null, filter, PsiUtilCore.toPsiElementArray(movedElements));
    final PsiTypeParameterList originalTypeParameterList = superClass.getTypeParameterList();
    assert originalTypeParameterList != null;
    final PsiTypeParameterList newList = typeParameterList != null ? (PsiTypeParameterList) originalTypeParameterList.replace(typeParameterList) : originalTypeParameterList;
    final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
    Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<>();
    for (final PsiTypeParameter parameter : newList.getTypeParameters()) {
        final PsiTypeParameter parameterInDerived = findTypeParameterInDerived(derivedClass, parameter.getName());
        if (parameterInDerived != null) {
            substitutionMap.put(parameter, factory.createType(parameterInDerived));
        }
    }
    final PsiClassType type = factory.createType(superClass, factory.createSubstitutor(substitutionMap));
    return factory.createReferenceElementByType(type);
}
Also used : TypeConversionUtil(com.intellij.psi.util.TypeConversionUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) NonNls(org.jetbrains.annotations.NonNls) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) HashSet(java.util.HashSet) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) Nullable(org.jetbrains.annotations.Nullable) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) MethodSignature(com.intellij.psi.util.MethodSignature) OverrideImplementExploreUtil(com.intellij.codeInsight.generation.OverrideImplementExploreUtil) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) RefactoringUtil(com.intellij.refactoring.util.RefactoringUtil) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) Function(com.intellij.util.Function) com.intellij.psi(com.intellij.psi) Condition(com.intellij.openapi.util.Condition) HashMap(com.intellij.util.containers.HashMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) HashSet(java.util.HashSet)

Example 39 with Condition

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

the class CodeStyleGenerationConfigurable method createComponent.

public JComponent createComponent() {
    myVisibilityPanel.add(myJavaVisibilityPanel, BorderLayout.CENTER);
    GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, new JBInsets(0, 0, 0, 0), 0, 0);
    final Condition<PsiClass> isApplicable = aClass -> aClass.isAnnotationType();
    //noinspection Convert2Diamond
    myRepeatAnnotationsModel = new SortedListModel<String>(Comparator.naturalOrder());
    myOverridePanel.add(SpecialAnnotationsUtil.createSpecialAnnotationsListControl("Annotations to Copy", false, isApplicable, myRepeatAnnotationsModel), gc);
    return myPanel;
}
Also used : JBInsets(com.intellij.util.ui.JBInsets) CommenterForm(com.intellij.application.options.codeStyle.CommenterForm) SpecialAnnotationsUtil(com.intellij.codeInspection.util.SpecialAnnotationsUtil) JBCheckBox(com.intellij.ui.components.JBCheckBox) StringUtil(com.intellij.openapi.util.text.StringUtil) Configurable(com.intellij.openapi.options.Configurable) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) java.awt(java.awt) PsiClass(com.intellij.psi.PsiClass) ProjectManager(com.intellij.openapi.project.ProjectManager) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) SortedListModel(com.intellij.ui.SortedListModel) JavaVisibilityPanel(com.intellij.refactoring.ui.JavaVisibilityPanel) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Comparator(java.util.Comparator) JavaLanguage(com.intellij.lang.java.JavaLanguage) ApplicationBundle(com.intellij.openapi.application.ApplicationBundle) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) PsiClass(com.intellij.psi.PsiClass) JBInsets(com.intellij.util.ui.JBInsets)

Example 40 with Condition

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

the class GitBranchWorker method checkoutNewBranch.

public void checkoutNewBranch(@NotNull final String name, @NotNull List<GitRepository> repositories) {
    updateInfo(repositories);
    repositories = ContainerUtil.filter(repositories, new Condition<GitRepository>() {

        @Override
        public boolean value(GitRepository repository) {
            GitLocalBranch currentBranch = repository.getCurrentBranch();
            return currentBranch == null || !currentBranch.getName().equals(name);
        }
    });
    if (!repositories.isEmpty()) {
        new GitCheckoutNewBranchOperation(myProject, myGit, myUiHandler, repositories, name).execute();
    } else {
        LOG.error("Creating new branch the same as current in all repositories: " + name);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch)

Aggregations

Condition (com.intellij.openapi.util.Condition)48 NotNull (org.jetbrains.annotations.NotNull)26 Nullable (org.jetbrains.annotations.Nullable)23 Project (com.intellij.openapi.project.Project)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 List (java.util.List)16 StringUtil (com.intellij.openapi.util.text.StringUtil)15 ContainerUtil (com.intellij.util.containers.ContainerUtil)14 javax.swing (javax.swing)13 PsiElement (com.intellij.psi.PsiElement)11 Module (com.intellij.openapi.module.Module)10 java.util (java.util)10 Logger (com.intellij.openapi.diagnostic.Logger)9 ApplicationManager (com.intellij.openapi.application.ApplicationManager)8 NonNls (org.jetbrains.annotations.NonNls)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 Collection (java.util.Collection)7 ModalityState (com.intellij.openapi.application.ModalityState)6 Document (com.intellij.openapi.editor.Document)6 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6