use of com.intellij.util.PairProcessor in project intellij-community by JetBrains.
the class RepositoryAttachHandler method searchArtifacts.
public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
if (coord == null || coord.length() == 0)
return;
final MavenArtifactInfo template;
if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
} else {
template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
}
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {
public void run(@NotNull ProgressIndicator indicator) {
String[] urls = MavenRepositoryServicesManager.getServiceUrls();
boolean tooManyResults = false;
final AtomicBoolean proceedFlag = new AtomicBoolean(true);
for (int i = 0, length = urls.length; i < length; i++) {
if (!proceedFlag.get())
break;
final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
try {
String serviceUrl = urls[i];
final List<MavenArtifactInfo> artifacts;
artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
if (!artifacts.isEmpty()) {
if (!proceedFlag.get()) {
break;
}
List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
Map<String, MavenRepositoryInfo> map = new THashMap<>();
for (MavenRepositoryInfo repository : repositories) {
map.put(repository.getId(), repository);
}
for (MavenArtifactInfo artifact : artifacts) {
if (artifact == null) {
tooManyResults = true;
} else {
MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
// because it won't be resolved anyway
if (repository == null)
continue;
resultList.add(Pair.create(artifact, repository));
}
}
}
} catch (Exception e) {
MavenLog.LOG.error(e);
} finally {
if (!proceedFlag.get())
break;
final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
}
}
}
});
}
use of com.intellij.util.PairProcessor in project intellij-community by JetBrains.
the class SSBasedInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final Map<Configuration, MatchContext> compiledOptions = SSBasedInspectionCompiledPatternsCache.getCompiledOptions(myConfigurations, holder.getProject());
if (compiledOptions.isEmpty())
return super.buildVisitor(holder, isOnTheFly);
return new PsiElementVisitor() {
final Matcher matcher = new Matcher(holder.getManager().getProject());
final PairProcessor<MatchResult, Configuration> processor = (matchResult, configuration) -> {
PsiElement element = matchResult.getMatch();
String name = configuration.getName();
LocalQuickFix fix = createQuickFix(holder.getManager().getProject(), matchResult, configuration);
holder.registerProblem(holder.getManager().createProblemDescriptor(element, name, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
return true;
};
@Override
public void visitElement(PsiElement element) {
synchronized (LOCK) {
if (LexicalNodesFilter.getInstance().accepts(element))
return;
final SsrFilteringNodeIterator matchedNodes = new SsrFilteringNodeIterator(element);
for (Map.Entry<Configuration, MatchContext> entry : compiledOptions.entrySet()) {
Configuration configuration = entry.getKey();
MatchContext context = entry.getValue();
if (MatcherImpl.checkIfShouldAttemptToMatch(context, matchedNodes)) {
final int nodeCount = context.getPattern().getNodeCount();
try {
matcher.processMatchesInElement(context, configuration, new CountingNodeIterator(nodeCount, matchedNodes), processor);
} catch (StructuralSearchException e) {
if (myProblemsReported.add(configuration.getName())) {
// don't overwhelm the user with messages
Notifications.Bus.notify(new Notification(SSRBundle.message("structural.search.title"), SSRBundle.message("template.problem", configuration.getName()), e.getMessage(), NotificationType.ERROR), element.getProject());
}
}
matchedNodes.reset();
}
}
}
}
};
}
use of com.intellij.util.PairProcessor in project intellij-community by JetBrains.
the class XsdEnumerationDescriptor method processEnumerationImpl.
private boolean processEnumerationImpl(final XmlTag declaration, final PairProcessor<PsiElement, String> pairProcessor, boolean forCompletion) {
XmlAttribute name = declaration.getAttribute("name");
if (name != null && "boolean".equals(name.getValue())) {
XmlAttributeValue valueElement = name.getValueElement();
pairProcessor.process(valueElement, "true");
pairProcessor.process(valueElement, "false");
if (!forCompletion) {
pairProcessor.process(valueElement, "1");
pairProcessor.process(valueElement, "0");
}
myExhaustiveEnum = true;
return true;
} else {
final Ref<Boolean> found = new Ref<>(Boolean.FALSE);
myExhaustiveEnum = XmlUtil.processEnumerationValues(declaration, tag -> {
found.set(Boolean.TRUE);
XmlAttribute name1 = tag.getAttribute("value");
return name1 == null || pairProcessor.process(tag, name1.getValue());
});
return found.get();
}
}
Aggregations