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);
}
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);
}
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;
}
Aggregations