com.intellij.psi.xml.XmlText Java Examples

The following examples show how to use com.intellij.psi.xml.XmlText. 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: DefaultViewHelpersProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
private @NotNull
String extractDocumentation(XmlTag attributeTag) {
    StringBuilder attributeDocumentation = new StringBuilder();

    XmlTag attributeAnnotation = attributeTag.findFirstSubTag("xsd:annotation");
    if (attributeAnnotation != null) {
        XmlTag attributeDoc = attributeAnnotation.findFirstSubTag("xsd:documentation");
        if (attributeDoc != null) {
            for (XmlText textElement : attributeDoc.getValue().getTextElements()) {
                attributeDocumentation.append(textElement.getValue());
            }
        }
    }

    return attributeDocumentation.toString();
}
 
Example #2
Source File: XmlIdeaUtils.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@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("&amp;")) {
                returnText = prevSibling.getText() + returnText;
            }
            return Optional.ofNullable(getInnerText(returnText));
        }
    }
    return Optional.empty();
}
 
Example #3
Source File: XmlGoToHandler.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
@NotNull
private Collection<PsiElement> getControllerActionElements(@NotNull XmlText xmlText) {
    PsiElement xmlTag = xmlText.getParent();
    if(!(xmlTag instanceof XmlTag)) {
        return Collections.emptyList();
    }

    String controllerName = ShopwareXmlCompletion.getControllerOnScope((XmlTag) xmlTag);
    if (controllerName == null) {
        return Collections.emptyList();
    }

    String value = xmlText.getValue();

    Collection<PsiElement> targets = new HashSet<>();

    ShopwareUtil.collectControllerAction(xmlText.getProject(), controllerName, (method, methodStripped, moduleName, controllerName1) -> {
        if(value.equalsIgnoreCase(methodStripped)) {
            targets.add(method);
        }
    }, "Backend");

    return targets;
}
 
Example #4
Source File: RouteXmlReferenceContributor.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    PsiElement element = getElement();
    PsiElement parent = element.getParent();

    String text = null;
    if(parent instanceof XmlText) {
        // <route><default key="_controller">Fo<caret>o\Bar</default></route>
        text = parent.getText();
    } else if(parent instanceof XmlAttribute) {
        // <route controller=""/>
        text = ((XmlAttribute) parent).getValue();
    }

    if(text == null || StringUtils.isBlank(text)) {
        return new ResolveResult[0];
    }

    return PsiElementResolveResult.createResults(
        RouteHelper.getMethodsOnControllerShortcut(getElement().getProject(), text)
    );
}
 
Example #5
Source File: DomUtil.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
public static List<PsiElement> findXmlTexts(PsiElement[] psiElements) {
    List<PsiElement> xmlTexts = new ArrayList<>();
    for (PsiElement psiElement : psiElements) {
        if (psiElement instanceof XmlText) {
            xmlTexts.add(psiElement);
        }
    }
    return xmlTexts;
}
 
Example #6
Source File: MuleConfigLiveTemplateContextType.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public boolean isInContext(@NotNull final PsiFile file, final int offset)
{
  if (!MuleConfigUtils.isMuleFile(file))
  {
      return false;
  }
  PsiElement element = file.findElementAt(offset);
  return element != null && PsiTreeUtil.getParentOfType(element, XmlText.class) != null;
}
 
Example #7
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host,
                                 @NotNull InjectedLanguagePlaces injectedLanguagePlaces) {
    if (MuleConfigUtils.isMuleFile(host.getContainingFile())) {
        if (host instanceof XmlAttributeValue) {
            // Try to inject a language, somewhat abusing the lazy evaluation of predicates :(
            for (Pair<String, String> language : languages) {
                if (tryInjectLanguage(language.getFirst(), language.getSecond(), host, injectedLanguagePlaces)) {
                    break;
                }
            }
        } else if (host instanceof XmlText) {
            final XmlTag tag = ((XmlText) host).getParentTag();
            if (tag != null) {
                final QName tagName = MuleConfigUtils.getQName(tag);
                if (tagName.equals(globalFunctions) || tagName.equals(expressionComponent) || tagName.equals(expressionTransformer)) {
                    final String scriptingName = MelLanguage.MEL_LANGUAGE_ID;
                    injectLanguage(host, injectedLanguagePlaces, scriptingName);
                } else if (tagName.equals(scriptingScript)) {
                    final String engine = tag.getAttributeValue("engine");
                    if (engine != null) {
                        injectLanguage(host, injectedLanguagePlaces, StringUtil.capitalize(engine));
                    }
                } else if (tagName.equals(dwSetPayload) || tagName.equals(dwSetProperty) || tagName.equals(dwSetVariable) || tagName.equals(dwSetSessionVar)) {
                    injectLanguage(host, injectedLanguagePlaces, WEAVE_LANGUAGE_ID);
                }
            }
        }
    }
}
 
Example #8
Source File: TagTextIntention.java    From weex-language-support with MIT License 5 votes vote down vote up
private boolean available(PsiElement element) {
    PsiElement context = element.getContext();
    return context instanceof JSBlockStatement
            || context instanceof CssDeclaration
            || context instanceof XmlAttributeValue
            || context instanceof XmlText;
}
 
Example #9
Source File: GotoCompletionUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public static String getTextValueForElement(@NotNull PsiElement psiElement) {
    PsiElement parent = psiElement.getParent();

    String value = null;
    if(parent instanceof StringLiteralExpression) {
        value = ((StringLiteralExpression) parent).getContents();
    } else if(parent instanceof XmlAttributeValue) {
        // <foo attr="FOO"/>
        value = ((XmlAttributeValue) parent).getValue();
    } else if(parent instanceof XmlText) {
        // <foo>FOO</foo>
        value = ((XmlText) parent).getValue();
    } else if(parent instanceof YAMLScalar) {
        // foo: foo, foo: 'foo', foo: "foo"
        value = ((YAMLScalar) parent).getTextValue();
    } else if(psiElement.getNode().getElementType() == TwigTokenTypes.STRING_TEXT) {
        // twig: 'foobar'
        value = psiElement.getText();
    }

    if(StringUtils.isBlank(value)) {
        return null;
    }

    return value;
}
 
Example #10
Source File: ContainerConstantInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void xmlVisitor(@NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement psiElement) {
            if(!XmlHelper.getArgumentValueWithTypePattern("constant").accepts(psiElement)) {
                super.visitElement(psiElement);
                return;
            }

            PsiElement xmlText = psiElement.getParent();
            if(!(xmlText instanceof XmlText)) {
                super.visitElement(psiElement);
                return;
            }

            String value = ((XmlText) xmlText).getValue();
            if(StringUtils.isBlank(value)) {
                super.visitElement(psiElement);
                return;
            }

            if(ServiceContainerUtil.getTargetsForConstant(xmlText.getProject(), value).size() == 0) {
                holder.registerProblem(xmlText, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }

            super.visitElement(psiElement);
        }
    });
}
 
Example #11
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")
            )
        );
}
 
Example #12
Source File: ParameterXmlReference.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public ParameterXmlReference(@NotNull XmlText element) {
    super(element);
    parameterName = element.getValue();
}
 
Example #13
Source File: ConstantXmlReference.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
ConstantXmlReference(@NotNull XmlText element) {
    super(element);
}