use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class PsiClassImplUtil method isMethodEquivalentTo.
public static boolean isMethodEquivalentTo(@NotNull PsiMethod method1, PsiElement another) {
if (method1 == another)
return true;
if (!(another instanceof PsiMethod))
return false;
PsiMethod method2 = (PsiMethod) another;
if (!another.isValid())
return false;
if (!method1.getName().equals(method2.getName()))
return false;
PsiClass aClass1 = method1.getContainingClass();
PsiClass aClass2 = method2.getContainingClass();
PsiManager manager = method1.getManager();
if (!(aClass1 != null && aClass2 != null && manager.areElementsEquivalent(aClass1, aClass2)))
return false;
PsiParameter[] parameters1 = method1.getParameterList().getParameters();
PsiParameter[] parameters2 = method2.getParameterList().getParameters();
if (parameters1.length != parameters2.length)
return false;
for (int i = 0; i < parameters1.length; i++) {
PsiParameter parameter1 = parameters1[i];
PsiParameter parameter2 = parameters2[i];
PsiType type1 = parameter1.getType();
PsiType type2 = parameter2.getType();
if (!compareParamTypes(manager, type1, type2, new HashSet<>()))
return false;
}
return true;
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class AbstractRunConfigurationTypeUsagesCollector method getProjectUsages.
@NotNull
@Override
public final Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) {
final Set<String> runConfigurationTypes = new HashSet<>();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
if (project.isDisposed())
return;
final RunManager runManager = RunManager.getInstance(project);
for (RunnerAndConfigurationSettings settings : runManager.getAllSettings()) {
RunConfiguration runConfiguration = settings.getConfiguration();
if (runConfiguration != null && isApplicable(runManager, settings)) {
final ConfigurationFactory configurationFactory = runConfiguration.getFactory();
final ConfigurationType configurationType = configurationFactory.getType();
final StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(configurationType.getId());
if (configurationType.getConfigurationFactories().length > 1) {
keyBuilder.append(".").append(configurationFactory.getName());
}
runConfigurationTypes.add(keyBuilder.toString());
}
}
}
});
return ContainerUtil.map2Set(runConfigurationTypes, runConfigurationType -> new UsageDescriptor(runConfigurationType, 1));
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class ModuleRunConfigurationManager method readExternal.
public void readExternal(@NotNull final Element element) {
LOG.debug("readExternal(" + myModule + ")");
myUnloadedElements = null;
final Set<String> existing = new HashSet<>();
for (final Element child : element.getChildren()) {
final RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true);
if (configuration == null && Comparing.strEqual(element.getName(), RunManagerImpl.CONFIGURATION)) {
if (myUnloadedElements == null)
myUnloadedElements = new ArrayList<>(2);
myUnloadedElements.add(element);
}
if (configuration != null) {
existing.add(configuration.getUniqueID());
}
}
for (final RunConfiguration configuration : myManager.getAllConfigurationsList()) {
if (!usesMyModule(configuration)) {
RunnerAndConfigurationSettings settings = myManager.getSettings(configuration);
if (settings != null) {
existing.add(settings.getUniqueID());
}
}
}
myManager.removeNotExistingSharedConfigurations(existing);
// IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read
myManager.setOrdered(false);
myManager.getSortedConfigurations();
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method cleanup.
private void cleanup(@NotNull final AnalysisScope scope, @NotNull InspectionProfile profile, @Nullable final Runnable postRunnable, @Nullable final String commandName) {
setCurrentScope(scope);
final int fileCount = scope.getFileCount();
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
final SearchScope searchScope = ReadAction.compute(scope::toSearchScope);
final TextRange range;
if (searchScope instanceof LocalSearchScope) {
final PsiElement[] elements = ((LocalSearchScope) searchScope).getScope();
range = elements.length == 1 ? ReadAction.compute(elements[0]::getTextRange) : null;
} else {
range = null;
}
final Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> {
assert tools != null;
return tools.getTool().getTool() instanceof CleanupLocalInspectionTool;
});
boolean includeDoNotShow = includeDoNotShow(profile);
final RefManagerImpl refManager = (RefManagerImpl) getRefManager();
refManager.inspectionReadActionStarted();
List<ProblemDescriptor> descriptors = new ArrayList<>();
Set<PsiFile> files = new HashSet<>();
try {
scope.accept(new PsiElementVisitor() {
private int myCount;
@Override
public void visitFile(PsiFile file) {
if (progressIndicator != null) {
progressIndicator.setFraction((double) ++myCount / fileCount);
}
if (isBinary(file))
return;
final List<LocalInspectionToolWrapper> lTools = new ArrayList<>();
for (final Tools tools : inspectionTools) {
final InspectionToolWrapper tool = tools.getEnabledTool(file, includeDoNotShow);
if (tool instanceof LocalInspectionToolWrapper) {
lTools.add((LocalInspectionToolWrapper) tool);
tool.initialize(GlobalInspectionContextImpl.this);
}
}
if (!lTools.isEmpty()) {
try {
final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(getProject()).getDocument(file), range != null ? range.getStartOffset() : 0, range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, HighlightInfoProcessor.getEmpty());
Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools);
ApplicationManager.getApplication().runReadAction(runnable);
final Set<ProblemDescriptor> localDescriptors = new TreeSet<>(CommonProblemDescriptor.DESCRIPTOR_COMPARATOR);
for (LocalInspectionToolWrapper tool : lTools) {
InspectionToolPresentation toolPresentation = getPresentation(tool);
for (CommonProblemDescriptor descriptor : toolPresentation.getProblemDescriptors()) {
if (descriptor instanceof ProblemDescriptor) {
localDescriptors.add((ProblemDescriptor) descriptor);
}
}
}
if (searchScope instanceof LocalSearchScope) {
for (Iterator<ProblemDescriptor> iterator = localDescriptors.iterator(); iterator.hasNext(); ) {
final ProblemDescriptor descriptor = iterator.next();
final TextRange infoRange = descriptor instanceof ProblemDescriptorBase ? ((ProblemDescriptorBase) descriptor).getTextRange() : null;
if (infoRange != null && !((LocalSearchScope) searchScope).containsRange(file, infoRange)) {
iterator.remove();
}
}
}
if (!localDescriptors.isEmpty()) {
descriptors.addAll(localDescriptors);
files.add(file);
}
} finally {
myPresentationMap.clear();
}
}
}
});
} finally {
refManager.inspectionReadActionFinished();
}
if (files.isEmpty()) {
GuiUtils.invokeLaterIfNeeded(() -> {
if (commandName != null) {
NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message", scope.getFileCount(), scope.getDisplayName()), MessageType.INFO).notify(getProject());
}
if (postRunnable != null) {
postRunnable.run();
}
}, ModalityState.defaultModalityState());
return;
}
Runnable runnable = () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(files))
return;
CleanupInspectionIntention.applyFixesNoSort(getProject(), "Code Cleanup", descriptors, null);
if (postRunnable != null) {
postRunnable.run();
}
};
TransactionGuard.submitTransaction(getProject(), runnable);
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class InspectionRVContentProviderImpl method appendDescriptor.
@Override
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context, @NotNull final InspectionToolWrapper toolWrapper, @NotNull final RefEntityContainer container, @NotNull final InspectionTreeNode pNode, final boolean canPackageRepeat) {
final RefEntity refElement = container.getRefEntity();
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
final CommonProblemDescriptor[] problems = ((RefEntityContainer<CommonProblemDescriptor>) container).getDescriptors();
if (problems != null) {
final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
for (CommonProblemDescriptor problem : problems) {
assert problem != null;
elemNode.insertByOrder(ReadAction.compute(() -> new ProblemDescriptionNode(refElement, problem, toolWrapper, presentation)), true);
elemNode.setProblem(elemNode.getChildCount() == 1 ? problems[0] : null);
}
} else {
if (canPackageRepeat && pNode instanceof InspectionPackageNode) {
final Set<RefEntity> currentElements = presentation.getContent().get(((InspectionPackageNode) pNode).getPackageName());
if (currentElements != null) {
final Set<RefEntity> currentEntities = new HashSet<>(currentElements);
if (RefUtil.contains(refElement, currentEntities))
return;
}
}
addNodeToParent(container, presentation, pNode);
}
}
Aggregations