Search in sources :

Example 46 with Condition

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

the class FindPopupScopeUIImpl method initComponents.

public void initComponents() {
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    String[] names = new String[modules.length];
    for (int i = 0; i < modules.length; i++) {
        names[i] = modules[i].getName();
    }
    Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
    myModuleComboBox = new ComboBox<>(names);
    ActionListener restartSearchListener = e -> scheduleResultsUpdate();
    myModuleComboBox.addActionListener(restartSearchListener);
    myDirectoryChooser = new FindPopupDirectoryChooser(myFindPopupPanel);
    myScopeCombo = new ScopeChooserCombo();
    myScopeCombo.init(myProject, true, true, FindSettings.getInstance().getDefaultScopeName(), new Condition<ScopeDescriptor>() {

        final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");

        final String moduleFilesScopeName;

        {
            String moduleScopeName = PsiBundle.message("search.scope.module", "");
            final int ind = moduleScopeName.indexOf(' ');
            moduleFilesScopeName = moduleScopeName.substring(0, ind + 1);
        }

        @Override
        public boolean value(ScopeDescriptor descriptor) {
            final String display = descriptor.getDisplay();
            return !projectFilesScopeName.equals(display) && !display.startsWith(moduleFilesScopeName);
        }
    });
    myScopeCombo.setBrowseListener(new ScopeChooserCombo.BrowseListener() {

        private FindModel myModelSnapshot;

        @Override
        public void onBeforeBrowseStarted() {
            myModelSnapshot = myHelper.getModel();
            myFindPopupPanel.getCanClose().set(false);
        }

        @Override
        public void onAfterBrowseFinished() {
            if (myModelSnapshot != null) {
                SearchScope scope = myScopeCombo.getSelectedScope();
                if (scope != null) {
                    myModelSnapshot.setCustomScope(scope);
                }
                myFindPopupPanel.getCanClose().set(true);
            }
        }
    });
    myScopeCombo.getComboBox().addActionListener(restartSearchListener);
    Disposer.register(myFindPopupPanel.getDisposable(), myScopeCombo);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) ModuleManager(com.intellij.openapi.module.ModuleManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.find(com.intellij.find) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Disposer(com.intellij.openapi.util.Disposer) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Condition(com.intellij.openapi.util.Condition) PsiBundle(com.intellij.psi.PsiBundle) javax.swing(javax.swing) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) ActionListener(java.awt.event.ActionListener) SearchScope(com.intellij.psi.search.SearchScope) Module(com.intellij.openapi.module.Module)

Example 47 with Condition

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

the class KotlinStandaloneScriptRunConfigurationEditor method initChooseFileField.

void initChooseFileField(Project project) {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withFileFilter(new Condition<VirtualFile>() {

        @Override
        public boolean value(VirtualFile file) {
            return file.isDirectory() || KotlinParserDefinition.STD_SCRIPT_SUFFIX.equals(file.getExtension());
        }
    }).withTreeRootVisible(true);
    chooseScriptFileTextField.addBrowseFolderListener("Choose script file", null, project, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
}
Also used : Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 48 with Condition

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

the class ActionUtil method findActionMethods.

/**
   * Returns all suitable action methods for the given Action class.
   *
   * @param actionClass Action class to search for action methods.
   * @param methodName  (Optional) Method name.
   * @return Methods suitable for action execution.
   */
static List<PsiMethod> findActionMethods(@NotNull final PsiClass actionClass, @Nullable final String methodName) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(actionClass);
    if (module == null) {
        return Collections.emptyList();
    }
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    final PsiClassType stringType = PsiType.getJavaLangString(actionClass.getManager(), scope);
    final PsiElementFactory psiElementFactory = JavaPsiFacade.getInstance(actionClass.getProject()).getElementFactory();
    final PsiClassType resultType = psiElementFactory.createTypeByFQClassName("com.opensymphony.xwork2.Result", scope);
    final boolean searchForMethod = methodName != null;
    final List<PsiMethod> actionMethods = new SmartList<>();
    final PsiMethod[] methods = searchForMethod ? actionClass.findMethodsByName(methodName, true) : actionClass.getAllMethods();
    for (final PsiMethod psiMethod : methods) {
        if (psiMethod.isConstructor()) {
            continue;
        }
        // only public non-static concrete methods
        final PsiModifierList modifiers = psiMethod.getModifierList();
        if (!modifiers.hasModifierProperty(PsiModifier.PUBLIC) || modifiers.hasModifierProperty(PsiModifier.STATIC) || modifiers.hasModifierProperty(PsiModifier.ABSTRACT)) {
            continue;
        }
        // no parameters
        if (psiMethod.getParameterList().getParametersCount() != 0) {
            continue;
        }
        // skip "toString()"
        final String psiMethodName = psiMethod.getName();
        if (Comparing.equal(psiMethodName, "toString")) {
            continue;
        }
        // do not include simple getters (with underlying field)
        if (PropertyUtil.isSimplePropertyGetter(psiMethod) && actionClass.findFieldByName(PropertyUtil.getPropertyName(psiMethod), true) != null) {
            continue;
        }
        // return type "java.lang.String" or "com.opensymphony.xwork2.Result"
        final PsiType type = psiMethod.getReturnType();
        if (type != null && type instanceof PsiClassType && (type.equals(stringType) || type.equals(resultType))) {
            // stop on first hit when searching for name
            if (searchForMethod) {
                return Collections.singletonList(psiMethod);
            }
            // do not add methods with same name from super-class
            final Condition<PsiMethod> nameCondition = method -> psiMethodName.equals(method.getName());
            if (!ContainerUtil.exists(actionMethods, nameCondition)) {
                actionMethods.add(psiMethod);
            }
        }
    }
    return actionMethods;
}
Also used : PatternSyntaxException(java.util.regex.PatternSyntaxException) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PropertyUtil(com.intellij.psi.util.PropertyUtil) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) com.intellij.psi(com.intellij.psi) Pattern(java.util.regex.Pattern) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList)

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