Java Code Examples for com.intellij.psi.xml.XmlTokenType

The following examples show how to use com.intellij.psi.xml.XmlTokenType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> results) {
    // we need project element; so get it from first item
    if(psiElements.size() == 0) {
        return;
    }

    Project project = psiElements.get(0).getProject();
    if(!Symfony2ProjectComponent.isEnabled(project)) {
        return;
    }

    for(PsiElement psiElement: psiElements) {
        if(psiElement.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
            continue;
        }

        PsiElement xmlAttributeValue = psiElement.getParent();
        if(xmlAttributeValue instanceof XmlAttributeValue && (DoctrineMetadataPattern.getXmlTargetDocumentClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getXmlTargetEntityClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getEmbeddableNameClassPattern().accepts(xmlAttributeValue))) {
            attachXmlRelationMarker(psiElement, (XmlAttributeValue) xmlAttributeValue, results);
        }
    }
}
 
Example 2
private void visitService(XmlTag xmlTag, @NotNull ProblemsHolder holder) {
    if(!ServiceActionUtil.isValidXmlParameterInspectionService(xmlTag)) {
        return;
    }

    final List<String> args = ServiceActionUtil.getXmlMissingArgumentTypes(xmlTag, false, getLazyServiceCollector(xmlTag));
    if (args.size() == 0) {
        return;
    }

    PsiElement childrenOfType = PsiElementUtils.getChildrenOfType(xmlTag, PlatformPatterns.psiElement(XmlTokenType.XML_NAME));
    if(childrenOfType == null) {
        return;
    }

    holder.registerProblem(childrenOfType, "Missing argument", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new AddServiceXmlArgumentLocalQuickFix(args));
}
 
Example 3
@NotNull
private static PsiElementPattern.Capture<PsiElement> parentWithName(@NotNull String parentTag, @NotNull String... names) {
    return XmlPatterns
        .psiElement(XmlTokenType.XML_DATA_CHARACTERS)
        .withParent(
            XmlPatterns.xmlText().withParent(
                XmlPatterns.xmlTag().withName(XmlPatterns.string().oneOf(names))
            )
        ).inside(XmlPatterns.xmlTag().withName(parentTag));
}
 
Example 4
public MuleElementsCompletionContributor() {
    extend(CompletionType.BASIC,
            psiElement(XmlTokenType.XML_NAME)
                    .afterSibling(psiElement(XmlTokenType.XML_START_TAG_START)).withSuperParent(2, or(
                    xmlTag().withLocalName(MuleConfigConstants.FLOW_TAG_NAME),
                    xmlTag().withLocalName(MuleConfigConstants.WHEN_TAG_NAME),
                    xmlTag().withLocalName(MuleConfigConstants.OTHERWISE_TAG_NAME),
                    xmlTag().withLocalName(MuleConfigConstants.FOREACH_TAG_NAME),
                    xmlTag().withLocalName(MuleConfigConstants.CHAIN_TAG_NAME),
                    xmlTag().withLocalName(MuleConfigConstants.ENRICHER),
                    xmlTag().withLocalName(MuleConfigConstants.SUB_FLOW_TAG_NAME))
            ), new MuleElementCompletionProvider());
}
 
Example 5
@Nullable
@Override
public PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file, @Nullable PsiElement contextElement) {
    // documentation from properties file will cause IDEA to call this method where we can tell IDEA we can provide
    // documentation for the element if we can detect its a Camel component

    if (contextElement != null) {
        ASTNode node = contextElement.getNode();
        if (node != null && node instanceof XmlToken) {
            //there is an &amp; in the route that splits the route in separated PsiElements
            if (node.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN
                //the caret is at the end of the route next to the " character
                || node.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER
                //the caret is placed on an &amp; element
                || contextElement.getText().equals("&amp;")) {
                if (hasDocumentationForCamelComponent(contextElement.getParent())) {
                    return contextElement.getParent();
                }
            }
        }
        if (hasDocumentationForCamelComponent(contextElement)) {
            return contextElement;
        }
    }

    return null;
}
 
Example 6
Source Project: react-templates-plugin   Source File: RTDocumentationProvider.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement getCustomDocumentationElement(@NotNull Editor editor,
                                                @NotNull PsiFile file,
                                                @Nullable PsiElement element) {
    final IElementType elementType = element != null ? element.getNode().getElementType() : null;
    if (elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) {
        return PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    }
    if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
        return PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    }
    return null;
}
 
Example 7
Source Project: react-templates-plugin   Source File: RTDocumentationProvider.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement getCustomDocumentationElement(@NotNull Editor editor,
                                                @NotNull PsiFile file,
                                                @Nullable PsiElement element) {
    final IElementType elementType = element != null ? element.getNode().getElementType() : null;
    if (elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) {
        return PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    }
    if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
        return PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    }
    return null;
}
 
Example 8
Source Project: idea-php-shopware-plugin   Source File: XmlPatternUtil.java    License: MIT License 5 votes vote down vote up
/**
 * <controller>SwagBackendExample</controller>
 */
public static PsiElementPattern.Capture<PsiElement> getMenuControllerPattern() {
    return XmlPatterns
            .psiElement(XmlTokenType.XML_DATA_CHARACTERS)
            .withParent(XmlPatterns
                    .xmlText()
                    .withParent(XmlPatterns
                            .xmlTag()
                            .withName("controller")
                    )
            ).inside(XmlHelper.getInsideTagPattern("menu"));
}
 
Example 9
Source Project: idea-php-shopware-plugin   Source File: XmlPatternUtil.java    License: MIT License 5 votes vote down vote up
/**
 * <parent identifiedBy="controller">SwagBackendExample</parent>
 */
public static PsiElementPattern.Capture<PsiElement> getMenuControllerByParentPattern() {
    return XmlPatterns
        .psiElement(XmlTokenType.XML_DATA_CHARACTERS)
        .withParent(XmlPatterns
            .xmlText()
            .withParent(XmlPatterns
                .xmlTag()
                .withName("parent").withAttributeValue("identifiedBy", "controller")
            )
        ).inside(XmlHelper.getInsideTagPattern("menu"));
}
 
Example 10
Source Project: idea-php-shopware-plugin   Source File: XmlPatternUtil.java    License: MIT License 5 votes vote down vote up
/**
 * <action>SwagBackendExample</action>
 */
public static PsiElementPattern.Capture<PsiElement> getMenuControllerActionPattern() {
    return XmlPatterns
        .psiElement(XmlTokenType.XML_DATA_CHARACTERS)
        .withParent(XmlPatterns
            .xmlText()
            .withParent(XmlPatterns
                .xmlTag()
                .withName("action")
            )
        ).inside(XmlHelper.getInsideTagPattern("menu"));
}
 
Example 11
@NotNull
public Collection<String> collect(@NotNull PsiElement psiElement, @NotNull Collection<ContainerService> serviceMap) {
    if(!(psiElement.getContainingFile() instanceof XmlFile) || psiElement.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
        return Collections.emptyList();
    }

    return ServiceSuggestionUtil.createSuggestions(ServiceContainerUtil.getXmlConstructorTypeHint(
        psiElement, new ContainerCollectionResolver.LazyServiceCollector(psiElement.getProject())
    ), serviceMap);
}
 
Example 12
@NotNull
public Collection<String> collect(@NotNull PsiElement psiElement, @NotNull Collection<ContainerService> serviceMap) {
    if(!(psiElement.getContainingFile() instanceof XmlFile) || psiElement.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
        return Collections.emptyList();
    }

    return ServiceSuggestionUtil.createSuggestions(ServiceContainerUtil.getXmlCallTypeHint(
        psiElement, new ContainerCollectionResolver.LazyServiceCollector(psiElement.getProject())
    ), serviceMap);
}
 
Example 13
public void update(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);

    if (project == null || !Symfony2ProjectComponent.isEnabled(project)) {
        this.setStatus(event, false);
        return;
    }

    PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
    if(!(psiFile instanceof TwigFile)) {
        this.setStatus(event, false);
        return;
    }

    Editor editor = event.getData(PlatformDataKeys.EDITOR);
    if(editor == null) {
        this.setStatus(event, false);
        return;
    }

    // find valid PsiElement context, because only html text is a valid extractor action
    PsiElement psiElement;
    if(editor.getSelectionModel().hasSelection()) {
        psiElement = psiFile.findElementAt(editor.getSelectionModel().getSelectionStart());
    } else {
        psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
    }

    if(psiElement == null) {
        this.setStatus(event, false);
        return;
    }

    // <a title="TEXT">TEXT</a>
    IElementType elementType = psiElement.getNode().getElementType();
    if(elementType == XmlTokenType.XML_DATA_CHARACTERS || elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
        this.setStatus(event, true);
    } else {
        this.setStatus(event, false);
    }

}
 
Example 14
public void actionPerformed(AnActionEvent event) {

        final Editor editor = event.getData(PlatformDataKeys.EDITOR);
        if(editor == null) {
            return;
        }

        PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
        if(!(psiFile instanceof TwigFile)) {
            return;
        }

        final Project project = ((TwigFile) psiFile).getProject();
        String translationText = editor.getSelectionModel().getSelectedText();

        int startOffset;
        int endOffset;
        int caretOffset = editor.getCaretModel().getOffset();

        if(translationText != null) {
            startOffset = editor.getSelectionModel().getSelectionStart();
            endOffset = editor.getSelectionModel().getSelectionEnd();
        } else {

            // use dont selected text, so find common PsiElement
            PsiElement psiElement = psiFile.findElementAt(caretOffset);
            if(psiElement == null) {
                return;
            }

            IElementType elementType = psiElement.getNode().getElementType();
            if(!(elementType == XmlTokenType.XML_DATA_CHARACTERS || elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)) {
                return;
            }

            startOffset = psiElement.getTextRange().getStartOffset();
            endOffset = psiElement.getTextRange().getEndOffset();
            translationText = psiElement.getText();
        }

        final Set<String> domainNames = TranslationUtil.getTranslationDomainLookupElements(project).stream()
            .map(LookupElement::getLookupString)
            .collect(Collectors.toCollection(TreeSet::new));

        // get default domain on twig tag
        // also pipe it to insert handler; to append it as parameter

        // scope to search translation domain
        PsiElement transDefaultScope = psiFile.findElementAt(caretOffset);
        if(transDefaultScope == null) {
            transDefaultScope = psiFile;
        }

        PsiElement element = TwigUtil.getElementOnTwigViewProvider(transDefaultScope);
        TwigUtil.DomainScope twigFileDomainScope = TwigUtil.getTwigFileDomainScope(element != null ? element : transDefaultScope);

        // we want to have mostly used domain preselected
        final String defaultDomain = twigFileDomainScope.getDefaultDomain();
        final String reselectedDomain = twigFileDomainScope.getDomain();

        String defaultKey = null;
        if(translationText.length() < 15) {
            defaultKey = translationText.toLowerCase().replace(" ", ".");
        }

        final int finalStartOffset = startOffset;
        final int finalEndOffset = endOffset;
        final String finalTranslationText = translationText;
        TranslatorKeyExtractorDialog extractorDialog = new TranslatorKeyExtractorDialog(project, psiFile, domainNames, defaultKey, reselectedDomain, new MyOnOkCallback(project, editor, defaultDomain, finalStartOffset, finalEndOffset, finalTranslationText));

        extractorDialog.setTitle("Symfony: Extract Translation Key");
        extractorDialog.setMinimumSize(new Dimension(600, 200));
        extractorDialog.pack();
        extractorDialog.setLocationRelativeTo(editor.getComponent());
        extractorDialog.setVisible(true);
        extractorDialog.setIconImage(Symfony2Icons.getImage(Symfony2Icons.SYMFONY));

    }