Search in sources :

Example 71 with THashMap

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

the class CommonCodeStyleSettingsManager method writeExternal.

public void writeExternal(@NotNull Element element) throws WriteExternalException {
    synchronized (this) {
        if (myCommonSettingsMap == null) {
            return;
        }
        final Map<String, Language> idToLang = new THashMap<>();
        for (Language language : myCommonSettingsMap.keySet()) {
            idToLang.put(language.getID(), language);
        }
        String[] languages = ArrayUtil.toStringArray(ContainerUtil.union(myUnknownSettingsMap.keySet(), idToLang.keySet()));
        Arrays.sort(languages);
        for (String id : languages) {
            final Language language = idToLang.get(id);
            if (language != null) {
                final CommonCodeStyleSettings commonSettings = myCommonSettingsMap.get(language);
                Element commonSettingsElement = new Element(COMMON_SETTINGS_TAG);
                commonSettings.writeExternal(commonSettingsElement);
                commonSettingsElement.setAttribute(LANGUAGE_ATTR, language.getID());
                if (!commonSettingsElement.getChildren().isEmpty()) {
                    element.addContent(commonSettingsElement);
                }
            } else {
                final Content unknown = myUnknownSettingsMap.get(id);
                if (unknown != null) {
                    element.addContent(unknown.detach());
                }
            }
        }
    }
}
Also used : THashMap(gnu.trove.THashMap) Language(com.intellij.lang.Language) Content(org.jdom.Content) Element(org.jdom.Element)

Example 72 with THashMap

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

the class UpdateFoldRegionsOperation method run.

@Override
public void run() {
    EditorFoldingInfo info = EditorFoldingInfo.get(myEditor);
    FoldingModelEx foldingModel = (FoldingModelEx) myEditor.getFoldingModel();
    Map<TextRange, Boolean> rangeToExpandStatusMap = new THashMap<>();
    // FoldingUpdate caches instances of our object, so they must be immutable.
    FoldingUpdate.FoldingMap elementsToFold = new FoldingUpdate.FoldingMap(myElementsToFoldMap);
    removeInvalidRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap);
    Map<FoldRegion, Boolean> shouldExpand = new THashMap<>();
    Map<FoldingGroup, Boolean> groupExpand = new THashMap<>();
    List<FoldRegion> newRegions = addNewRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap, shouldExpand, groupExpand);
    applyExpandStatus(newRegions, shouldExpand, groupExpand);
    foldingModel.clearDocumentRangesModificationStatus();
}
Also used : FoldingGroup(com.intellij.openapi.editor.FoldingGroup) FoldRegion(com.intellij.openapi.editor.FoldRegion) TextRange(com.intellij.openapi.util.TextRange) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) THashMap(gnu.trove.THashMap)

Example 73 with THashMap

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

the class GenericsHighlightUtil method checkUnrelatedConcrete.

static HighlightInfo checkUnrelatedConcrete(@NotNull PsiClass psiClass, @NotNull PsiIdentifier classIdentifier) {
    final PsiClass superClass = psiClass.getSuperClass();
    if (superClass != null && superClass.hasTypeParameters()) {
        final Collection<HierarchicalMethodSignature> visibleSignatures = superClass.getVisibleSignatures();
        final Map<MethodSignature, PsiMethod> overrideEquivalent = new THashMap<>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
        for (HierarchicalMethodSignature hms : visibleSignatures) {
            final PsiMethod method = hms.getMethod();
            if (method.isConstructor())
                continue;
            if (method.hasModifierProperty(PsiModifier.ABSTRACT) || method.hasModifierProperty(PsiModifier.DEFAULT))
                continue;
            if (psiClass.findMethodsBySignature(method, false).length > 0)
                continue;
            final PsiClass containingClass = method.getContainingClass();
            if (containingClass == null)
                continue;
            final PsiSubstitutor containingClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, psiClass, PsiSubstitutor.EMPTY);
            final PsiSubstitutor finalSubstitutor = PsiSuperMethodUtil.obtainFinalSubstitutor(containingClass, containingClassSubstitutor, hms.getSubstitutor(), false);
            final MethodSignatureBackedByPsiMethod signature = MethodSignatureBackedByPsiMethod.create(method, finalSubstitutor, false);
            final PsiMethod foundMethod = overrideEquivalent.get(signature);
            PsiClass foundMethodContainingClass;
            if (foundMethod != null && !foundMethod.hasModifierProperty(PsiModifier.ABSTRACT) && !foundMethod.hasModifierProperty(PsiModifier.DEFAULT) && (foundMethodContainingClass = foundMethod.getContainingClass()) != null) {
                final String description = "Methods " + JavaHighlightUtil.formatMethod(foundMethod) + " from " + HighlightUtil.formatClass(foundMethodContainingClass) + " and " + JavaHighlightUtil.formatMethod(method) + " from " + HighlightUtil.formatClass(containingClass) + " are inherited with the same signature";
                final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(description).create();
                //todo override fix
                return info;
            }
            overrideEquivalent.put(signature, method);
        }
    }
    return null;
}
Also used : THashMap(gnu.trove.THashMap) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

Example 74 with THashMap

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

the class JavaBuilder method buildOutputDirectoriesMap.

private static Map<File, Set<File>> buildOutputDirectoriesMap(CompileContext context, ModuleChunk chunk) {
    final Map<File, Set<File>> map = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
    for (ModuleBuildTarget target : chunk.getTargets()) {
        final File outputDir = target.getOutputDir();
        if (outputDir == null) {
            continue;
        }
        final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        for (JavaSourceRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
            roots.add(descriptor.root);
        }
        map.put(outputDir, roots);
    }
    return map;
}
Also used : THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) THashSet(gnu.trove.THashSet)

Example 75 with THashMap

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

the class CompilerEncodingConfiguration method computeModuleCharsetMap.

private Map<JpsModule, Set<String>> computeModuleCharsetMap() {
    final Map<JpsModule, Set<String>> map = new THashMap<>();
    final Iterable<JavaBuilderExtension> builderExtensions = JpsServiceManager.getInstance().getExtensions(JavaBuilderExtension.class);
    for (Map.Entry<String, String> entry : myUrlToCharset.entrySet()) {
        final String fileUrl = entry.getKey();
        final String charset = entry.getValue();
        File file = JpsPathUtil.urlToFile(fileUrl);
        if (charset == null || (!file.isDirectory() && !shouldHonorEncodingForCompilation(builderExtensions, file))) {
            continue;
        }
        final JavaSourceRootDescriptor rootDescriptor = myRootsIndex.findJavaRootDescriptor(null, file);
        if (rootDescriptor == null) {
            continue;
        }
        final JpsModule module = rootDescriptor.target.getModule();
        Set<String> set = map.get(module);
        if (set == null) {
            set = new LinkedHashSet<>();
            map.put(module, set);
            // need to search parents only once because
            // file parent's charset, if explicitly defined, has higher priority than the charset assigned to individual files
            // we deliberately check parents until the source roots
            final File sourceRoot = rootDescriptor.root;
            File current = FileUtilRt.getParentFile(file);
            String parentCharset = null;
            while (current != null) {
                final String currentCharset = lookupCharsetMap(current);
                if (currentCharset != null) {
                    parentCharset = currentCharset;
                }
                if (FileUtil.filesEqual(current, sourceRoot)) {
                    break;
                }
                current = FileUtilRt.getParentFile(current);
            }
            if (parentCharset != null) {
                set.add(parentCharset);
            }
        }
        set.add(charset);
    }
    for (JpsModule module : myJpsModel.getProject().getModules()) {
        for (JpsModuleSourceRoot srcRoot : module.getSourceRoots()) {
            final String encoding = getEncoding(srcRoot.getFile());
            if (encoding != null) {
                Set<String> charsets = map.get(module);
                if (charsets == null) {
                    charsets = new LinkedHashSet<>();
                    map.put(module, charsets);
                }
                charsets.add(encoding);
            }
        }
    }
    return map;
}
Also used : JavaBuilderExtension(org.jetbrains.jps.builders.java.JavaBuilderExtension) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) THashMap(gnu.trove.THashMap) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) THashMap(gnu.trove.THashMap) 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