Search in sources :

Example 46 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class DirectoryStorageUtil method loadFrom.

@NotNull
public static Map<String, Element> loadFrom(@Nullable VirtualFile dir, @Nullable PathMacroSubstitutor pathMacroSubstitutor) {
    if (dir == null || !dir.exists()) {
        return Collections.emptyMap();
    }
    StringInterner interner = new StringInterner();
    Map<String, Element> fileToState = new THashMap<>();
    for (VirtualFile file : dir.getChildren()) {
        // ignore system files like .DS_Store on Mac
        if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), FileStorageCoreUtil.DEFAULT_EXT)) {
            continue;
        }
        try {
            if (file.getLength() == 0) {
                LOG.warn("Ignore empty file " + file.getPath());
                continue;
            }
            Element element = JDOMUtil.load(file.getInputStream());
            String componentName = FileStorageCoreUtil.getComponentNameIfValid(element);
            if (componentName == null) {
                continue;
            }
            if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) {
                LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl());
                continue;
            }
            List<Element> elementChildren = element.getChildren();
            if (elementChildren.isEmpty()) {
                continue;
            }
            Element state = (Element) elementChildren.get(0).detach();
            if (JDOMUtil.isEmpty(state)) {
                continue;
            }
            JDOMUtil.internElement(state, interner);
            if (pathMacroSubstitutor != null) {
                pathMacroSubstitutor.expandPaths(state);
                if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
                    ((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(componentName, PathMacrosCollector.getMacroNames(state));
                }
            }
            fileToState.put(file.getName(), state);
        } catch (Throwable e) {
            LOG.warn("Unable to load state", e);
        }
    }
    return fileToState;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringInterner(com.intellij.util.containers.StringInterner) THashMap(gnu.trove.THashMap) Element(org.jdom.Element) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class ModuleManagerImpl method loadModules.

protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
    myFailedModulePaths.clear();
    if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
        return;
    }
    myFailedModulePaths.addAll(myModulePathsToLoad);
    ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
    progressIndicator.setText("Loading modules...");
    progressIndicator.setText2("");
    List<Module> modulesWithUnknownTypes = new SmartList<>();
    List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
    ModuleGroupInterner groupInterner = new ModuleGroupInterner();
    ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
    List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
    Set<String> paths = new THashSet<>();
    boolean parallel = Registry.is("parallel.modules.loading");
    for (ModulePath modulePath : myModulePathsToLoad) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            String path = modulePath.getPath();
            if (!paths.add(path))
                continue;
            if (!parallel) {
                tasks.add(Pair.create(null, modulePath));
                continue;
            }
            ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
            Future<Module> future = service.submit(() -> {
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
                try {
                    return computable.compute();
                } catch (IOException e) {
                    reportError(errors, modulePath, e);
                } catch (Exception e) {
                    LOG.error(e);
                }
                return null;
            });
            tasks.add(Pair.create(future, modulePath));
        } catch (IOException e) {
            reportError(errors, modulePath, e);
        }
    }
    for (Pair<Future<Module>, ModulePath> task : tasks) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            Module module;
            if (parallel) {
                module = task.first.get();
            } else {
                module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
            }
            if (module == null)
                continue;
            if (isUnknownModuleType(module)) {
                modulesWithUnknownTypes.add(module);
            }
            ModulePath modulePath = task.second;
            final String groupPathString = modulePath.getGroup();
            if (groupPathString != null) {
                // model should be updated too
                groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
            }
            myFailedModulePaths.remove(modulePath);
        } catch (IOException e) {
            reportError(errors, task.second, e);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
    service.shutdown();
    progressIndicator.checkCanceled();
    Application app = ApplicationManager.getApplication();
    if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
        Map<String, Module> track = new THashMap<>();
        for (Module module : moduleModel.getModules()) {
            for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
                Module oldModule = track.put(url, module);
                if (oldModule != null) {
                    //Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
                    //VirtualFilePointer pointer = track1.get(url);
                    LOG.error("duplicated content url: " + url);
                }
            }
        }
    }
    onModuleLoadErrors(moduleModel, errors);
    showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SmartList(com.intellij.util.SmartList) Application(com.intellij.openapi.application.Application)

Example 48 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class MethodParameterPanel method resetImpl.

protected void resetImpl() {
    setPsiClass(myOrigInjection.getClassName());
    rebuildTreeModel();
    final THashMap<String, MethodParameterInjection.MethodInfo> map = new THashMap<>();
    for (PsiMethod method : myData.keySet()) {
        final MethodParameterInjection.MethodInfo methodInfo = myData.get(method);
        map.put(methodInfo.getMethodSignature(), methodInfo);
    }
    for (MethodParameterInjection.MethodInfo info : myOrigInjection.getMethodInfos()) {
        final MethodParameterInjection.MethodInfo curInfo = map.get(info.getMethodSignature());
        if (curInfo != null) {
            System.arraycopy(info.getParamFlags(), 0, curInfo.getParamFlags(), 0, Math.min(info.getParamFlags().length, curInfo.getParamFlags().length));
            curInfo.setReturnFlag(info.isReturnFlag());
        } else {
            final PsiMethod missingMethod = MethodParameterInjection.makeMethod(myProject, info.getMethodSignature());
            myData.put(missingMethod, info.copy());
        }
    }
    refreshTreeStructure();
    final Enumeration enumeration = myRootNode.children();
    while (enumeration.hasMoreElements()) {
        PsiMethod method = (PsiMethod) ((DefaultMutableTreeNode) enumeration.nextElement()).getUserObject();
        assert myData.containsKey(method);
    }
}
Also used : Enumeration(java.util.Enumeration) THashMap(gnu.trove.THashMap) MethodParameterInjection(org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection)

Example 49 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class ShuffleNamesAction method shuffleIds.

private static boolean shuffleIds(PsiFile file, Editor editor) {
    final Map<String, String> map = new THashMap<>();
    final StringBuilder sb = new StringBuilder();
    final StringBuilder quote = new StringBuilder();
    final ArrayList<String> split = new ArrayList<>(100);
    file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof LeafPsiElement) {
                String type = ((LeafPsiElement) element).getElementType().toString();
                String text = element.getText();
                if (text.isEmpty())
                    return;
                for (int i = 0, len = text.length(); i < len / 2; i++) {
                    char c = text.charAt(i);
                    if (c == text.charAt(len - i - 1) && !Character.isLetter(c)) {
                        quote.append(c);
                    } else
                        break;
                }
                boolean isQuoted = quote.length() > 0;
                boolean isNumber = false;
                if (isQuoted || type.equals("ID") || type.contains("IDENT") && !"ts".equals(text) || (isNumber = text.matches("[0-9]+"))) {
                    String replacement = map.get(text);
                    if (replacement == null) {
                        split.addAll(Arrays.asList((isQuoted ? text.substring(quote.length(), text.length() - quote.length()).replace("''", "") : text).split("")));
                        if (!isNumber) {
                            for (ListIterator<String> it = split.listIterator(); it.hasNext(); ) {
                                String s = it.next();
                                if (s.isEmpty()) {
                                    it.remove();
                                    continue;
                                }
                                int c = s.charAt(0);
                                int cap = c & 32;
                                c &= ~cap;
                                c = (char) ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 7) % 26 + 'A') : c) | cap;
                                it.set(String.valueOf((char) c));
                            }
                        }
                        Collections.shuffle(split);
                        if (isNumber && "0".equals(split.get(0))) {
                            split.set(0, "1");
                        }
                        replacement = StringUtil.join(split, "");
                        if (isQuoted) {
                            replacement = quote + replacement + quote.reverse();
                        }
                        map.put(text, replacement);
                    }
                    text = replacement;
                }
                sb.append(text);
                quote.setLength(0);
                split.clear();
            }
            super.visitElement(element);
        }
    });
    editor.getDocument().setText(sb.toString());
    return true;
}
Also used : THashMap(gnu.trove.THashMap) PsiRecursiveElementWalkingVisitor(com.intellij.psi.PsiRecursiveElementWalkingVisitor) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 50 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class EclipseImportBuilder method validate.

@Override
public boolean validate(final Project currentProject, final Project dstProject) {
    final Ref<Exception> refEx = new Ref<>();
    final Set<String> variables = new THashSet<>();
    final Map<String, String> naturesNames = new THashMap<>();
    final List<String> projectsToConvert = getParameters().projectsToConvert;
    final boolean oneProjectToConvert = projectsToConvert.size() == 1;
    final String separator = oneProjectToConvert ? "<br>" : ", ";
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        try {
            for (String path : projectsToConvert) {
                File classPathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
                if (classPathFile.exists()) {
                    EclipseClasspathReader.collectVariables(variables, JDOMUtil.load(classPathFile), path);
                }
                collectUnknownNatures(path, naturesNames, separator);
            }
        } catch (IOException | JDOMException e) {
            refEx.set(e);
        }
    }, EclipseBundle.message("eclipse.import.converting"), false, currentProject);
    if (!refEx.isNull()) {
        Messages.showErrorDialog(dstProject, refEx.get().getMessage(), getTitle());
        return false;
    }
    if (!ProjectMacrosUtil.checkNonIgnoredMacros(dstProject, variables)) {
        return false;
    }
    if (!naturesNames.isEmpty()) {
        final String title = "Unknown Natures Detected";
        final String naturesByProject;
        if (oneProjectToConvert) {
            naturesByProject = naturesNames.values().iterator().next();
        } else {
            naturesByProject = StringUtil.join(naturesNames.keySet(), projectPath -> projectPath + "(" + naturesNames.get(projectPath) + ")", "<br>");
        }
        Notifications.Bus.notify(new Notification(title, title, "Imported projects contain unknown natures:<br>" + naturesByProject + "<br>" + "Some settings may be lost after import.", NotificationType.WARNING));
    }
    return true;
}
Also used : ClassPathStorageUtil(com.intellij.openapi.roots.impl.storage.ClassPathStorageUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) IdeaXml(org.jetbrains.idea.eclipse.IdeaXml) ClasspathStorage(com.intellij.openapi.roots.impl.storage.ClasspathStorage) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) EclipseIcons(icons.EclipseIcons) Library(com.intellij.openapi.roots.libraries.Library) ProjectImportBuilder(com.intellij.projectImport.ProjectImportBuilder) Task(com.intellij.openapi.progress.Task) JDOMException(org.jdom.JDOMException) EclipseUserLibrariesHelper(org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) ModuleManagerImpl(com.intellij.openapi.module.impl.ModuleManagerImpl) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryTablesRegistrar(com.intellij.openapi.roots.libraries.LibraryTablesRegistrar) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) Comparing(com.intellij.openapi.util.Comparing) StartupManager(com.intellij.openapi.startup.StartupManager) JDOMUtil(com.intellij.openapi.util.JDOMUtil) EclipseXml(org.jetbrains.idea.eclipse.EclipseXml) Project(com.intellij.openapi.project.Project) JpsEclipseClasspathSerializer(org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) File(java.io.File) EclipseProjectFinder(org.jetbrains.idea.eclipse.EclipseProjectFinder) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectMacrosUtil(com.intellij.openapi.project.impl.ProjectMacrosUtil) ModifiableArtifactModel(com.intellij.packaging.artifacts.ModifiableArtifactModel) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) EclipseBundle(org.jetbrains.idea.eclipse.EclipseBundle) javax.swing(javax.swing) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) Notification(com.intellij.notification.Notification) Ref(com.intellij.openapi.util.Ref) THashMap(gnu.trove.THashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

THashMap (gnu.trove.THashMap)129 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)16 IOException (java.io.IOException)16 File (java.io.File)15 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)9 List (java.util.List)9 Module (com.intellij.openapi.module.Module)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 Map (java.util.Map)7 java.util (java.util)6 ArrayList (java.util.ArrayList)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5