Search in sources :

Example 1 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class MavenPluginConfigurationLanguageInjector method getLanguagesToInject.

@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) {
    if (host.isValid() && host.getContainingFile().getLanguage().is(HTMLLanguage.INSTANCE))
        return;
    if (!(host instanceof XmlText))
        return;
    final XmlText xmlText = (XmlText) host;
    if (!MavenPluginParamInfo.isSimpleText(xmlText))
        return;
    MavenPluginParamInfo.ParamInfoList infoList = MavenPluginParamInfo.getParamInfoList(xmlText);
    for (MavenPluginParamInfo.ParamInfo info : infoList) {
        Language language = info.getLanguage();
        if (language == null) {
            MavenParamLanguageProvider provider = info.getLanguageProvider();
            if (provider != null) {
                language = provider.getLanguage(xmlText, infoList.getDomCfg());
            }
        }
        if (language != null) {
            injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix());
            return;
        }
    }
}
Also used : Language(com.intellij.lang.Language) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) XmlText(com.intellij.psi.xml.XmlText)

Example 2 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class DomElementProblemDescriptorImpl method getPsiElement.

@Nullable
private PsiElement getPsiElement() {
    if (myDomElement instanceof DomFileElement) {
        return ((DomFileElement) myDomElement).getFile();
    }
    if (myDomElement instanceof GenericAttributeValue) {
        final GenericAttributeValue attributeValue = (GenericAttributeValue) myDomElement;
        final XmlAttributeValue value = attributeValue.getXmlAttributeValue();
        return value != null && StringUtil.isNotEmpty(value.getText()) ? value : attributeValue.getXmlElement();
    }
    final XmlTag tag = myDomElement.getXmlTag();
    if (myDomElement instanceof GenericValue && tag != null) {
        final XmlText[] textElements = tag.getValue().getTextElements();
        if (textElements.length > 0) {
            return textElements[0];
        }
    }
    return tag;
}
Also used : XmlText(com.intellij.psi.xml.XmlText) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with XmlText

use of com.intellij.psi.xml.XmlText 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 4 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class XmlWhiteSpaceFormattingStrategy method addWhitespaceToTagBody.

private static void addWhitespaceToTagBody(final ASTNode treePrev, final LeafElement whiteSpaceElement) {
    final CharTable charTable = SharedImplUtil.findCharTableByTree(treePrev);
    final ASTNode treeParent = treePrev.getTreeParent();
    final boolean before;
    final XmlText xmlText;
    if (treePrev.getElementType() == XmlElementType.XML_TEXT) {
        xmlText = (XmlText) treePrev.getPsi();
        before = true;
    } else if (treePrev.getTreePrev().getElementType() == XmlElementType.XML_TEXT) {
        xmlText = (XmlText) treePrev.getTreePrev().getPsi();
        before = false;
    } else {
        xmlText = (XmlText) Factory.createCompositeElement(XmlElementType.XML_TEXT, charTable, treeParent.getPsi().getManager());
        CodeEditUtil.setNodeGenerated(xmlText.getNode(), true);
        treeParent.addChild(xmlText.getNode(), treePrev);
        before = true;
    }
    final ASTNode node = xmlText.getNode();
    assert node != null;
    final TreeElement anchorInText = (TreeElement) (before ? node.getFirstChildNode() : node.getLastChildNode());
    if (anchorInText == null)
        node.addChild(whiteSpaceElement);
    else if (anchorInText.getElementType() != XmlTokenType.XML_WHITE_SPACE)
        node.addChild(whiteSpaceElement, before ? anchorInText : null);
    else {
        final String text = before ? whiteSpaceElement.getText() + anchorInText.getText() : anchorInText.getText() + whiteSpaceElement.getText();
        node.replaceChild(anchorInText, ASTFactory.whitespace(text));
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) XmlText(com.intellij.psi.xml.XmlText) CharTable(com.intellij.util.CharTable) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 5 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class XmlVcsSelectionProvider method getSelection.

@Override
public VcsSelection getSelection(VcsContext context) {
    final Editor editor = context.getEditor();
    if (editor == null)
        return null;
    PsiElement psiElement = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    if (psiElement == null || !psiElement.isValid()) {
        return null;
    }
    final String actionName;
    if (psiElement instanceof XmlTag) {
        actionName = VcsBundle.message("action.name.show.history.for.tag");
    } else if (psiElement instanceof XmlText) {
        actionName = VcsBundle.message("action.name.show.history.for.text");
    } else {
        return null;
    }
    TextRange textRange = psiElement.getTextRange();
    if (textRange == null) {
        return null;
    }
    VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    if (!virtualFile.isValid()) {
        return null;
    }
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    return new VcsSelection(document, textRange, actionName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlText(com.intellij.psi.xml.XmlText) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlText (com.intellij.psi.xml.XmlText)24 XmlTag (com.intellij.psi.xml.XmlTag)16 PsiElement (com.intellij.psi.PsiElement)12 ASTNode (com.intellij.lang.ASTNode)5 TextRange (com.intellij.openapi.util.TextRange)3 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 XmlFile (com.intellij.psi.xml.XmlFile)3 Nullable (org.jetbrains.annotations.Nullable)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Language (com.intellij.lang.Language)2 Project (com.intellij.openapi.project.Project)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlTagValue (com.intellij.psi.xml.XmlTagValue)2 DomElement (com.intellij.util.xml.DomElement)2 NotNull (org.jetbrains.annotations.NotNull)2 MavenProjectIndicesManager (org.jetbrains.idea.maven.indices.MavenProjectIndicesManager)2 TypographyDetector (com.android.tools.lint.checks.TypographyDetector)1 NegatingComparable (com.intellij.codeInsight.completion.impl.NegatingComparable)1 LookupElementWeigher (com.intellij.codeInsight.lookup.LookupElementWeigher)1