Search in sources :

Example 1 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.

the class ProjectViewTree method getColorForObject.

@Nullable
public static <T> Color getColorForObject(T object, Project project, @NotNull Function<T, PsiElement> converter) {
    Color color = null;
    final PsiElement psi = converter.fun(object);
    if (psi != null) {
        if (!psi.isValid())
            return null;
        final VirtualFile file = PsiUtilCore.getVirtualFile(psi);
        if (file != null) {
            color = FileColorManager.getInstance(project).getFileColor(file);
        } else if (psi instanceof PsiDirectory) {
            color = FileColorManager.getInstance(project).getFileColor(((PsiDirectory) psi).getVirtualFile());
        } else if (psi instanceof PsiDirectoryContainer) {
            final PsiDirectory[] dirs = ((PsiDirectoryContainer) psi).getDirectories();
            for (PsiDirectory dir : dirs) {
                Color c = FileColorManager.getInstance(project).getFileColor(dir.getVirtualFile());
                if (c != null && color == null) {
                    color = c;
                } else if (c != null) {
                    color = null;
                    break;
                }
            }
        }
    }
    return color == null ? null : ColorUtil.softer(color);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.

the class FlexUnitRuntimeConfigurationProducer method configureRunnerParameters.

private static boolean configureRunnerParameters(final FlexUnitRunnerParameters params, final Module module, final PsiElement element) {
    final FlexBuildConfigurationManager manager = FlexBuildConfigurationManager.getInstance(module);
    FlexUnitSupport support = null;
    FlexBuildConfiguration bc = null;
    if (module.getName().equals(params.getModuleName()) && !params.getBCName().isEmpty()) {
        bc = manager.findConfigurationByName(params.getBCName());
        if (bc != null) {
            support = FlexUnitSupport.getSupport(bc, module);
        }
    }
    if (support == null) {
        bc = manager.getActiveConfiguration();
        support = FlexUnitSupport.getSupport(bc, module);
    }
    if (support == null) {
        for (FlexBuildConfiguration anyBC : manager.getBuildConfigurations()) {
            bc = anyBC;
            support = FlexUnitSupport.getSupport(bc, module);
            if (support != null) {
                break;
            }
        }
    }
    if (support == null) {
        return false;
    }
    params.setModuleName(module.getName());
    params.setBCName(bc.getName());
    if (bc.getTargetPlatform() == TargetPlatform.Mobile) {
        if (bc.getAndroidPackagingOptions().isEnabled()) {
            params.setAppDescriptorForEmulator(FlashRunnerParameters.AppDescriptorForEmulator.Android);
        } else if (bc.getIosPackagingOptions().isEnabled()) {
            params.setAppDescriptorForEmulator(FlashRunnerParameters.AppDescriptorForEmulator.IOS);
        }
    }
    if (element instanceof JSClass) {
        final JSClass clazz = (JSClass) element;
        if (!support.isTestClass(clazz, true))
            return false;
        forClass(clazz, params);
    } else if (element instanceof JSFunction) {
        final JSFunction method = (JSFunction) element;
        final String methodName = method.getName();
        final JSClass clazz = (JSClass) element.getParent();
        if (!support.isTestClass(clazz, true))
            return false;
        if (methodName == null || !support.isTestMethod(method)) {
            forClass(clazz, params);
        } else {
            params.setClassName(clazz.getQualifiedName());
            params.setMethodName(methodName);
            params.setScope(FlexUnitRunnerParameters.Scope.Method);
        }
    } else if (element instanceof PsiDirectory) {
        if (!forDirectory((PsiDirectory) element, module, params))
            return false;
    } else if (element instanceof PsiDirectoryContainer) {
        if (!forPackage((PsiDirectoryContainer) element, module, params))
            return false;
    } else {
        return false;
    }
    return true;
}
Also used : FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiDirectory(com.intellij.psi.PsiDirectory) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 3 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.

the class CommonRefactoringUtil method checkReadOnlyStatus.

private static boolean checkReadOnlyStatus(Collection<? extends PsiElement> elements, boolean recursively, Collection<VirtualFile> readonly, Collection<VirtualFile> failed) {
    boolean seenNonWritablePsiFilesWithoutVirtualFile = false;
    for (PsiElement element : elements) {
        if (element instanceof PsiDirectory) {
            final PsiDirectory dir = (PsiDirectory) element;
            final VirtualFile vFile = dir.getVirtualFile();
            if (vFile.getFileSystem().isReadOnly()) {
                failed.add(vFile);
            } else if (recursively) {
                collectReadOnlyFiles(vFile, readonly);
            } else {
                readonly.add(vFile);
            }
        } else if (element instanceof PsiDirectoryContainer) {
            final PsiDirectory[] directories = ((PsiDirectoryContainer) element).getDirectories();
            for (PsiDirectory directory : directories) {
                VirtualFile virtualFile = directory.getVirtualFile();
                if (recursively) {
                    if (virtualFile.getFileSystem().isReadOnly()) {
                        failed.add(virtualFile);
                    } else {
                        collectReadOnlyFiles(virtualFile, readonly);
                    }
                } else if (virtualFile.getFileSystem().isReadOnly()) {
                    failed.add(virtualFile);
                } else {
                    readonly.add(virtualFile);
                }
            }
        } else {
            PsiFile file = element.getContainingFile();
            if (file == null) {
                if (!element.isWritable()) {
                    seenNonWritablePsiFilesWithoutVirtualFile = true;
                }
            } else {
                final VirtualFile vFile = file.getVirtualFile();
                if (vFile != null) {
                    readonly.add(vFile);
                } else if (!element.isWritable()) {
                    seenNonWritablePsiFilesWithoutVirtualFile = true;
                }
            }
        }
    }
    return seenNonWritablePsiFilesWithoutVirtualFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-community by JetBrains.

the class DeleteUtil method generateWarningMessage.

public static String generateWarningMessage(String messageTemplate, final PsiElement[] elements) {
    if (elements.length == 1) {
        String name = ElementDescriptionUtil.getElementDescription(elements[0], DeleteNameDescriptionLocation.INSTANCE);
        String type = ElementDescriptionUtil.getElementDescription(elements[0], DeleteTypeDescriptionLocation.SINGULAR);
        return MessageFormat.format(messageTemplate, type + " \"" + name + "\"");
    }
    FactoryMap<String, Integer> countMap = new FactoryMap<String, Integer>() {

        @Override
        protected Integer create(final String key) {
            return 0;
        }
    };
    Map<String, String> pluralToSingular = new HashMap<>();
    int directoryCount = 0;
    String containerType = null;
    for (final PsiElement elementToDelete : elements) {
        String type = ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.PLURAL);
        pluralToSingular.put(type, ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.SINGULAR));
        int oldCount = countMap.get(type).intValue();
        countMap.put(type, oldCount + 1);
        if (elementToDelete instanceof PsiDirectoryContainer) {
            containerType = type;
            directoryCount += ((PsiDirectoryContainer) elementToDelete).getDirectories().length;
        }
    }
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
        if (buffer.length() > 0) {
            if (buffer.length() > 0) {
                buffer.append(" ").append(IdeBundle.message("prompt.delete.and")).append(" ");
            }
        }
        final int count = entry.getValue().intValue();
        buffer.append(count).append(" ");
        if (count == 1) {
            buffer.append(pluralToSingular.get(entry.getKey()));
        } else {
            buffer.append(entry.getKey());
        }
        if (entry.getKey().equals(containerType)) {
            buffer.append(" ").append(IdeBundle.message("prompt.delete.directory.paren", directoryCount));
        }
    }
    return MessageFormat.format(messageTemplate, buffer.toString());
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) HashMap(com.intellij.util.containers.HashMap) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) FactoryMap(com.intellij.util.containers.FactoryMap) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PsiDirectoryContainer

use of com.intellij.psi.PsiDirectoryContainer in project intellij-plugins by JetBrains.

the class FlashRunConfiguration method getRefactoringElementListener.

@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
    if (!myRunnerParameters.isOverrideMainClass()) {
        return null;
    }
    final Module module = ModuleManager.getInstance(getProject()).findModuleByName(myRunnerParameters.getModuleName());
    if (!(element instanceof PsiDirectoryContainer) && !(element instanceof JSPackage) && !(element instanceof JSPackageStatement) && (module == null || !module.equals(ModuleUtilCore.findModuleForPsiElement(element)))) {
        return null;
    }
    final String currentPackage = StringUtil.getPackageName(myRunnerParameters.getOverriddenMainClass());
    if ((element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) && Comparing.strEqual(FlexRefactoringListenerProvider.getPackageName(element), currentPackage)) {
        return new FlexRunConfigRefactoringListener.PackageRefactoringListener(this);
    }
    if (element instanceof PsiDirectory && containsClass(module, ((PsiDirectory) element), myRunnerParameters.getOverriddenMainClass())) {
        return new FlexRunConfigRefactoringListener.PsiDirectoryRefactoringListener(this);
    }
    final JSClass jsClass = FlexRefactoringListenerProvider.getJSClass(element);
    if (jsClass != null && Comparing.strEqual(jsClass.getQualifiedName(), myRunnerParameters.getOverriddenMainClass())) {
        return new FlexRunConfigRefactoringListener.JSClassRefactoringListener(this);
    }
    return null;
}
Also used : JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryContainer(com.intellij.psi.PsiDirectoryContainer) JSPackage(com.intellij.lang.javascript.psi.ecmal4.JSPackage) Module(com.intellij.openapi.module.Module) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Aggregations

PsiDirectoryContainer (com.intellij.psi.PsiDirectoryContainer)7 PsiDirectory (com.intellij.psi.PsiDirectory)5 PsiElement (com.intellij.psi.PsiElement)4 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)3 Module (com.intellij.openapi.module.Module)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 JSPackage (com.intellij.lang.javascript.psi.ecmal4.JSPackage)2 JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)2 PsiFile (com.intellij.psi.PsiFile)2 Nullable (org.jetbrains.annotations.Nullable)2 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 HashMap (com.intellij.util.containers.HashMap)1 Map (java.util.Map)1