Search in sources :

Example 1 with GenericDomValue

use of com.intellij.util.xml.GenericDomValue in project intellij-community by JetBrains.

the class GoToSymbolProvider method createNavigationItem.

@Nullable
protected static NavigationItem createNavigationItem(final DomElement domElement) {
    final GenericDomValue name = domElement.getGenericInfo().getNameDomElement(domElement);
    assert name != null;
    final XmlElement psiElement = name.getXmlElement();
    final String value = name.getStringValue();
    if (psiElement == null || value == null) {
        return null;
    }
    final Icon icon = ElementPresentationManager.getIcon(domElement);
    return createNavigationItem(psiElement, value, icon);
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) GenericDomValue(com.intellij.util.xml.GenericDomValue) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GenericDomValue

use of com.intellij.util.xml.GenericDomValue in project intellij-community by JetBrains.

the class BasicDomElementComponent method bindProperties.

protected final void bindProperties(final DomElement domElement) {
    if (domElement == null)
        return;
    DomElementAnnotationsManager.getInstance(domElement.getManager().getProject()).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() {

        @Override
        public void highlightingFinished(@NotNull final DomFileElement element) {
            ApplicationManager.getApplication().invokeLater(() -> {
                if (getComponent().isShowing() && element.isValid()) {
                    updateHighlighting();
                }
            });
        }
    }, this);
    for (final AbstractDomChildrenDescription description : domElement.getGenericInfo().getChildrenDescriptions()) {
        final JComponent boundComponent = getBoundComponent(description);
        if (boundComponent != null) {
            if (description instanceof DomFixedChildDescription && DomUtil.isGenericValueType(description.getType())) {
                if ((description.getValues(domElement)).size() == 1) {
                    final GenericDomValue element = domElement.getManager().createStableValue(() -> domElement.isValid() ? (GenericDomValue) description.getValues(domElement).get(0) : null);
                    doBind(DomUIFactory.createControl(element, commitOnEveryChange(element)), boundComponent);
                } else {
                //todo not bound
                }
            } else if (description instanceof DomCollectionChildDescription) {
                doBind(DomUIFactory.getDomUIFactory().createCollectionControl(domElement, (DomCollectionChildDescription) description), boundComponent);
            }
        }
    }
    reset();
}
Also used : DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) DomFileElement(com.intellij.util.xml.DomFileElement) AbstractDomChildrenDescription(com.intellij.util.xml.reflect.AbstractDomChildrenDescription) DomFixedChildDescription(com.intellij.util.xml.reflect.DomFixedChildDescription) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 3 with GenericDomValue

use of com.intellij.util.xml.GenericDomValue in project intellij-community by JetBrains.

the class BasicDomElementsInspection method checkDomElement.

/**
   * The default implementations checks for resolve problems (if {@link #shouldCheckResolveProblems(com.intellij.util.xml.GenericDomValue)}
   * returns true), then runs annotators (see {@link com.intellij.util.xml.DomFileDescription#createAnnotator()}),
   * checks for {@link com.intellij.util.xml.Required} and {@link com.intellij.util.xml.ExtendClass} annotation
   * problems, checks for name identity (see {@link com.intellij.util.xml.NameValue} annotation) and custom annotation
   * checkers (see {@link com.intellij.util.xml.highlighting.DomCustomAnnotationChecker}).
   *
   * @param element element to check
   * @param holder  a place to add problems to
   * @param helper  helper object
   */
@Override
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
    final int oldSize = holder.getSize();
    if (element instanceof GenericDomValue) {
        final GenericDomValue genericDomValue = (GenericDomValue) element;
        if (shouldCheckResolveProblems(genericDomValue)) {
            helper.checkResolveProblems(genericDomValue, holder);
        }
    }
    for (final Class<? extends T> aClass : getDomClasses()) {
        helper.runAnnotators(element, holder, aClass);
    }
    if (oldSize != holder.getSize())
        return;
    if (!helper.checkRequired(element, holder).isEmpty())
        return;
    if (!(element instanceof GenericAttributeValue) && !GenericDomValue.class.equals(ReflectionUtil.getRawType(element.getDomElementType()))) {
        if (!helper.checkNameIdentity(element, holder).isEmpty())
            return;
    }
    helper.checkCustomAnnotations(element, holder);
}
Also used : GenericDomValue(com.intellij.util.xml.GenericDomValue) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue)

Example 4 with GenericDomValue

use of com.intellij.util.xml.GenericDomValue 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 5 with GenericDomValue

use of com.intellij.util.xml.GenericDomValue in project intellij-plugins by JetBrains.

the class StrutsPackageExtendsResolveConverterImpl method removeCurrentElementFromVariants.

private static Collection<StrutsPackage> removeCurrentElementFromVariants(final ConvertContext context, final Collection<StrutsPackage> allVariants) {
    final StrutsPackage currentElement = (StrutsPackage) DomUtil.getDomElement(context.getTag());
    assert currentElement != null : "currentElement was null for " + context.getTag();
    final GenericDomValue currentNameElement = currentElement.getGenericInfo().getNameDomElement(currentElement);
    if (currentNameElement == null) {
        // skip due to XML errors
        return allVariants;
    }
    final String currentName = currentNameElement.getStringValue();
    if (currentName == null) {
        // skip due to XML errors
        return allVariants;
    }
    final StrutsPackage currentElementInVariants = DomUtil.findByName(allVariants, currentName);
    if (currentElementInVariants != null) {
        allVariants.remove(currentElementInVariants);
    }
    return allVariants;
}
Also used : StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Aggregations

GenericDomValue (com.intellij.util.xml.GenericDomValue)7 XmlElement (com.intellij.psi.xml.XmlElement)2 DomElement (com.intellij.util.xml.DomElement)2 NegatingComparable (com.intellij.codeInsight.completion.impl.NegatingComparable)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementWeigher (com.intellij.codeInsight.lookup.LookupElementWeigher)1 ClassFilter (com.intellij.ide.util.ClassFilter)1 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XmlText (com.intellij.psi.xml.XmlText)1 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)1 SmartList (com.intellij.util.SmartList)1 DomFileElement (com.intellij.util.xml.DomFileElement)1 ExtendClass (com.intellij.util.xml.ExtendClass)1 GenericAttributeValue (com.intellij.util.xml.GenericAttributeValue)1 DomElementAnnotationsManager (com.intellij.util.xml.highlighting.DomElementAnnotationsManager)1 AbstractDomChildrenDescription (com.intellij.util.xml.reflect.AbstractDomChildrenDescription)1