Search in sources :

Example 6 with DomElement

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));
    }
}
Also used : NegatingComparable(com.intellij.codeInsight.completion.impl.NegatingComparable) MavenProjectIndicesManager(org.jetbrains.idea.maven.indices.MavenProjectIndicesManager) MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) MavenArtifactCoordinatesVersionConverter(org.jetbrains.idea.maven.dom.converters.MavenArtifactCoordinatesVersionConverter) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) LookupElementWeigher(com.intellij.codeInsight.lookup.LookupElementWeigher) XmlText(com.intellij.psi.xml.XmlText) MavenDomArtifactCoordinates(org.jetbrains.idea.maven.dom.model.MavenDomArtifactCoordinates) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 7 with DomElement

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;
}
Also used : DomElement(com.intellij.util.xml.DomElement) THashMap(gnu.trove.THashMap) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with DomElement

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);
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlFile(com.intellij.psi.xml.XmlFile) MergedObject(com.intellij.util.xml.MergedObject) List(java.util.List) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 9 with DomElement

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);
    }
}
Also used : BaseDomElementNode(com.intellij.util.xml.tree.BaseDomElementNode) DomElement(com.intellij.util.xml.DomElement) DomElementNavigationProvider(com.intellij.util.xml.DomElementNavigationProvider) SimpleNode(com.intellij.ui.treeStructure.SimpleNode)

Example 10 with DomElement

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());
}
Also used : DomElement(com.intellij.util.xml.DomElement) UserActivityWatcher(com.intellij.ui.UserActivityWatcher) UserActivityListener(com.intellij.ui.UserActivityListener)

Aggregations

DomElement (com.intellij.util.xml.DomElement)97 XmlTag (com.intellij.psi.xml.XmlTag)34 PsiElement (com.intellij.psi.PsiElement)19 Nullable (org.jetbrains.annotations.Nullable)19 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)11 PsiFile (com.intellij.psi.PsiFile)11 XmlFile (com.intellij.psi.xml.XmlFile)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)9 ArrayList (java.util.ArrayList)8 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)7 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)6 DomManager (com.intellij.util.xml.DomManager)5 Style (org.jetbrains.android.dom.resources.Style)5 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)4 XmlElement (com.intellij.psi.xml.XmlElement)4 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 TextRange (com.intellij.openapi.util.TextRange)3