use of com.intellij.psi.templateLanguages.OuterLanguageElement in project intellij-community by JetBrains.
the class GroovyBlockGenerator method getGroovyChildren.
private static ASTNode[] getGroovyChildren(final ASTNode node) {
PsiElement psi = node.getPsi();
if (psi instanceof OuterLanguageElement) {
TextRange range = node.getTextRange();
ArrayList<ASTNode> childList = new ArrayList<>();
PsiFile groovyFile = psi.getContainingFile().getViewProvider().getPsi(GroovyLanguage.INSTANCE);
if (groovyFile instanceof GroovyFileBase) {
addChildNodes(groovyFile, childList, range, psi);
}
return childList.toArray(new ASTNode[childList.size()]);
}
return node.getChildren(null);
}
use of com.intellij.psi.templateLanguages.OuterLanguageElement in project intellij-community by JetBrains.
the class XmlBlock method createLeafBlocks.
private void createLeafBlocks(ASTNode node, List<Block> result) {
if (node instanceof OuterLanguageElement) {
processChild(result, node, null, null, null);
return;
}
ASTNode child = node.getFirstChildNode();
if (child == null && !(node instanceof PsiWhiteSpace) && node.getElementType() != TokenType.ERROR_ELEMENT && node.getTextLength() > 0) {
result.add(new ReadOnlyBlock(node));
return;
}
while (child != null) {
createLeafBlocks(child, result);
child = child.getTreeNext();
}
}
use of com.intellij.psi.templateLanguages.OuterLanguageElement in project intellij-community by JetBrains.
the class XmlUnboundNsPrefixInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
private Boolean isXml;
private boolean isXmlFile(XmlElement element) {
if (isXml == null) {
final PsiFile file = element.getContainingFile();
isXml = file instanceof XmlFile && !InjectedLanguageManager.getInstance(element.getProject()).isInjectedFragment(file);
}
return isXml.booleanValue();
}
@Override
public void visitXmlToken(final XmlToken token) {
if (isXmlFile(token) && token.getTokenType() == XmlTokenType.XML_NAME) {
PsiElement element = token.getPrevSibling();
while (element instanceof PsiWhiteSpace) element = element.getPrevSibling();
if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
PsiElement parent = element.getParent();
if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
XmlTag tag = (XmlTag) parent;
checkUnboundNamespacePrefix(tag, tag, tag.getNamespacePrefix(), token, holder, isOnTheFly);
}
}
}
}
@Override
public void visitXmlAttribute(final XmlAttribute attribute) {
if (!isXmlFile(attribute)) {
return;
}
final String namespace = attribute.getNamespace();
if (attribute.isNamespaceDeclaration() || XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(namespace)) {
return;
}
XmlTag tag = attribute.getParent();
if (tag == null)
return;
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
return;
}
final String name = attribute.getName();
checkUnboundNamespacePrefix(attribute, tag, XmlUtil.findPrefixByQualifiedName(name), null, holder, isOnTheFly);
}
@Override
public void visitXmlAttributeValue(XmlAttributeValue value) {
PsiReference[] references = value.getReferences();
for (PsiReference reference : references) {
if (reference instanceof SchemaPrefixReference) {
if (!XML.equals(((SchemaPrefixReference) reference).getNamespacePrefix()) && reference.resolve() == null) {
holder.registerProblem(reference, XmlErrorMessages.message("unbound.namespace", ((SchemaPrefixReference) reference).getNamespacePrefix()), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
}
}
};
}
use of com.intellij.psi.templateLanguages.OuterLanguageElement in project intellij-plugins by JetBrains.
the class AngularJSInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
// check that we have angular directives indexed before injecting
final Project project = context.getProject();
if (!AngularIndexUtil.hasAngularJS(project))
return;
final PsiElement parent = context.getParent();
if (context instanceof XmlAttributeValueImpl && parent instanceof XmlAttribute) {
final String value = context.getText();
final int start = value.startsWith("'") || value.startsWith("\"") ? 1 : 0;
final int end = value.endsWith("'") || value.endsWith("\"") ? 1 : 0;
final int length = value.length();
if (AngularAttributesRegistry.isAngularExpressionAttribute((XmlAttribute) parent) && length > 1) {
registrar.startInjecting(AngularJSLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(start, length - end)).doneInjecting();
return;
}
if (AngularAttributesRegistry.isJSONAttribute((XmlAttribute) parent) && length > 1) {
registrar.startInjecting(JsonLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(start, length - end)).doneInjecting();
return;
}
}
if (context instanceof XmlTextImpl || context instanceof XmlAttributeValueImpl) {
final String start = AngularJSBracesUtil.getInjectionStart(project);
final String end = AngularJSBracesUtil.getInjectionEnd(project);
if (AngularJSBracesUtil.hasConflicts(start, end, context))
return;
final String text = context.getText();
int endIndex = -1;
int afterStart = -1;
while (true) {
final int startIdx = text.indexOf(start, Math.max(endIndex, afterStart));
afterStart = startIdx < 0 ? -1 : (startIdx + start.length());
if (afterStart < 0)
return;
endIndex = afterStart;
endIndex = InjectorMatchingEndFinder.findMatchingEnd(start, end, text, endIndex);
endIndex = endIndex > 0 ? endIndex : ElementManipulators.getValueTextRange(context).getEndOffset();
final PsiElement injectionCandidate = afterStart >= 0 ? context.findElementAt(afterStart) : null;
if (injectionCandidate != null && injectionCandidate.getNode().getElementType() != XmlTokenType.XML_COMMENT_CHARACTERS && !(injectionCandidate instanceof OuterLanguageElement)) {
if (afterStart > endIndex) {
if (ApplicationManager.getApplication().isInternal()) {
LOG.error("Braces: " + start + "," + end + "\n" + "Text: \"" + text + "\"" + "\n" + "Interval: (" + afterStart + "," + endIndex + ")" + "\n" + "File: " + context.getContainingFile().getName() + ", language:" + context.getContainingFile().getLanguage());
}
return;
}
registrar.startInjecting(AngularJSLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(afterStart, endIndex)).doneInjecting();
}
}
}
}
Aggregations