Search in sources :

Example 61 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class DartControlFlowUtil method getSimpleDeclarations.

public static Set<DartComponentName> getSimpleDeclarations(PsiElement[] children, @Nullable PsiElement lastParent, boolean stopAtLastParent) {
    final Set<DartComponentName> result = new THashSet<>();
    boolean addComponentsFlag = true;
    for (PsiElement child : children) {
        if (child == lastParent && stopAtLastParent) {
            addComponentsFlag = false;
        }
        if (addComponentsFlag && child instanceof DartVarDeclarationList) {
            addFromVarDeclarationList(result, (DartVarDeclarationList) child);
        } else if (child instanceof DartComponent) {
            boolean isFieldOrVar = child instanceof DartVarAccessDeclaration || child instanceof DartVarDeclarationListPart;
            if (!isFieldOrVar) {
                result.add(((DartComponent) child).getComponentName());
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 62 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class CfmlComponentReference method buildVariants.

@NotNull
public static Object[] buildVariants(String text, PsiFile containingFile, final Project project, @Nullable CfmlComponentReference reference, final boolean forceQualify) {
    Collection<Object> variants = new THashSet<>();
    String directoryName = "";
    if (text.contains(".")) {
        int i = text.lastIndexOf(".");
        directoryName = text.substring(0, i);
    }
    CfmlProjectConfiguration.State state = CfmlProjectConfiguration.getInstance(project).getState();
    CfmlMappingsConfig mappings = state != null ? state.getMapps().clone() : new CfmlMappingsConfig();
    adjustMappingsIfEmpty(mappings, project);
    if (reference != null)
        addFakeMappingsForImports(reference, mappings);
    List<String> realPossiblePaths = mappings.mapVirtualToReal(directoryName);
    for (String realPath : realPossiblePaths) {
        addVariantsFromPath(variants, directoryName, realPath);
    }
    for (String value : mappings.getServerMappings().keySet()) {
        if (value.startsWith(directoryName) && !value.isEmpty() && (StringUtil.startsWithChar(value, '/') || StringUtil.startsWithChar(value, '\\'))) {
            variants.add(value.replace('\\', '.').replace('/', '.').substring(1));
        }
    }
    containingFile = containingFile == null ? null : containingFile.getOriginalFile();
    if (containingFile != null && containingFile instanceof CfmlFile) {
        CfmlFile cfmlContainingFile = (CfmlFile) containingFile;
        if (directoryName.length() == 0) {
            PsiDirectory directory = cfmlContainingFile.getParent();
            if (directory != null) {
                addVariantsFromPath(variants, "", directory.getVirtualFile().getPresentableUrl());
            }
        } else {
            String dirPath = cfmlContainingFile.getParent().getVirtualFile().getPath() + "/" + directoryName.replaceAll("[./]+", "/");
            addVariantsFromPath(variants, directoryName, dirPath);
        }
    }
    final String finalDirectoryName = directoryName;
    return ContainerUtil.map2Array(variants, new Function<Object, Object>() {

        class DotInsertHandler implements InsertHandler<LookupElement> {

            @Override
            public void handleInsert(InsertionContext context, LookupElement item) {
                Document document = context.getDocument();
                int offset = context.getEditor().getCaretModel().getOffset();
                document.insertString(offset, ".");
                context.getEditor().getCaretModel().moveToOffset(offset + 1);
            }
        }

        public Object fun(final Object object) {
            if (object instanceof VirtualFile) {
                VirtualFile element = (VirtualFile) object;
                String elementNameWithoutExtension = element.getNameWithoutExtension();
                String name = forceQualify ? finalDirectoryName + (finalDirectoryName.length() == 0 ? "" : ".") + elementNameWithoutExtension : elementNameWithoutExtension;
                if (name.length() == 0)
                    name = element.getName();
                if (element.isDirectory()) {
                    return LookupElementBuilder.create(name).withIcon(DIRECTORY_CLOSED_ICON).withInsertHandler(new DotInsertHandler()).withCaseSensitivity(false);
                } else {
                    Icon icon = CLASS_ICON;
                    // choosing correct icon (class or interface)
                    if (CfmlIndex.getInstance(project).getComponentsByNameInScope(elementNameWithoutExtension, GlobalSearchScope.fileScope(project, element)).size() == 1) {
                        icon = CLASS_ICON;
                    } else if (CfmlIndex.getInstance(project).getInterfacesByNameInScope(elementNameWithoutExtension, GlobalSearchScope.fileScope(project, element)).size() == 1) {
                        icon = INTERFACE_ICON;
                    }
                    return LookupElementBuilder.create(name).withIcon(icon).withCaseSensitivity(false);
                }
            } else if (object instanceof String) {
                return LookupElementBuilder.create((String) object).withInsertHandler(new DotInsertHandler()).withCaseSensitivity(false);
            }
            return object;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) InsertionContext(com.intellij.codeInsight.completion.InsertionContext) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) CfmlMappingsConfig(com.intellij.coldFusion.UI.config.CfmlMappingsConfig) CfmlProjectConfiguration(com.intellij.coldFusion.UI.config.CfmlProjectConfiguration) InsertHandler(com.intellij.codeInsight.completion.InsertHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class CompilerConfigGeneratorRt method addSourcePaths.

private void addSourcePaths(final Element rootElement) {
    final String localeValue = getValueAndSource(CompilerOptionInfo.getOptionInfo("compiler.locale")).first;
    final List<String> locales = StringUtil.split(localeValue, CompilerOptionInfo.LIST_ENTRIES_SEPARATOR);
    // when adding source paths we respect locales set both in UI and in Additional compiler options
    locales.addAll(FlexCommonUtils.getOptionValues(myProjectLevelCompilerOptions.getAdditionalOptions(), "locale", "compiler.locale"));
    locales.addAll(FlexCommonUtils.getOptionValues(myModuleLevelCompilerOptions.getAdditionalOptions(), "locale", "compiler.locale"));
    locales.addAll(FlexCommonUtils.getOptionValues(myBC.getCompilerOptions().getAdditionalOptions(), "locale", "compiler.locale"));
    // Set - to avoid duplication of paths like "locale/{locale}"
    final Set<String> sourcePathsWithLocaleToken = new THashSet<>();
    final List<String> sourcePathsWithoutLocaleToken = new LinkedList<>();
    for (JpsModuleSourceRoot srcRoot : myModule.getSourceRoots(JavaSourceRootType.SOURCE)) {
        final String srcRootPath = JpsPathUtil.urlToPath(srcRoot.getUrl());
        if (locales.contains(PathUtilRt.getFileName(srcRootPath))) {
            sourcePathsWithLocaleToken.add(PathUtilRt.getParentPath(srcRootPath) + "/" + FlexCommonUtils.LOCALE_TOKEN);
        } else {
            sourcePathsWithoutLocaleToken.add(srcRootPath);
        }
    }
    if (includeTestRoots()) {
        for (JpsModuleSourceRoot srcRoot : myModule.getSourceRoots(JavaSourceRootType.TEST_SOURCE)) {
            final String srcRootPath = JpsPathUtil.urlToPath(srcRoot.getUrl());
            if (locales.contains(PathUtilRt.getFileName(srcRootPath))) {
                sourcePathsWithLocaleToken.add(PathUtilRt.getParentPath(srcRootPath) + "/" + FlexCommonUtils.LOCALE_TOKEN);
            } else {
                sourcePathsWithoutLocaleToken.add(srcRootPath);
            }
        }
    }
    final StringBuilder sourcePathBuilder = new StringBuilder();
    if (myCSS) {
        final String cssFolderPath = PathUtilRt.getParentPath(myBC.getMainClass());
        if (!sourcePathsWithoutLocaleToken.contains(cssFolderPath)) {
            sourcePathBuilder.append(cssFolderPath);
        }
    }
    for (final String sourcePath : sourcePathsWithLocaleToken) {
        if (sourcePathBuilder.length() > 0) {
            sourcePathBuilder.append(CompilerOptionInfo.LIST_ENTRIES_SEPARATOR);
        }
        sourcePathBuilder.append(sourcePath);
    }
    for (final String sourcePath : sourcePathsWithoutLocaleToken) {
        if (sourcePathBuilder.length() > 0) {
            sourcePathBuilder.append(CompilerOptionInfo.LIST_ENTRIES_SEPARATOR);
        }
        sourcePathBuilder.append(sourcePath);
    }
    addOption(rootElement, CompilerOptionInfo.SOURCE_PATH_INFO, sourcePathBuilder.toString());
}
Also used : JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) THashSet(gnu.trove.THashSet)

Example 64 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class AdtTask method appendANEPaths.

private static void appendANEPaths(final List<String> command, final Module module, final FlexBuildConfiguration bc) {
    final Set<VirtualFile> extDirPaths = new THashSet<>();
    for (VirtualFile aneFile : FlexCompilationUtils.getANEFiles(ModuleRootManager.getInstance(module), bc.getDependencies())) {
        if (extDirPaths.add(aneFile.getParent())) {
            command.add("-extdir");
            command.add(FileUtil.toSystemDependentName(aneFile.getParent().getPath()));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet)

Example 65 with THashSet

use of gnu.trove.THashSet in project intellij-plugins by JetBrains.

the class AirPackageAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null)
        return;
    final AirPackageDialog dialog = new AirPackageDialog(project);
    if (!dialog.showAndGet()) {
        return;
    }
    final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCs = dialog.getSelectedBCs();
    final Set<Module> modules = new THashSet<>();
    for (Pair<Module, FlexBuildConfiguration> bc : modulesAndBCs) {
        modules.add(bc.first);
    }
    final CompilerManager compilerManager = CompilerManager.getInstance(project);
    final CompileScope compileScope = compilerManager.createModulesCompileScope(modules.toArray(new Module[modules.size()]), false);
    FlexResourceBuildTargetScopeProvider.setBCsToCompileForPackaging(compileScope, modulesAndBCs);
    compilerManager.make(compileScope, new CompileStatusNotification() {

        public void finished(final boolean aborted, final int errors, final int warnings, final CompileContext compileContext) {
            if (!aborted && errors == 0) {
                createPackages(project, modulesAndBCs, dialog.getPasswords());
            }
        }
    });
}
Also used : CompilerManager(com.intellij.openapi.compiler.CompilerManager) CompileContext(com.intellij.openapi.compiler.CompileContext) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) CompileStatusNotification(com.intellij.openapi.compiler.CompileStatusNotification) CompileScope(com.intellij.openapi.compiler.CompileScope) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair)

Aggregations

THashSet (gnu.trove.THashSet)239 NotNull (org.jetbrains.annotations.NotNull)65 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 Project (com.intellij.openapi.project.Project)35 File (java.io.File)35 THashMap (gnu.trove.THashMap)31 Nullable (org.jetbrains.annotations.Nullable)31 Module (com.intellij.openapi.module.Module)29 IOException (java.io.IOException)24 PsiElement (com.intellij.psi.PsiElement)21 PsiFile (com.intellij.psi.PsiFile)18 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)16 java.util (java.util)16 Element (org.jdom.Element)14 Pair (com.intellij.openapi.util.Pair)13 Logger (com.intellij.openapi.diagnostic.Logger)12 ContainerUtil (com.intellij.util.containers.ContainerUtil)12 Document (com.intellij.openapi.editor.Document)11 Library (com.intellij.openapi.roots.libraries.Library)11 StringUtil (com.intellij.openapi.util.text.StringUtil)10