use of org.jetbrains.idea.maven.indices.MavenProjectIndicesManager in project intellij-community by JetBrains.
the class MavenDependenciesCompletionProvider method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiElement xmlText = parameters.getPosition().getParent();
if (!(xmlText instanceof XmlText))
return;
PsiElement eDependencyTag = xmlText.getParent();
if (!(eDependencyTag instanceof XmlTag))
return;
XmlTag dependencyTag = (XmlTag) eDependencyTag;
if (!"dependency".equals(dependencyTag.getName()))
return;
if (!PsiImplUtil.isLeafElementOfType(xmlText.getPrevSibling(), XmlTokenType.XML_TAG_END) || !PsiImplUtil.isLeafElementOfType(xmlText.getNextSibling(), XmlTokenType.XML_END_TAG_START)) {
return;
}
Project project = dependencyTag.getProject();
DomElement domElement = DomManager.getDomManager(project).getDomElement(dependencyTag);
if (!(domElement instanceof MavenDomDependency)) {
return;
}
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
for (String groupId : indicesManager.getGroupIds()) {
for (String artifactId : indicesManager.getArtifactIds(groupId)) {
LookupElement builder = LookupElementBuilder.create(groupId + ':' + artifactId).withIcon(AllIcons.Nodes.PpLib).withInsertHandler(MavenDependencyInsertHandler.INSTANCE);
result.addElement(builder);
}
}
}
use of org.jetbrains.idea.maven.indices.MavenProjectIndicesManager in project intellij-community by JetBrains.
the class MavenDependencyCompletionUtil method addTypeAndClassifierAndVersion.
public static void addTypeAndClassifierAndVersion(@NotNull InsertionContext context, @NotNull MavenDomDependency dependency, @NotNull String groupId, @NotNull String artifactId) {
if (!StringUtil.isEmpty(dependency.getVersion().getStringValue()))
return;
Project project = context.getProject();
if (!isInsideManagedDependency(dependency)) {
MavenDomProjectModel model = DomUtil.<MavenDomProjectModel>getFileElement(dependency).getRootElement();
MavenDomDependency managedDependency = findManagedDependency(model, project, groupId, artifactId);
if (managedDependency != null) {
if (dependency.getClassifier().getXmlTag() == null && dependency.getType().getXmlTag() == null) {
String classifier = managedDependency.getClassifier().getRawText();
if (StringUtil.isNotEmpty(classifier)) {
dependency.getClassifier().setStringValue(classifier);
}
String type = managedDependency.getType().getRawText();
if (StringUtil.isNotEmpty(type)) {
dependency.getType().setStringValue(type);
}
}
return;
}
}
MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(project);
Set<String> versions = manager.getVersions(groupId, artifactId);
if (versions.size() == 1) {
dependency.getVersion().setStringValue(ContainerUtil.getFirstItem(versions));
return;
}
dependency.getVersion().setStringValue("");
int versionPosition = dependency.getVersion().getXmlTag().getValue().getTextRange().getStartOffset();
context.getEditor().getCaretModel().moveToOffset(versionPosition);
if (versions.size() > 0) {
invokeCompletion(context, CompletionType.BASIC);
}
}
use of org.jetbrains.idea.maven.indices.MavenProjectIndicesManager in project intellij-community by JetBrains.
the class MavenGroovyPomCompletionContributor method completeVersions.
private static void completeVersions(@NotNull CompletionResultSet completionResultSet, @NotNull Project project, @Nullable String groupId, @Nullable String artifactId, @NotNull String prefix) {
if (StringUtil.isEmptyOrSpaces(artifactId))
return;
CompletionResultSet newResultSet = completionResultSet.withRelevanceSorter(CompletionService.getCompletionService().emptySorter().weigh(new LookupElementWeigher("mavenVersionWeigher") {
@Nullable
@Override
public Comparable weigh(@NotNull LookupElement element) {
return new NegatingComparable(new MavenVersionComparable(StringUtil.trimStart(element.getLookupString(), prefix)));
}
}));
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
Set<String> versions;
if (StringUtil.isEmptyOrSpaces(groupId)) {
versions = Collections.emptySet();
//if (!(coordinates instanceof MavenDomPlugin)) return;
//
//versions = indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[0], artifactId);
//for (int i = 0; i < MavenArtifactUtil.DEFAULT_GROUPS.length; i++) {
// versions = Sets.union(versions, indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[i], artifactId));
//}
} else {
versions = indicesManager.getVersions(groupId, artifactId);
}
for (String version : versions) {
newResultSet.addElement(LookupElementBuilder.create(prefix + version));
}
newResultSet.addElement(LookupElementBuilder.create(prefix + RepositoryUtils.ReleaseVersionId));
newResultSet.addElement(LookupElementBuilder.create(prefix + RepositoryUtils.LatestVersionId));
}
Aggregations