com.intellij.psi.html.HtmlTag Java Examples

The following examples show how to use com.intellij.psi.html.HtmlTag. 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 check out the related API usage on the sidebar.
Example #1
Source File: WeexAnnotator.java    From weex-language-support with MIT License 6 votes vote down vote up
private void checkStructure(PsiElement document, @NotNull AnnotationHolder annotationHolder) {
    PsiElement[] children = document.getChildren();
    List<String> acceptedTag = Arrays.asList("template","element","script", "style");
    for (PsiElement element : children) {
        if (element instanceof HtmlTag) {
            if (!acceptedTag.contains(((HtmlTag) element).getName().toLowerCase())) {
                annotationHolder.createErrorAnnotation(element, "Invalid tag '"
                        + ((HtmlTag) element).getName() + "', only the [template, element, script, style] tags are allowed here.");
            }
            checkAttributes((XmlTag) element, annotationHolder);
        } else {
            if (!(element instanceof PsiWhiteSpace)
                    && !(element instanceof XmlProlog)
                    && !(element instanceof XmlText)
                    && !(element instanceof XmlComment)) {
                String s = element.getText();
                if (s.length() > 20) {
                    s = s.substring(0, 20);
                }
                annotationHolder.createErrorAnnotation(element, "Invalid content '" + s +
                        "', only the [template, script, style] tags are allowed here.");
            }
        }
    }
}
 
Example #2
Source File: RTHtmlExtension.java    From react-templates-plugin with MIT License 6 votes vote down vote up
public static List<String> loadImportedTags(@NotNull XmlFile file, @NotNull XmlTag context) {
//        PsiElement[] arr = file.getRootTag().getChildren();
//        Collection<HtmlTag> tags = PsiTreeUtil.findChildrenOfType(file, HtmlTag.class);
        PsiElement[] reqTags = PsiTreeUtil.collectElements(file, new PsiElementFilter() {
            @Override
            public boolean isAccepted(PsiElement element) {
                return element instanceof HtmlTag && (((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_REQUIRE) || ((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_IMPORT));
            }
        });

        List<String> importedTags = new ArrayList<String>();
        for (PsiElement elem : reqTags) {
            String as = ((HtmlTag) elem).getAttributeValue("as");
            if (!Strings.isNullOrEmpty(as)) {
                importedTags.add(as);
            }
        }
        return importedTags;
    }
 
Example #3
Source File: RTHtmlExtension.java    From react-templates-plugin with MIT License 6 votes vote down vote up
public static List<String> loadImportedTags(@NotNull XmlFile file, @NotNull XmlTag context) {
//        PsiElement[] arr = file.getRootTag().getChildren();
//        Collection<HtmlTag> tags = PsiTreeUtil.findChildrenOfType(file, HtmlTag.class);
        PsiElement[] reqTags = PsiTreeUtil.collectElements(file, new PsiElementFilter() {
            @Override
            public boolean isAccepted(PsiElement element) {
                return element instanceof HtmlTag && (((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_REQUIRE) || ((HtmlTag) element).getName().equals(RTTagDescriptorsProvider.RT_IMPORT));
            }
        });

        List<String> importedTags = new ArrayList<String>();
        for (PsiElement elem : reqTags) {
            String as = ((HtmlTag) elem).getAttributeValue("as");
            if (!Strings.isNullOrEmpty(as)) {
                importedTags.add(as);
            }
        }
        return importedTags;
    }
 
Example #4
Source File: RTTagDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Nullable
    @Override
    public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
//        System.out.println("getDescriptor " + xmlTag);
        if (!(xmlTag instanceof HtmlTag && RTProjectComponent.isEnabled(xmlTag.getProject()))) {
            return null;
        }
        final String directiveName = DirectiveUtil.normalizeAttributeName(xmlTag.getName());
        if (directiveName.equals(RT_REQUIRE)) {
            return new RTRequireTagDescriptor(RT_REQUIRE, xmlTag);
        }
        if (directiveName.equals(RT_IMPORT)) {
            return new RTImportTagDescriptor(RT_IMPORT, xmlTag);
        }

        if (xmlTag.getContainingFile() instanceof XmlFile) {
            List<String> tags = RTHtmlExtension.loadImportedTags((XmlFile) xmlTag.getContainingFile(), xmlTag);
            for (String tag : tags) {
                if (Strings.areEqual(tag, directiveName)) {
                    return new RTClassTagDescriptor(directiveName, xmlTag);
                }
            }
        }
        // TODO: support required tags
        //return new AnyXmlElementDescriptor()
        return null;
    }
 
Example #5
Source File: RTAttributeDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
    public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) {
        if (xmlTag instanceof HtmlTag /*&& RTFileUtil.hasRTExt(xmlTag.getContainingFile())*/) {
            final Project project = xmlTag.getProject();
            if (RTActionUtil.isRTEnabled(project)) {
                final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<String, XmlAttributeDescriptor>();
                for (String attr : RTAttributes.ALL_ATTRIBUTES) {
                    result.put(attr, new RTXmlAttributeDescriptor(attr));
                }
//                result.put("rt-repeat", new RTXmlAttributeDescriptor("rt-repeat")); // x in [javascript]
//                result.put("rt-if", new RTXmlAttributeDescriptor("rt-if")); //[javascript]
//                result.put("rt-scope", new RTXmlAttributeDescriptor("rt-scope")); //a as b;c as d
//                result.put("rt-class", new RTXmlAttributeDescriptor("rt-class")); // [javascript]
//                result.put("rt-props", new RTXmlAttributeDescriptor("rt-props")); // [javascript]
                return result.values().toArray(new XmlAttributeDescriptor[result.size()]);

    //            return new XmlAttributeDescriptor[]{
    //                    new AnyXmlAttributeDescriptor("rt-if"),
    //                    new AnyXmlAttributeDescriptor("rt-repeat"),
    //                    new AnyXmlAttributeDescriptor("rt-scope"),
    //                    new AnyXmlAttributeDescriptor("rt-props"),
    //                    new AnyXmlAttributeDescriptor("rt-class"),
    //                    new AnyXmlAttributeDescriptor("rt-require")
    //            };
            }
        }
        return XmlAttributeDescriptor.EMPTY;
    }
 
Example #6
Source File: ISMLTagDescriptorsProvider.java    From intellij-demandware with MIT License 5 votes vote down vote up
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag tag) {
    if (!(tag instanceof HtmlTag)) {
        return null;
    }

    final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(tag.getNamespace(), false);
    final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(tag) : null;
    if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
        return null;
    }

    return new ISMLTagDescriptor(tag.getName(), tag);
}
 
Example #7
Source File: ISMLTagDescriptorsProvider.java    From intellij-demandware with MIT License 5 votes vote down vote up
@Override
public void addTagNameVariants(List<LookupElement> elements, XmlTag tag, String prefix) {
    if (!(tag instanceof HtmlTag)) return;
    for (String tagName : ismlTagNames) {
        elements.add(LookupElementBuilder.create(tagName));
    }
}
 
Example #8
Source File: RTTagDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Nullable
    @Override
    public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
//        System.out.println("getDescriptor " + xmlTag);
        if (!(xmlTag instanceof HtmlTag && RTProjectComponent.isEnabled(xmlTag.getProject()))) {
            return null;
        }
        final String directiveName = DirectiveUtil.normalizeAttributeName(xmlTag.getName());
        if (directiveName.equals(RT_REQUIRE)) {
            return new RTRequireTagDescriptor(RT_REQUIRE, xmlTag);
        }
        if (directiveName.equals(RT_IMPORT)) {
            return new RTImportTagDescriptor(RT_IMPORT, xmlTag);
        }

        if (xmlTag.getContainingFile() instanceof XmlFile) {
            List<String> tags = RTHtmlExtension.loadImportedTags((XmlFile) xmlTag.getContainingFile(), xmlTag);
            for (String tag : tags) {
                if (Strings.areEqual(tag, directiveName)) {
                    return new RTClassTagDescriptor(directiveName, xmlTag);
                }
            }
        }
        // TODO: support required tags
        //return new AnyXmlElementDescriptor()
        return null;
    }
 
Example #9
Source File: RTAttributeDescriptorsProvider.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
    public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) {
        if (xmlTag instanceof HtmlTag /*&& RTFileUtil.hasRTExt(xmlTag.getContainingFile())*/) {
            final Project project = xmlTag.getProject();
            if (RTActionUtil.isRTEnabled(project)) {
                final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<String, XmlAttributeDescriptor>();
                for (String attr : RTAttributes.ALL_ATTRIBUTES) {
                    result.put(attr, new RTXmlAttributeDescriptor(attr));
                }
//                result.put("rt-repeat", new RTXmlAttributeDescriptor("rt-repeat")); // x in [javascript]
//                result.put("rt-if", new RTXmlAttributeDescriptor("rt-if")); //[javascript]
//                result.put("rt-scope", new RTXmlAttributeDescriptor("rt-scope")); //a as b;c as d
//                result.put("rt-class", new RTXmlAttributeDescriptor("rt-class")); // [javascript]
//                result.put("rt-props", new RTXmlAttributeDescriptor("rt-props")); // [javascript]
                return result.values().toArray(new XmlAttributeDescriptor[result.size()]);

    //            return new XmlAttributeDescriptor[]{
    //                    new AnyXmlAttributeDescriptor("rt-if"),
    //                    new AnyXmlAttributeDescriptor("rt-repeat"),
    //                    new AnyXmlAttributeDescriptor("rt-scope"),
    //                    new AnyXmlAttributeDescriptor("rt-props"),
    //                    new AnyXmlAttributeDescriptor("rt-class"),
    //                    new AnyXmlAttributeDescriptor("rt-require")
    //            };
            }
        }
        return XmlAttributeDescriptor.EMPTY;
    }
 
Example #10
Source File: TwigHtmlCompletionUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * <foo>bar</foo>
 */
public static PsiElementPattern.Capture<PsiElement> getTagTextPattern(@NotNull String... tag) {
    return XmlPatterns
        .psiElement().withParent(
            PlatformPatterns.psiElement(XmlText.class).withParent(
                PlatformPatterns.psiElement(HtmlTag.class).withName(tag)
            )
        )
        .inFile(XmlPatterns.psiFile()
            .withName(XmlPatterns
                .string().endsWith(".twig")
            )
        );
}