Search in sources :

Example 1 with TObjectIntHashMap

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

the class GroovyIntroduceParameterUtil method findParametersToRemove.

public static TObjectIntHashMap<GrParameter> findParametersToRemove(IntroduceParameterInfo helper) {
    final TObjectIntHashMap<GrParameter> result = new TObjectIntHashMap<>();
    final TextRange range = ExtractUtil.getRangeOfRefactoring(helper);
    GrParameter[] parameters = helper.getToReplaceIn().getParameters();
    for (int i = 0; i < parameters.length; i++) {
        GrParameter parameter = parameters[i];
        if (shouldRemove(parameter, range.getStartOffset(), range.getEndOffset())) {
            result.put(parameter, i);
        }
    }
    return result;
}
Also used : TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TextRange(com.intellij.openapi.util.TextRange) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)

Example 2 with TObjectIntHashMap

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

the class ResourceBundleFileStructureViewElement method getChildrenIdShowOnlyIncomplete.

private static MultiMap<String, IProperty> getChildrenIdShowOnlyIncomplete(ResourceBundle resourceBundle) {
    final MultiMap<String, IProperty> propertyNames = MultiMap.createLinked();
    TObjectIntHashMap<String> occurrences = new TObjectIntHashMap<>();
    for (PropertiesFile file : resourceBundle.getPropertiesFiles()) {
        MultiMap<String, IProperty> currentFilePropertyNames = MultiMap.createLinked();
        for (IProperty property : file.getProperties()) {
            String name = property.getKey();
            currentFilePropertyNames.putValue(name, property);
        }
        propertyNames.putAllValues(currentFilePropertyNames);
        for (String propertyName : currentFilePropertyNames.keySet()) {
            if (occurrences.contains(propertyName)) {
                occurrences.adjustValue(propertyName, 1);
            } else {
                occurrences.put(propertyName, 1);
            }
        }
    }
    final int targetOccurrences = resourceBundle.getPropertiesFiles().size();
    occurrences.forEachEntry(new TObjectIntProcedure<String>() {

        @Override
        public boolean execute(String propertyName, int occurrences) {
            if (occurrences == targetOccurrences) {
                propertyNames.remove(propertyName);
            }
            return true;
        }
    });
    return propertyNames;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 3 with TObjectIntHashMap

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

the class BuildOperations method cleanOutputsCorrespondingToChangedFiles.

public static <R extends BuildRootDescriptor, T extends BuildTarget<R>> Map<T, Set<File>> cleanOutputsCorrespondingToChangedFiles(final CompileContext context, DirtyFilesHolder<R, T> dirtyFilesHolder) throws ProjectBuildException {
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    try {
        final Map<T, Set<File>> cleanedSources = new HashMap<>();
        final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        final Collection<String> deletedPaths = new ArrayList<>();
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<R, T>() {

            // cache the mapping locally
            private final Map<T, SourceToOutputMapping> mappingsCache = new HashMap<>();

            private final TObjectIntHashMap<T> idsCache = new TObjectIntHashMap<>();

            @Override
            public boolean apply(T target, File file, R sourceRoot) throws IOException {
                SourceToOutputMapping srcToOut = mappingsCache.get(target);
                if (srcToOut == null) {
                    srcToOut = dataManager.getSourceToOutputMap(target);
                    mappingsCache.put(target, srcToOut);
                }
                final int targetId;
                if (!idsCache.containsKey(target)) {
                    targetId = dataManager.getTargetsState().getBuildTargetId(target);
                    idsCache.put(target, targetId);
                } else {
                    targetId = idsCache.get(target);
                }
                final String srcPath = file.getPath();
                final Collection<String> outputs = srcToOut.getOutputs(srcPath);
                if (outputs != null) {
                    final boolean shouldPruneOutputDirs = target instanceof ModuleBasedTarget;
                    final List<String> deletedForThisSource = new ArrayList<>(outputs.size());
                    for (String output : outputs) {
                        deleteRecursively(output, deletedForThisSource, shouldPruneOutputDirs ? dirsToDelete : null);
                    }
                    deletedPaths.addAll(deletedForThisSource);
                    dataManager.getOutputToTargetRegistry().removeMapping(deletedForThisSource, targetId);
                    Set<File> cleaned = cleanedSources.get(target);
                    if (cleaned == null) {
                        cleaned = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                        cleanedSources.put(target, cleaned);
                    }
                    cleaned.add(file);
                }
                return true;
            }
        });
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled()) {
                logger.logDeletedFiles(deletedPaths);
            }
        }
        if (!deletedPaths.isEmpty()) {
            context.processMessage(new FileDeletedEvent(deletedPaths));
        }
        // attempting to delete potentially empty directories
        FSOperations.pruneEmptyDirs(context, dirsToDelete);
        return cleanedSources;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileDeletedEvent(org.jetbrains.jps.incremental.messages.FileDeletedEvent) File(java.io.File)

Example 4 with TObjectIntHashMap

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

the class SeverityRegistrar method fromList.

@NotNull
private static OrderMap fromList(@NotNull List<HighlightSeverity> orderList) {
    if (orderList.size() != new HashSet<>(orderList).size()) {
        LOG.error("Severities order list MUST contain only unique severities: " + orderList);
    }
    TObjectIntHashMap<HighlightSeverity> map = new TObjectIntHashMap<>();
    for (int i = 0; i < orderList.size(); i++) {
        HighlightSeverity severity = orderList.get(i);
        map.put(severity, i);
    }
    return new OrderMap(map);
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with TObjectIntHashMap

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

the class AddMissingRequiredAnnotationParametersFix method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    final PsiNameValuePair[] addedParameters = myAnnotation.getParameterList().getAttributes();
    final TObjectIntHashMap<String> annotationsOrderMap = getAnnotationsOrderMap();
    final SortedSet<Pair<String, PsiAnnotationMemberValue>> newParameters = new TreeSet<>(Comparator.comparingInt(o -> annotationsOrderMap.get(o.getFirst())));
    final boolean order = isAlreadyAddedOrdered(annotationsOrderMap, addedParameters);
    if (order) {
        if (addedParameters.length != 0) {
            final PsiAnnotationParameterList parameterList = myAnnotation.getParameterList();
            parameterList.deleteChildRange(addedParameters[0], addedParameters[addedParameters.length - 1]);
            for (final PsiNameValuePair addedParameter : addedParameters) {
                final String name = addedParameter.getName();
                final PsiAnnotationMemberValue value = addedParameter.getValue();
                if (name == null || value == null) {
                    LOG.error(String.format("Invalid annotation parameter name = %s, value = %s", name, value));
                    continue;
                }
                newParameters.add(Pair.create(name, value));
            }
        }
    }
    final PsiExpression nullValue = JavaPsiFacade.getElementFactory(project).createExpressionFromText(PsiKeyword.NULL, null);
    for (final String misssedParameter : myMissedElements) {
        newParameters.add(Pair.create(misssedParameter, nullValue));
    }
    TemplateBuilderImpl builder = null;
    for (final Pair<String, PsiAnnotationMemberValue> newParameter : newParameters) {
        final PsiAnnotationMemberValue value = myAnnotation.setDeclaredAttributeValue(newParameter.getFirst(), newParameter.getSecond());
        if (myMissedElements.contains(newParameter.getFirst())) {
            if (builder == null) {
                builder = new TemplateBuilderImpl(myAnnotation.getParameterList());
            }
            builder.replaceElement(value, new EmptyExpression(), true);
        }
    }
    editor.getCaretModel().moveToOffset(myAnnotation.getParameterList().getTextRange().getStartOffset());
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    final Document document = documentManager.getDocument(file);
    if (document == null) {
        throw new IllegalStateException();
    }
    documentManager.doPostponedOperationsAndUnblockDocument(document);
    TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), null);
}
Also used : QuickFixBundle(com.intellij.codeInsight.daemon.QuickFixBundle) IncorrectOperationException(com.intellij.util.IncorrectOperationException) SortedSet(java.util.SortedSet) StringUtil(com.intellij.openapi.util.text.StringUtil) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) Document(com.intellij.openapi.editor.Document) Collection(java.util.Collection) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) Editor(com.intellij.openapi.editor.Editor) TreeSet(java.util.TreeSet) TemplateManager(com.intellij.codeInsight.template.TemplateManager) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Document(com.intellij.openapi.editor.Document) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) TreeSet(java.util.TreeSet) Pair(com.intellij.openapi.util.Pair)

Aggregations

TObjectIntHashMap (gnu.trove.TObjectIntHashMap)20 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ResourceType (com.android.resources.ResourceType)3 Pair (com.intellij.openapi.util.Pair)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)2 PsiClass (com.intellij.psi.PsiClass)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Pair (com.android.util.Pair)1 QuickFixBundle (com.intellij.codeInsight.daemon.QuickFixBundle)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)1 TemplateManager (com.intellij.codeInsight.template.TemplateManager)1 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 PsiFragment (com.intellij.dupLocator.util.PsiFragment)1