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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations