@NotNull public static List<MavenDomDependency> chooseDependencies( Collection<MavenDomDependency> candidates, final Project project) { List<MavenDomDependency> dependencies = new ArrayList<MavenDomDependency>(); MavenDomProjectModelMember[] memberCandidates = ContainerUtil.map2Array( candidates, MavenDomProjectModelMember.class, dependency -> new MavenDomProjectModelMember(dependency)); MemberChooser<MavenDomProjectModelMember> chooser = new MemberChooser<MavenDomProjectModelMember>(memberCandidates, true, true, project) { protected ShowContainersAction getShowContainersAction() { return new ShowContainersAction( MavenDomBundle.message("chooser.show.project.files"), MavenIcons.MavenProject); } @NotNull @Override protected String convertElementText(@NotNull String originalElementText) { return originalElementText; } protected String getAllContainersNodeName() { return MavenDomBundle.message("all.dependencies"); } }; chooser.setTitle(MavenDomBundle.message("dependencies.chooser.title")); chooser.setCopyJavadocVisible(false); chooser.show(); if (chooser.getExitCode() == MemberChooser.OK_EXIT_CODE) { final MavenDomProjectModelMember[] members = chooser.getSelectedElements(new MavenDomProjectModelMember[0]); if (members != null) { dependencies.addAll( ContainerUtil.mapNotNull( members, mavenDomProjectModelMember -> mavenDomProjectModelMember.getDependency())); } } return dependencies; }
private static void addProblem( @NotNull MavenDomDependency dependency, @NotNull Set<MavenDomDependency> dependencies, @NotNull DomElementAnnotationHolder holder) { StringBuffer sb = new StringBuffer(); Set<MavenDomProjectModel> processed = new HashSet<MavenDomProjectModel>(); for (MavenDomDependency domDependency : dependencies) { if (dependency.equals(domDependency)) continue; MavenDomProjectModel model = domDependency.getParentOfType(MavenDomProjectModel.class, false); if (model != null && !processed.contains(model)) { if (processed.size() > 0) sb.append(", "); sb.append(createLinkText(model, domDependency)); processed.add(model); } } holder.createProblem( dependency, HighlightSeverity.WARNING, MavenDomBundle.message( "MavenDuplicateDependenciesInspection.has.duplicates", sb.toString())); }
@NotNull public String getName() { return MavenDomBundle.message("fix.parent.path"); }
@NotNull public String getFamilyName() { return MavenDomBundle.message("inspection.group"); }
@NotNull public String getDisplayName() { return MavenDomBundle.message("inspection.duplicate.dependencies.name"); }