Search in sources :

Example 16 with Condition

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

the class EntryPointsManagerImpl method configureAnnotations.

@Override
public void configureAnnotations() {
    final List<String> list = new ArrayList<>(ADDITIONAL_ANNOTATIONS);
    final List<String> writeList = new ArrayList<>(myWriteAnnotations);
    final JPanel listPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(list, "Mark as entry point if annotated by", true);
    Condition<PsiClass> applicableToField = psiClass -> {
        Set<PsiAnnotation.TargetType> annotationTargets = AnnotationTargetUtil.getAnnotationTargets(psiClass);
        return annotationTargets != null && annotationTargets.contains(PsiAnnotation.TargetType.FIELD);
    };
    final JPanel writtenAnnotationsPanel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl(writeList, "Mark field as implicitly written if annotated by", false, applicableToField);
    new DialogWrapper(myProject) {

        {
            init();
            setTitle("Configure Annotations");
        }

        @Override
        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new VerticalFlowLayout());
            panel.add(listPanel);
            panel.add(writtenAnnotationsPanel);
            return panel;
        }

        @Override
        protected void doOKAction() {
            ADDITIONAL_ANNOTATIONS.clear();
            ADDITIONAL_ANNOTATIONS.addAll(list);
            myWriteAnnotations.clear();
            myWriteAnnotations.addAll(writeList);
            DaemonCodeAnalyzer.getInstance(myProject).restart();
            super.doOKAction();
        }
    }.show();
}
Also used : SpecialAnnotationsUtil(com.intellij.codeInspection.util.SpecialAnnotationsUtil) ActionListener(java.awt.event.ActionListener) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) Set(java.util.Set) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ProjectUtil(com.intellij.openapi.project.ProjectUtil) ActionEvent(java.awt.event.ActionEvent) AnnotationTargetUtil(com.intellij.codeInsight.AnnotationTargetUtil) ArrayList(java.util.ArrayList) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Nullable(org.jetbrains.annotations.Nullable) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) State(com.intellij.openapi.components.State) PsiAnnotation(com.intellij.psi.PsiAnnotation) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Element(org.jdom.Element) LinkedHashSet(java.util.LinkedHashSet) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiAnnotation(com.intellij.psi.PsiAnnotation) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Example 17 with Condition

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

the class AbstractUnwrapRemoveTest method doTest.

private void doTest(@NotNull String path, final Class<? extends Unwrapper> unwrapperClass) throws Exception {
    configureByFile(path);
    String fileText = FileUtil.loadFile(new File(path), true);
    String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
    boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
    String option = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// OPTION: ");
    Integer optionIndex = option != null ? Integer.parseInt(option) : 0;
    List<Pair<PsiElement, Unwrapper>> unwrappersWithPsi = new KotlinUnwrapDescriptor().collectUnwrappers(getProject(), getEditor(), getFile());
    if (isApplicableExpected) {
        final Pair<PsiElement, Unwrapper> selectedUnwrapperWithPsi = unwrappersWithPsi.get(optionIndex);
        assertEquals(unwrapperClass, selectedUnwrapperWithPsi.second.getClass());
        final PsiElement first = selectedUnwrapperWithPsi.first;
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                selectedUnwrapperWithPsi.second.unwrap(getEditor(), first);
            }
        });
        checkResultByFile(path + ".after");
    } else {
        assertTrue(ContainerUtil.and(unwrappersWithPsi, new Condition<Pair<PsiElement, Unwrapper>>() {

            @Override
            public boolean value(Pair<PsiElement, Unwrapper> pair) {
                return pair.second.getClass() != unwrapperClass;
            }
        }));
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) Unwrapper(com.intellij.codeInsight.unwrap.Unwrapper) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 18 with Condition

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

the class StrutsConstantManagerImpl method getStringValue.

/**
   * Returns the plain String value for the given constant.
   *
   * @param context     Current context.
   * @param strutsModel StrutsModel.
   * @param name        Name of constant.
   * @return {@code null} if no value could be resolved.
   */
@Nullable
private static String getStringValue(@NotNull final PsiFile context, @NotNull final StrutsModel strutsModel, @NotNull @NonNls final String name) {
    final Project project = context.getProject();
    final Module module = ModuleUtilCore.findModuleForPsiElement(context);
    assert module != null : context;
    // collect all properties with matching key
    final List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(project, name);
    String value = null;
    // 1. default.properties from struts2-core.jar
    final IProperty strutsDefaultProperty = ContainerUtil.find(properties, property -> {
        final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
        return virtualFile != null && virtualFile.getFileSystem() instanceof JarFileSystem && StringUtil.endsWith(virtualFile.getPath(), STRUTS_DEFAULT_PROPERTIES) && ModuleUtilCore.moduleContainsFile(module, virtualFile, true);
    });
    if (strutsDefaultProperty != null) {
        value = strutsDefaultProperty.getValue();
    }
    // 2. <constant> from StrutsModel
    final Condition<Constant> constantNameCondition = constant -> Comparing.equal(constant.getName().getStringValue(), name);
    final List<DomFileElement<StrutsRoot>> domFileElements = new ArrayList<>();
    collectStrutsXmls(domFileElements, strutsModel, "struts-default.xml", true);
    collectStrutsXmls(domFileElements, strutsModel, "struts-plugin.xml", true);
    collectStrutsXmls(domFileElements, strutsModel, "struts.xml", false);
    for (final DomFileElement<StrutsRoot> domFileElement : domFileElements) {
        final Constant constant = ContainerUtil.find(domFileElement.getRootElement().getConstants(), constantNameCondition);
        final String strutsXmlValue = constant != null ? constant.getValue().getStringValue() : null;
        if (strutsXmlValue != null) {
            value = strutsXmlValue;
        }
    }
    // 3. struts.properties in current module
    final IProperty strutsProperty = ContainerUtil.find(properties, property -> {
        final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
        return virtualFile != null && Comparing.equal(virtualFile.getName(), STRUTS_PROPERTIES_FILENAME) && ModuleUtilCore.moduleContainsFile(module, virtualFile, false);
    });
    if (strutsProperty != null) {
        value = strutsProperty.getValue();
    }
    // 4. web.xml
    final WebFacet webFacet = WebUtil.getWebFacet(context);
    if (webFacet == null) {
        // should not happen in real projects..
        return value;
    }
    final WebApp webApp = webFacet.getRoot();
    if (webApp == null) {
        // no web.xml
        return value;
    }
    final Filter filter = ContainerUtil.find(webApp.getFilters(), WEB_XML_STRUTS_FILTER_CONDITION);
    if (filter != null) {
        final ParamValue initParam = ContainerUtil.find(filter.getInitParams(), (Condition<ParamValue>) paramValue -> Comparing.equal(paramValue.getParamName().getStringValue(), name));
        if (initParam != null) {
            value = initParam.getParamValue().getStringValue();
        }
    }
    return value;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WebFacet(com.intellij.javaee.web.facet.WebFacet) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ArrayList(java.util.ArrayList) FilteringProcessor(com.intellij.util.FilteringProcessor) PsiClass(com.intellij.psi.PsiClass) StrutsRoot(com.intellij.struts2.dom.struts.StrutsRoot) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) WebUtil(com.intellij.javaee.web.WebUtil) Module(com.intellij.openapi.module.Module) StrutsConstants(com.intellij.struts2.StrutsConstants) CommonProcessors(com.intellij.util.CommonProcessors) Converter(com.intellij.util.xml.Converter) Extensions(com.intellij.openapi.extensions.Extensions) Constant(com.intellij.struts2.dom.struts.constant.Constant) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) DomFileElement(com.intellij.util.xml.DomFileElement) ConvertContextFactory(com.intellij.util.xml.impl.ConvertContextFactory) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IProperty(com.intellij.lang.properties.IProperty) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) WebApp(com.intellij.javaee.model.xml.web.WebApp) ParamValue(com.intellij.javaee.model.xml.ParamValue) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Filter(com.intellij.javaee.model.xml.web.Filter) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Constant(com.intellij.struts2.dom.struts.constant.Constant) ArrayList(java.util.ArrayList) DomFileElement(com.intellij.util.xml.DomFileElement) ParamValue(com.intellij.javaee.model.xml.ParamValue) Project(com.intellij.openapi.project.Project) IProperty(com.intellij.lang.properties.IProperty) Filter(com.intellij.javaee.model.xml.web.Filter) StrutsRoot(com.intellij.struts2.dom.struts.StrutsRoot) Module(com.intellij.openapi.module.Module) WebFacet(com.intellij.javaee.web.facet.WebFacet) WebApp(com.intellij.javaee.model.xml.web.WebApp) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with Condition

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

the class InterceptorRefResolveConverterImpl method fromString.

public InterceptorOrStackBase fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorOrStackBase> nameCondition = interceptorOrStackBase -> name.equals(interceptorOrStackBase.getName().getStringValue());
    final Ref<InterceptorOrStackBase> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorOrStackBase result = ContainerUtil.find(getAllInterceptors(strutsPackage), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) InterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 20 with Condition

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

the class ResultTypeResolvingConverterImpl method fromString.

public ResultType fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (StringUtil.isEmpty(name)) {
        return null;
    }
    final Condition<ResultType> nameCondition = resultType -> Comparing.equal(name, resultType.getName().getStringValue());
    final Ref<ResultType> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final ResultType result = ContainerUtil.find(strutsPackage.getResultTypes(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) ResultTypeResolvingConverter(com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

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