com.intellij.psi.xml.XmlToken Java Examples
The following examples show how to use
com.intellij.psi.xml.XmlToken.
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: HtmlTemplateLineUtil.java From NutzCodeInsight with Apache License 2.0 | 6 votes |
/** * 判断是否是资源文件 * * @param bindingElement * @return */ public static boolean isRes(PsiElement bindingElement) { if (bindingElement instanceof XmlToken) { XmlToken xmlToken = (XmlToken) bindingElement; List<String> layouts = BeetlHtmlLineUtil.showBeetlLayout(xmlToken); List<String> includes = BeetlHtmlLineUtil.showBeetlInclude(xmlToken); return layouts.size() > 0 || includes.size() > 0; } if (!(bindingElement instanceof XmlAttribute)) { return false; } XmlAttribute attribute = (XmlAttribute) bindingElement; String name = Strings.nullToEmpty(attribute.getName()); String path = Strings.nullToEmpty(attribute.getValue()); int sp = path.indexOf("?"); if (sp > -1) { path = path.substring(0, sp); } return resTag.contains(name) && path.startsWith("${") && endWithRes(path); }
Example #2
Source File: XmlCamelRouteLineMarkerProviderTestIT.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public void testCamelGutterForToD() { myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderToDTestData.xml"); List<GutterMark> gutters = myFixture.findAllGutters(); assertNotNull(gutters); assertEquals("Should contain 1 Camel gutter", 1, gutters.size()); assertSame("Gutter should have the Camel icon", ServiceManager.getService(CamelPreferenceService.class).getCamelIcon(), gutters.get(0).getIcon()); assertEquals("Camel route", gutters.get(0).getTooltipText()); LineMarkerInfo.LineMarkerGutterIconRenderer gutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(0); assertTrue(gutter.getLineMarkerInfo().getElement() instanceof XmlToken); assertEquals("The navigation start element doesn't match", "file:inbox", PsiTreeUtil.getParentOfType(gutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue()); List<GotoRelatedItem> gutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(gutter); assertEquals("Navigation should have one target", 1, gutterTargets.size()); assertEquals("The navigation target route doesn't match", "file:inbox", gutterTargets.get(0).getElement().getText()); assertEquals("The navigation target tag name doesn't match", "toD", GutterTestUtil.getGuttersWithXMLTarget(gutterTargets).get(0).getLocalName()); }
Example #3
Source File: TagTextIntention.java From weex-language-support with MIT License | 6 votes |
@Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { if (!WeexFileUtil.isOnWeexFile(element)) { return false; } int offset = editor.getCaretModel().getOffset(); Document document = editor.getDocument(); if (!element.isWritable() || element.getContext() == null || !element.getContext().isWritable()) { return false; } if (element instanceof XmlToken && ((XmlToken) element).getTokenType().toString().equals("XML_END_TAG_START")) { String next = document.getText(new TextRange(offset, offset + 1)); if (next != null && next.equals("<")) { return true; } } return available(element); }
Example #4
Source File: XmlIdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@Override public Optional<String> extractTextFromElement(PsiElement element, boolean concatString, boolean stripWhitespace) { // maybe its xml then try that if (element instanceof XmlAttributeValue) { return Optional.ofNullable(((XmlAttributeValue) element).getValue()); } else if (element instanceof XmlText) { return Optional.ofNullable(((XmlText) element).getValue()); } else if (element instanceof XmlToken) { // it may be a token which is a part of an combined attribute if (concatString) { XmlAttributeValue xml = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class); if (xml != null) { return Optional.ofNullable(getInnerText(xml.getValue())); } } else { String returnText = element.getText(); final PsiElement prevSibling = element.getPrevSibling(); if (prevSibling != null && prevSibling.getText().equalsIgnoreCase("&")) { returnText = prevSibling.getText() + returnText; } return Optional.ofNullable(getInnerText(returnText)); } } return Optional.empty(); }
Example #5
Source File: UserFuncReference.java From idea-php-typo3-plugin with MIT License | 6 votes |
public UserFuncReference(XmlToken xmlText) { super(xmlText); String text = xmlText.getText(); if (text.contains("->")) { String[] split = StringUtils.split(text, "->"); switch (split.length) { case 1: className = split[0].trim(); methodName = null; break; case 2: className = split[0].trim(); methodName = split[1].trim(); break; default: className = null; methodName = null; } } else { className = null; methodName = text; } }
Example #6
Source File: XmlCamelIdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@Override public PsiClass getBeanClass(PsiElement element) { if (element instanceof XmlToken) { } return null; }
Example #7
Source File: XmlGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void getLookupElements(@NotNull GotoCompletionProviderLookupArguments arguments) { // find class name of service tag PsiElement xmlToken = this.getElement(); if(xmlToken instanceof XmlToken) { PsiElement xmlAttrValue = xmlToken.getParent(); if(xmlAttrValue instanceof XmlAttributeValue) { PsiElement xmlAttribute = xmlAttrValue.getParent(); if(xmlAttribute instanceof XmlAttribute) { PsiElement xmlTag = xmlAttribute.getParent(); if(xmlTag instanceof XmlTag) { String aClass = ((XmlTag) xmlTag).getAttributeValue("class"); if(aClass == null) { // <service id="Foo\Bar"/> PhpClassCompletionProvider.addClassCompletion( arguments.getParameters(), arguments.getResultSet(), getElement(), false ); } else if(StringUtils.isNotBlank(aClass)) { // <service id="foo.bar" class="Foo\Bar"/> LookupElementBuilder lookupElement = LookupElementBuilder .create(ServiceUtil.getServiceNameForClass(getProject(), aClass)) .withIcon(Symfony2Icons.SERVICE); LookupElementBuilder lookupElementWithClassName = LookupElementBuilder .create(aClass) .withIcon(Symfony2Icons.SERVICE); arguments.getResultSet().addElement(lookupElement); arguments.getResultSet().addElement(lookupElementWithClassName); } } } } } }
Example #8
Source File: MultiLanguageCamelRouteLineMarkerProviderTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testCamelGutterForJavaAndXMLRoutes() { myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml", "JavaCamelRouteLineMarkerProviderTestData.java"); List<GutterMark> javaGutters = myFixture.findAllGutters("JavaCamelRouteLineMarkerProviderTestData.java"); assertNotNull(javaGutters); List<GutterMark> xmlGutters = myFixture.findAllGutters("XmlCamelRouteLineMarkerProviderTestData.xml"); assertNotNull(xmlGutters); //remove first element since it is navigate to super implementation gutter icon javaGutters.remove(0); assertEquals("Should contain 3 Java Camel gutters", 3, javaGutters.size()); assertEquals("Should contain 2 XML Camel gutters", 3, xmlGutters.size()); //from Java to XML LineMarkerInfo.LineMarkerGutterIconRenderer firstJavaGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) javaGutters.get(1); assertTrue(firstJavaGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken); assertEquals("The navigation start element doesn't match", "\"file:inbox\"", firstJavaGutter.getLineMarkerInfo().getElement().getText()); List<GotoRelatedItem> firstJavaGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstJavaGutter); assertEquals("Navigation should have two targets", 2, firstJavaGutterTargets.size()); assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstJavaGutterTargets).get(0).getLocalName()); assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")", getGuttersWithJavaTarget(firstJavaGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText()); //from XML to Java LineMarkerInfo.LineMarkerGutterIconRenderer firstXmlGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) xmlGutters.get(1); assertTrue(firstXmlGutter.getLineMarkerInfo().getElement() instanceof XmlToken); assertEquals("The navigation start element doesn't match", "\"file:inbox\"", (firstJavaGutter.getLineMarkerInfo().getElement()).getText()); List<GotoRelatedItem> firstXmlGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstXmlGutter); assertEquals("Navigation should have two targets", 2, firstXmlGutterTargets.size()); assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstXmlGutterTargets).get(0).getLocalName()); assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")", getGuttersWithJavaTarget(firstXmlGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText()); }
Example #9
Source File: XmlCamelRouteLineMarkerProviderTestIT.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testCamelGutter() { myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml"); List<GutterMark> gutters = myFixture.findAllGutters(); assertNotNull(gutters); assertEquals("Does not contain the expected amount of Camel gutters", 3, gutters.size()); Icon defaultIcon = ServiceManager.getService(CamelPreferenceService.class).getCamelIcon(); gutters.forEach(gutterMark -> { assertSame("Gutter should have the Camel icon", defaultIcon, gutterMark.getIcon()); assertEquals("Camel route", gutterMark.getTooltipText()); }); LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(1); assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof XmlToken); assertEquals("The navigation start element doesn't match", "file:inbox", PsiTreeUtil.getParentOfType(firstGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue()); List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter); assertEquals("Navigation should have one target", 1, firstGutterTargets.size()); assertEquals("The navigation target route doesn't match", "file:inbox", firstGutterTargets.get(0).getElement().getText()); assertEquals("The navigation target tag name doesn't match", "to", GutterTestUtil.getGuttersWithXMLTarget(firstGutterTargets).get(0).getLocalName()); LineMarkerInfo.LineMarkerGutterIconRenderer secondGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(2); assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof XmlToken); assertEquals("The navigation start element doesn't match", "file:outbox", PsiTreeUtil.getParentOfType(secondGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue()); List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter); assertEquals("Navigation should have one target", 1, secondGutterTargets.size()); assertEquals("The navigation target route doesn't match", "file:outbox", secondGutterTargets.get(0).getElement().getText()); assertEquals("The navigation target tag name doesn't match", "to", GutterTestUtil.getGuttersWithXMLTarget(secondGutterTargets).get(0).getLocalName()); }
Example #10
Source File: CamelRouteLineMarkerProvider.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
/** * Further refine search in order to match the exact XML Camel route. * * @param route the complete Camel route to search for * @param psiElement the {@link PsiElement} that might contain the complete route definition * @return the {@link PsiElement} that contains the exact match of the Camel route */ private PsiElement findXMLElement(String route, XmlToken psiElement) { if (psiElement.getTokenType() == XmlElementType.XML_ATTRIBUTE_VALUE_TOKEN) { if (Arrays.stream(XML_ROUTE_CALL).anyMatch(s -> s.equals(PsiTreeUtil.getParentOfType(psiElement, XmlTag.class).getLocalName()))) { if (psiElement.getText().equals(route)) { return psiElement; } } } return null; }
Example #11
Source File: CamelInspection.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@Override boolean accept(PsiElement element) { // skip tokens as we want to only trigger on attributes and xml value if in XML mode boolean token = element instanceof XmlToken; if (token) { return false; } return getIdeaUtils().isFromFileType(element, CamelIdeaUtils.CAMEL_FILE_EXTENSIONS); }
Example #12
Source File: CamelEndpointAnnotator.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
private void extractMapValue(EndpointValidationResult result, Map<String, String> validationMap, String fromElement, @NotNull PsiElement element, @NotNull AnnotationHolder holder, CamelAnnotatorEndpointMessage msg) { if ((!result.isSuccess()) && validationMap != null) { for (Map.Entry<String, String> entry : validationMap.entrySet()) { String propertyValue = entry.getValue(); String propertyKey = entry.getKey(); int startIdxQueryParameters = fromElement.indexOf("?"); int propertyIdx = fromElement.indexOf(propertyKey, startIdxQueryParameters); int startIdx = propertyIdx; int equalsSign = fromElement.indexOf("=", propertyIdx); if (equalsSign > 0) { startIdx = equalsSign + 1; } int propertyLength = propertyValue.isEmpty() ? propertyKey.length() : propertyValue.length(); propertyLength = element instanceof XmlToken ? propertyLength - 1 : propertyLength; startIdx = propertyValue.isEmpty() ? propertyIdx + 1 : fromElement.indexOf(propertyValue, startIdx) + 1; startIdx = getIdeaUtils().isJavaLanguage(element) || getIdeaUtils().isXmlLanguage(element) ? startIdx : startIdx - 1; TextRange range = new TextRange(element.getTextRange().getStartOffset() + startIdx, element.getTextRange().getStartOffset() + startIdx + propertyLength); holder.createErrorAnnotation(range, summaryMessage(result, entry, msg)); } } }
Example #13
Source File: XmlCamelIdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@Override public boolean isCamelRouteStartExpression(PsiElement element) { boolean textualXmlToken = element instanceof XmlToken && !element.getText().equals("<") && !element.getText().equals("</") && !element.getText().equals(">") && !element.getText().equals("/>"); return textualXmlToken && isCamelRouteStart(element); }
Example #14
Source File: CamelDocumentationProvider.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@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 & 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 & element || contextElement.getText().equals("&")) { if (hasDocumentationForCamelComponent(contextElement.getParent())) { return contextElement.getParent(); } } } if (hasDocumentationForCamelComponent(contextElement)) { return contextElement; } } return null; }
Example #15
Source File: DocumentIntention.java From weex-language-support with MIT License | 5 votes |
@Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) { if (psiElement instanceof XmlToken && false) { String tokenType = ((XmlToken) psiElement).getTokenType().toString(); if ("XML_NAME".equals(tokenType)) { String tagName = psiElement.getText(); return DirectiveLint.containsTag(tagName); } } return false; }
Example #16
Source File: BeetlHtmlLineUtil.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
private static List<String> getMatchers(XmlToken xmlToken, String regRegular) { List<String> descriptors = new ArrayList<>(); String text = xmlToken.getText().replace("\r", "").replace("\n", ""); Pattern layoutPattern = Pattern.compile(regRegular); Matcher m = layoutPattern.matcher(text); Matcher m2 = FUN_PATTERN.matcher(text); while (m.find() && m2.find()) { int start = m2.start(); int end = m2.end(); String value = text.substring(start + 1, end - 1); descriptors.add(value); } return descriptors; }
Example #17
Source File: HtmlTemplateLineUtil.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
/** * 取得静态资源文件layout("/layouts/lay.html"){}和include("/header.html"){}等等类型 * * @return */ private static String getBeetlResPath(XmlToken xmlToken) { List<String> includes = BeetlHtmlLineUtil.showBeetlInclude(xmlToken); if (includes.size() > 0) { return includes.get(0); } List<String> layouts = BeetlHtmlLineUtil.showBeetlLayout(xmlToken); if (layouts.size() > 0) { return layouts.get(0); } return ""; }
Example #18
Source File: HtmlTemplateLineUtil.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
/** * 取得模版文件相对路径 * * @param bindingElement * @return */ public static String getTemplateFilePathAndName(PsiElement bindingElement) { if (bindingElement instanceof XmlAttribute) { return getResPath((XmlAttribute) bindingElement); } else if (bindingElement instanceof XmlToken) { return getBeetlResPath((XmlToken) bindingElement); } else { throw new RuntimeException("未知类型??请提交issues"); } }
Example #19
Source File: CamelRouteLineMarkerProvider.java From camel-idea-plugin with Apache License 2.0 | 4 votes |
private boolean isXmlTokenLiteralExpression(@NotNull PsiElement element) { return element instanceof XmlToken && (element.getParent() instanceof XmlTag); }
Example #20
Source File: BeetlHtmlLineUtil.java From NutzCodeInsight with Apache License 2.0 | 4 votes |
public static List<String> showBeetlInclude(XmlToken xmlToken) { return getMatchers(xmlToken, cfiguration.getSettingVO().getBeetlIncludeRegular()); }
Example #21
Source File: BeetlHtmlLineUtil.java From NutzCodeInsight with Apache License 2.0 | 4 votes |
public static List<String> showBeetlLayout(XmlToken xmlToken) { return getMatchers(xmlToken, cfiguration.getSettingVO().getBeetlLayoutRegular()); }
Example #22
Source File: TranslationTagGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@NotNull private PsiElementPattern.Capture<XmlToken> getTranslationTagValuePattern() { return PlatformPatterns.psiElement(XmlToken.class) .inVirtualFile(new VirtualFilePattern().withExtension("twig")) .withLanguage(XMLLanguage.INSTANCE); }
Example #23
Source File: RouteSettingDeprecatedInspection.java From idea-php-symfony2-plugin with MIT License | 2 votes |
/** * Find child token which stores value * * XmlToken: "'" * XmlToken: "attributeText" * XmlToken: "'" */ private PsiElement findAttributeValueToken(@NotNull XmlAttributeValue xmlAttributeValue, @NotNull final String attributeText) { return ContainerUtil.find(xmlAttributeValue.getChildren(), psiElement -> psiElement instanceof XmlToken && attributeText.equals(psiElement.getText()) ); }