Search in sources :

Example 11 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class DissociateResourceBundleAction method dissociate.

public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
    final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
    for (ResourceBundle resourceBundle : resourceBundles) {
        for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
            PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
            if (containingDirectory != null) {
                toUpdateInProjectView.add(containingDirectory);
            }
        }
        ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
    }
    AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
    if (currentProjectViewPane == null) {
        return;
    }
    AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
    if (treeBuilder != null) {
        for (PsiFileSystemItem item : toUpdateInProjectView) {
            treeBuilder.queueUpdateFrom(item, false);
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(com.intellij.util.containers.HashSet)

Example 12 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class PyReachingDefsSemilattice method join.

public DFAMap<ScopeVariable> join(ArrayList<DFAMap<ScopeVariable>> ins) {
    if (ins.isEmpty()) {
        return DFAMap.empty();
    }
    if (ins.size() == 1) {
        return ins.get(0);
    }
    final Set<String> resultNames = getResultNames(ins);
    if (resultNames == null || resultNames.isEmpty()) {
        return new DFAMap<>();
    }
    final DFAMap<ScopeVariable> result = new DFAMap<>();
    for (String name : resultNames) {
        boolean isParameter = true;
        Set<PsiElement> declarations = new HashSet<>();
        // iterating over all maps
        for (DFAMap<ScopeVariable> map : ins) {
            final ScopeVariable variable = map.get(name);
            if (variable == null) {
                continue;
            }
            isParameter = isParameter && variable.isParameter();
            declarations.addAll(variable.getDeclarations());
        }
        final ScopeVariable scopeVariable = new ScopeVariableImpl(name, isParameter, declarations);
        result.put(name, scopeVariable);
    }
    return result;
}
Also used : ScopeVariableImpl(com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl) ScopeVariable(com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable) PsiElement(com.intellij.psi.PsiElement) DFAMap(com.intellij.codeInsight.dataflow.map.DFAMap) HashSet(com.intellij.util.containers.HashSet)

Example 13 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class PreviewFormAction method showPreviewFrame.

private static void showPreviewFrame(@NotNull final Module module, @NotNull final VirtualFile formFile, @Nullable final Locale stringDescriptorLocale) {
    final String tempPath;
    try {
        final File tempDirectory = FileUtil.createTempDirectory("FormPreview", "");
        tempPath = tempDirectory.getAbsolutePath();
        CopyResourcesUtil.copyFormsRuntime(tempPath, true);
    } catch (IOException e) {
        Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.toString()), CommonBundle.getErrorTitle());
        return;
    }
    final PathsList sources = OrderEnumerator.orderEntries(module).withoutSdk().withoutLibraries().withoutDepModules().getSourcePathsList();
    final String classPath = OrderEnumerator.orderEntries(module).recursively().getPathsList().getPathsString() + File.pathSeparator + sources.getPathsString() + File.pathSeparator + /* resources bundles */
    tempPath;
    final InstrumentationClassFinder finder = createClassFinder(classPath);
    try {
        final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
        final LwRootContainer rootContainer;
        try {
            rootContainer = Utils.getRootContainer(doc.getText(), new CompiledClassPropertiesProvider(finder.getLoader()));
        } catch (Exception e) {
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.read.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage()), CommonBundle.getErrorTitle());
            return;
        }
        if (rootContainer.getComponentCount() == 0) {
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.empty.form", formFile.getPath().replace('/', File.separatorChar)), CommonBundle.getErrorTitle());
            return;
        }
        setPreviewBindings(rootContainer, CLASS_TO_BIND_NAME);
        // 2. Copy previewer class and all its superclasses into TEMP directory and instrument it.
        try {
            PreviewNestedFormLoader nestedFormLoader = new PreviewNestedFormLoader(module, tempPath, finder);
            final File tempFile = CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME, true);
            //CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$1", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyExitAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyPackAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MySetLafAction", true);
            Locale locale = Locale.getDefault();
            if (locale.getCountry().length() > 0 && locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + "_" + locale.getCountry() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            if (locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, finder, nestedFormLoader, true, new PsiClassWriter(module));
            codeGenerator.patchFile(tempFile);
            final FormErrorInfo[] errors = codeGenerator.getErrors();
            if (errors.length != 0) {
                Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), errors[0].getErrorMessage()), CommonBundle.getErrorTitle());
                return;
            }
        } catch (Exception e) {
            LOG.debug(e);
            Messages.showErrorDialog(module.getProject(), UIDesignerBundle.message("error.cannot.preview.form", formFile.getPath().replace('/', File.separatorChar), e.getMessage() != null ? e.getMessage() : e.toString()), CommonBundle.getErrorTitle());
            return;
        }
        // 2.5. Copy up-to-date properties files to the output directory.
        final HashSet<String> bundleSet = new HashSet<>();
        FormEditingUtil.iterateStringDescriptors(rootContainer, new FormEditingUtil.StringDescriptorVisitor<IComponent>() {

            public boolean visit(final IComponent component, final StringDescriptor descriptor) {
                if (descriptor.getBundleName() != null) {
                    bundleSet.add(descriptor.getDottedBundleName());
                }
                return true;
            }
        });
        if (bundleSet.size() > 0) {
            HashSet<VirtualFile> virtualFiles = new HashSet<>();
            HashSet<Module> modules = new HashSet<>();
            PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
            for (String bundleName : bundleSet) {
                for (PropertiesFile propFile : manager.findPropertiesFiles(module, bundleName)) {
                    virtualFiles.add(propFile.getVirtualFile());
                    final Module moduleForFile = ModuleUtil.findModuleForFile(propFile.getVirtualFile(), module.getProject());
                    if (moduleForFile != null) {
                        modules.add(moduleForFile);
                    }
                }
            }
            FileSetCompileScope scope = new FileSetCompileScope(virtualFiles, modules.toArray(new Module[modules.size()]));
            CompilerManager.getInstance(module.getProject()).make(scope, new CompileStatusNotification() {

                public void finished(boolean aborted, int errors, int warnings, final CompileContext compileContext) {
                    if (!aborted && errors == 0) {
                        runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
                    }
                }
            });
        } else {
            runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
        }
    } finally {
        finder.releaseResources();
    }
}
Also used : Locale(java.util.Locale) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClassWriter(com.intellij.compiler.PsiClassWriter) PreviewNestedFormLoader(com.intellij.uiDesigner.make.PreviewNestedFormLoader) Document(com.intellij.openapi.editor.Document) CompileContext(com.intellij.openapi.compiler.CompileContext) CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) FormErrorInfo(com.intellij.uiDesigner.compiler.FormErrorInfo) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertiesReferenceManager(com.intellij.lang.properties.PropertiesReferenceManager) HashSet(com.intellij.util.containers.HashSet) InstrumentationClassFinder(com.intellij.compiler.instrumentation.InstrumentationClassFinder) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) CantRunException(com.intellij.execution.CantRunException) PathsList(com.intellij.util.PathsList) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) File(java.io.File) AsmCodeGenerator(com.intellij.uiDesigner.compiler.AsmCodeGenerator) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) FileSetCompileScope(com.intellij.compiler.impl.FileSetCompileScope)

Example 14 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class GrChangeSignatureProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
    collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
    final UsageInfo[] usagesIn = refUsages.get();
    RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
    Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
    RenameUtil.removeConflictUsages(usagesSet);
    if (!conflictDescriptions.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new ConflictsInTestsException(conflictDescriptions.values());
        }
        ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
        if (!dialog.showAndGet()) {
            if (dialog.isShowConflicts())
                prepareSuccessful();
            return false;
        }
    }
    refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
    prepareSuccessful();
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet)

Example 15 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class GrChangeSignatureUsageProcessor method createDefaultValue.

@Nullable
private static GrExpression createDefaultValue(GroovyPsiElementFactory factory, JavaChangeInfo changeInfo, JavaParameterInfo info, final GrArgumentList list, PsiSubstitutor substitutor) {
    if (info.isUseAnySingleVariable()) {
        final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(list.getProject()).getResolveHelper();
        final PsiType type = info.getTypeWrapper().getType(changeInfo.getMethod(), list.getManager());
        final VariablesProcessor processor = new VariablesProcessor(false) {

            @Override
            protected boolean check(PsiVariable var, ResolveState state) {
                if (var instanceof PsiField && !resolveHelper.isAccessible((PsiField) var, list, null))
                    return false;
                if (var instanceof GrVariable && PsiUtil.isLocalVariable(var) && list.getTextRange().getStartOffset() <= var.getTextRange().getStartOffset()) {
                    return false;
                }
                if (PsiTreeUtil.isAncestor(var, list, false))
                    return false;
                final PsiType _type = var instanceof GrVariable ? ((GrVariable) var).getTypeGroovy() : var.getType();
                final PsiType varType = state.get(PsiSubstitutor.KEY).substitute(_type);
                return type.isAssignableFrom(varType);
            }

            @Override
            public boolean execute(@NotNull PsiElement pe, @NotNull ResolveState state) {
                super.execute(pe, state);
                return size() < 2;
            }
        };
        treeWalkUp(list, processor);
        if (processor.size() == 1) {
            final PsiVariable result = processor.getResult(0);
            return factory.createExpressionFromText(result.getName(), list);
        }
        if (processor.size() == 0) {
            final PsiClass parentClass = PsiTreeUtil.getParentOfType(list, PsiClass.class);
            if (parentClass != null) {
                PsiClass containingClass = parentClass;
                final Set<PsiClass> containingClasses = new HashSet<>();
                final PsiElementFactory jfactory = JavaPsiFacade.getElementFactory(list.getProject());
                while (containingClass != null) {
                    if (type.isAssignableFrom(jfactory.createType(containingClass, PsiSubstitutor.EMPTY))) {
                        containingClasses.add(containingClass);
                    }
                    containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class);
                }
                if (containingClasses.size() == 1) {
                    return factory.createThisExpression(containingClasses.contains(parentClass) ? null : containingClasses.iterator().next());
                }
            }
        }
    }
    final PsiElement element = info.getActualValue(list.getParent(), substitutor);
    if (element instanceof GrExpression) {
        return (GrExpression) element;
    }
    final String value = info.getDefaultValue();
    return !StringUtil.isEmpty(value) ? factory.createExpressionFromText(value, list) : null;
}
Also used : VariablesProcessor(com.intellij.psi.scope.processor.VariablesProcessor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) HashSet(com.intellij.util.containers.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5