Search in sources :

Example 21 with Condition

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

the class DefaultInterceptorRefResolveConverterImpl method fromString.

public InterceptorStack fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorStack> nameCondition = interceptorStack -> name.equals(interceptorStack.getName().getStringValue());
    final Ref<InterceptorStack> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorStack result = ContainerUtil.find(strutsPackage.getInterceptorStacks(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : DefaultInterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.DefaultInterceptorRefResolveConverter) 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) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DomUtil(com.intellij.util.xml.DomUtil) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 22 with Condition

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

the class DartCallHierarchyTreeStructure method collectDeclarations.

public static void collectDeclarations(@Nullable final PsiElement element, @NotNull final List<PsiElement> results) {
    if (element != null) {
        Condition<PsiElement> isExecutable = object -> {
            if (object == null)
                return false;
            return DartHierarchyUtil.isExecutable(object);
        };
        PsiElement ref = PsiTreeUtil.findFirstParent(element, isExecutable);
        if (ref != null) {
            results.add(ref);
        }
    }
}
Also used : HierarchyTreeStructure(com.intellij.ide.hierarchy.HierarchyTreeStructure) DartHierarchyUtil(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) ArrayUtil(com.intellij.util.ArrayUtil) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartServerFindUsagesHandler(com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) com.jetbrains.lang.dart.psi(com.jetbrains.lang.dart.psi) NotNull(org.jetbrains.annotations.NotNull) HierarchyBrowserBaseEx(com.intellij.ide.hierarchy.HierarchyBrowserBaseEx) Condition(com.intellij.openapi.util.Condition) PsiElement(com.intellij.psi.PsiElement)

Example 23 with Condition

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

the class PropertyProcessor method writeClassFactory.

private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    if (valueProvider instanceof XmlTagValueProvider) {
        XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
        XmlTag[] subTags = tag.getSubTags();
        if (subTags.length > 0) {
            processFxComponent(subTags[0], true);
            return;
        }
    }
    String className = valueProvider.getTrimmed();
    if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
        return;
    }
    final JSClass jsClass = valueProvider.getJsClass();
    if (jsClass == null) {
        throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
    }
    final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
    final PsiElement parent = jsClass.getNavigationElement().getParent();
    if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
        // if referenced by inner class name, but inner fx component is not yet processed
        if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
            processFxComponent((XmlTag) parent, false);
            return;
        } else {
            effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
        }
    } else {
        effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
    }
    if (effectiveClassInfo.first == -1) {
        if (effectiveClassInfo.second != null) {
            if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
                PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
                if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
                    className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
                } else {
                    className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
                }
            } else {
                className = effectiveClassInfo.second;
            }
        }
        writeNonProjectUnreferencedClassFactory(className);
    } else {
        writer.documentFactoryReference(effectiveClassInfo.first);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 24 with Condition

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

the class CreateFlexUnitTestDialog method createUIComponents.

private void createUIComponents() {
    final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
    assert module != null;
    myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
    final Condition<JSClass> filter = jsClass -> {
        final JSAttributeList attributeList = jsClass.getAttributeList();
        return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
    };
    mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        public boolean includeMember(final JSAttributeListOwner member) {
            final JSAttributeList attributeList = member.getAttributeList();
            return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
        }
    });
    myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
Also used : ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) NullableComputable(com.intellij.openapi.util.NullableComputable) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) PsiManager(com.intellij.psi.PsiManager) ArrayList(java.util.ArrayList) ContentEntry(com.intellij.openapi.roots.ContentEntry) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JSRefactoringUtil(com.intellij.lang.javascript.refactoring.util.JSRefactoringUtil) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) PsiElement(com.intellij.psi.PsiElement) Conditions(com.intellij.openapi.util.Conditions) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceEditor(com.intellij.lang.javascript.refactoring.ui.JSReferenceEditor) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) ThreeState(com.intellij.util.ThreeState) MarkRootActionBase(com.intellij.ide.projectView.actions.MarkRootActionBase) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IOException(java.io.IOException) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) ActionEvent(java.awt.event.ActionEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) Nullable(org.jetbrains.annotations.Nullable) JSFunction(com.intellij.lang.javascript.psi.JSFunction) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) PsiDirectory(com.intellij.psi.PsiDirectory) JSBundle(com.intellij.lang.javascript.JSBundle) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) JSMemberSelectionPanel(com.intellij.lang.javascript.refactoring.ui.JSMemberSelectionPanel) JSFunction(com.intellij.lang.javascript.psi.JSFunction) Module(com.intellij.openapi.module.Module) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 25 with Condition

use of com.intellij.openapi.util.Condition in project idea-handlebars by dmarcotte.

the class HbBlockMismatchFix method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final int offset = editor.getCaretModel().getOffset();
    PsiElement psiElement = file.findElementAt(offset);
    if (psiElement == null || !psiElement.isValid())
        return;
    if (!FileModificationService.getInstance().prepareFileForWrite(psiElement.getContainingFile()))
        return;
    if (psiElement instanceof PsiWhiteSpace)
        psiElement = PsiTreeUtil.prevLeaf(psiElement);
    HbBlockMustache blockMustache = (HbBlockMustache) PsiTreeUtil.findFirstParent(psiElement, true, new Condition<PsiElement>() {

        @Override
        public boolean value(PsiElement psiElement) {
            return psiElement instanceof HbBlockMustache;
        }
    });
    if (blockMustache == null) {
        return;
    }
    HbBlockMustache targetBlockMustache = blockMustache;
    // ensure we update the open or close mustache for this block appropriately
    if (myUpdateOpenMustache != (targetBlockMustache instanceof HbOpenBlockMustache)) {
        targetBlockMustache = blockMustache.getPairedElement();
    }
    HbPath path = PsiTreeUtil.findChildOfType(targetBlockMustache, HbPath.class);
    final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
    if (path != null && document != null) {
        final TextRange textRange = path.getTextRange();
        document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myCorrectedName);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) HbOpenBlockMustache(com.dmarcotte.handlebars.psi.HbOpenBlockMustache) HbPath(com.dmarcotte.handlebars.psi.HbPath) HbBlockMustache(com.dmarcotte.handlebars.psi.HbBlockMustache) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

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