use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class MavenVersionCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC)
return;
PsiElement element = parameters.getPosition();
PsiElement xmlText = element.getParent();
if (!(xmlText instanceof XmlText))
return;
PsiElement tagElement = xmlText.getParent();
if (!(tagElement instanceof XmlTag))
return;
XmlTag tag = (XmlTag) tagElement;
Project project = element.getProject();
DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
if (!(domElement instanceof GenericDomValue))
return;
DomElement parent = domElement.getParent();
if (parent instanceof MavenDomArtifactCoordinates && ((GenericDomValue) domElement).getConverter() instanceof MavenArtifactCoordinatesVersionConverter) {
MavenDomArtifactCoordinates coordinates = (MavenDomArtifactCoordinates) parent;
String groupId = coordinates.getGroupId().getStringValue();
String artifactId = coordinates.getArtifactId().getStringValue();
if (StringUtil.isEmptyOrSpaces(artifactId))
return;
CompletionResultSet newResultSet = result.withRelevanceSorter(CompletionService.getCompletionService().emptySorter().weigh(new LookupElementWeigher("mavenVersionWeigher") {
@Nullable
@Override
public Comparable weigh(@NotNull LookupElement element) {
return new NegatingComparable(new MavenVersionComparable(element.getLookupString()));
}
}));
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
Set<String> versions;
if (StringUtil.isEmptyOrSpaces(groupId)) {
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(version));
}
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.ReleaseVersionId));
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.LatestVersionId));
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class GetCompositeCollectionInvocation method invoke.
@Override
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable {
Map<XmlTag, DomElement> map = new THashMap<>();
for (final CollectionChildDescriptionImpl qname : myQnames) {
for (DomElement element : handler.getCollectionChildren(qname)) {
map.put(element.getXmlTag(), element);
}
}
final XmlTag tag = handler.getXmlTag();
if (tag == null)
return Collections.emptyList();
final List<DomElement> list = new ArrayList<>();
for (final XmlTag subTag : tag.getSubTags()) {
ContainerUtil.addIfNotNull(list, map.get(subTag));
}
return list;
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AddElementInCollectionAction method createAddingAction.
@Override
protected AnAction createAddingAction(final AnActionEvent e, final String name, final Icon icon, final Type type, final DomCollectionChildDescription description) {
final DomElement parentDomElement = getParentDomElement(e);
if (parentDomElement instanceof MergedObject) {
final List<DomElement> implementations = (List<DomElement>) ((MergedObject) parentDomElement).getImplementations();
final DefaultActionGroup actionGroup = new DefaultActionGroup(name, true);
for (DomElement implementation : implementations) {
final XmlFile xmlFile = DomUtil.getFile(implementation);
actionGroup.add(new MyDefaultAddAction(implementation, xmlFile.getName(), xmlFile.getIcon(0), e, type, description));
}
return actionGroup;
}
return new MyDefaultAddAction(parentDomElement, name, icon, e, type, description);
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class GotoDomElementDeclarationAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e, DomModelTreeView treeView) {
final SimpleNode simpleNode = treeView.getTree().getSelectedNode();
if (simpleNode instanceof BaseDomElementNode) {
final DomElement domElement = ((BaseDomElementNode) simpleNode).getDomElement();
final DomElementNavigationProvider provider = DomElementsNavigationManager.getManager(domElement.getManager().getProject()).getDomElementsNavigateProvider(DomElementsNavigationManager.DEFAULT_PROVIDER_NAME);
provider.navigate(domElement, true);
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class DomUIFactoryImpl method setupErrorOutdatingUserActivityWatcher.
@Override
public void setupErrorOutdatingUserActivityWatcher(final CommittablePanel panel, final DomElement... elements) {
final UserActivityWatcher userActivityWatcher = createEditorAwareUserActivityWatcher();
userActivityWatcher.addUserActivityListener(new UserActivityListener() {
private boolean isProcessingChange;
@Override
public void stateChanged() {
if (isProcessingChange)
return;
isProcessingChange = true;
try {
for (final DomElement element : elements) {
DomElementAnnotationsManagerImpl.outdateProblemHolder(element);
}
CommittableUtil.updateHighlighting(panel);
} finally {
isProcessingChange = false;
}
}
}, panel);
userActivityWatcher.register(panel.getComponent());
}
Aggregations