use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class RenameAliasedUsagesUtil method filterAliasedRefs.
public static Collection<PsiReference> filterAliasedRefs(Collection<PsiReference> refs, PsiElement element) {
Map<GroovyFile, String> aliases = new HashMap<>();
ArrayList<PsiReference> result = new ArrayList<>();
for (PsiReference ref : refs) {
final PsiElement e = ref.getElement();
if (e == null)
continue;
if (skipReference(element, aliases, e))
continue;
result.add(ref);
}
return result;
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class SchemaDefinitionsSearch method execute.
@Override
public boolean execute(@NotNull final PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
if (queryParameters instanceof XmlTagImpl) {
final XmlTagImpl xml = (XmlTagImpl) queryParameters;
if (ReadAction.compute(() -> isTypeElement(xml))) {
final Collection<SchemaTypeInfo> infos = ApplicationManager.getApplication().runReadAction(new Computable<Collection<SchemaTypeInfo>>() {
@Override
public Collection<SchemaTypeInfo> compute() {
return gatherInheritors(xml);
}
});
if (infos != null && !infos.isEmpty()) {
final XmlFile file = XmlUtil.getContainingFile(xml);
final Project project = file.getProject();
final Module module = ModuleUtilCore.findModuleForPsiElement(queryParameters);
//if (module == null) return false;
final VirtualFile vf = file.getVirtualFile();
String thisNs = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return XmlNamespaceIndex.getNamespace(vf, project, file);
}
});
thisNs = thisNs == null ? getDefaultNs(file) : thisNs;
// so thisNs can be null
if (thisNs == null)
return false;
final ArrayList<SchemaTypeInfo> infosLst = new ArrayList<>(infos);
Collections.sort(infosLst);
final Map<String, Set<XmlFile>> nsMap = new HashMap<>();
for (final SchemaTypeInfo info : infosLst) {
Set<XmlFile> targetFiles = nsMap.get(info.getNamespaceUri());
if (targetFiles == null) {
targetFiles = new HashSet<>();
if (Comparing.equal(info.getNamespaceUri(), thisNs)) {
targetFiles.add(file);
}
final Collection<XmlFile> files = ApplicationManager.getApplication().runReadAction(new Computable<Collection<XmlFile>>() {
@Override
public Collection<XmlFile> compute() {
return XmlUtil.findNSFilesByURI(info.getNamespaceUri(), project, module);
}
});
if (files != null) {
targetFiles.addAll(files);
}
nsMap.put(info.getNamespaceUri(), targetFiles);
}
if (!targetFiles.isEmpty()) {
for (final XmlFile targetFile : targetFiles) {
ApplicationManager.getApplication().runReadAction(() -> {
final String prefixByURI = XmlUtil.findNamespacePrefixByURI(targetFile, info.getNamespaceUri());
if (prefixByURI == null)
return;
final PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof XmlTagImpl) {
if (isCertainTypeElement((XmlTagImpl) element, info.getTagName(), prefixByURI) || isElementWithEmbeddedType((XmlTagImpl) element, info.getTagName(), prefixByURI)) {
consumer.process(element);
return false;
}
}
return true;
}
};
XmlUtil.processXmlElements(targetFile, processor, true);
});
}
}
}
}
}
}
return true;
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class DeleteFromFavoritesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
if (project == null || builder == null) {
return;
}
Set<Object> selection = builder.getSelectedElements();
if (selection.isEmpty()) {
return;
}
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
return;
}
FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
assert roots != null && tree != null;
Map<String, List<AbstractTreeNode>> toRemove = new HashMap<>();
for (FavoritesTreeNodeDescriptor root : roots) {
final AbstractTreeNode node = root.getElement();
if (node instanceof FavoritesListNode) {
favoritesManager.removeFavoritesList((String) node.getValue());
} else {
final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
LOG.assertTrue(listNode != null);
final String name = listNode.getName();
if (!toRemove.containsKey(name)) {
toRemove.put(name, new ArrayList<>());
}
toRemove.get(name).add(node);
}
}
for (String name : toRemove.keySet()) {
favoritesManager.removeRoot(name, toRemove.get(name));
}
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class ExternalDiffToolUtil method executeMerge.
public static void executeMerge(@Nullable Project project, @NotNull ExternalDiffSettings settings, @NotNull ThreesideMergeRequest request) throws IOException, ExecutionException {
boolean success = false;
OutputFile outputFile = null;
List<InputFile> inputFiles = new ArrayList<>();
try {
DiffContent outputContent = request.getOutputContent();
List<? extends DiffContent> contents = request.getContents();
List<String> titles = request.getContentTitles();
String windowTitle = request.getTitle();
assert contents.size() == 3;
assert titles.size() == contents.size();
for (int i = 0; i < contents.size(); i++) {
DiffContent content = contents.get(i);
FileNameInfo fileName = FileNameInfo.create(contents, titles, windowTitle, i);
inputFiles.add(createFile(content, fileName));
}
outputFile = createOutputFile(outputContent, FileNameInfo.createMergeResult(outputContent, windowTitle));
Map<String, String> patterns = new HashMap<>();
patterns.put("%1", inputFiles.get(0).getPath());
patterns.put("%2", inputFiles.get(2).getPath());
patterns.put("%3", inputFiles.get(1).getPath());
patterns.put("%4", outputFile.getPath());
final Process process = execute(settings.getMergeExePath(), settings.getMergeParameters(), patterns);
if (settings.isMergeTrustExitCode()) {
final Ref<Boolean> resultRef = new Ref<>();
ProgressManager.getInstance().run(new Task.Modal(project, "Waiting for External Tool", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final Semaphore semaphore = new Semaphore(0);
final Thread waiter = new Thread("external process waiter") {
@Override
public void run() {
try {
resultRef.set(process.waitFor() == 0);
} catch (InterruptedException ignore) {
} finally {
semaphore.release();
}
}
};
waiter.start();
try {
while (true) {
indicator.checkCanceled();
if (semaphore.tryAcquire(200, TimeUnit.MILLISECONDS))
break;
}
} catch (InterruptedException ignore) {
} finally {
waiter.interrupt();
}
}
});
success = resultRef.get() == Boolean.TRUE;
} else {
ProgressManager.getInstance().run(new Task.Modal(project, "Launching External Tool", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
TimeoutUtil.sleep(1000);
}
});
success = Messages.showYesNoDialog(project, "Press \"Mark as Resolved\" when you finish resolving conflicts in the external tool", "Merge In External Tool", "Mark as Resolved", "Revert", null) == Messages.YES;
}
if (success)
outputFile.apply();
} finally {
request.applyResult(success ? MergeResult.RESOLVED : MergeResult.CANCEL);
if (outputFile != null)
outputFile.cleanup();
for (InputFile file : inputFiles) {
file.cleanup();
}
}
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class JpsRunConfigurationSerializer method loadRunConfigurations.
public static void loadRunConfigurations(@NotNull JpsProject project, @Nullable Element runManagerTag) {
Map<String, JpsRunConfigurationPropertiesSerializer<?>> serializers = new HashMap<>();
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
for (JpsRunConfigurationPropertiesSerializer<?> serializer : extension.getRunConfigurationPropertiesSerializers()) {
serializers.put(serializer.getTypeId(), serializer);
}
}
for (Element configurationTag : JDOMUtil.getChildren(runManagerTag, "configuration")) {
if (Boolean.parseBoolean(configurationTag.getAttributeValue("default"))) {
continue;
}
String typeId = configurationTag.getAttributeValue("type");
JpsRunConfigurationPropertiesSerializer<?> serializer = serializers.get(typeId);
String name = configurationTag.getAttributeValue("name");
if (serializer != null) {
loadRunConfiguration(name, configurationTag, serializer, project);
} else if (typeId != null) {
project.addRunConfiguration(name, new JpsUnknownRunConfigurationType(typeId), JpsElementFactory.getInstance().createDummyElement());
} else {
LOG.info("Run configuration '" + name + "' wasn't loaded because 'type' attribute is missing");
}
}
}
Aggregations