Search in sources :

Example 16 with DomElement

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

the class MavenSourceDirectoryConverter method isSoft.

@Override
public boolean isSoft(@NotNull DomElement element) {
    DomElement buildElement = element.getParent();
    if (!(buildElement instanceof MavenDomBuild)) {
        return false;
    }
    DomElement mavenProject = buildElement.getParent();
    if (!(mavenProject instanceof MavenDomProjectModel)) {
        return false;
    }
    return "pom".equals(((MavenDomProjectModel) mavenProject).getPackaging().getStringValue());
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) DomElement(com.intellij.util.xml.DomElement) MavenDomBuild(org.jetbrains.idea.maven.dom.model.MavenDomBuild)

Example 17 with DomElement

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

the class MavenProjectConstantListConverter method getValues.

protected Collection<String> getValues(@NotNull ConvertContext context) {
    DomElement element = context.getInvocationElement();
    MavenProject project = MavenDomUtil.findContainingProject(element);
    if (project == null)
        return Collections.emptyList();
    return getValues(context, project);
}
Also used : DomElement(com.intellij.util.xml.DomElement) MavenProject(org.jetbrains.idea.maven.project.MavenProject)

Example 18 with DomElement

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

the class ChooseFileIntentionAction method getDependency.

@Nullable
private static MavenDomDependency getDependency(PsiFile file, Editor editor) {
    PsiElement el = PsiUtilCore.getElementAtOffset(file, editor.getCaretModel().getOffset());
    XmlTag tag = PsiTreeUtil.getParentOfType(el, XmlTag.class, false);
    if (tag == null)
        return null;
    DomElement dom = DomManager.getDomManager(el.getProject()).getDomElement(tag);
    if (dom == null)
        return null;
    return dom.getParentOfType(MavenDomDependency.class, false);
}
Also used : DomElement(com.intellij.util.xml.DomElement) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 19 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 20 with DomElement

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

the class AntDomDocumentationProvider method getQuickNavigateInfo.

@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
    // todo!
    if (element instanceof PomTargetPsiElement) {
        final PomTarget pomTarget = ((PomTargetPsiElement) element).getTarget();
        if (pomTarget instanceof DomTarget) {
            final DomElement domElement = ((DomTarget) pomTarget).getDomElement();
            if (domElement instanceof AntDomTarget) {
                final AntDomTarget antTarget = (AntDomTarget) domElement;
                final String description = antTarget.getDescription().getRawText();
                if (description != null && description.length() > 0) {
                    final String targetName = antTarget.getName().getRawText();
                    final StringBuilder builder = StringBuilderSpinAllocator.alloc();
                    try {
                        builder.append("Target");
                        if (targetName != null) {
                            builder.append(" \"").append(targetName).append("\"");
                        }
                        final XmlElement xmlElement = antTarget.getXmlElement();
                        if (xmlElement != null) {
                            final PsiFile containingFile = xmlElement.getContainingFile();
                            if (containingFile != null) {
                                final String fileName = containingFile.getName();
                                builder.append(" [").append(fileName).append("]");
                            }
                        }
                        return builder.append(" ").append(description).toString();
                    } finally {
                        StringBuilderSpinAllocator.dispose(builder);
                    }
                }
            }
        } else if (pomTarget instanceof DomChildrenDescription) {
            final DomChildrenDescription description = (DomChildrenDescription) pomTarget;
            Type type = null;
            try {
                type = description.getType();
            } catch (UnsupportedOperationException e) {
                LOG.info(e);
            }
            if (type instanceof Class && AntDomElement.class.isAssignableFrom(((Class) type))) {
                final String elemName = description.getName();
                if (elemName != null) {
                    final AntDomElement.Role role = description.getUserData(AntDomElement.ROLE);
                    final StringBuilder builder = StringBuilderSpinAllocator.alloc();
                    try {
                        if (role == AntDomElement.Role.TASK) {
                            builder.append("Task ");
                        } else if (role == AntDomElement.Role.DATA_TYPE) {
                            builder.append("Data structure ");
                        }
                        builder.append(elemName);
                        return builder.toString();
                    } finally {
                        StringBuilderSpinAllocator.dispose(builder);
                    }
                }
            }
        }
    }
    return null;
}
Also used : AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) DomTarget(com.intellij.util.xml.DomTarget) DomChildrenDescription(com.intellij.util.xml.reflect.DomChildrenDescription) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) PomTarget(com.intellij.pom.PomTarget) Type(java.lang.reflect.Type) DomElement(com.intellij.util.xml.DomElement) AntDomElement(com.intellij.lang.ant.dom.AntDomElement) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) Nullable(org.jetbrains.annotations.Nullable)

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