public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { GenericDomValue el = (GenericDomValue) myContext.getInvocationElement(); MavenId id = MavenArtifactCoordinatesHelper.getId(myContext); MavenProjectsManager manager = MavenProjectsManager.getInstance(project); MavenProject parentFile = manager.findProject(id); if (parentFile != null) { VirtualFile currentFile = myContext.getFile().getVirtualFile(); el.setStringValue( MavenDomUtil.calcRelativePath(currentFile.getParent(), parentFile.getFile())); } }
public static boolean processDependenciesInDependencyManagement( @NotNull MavenDomProjectModel projectDom, @NotNull final Processor<MavenDomDependency> processor, @NotNull final Project project) { Processor<MavenDomDependencies> managedDependenciesListProcessor = dependencies -> { SmartList<MavenDomDependency> importDependencies = null; for (MavenDomDependency domDependency : dependencies.getDependencies()) { if ("import".equals(domDependency.getScope().getRawText())) { if (importDependencies == null) { importDependencies = new SmartList<MavenDomDependency>(); } importDependencies.add(domDependency); } else { if (processor.process(domDependency)) return true; } } if (importDependencies != null) { for (MavenDomDependency domDependency : importDependencies) { GenericDomValue<String> version = domDependency.getVersion(); if (version.getXmlElement() != null) { GenericDomValueReference reference = new GenericDomValueReference(version); PsiElement resolve = reference.resolve(); if (resolve instanceof XmlFile) { MavenDomProjectModel dependModel = MavenDomUtil.getMavenDomModel((PsiFile) resolve, MavenDomProjectModel.class); if (dependModel != null) { for (MavenDomDependency dep : dependModel.getDependencyManagement().getDependencies().getDependencies()) { if (processor.process(dep)) return true; } } } } } } return false; }; Function<MavenDomProjectModelBase, MavenDomDependencies> domFunction = mavenDomProfile -> mavenDomProfile.getDependencyManagement().getDependencies(); return process(projectDom, managedDependenciesListProcessor, project, domFunction, domFunction); }
@NotNull @Override public PsiReference[] createReferences( GenericDomValue value, final PsiElement element, final ConvertContext context) { String text = value.getStringValue(); TextRange range = ElementManipulators.getValueTextRange(element); return new PsiReference[] { new MavenUrlPsiReference(element, text, range) { @NotNull @Override public Object[] getVariants() { Module module = context.getModule(); if (module != null) { String name = MavenRepositoriesProvider.getInstance() .getRepositoryUrl(getRepositoryId(context)); if (!StringUtil.isEmptyOrSpaces(name)) return new Object[] {name}; } return super.getVariants(); } } }; }