@Override public void getLanguagesToInject(@NotNull final MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement context) { final PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; InjectedLanguagePlaces placesRegistrar = new InjectedLanguagePlaces() { @Override public void addPlace(@NotNull Language language, @NotNull TextRange rangeInsideHost, @NonNls @Nullable String prefix, @NonNls @Nullable String suffix) { injectionPlacesRegistrar .startInjecting(language) .addPlace(prefix, suffix, host, rangeInsideHost) .doneInjecting(); } }; for (LanguageInjector injector : Extensions.getExtensions(LanguageInjector.EXTENSION_POINT_NAME)) { injector.getLanguagesToInject(host, placesRegistrar); } }
@Override @NotNull public MultiHostRegistrar startInjecting(@NotNull Language language) { escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>(); shreds = new SmartList<PsiLanguageInjectionHost.Shred>(); outChars = new StringBuilder(); if (!cleared) { clear(); throw new IllegalStateException("Seems you haven't called doneInjecting()"); } if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) { ReferenceInjector injector = ReferenceInjector.findById(language.getID()); if (injector == null) { throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null"); } myLanguage = null; myReferenceInjector = injector; } myLanguage = language; return this; }
@NotNull private static PyInjectionUtil.InjectionResult registerCommentInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiLanguageInjectionHost host) { final String text = host.getText(); final Matcher m = PyTypingTypeProvider.TYPE_COMMENT_PATTERN.matcher(text); if (m.matches()) { final String annotationText = m.group(1); if (annotationText != null && isTypingAnnotation(annotationText)) { final int start = m.start(1); final int end = m.end(1); if (start < end && allowInjectionInComment(host)) { final Language language = PyDocstringLanguageDialect.getInstance(); registrar.startInjecting(language); registrar.addPlace("", "", host, TextRange.create(start, end)); registrar.doneInjecting(); return new PyInjectionUtil.InjectionResult(true, true); } } } return PyInjectionUtil.InjectionResult.EMPTY; }
@Override public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) { Pair<ASTNode, ASTNode> pair = parseConditionalCommentBoundaries(host); if (pair == null) { return; } final TextRange textRange = host.getTextRange(); final int startOffset = textRange.getStartOffset(); Language language = host.getParent().getLanguage(); ASTNode conditionalStart = pair.first; ASTNode conditionalEnd = pair.second; TextRange range = new UnfairTextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset); if (range.getStartOffset() < range.getEndOffset()) { registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting(); } }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) { if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) { return; } XmlTag scriptTag = ((XmlText)host).getParentTag(); if (scriptTag == null) { return; } final Language language = getScriptLanguageToInject(scriptTag); if (language == null || HtmlScriptInjectionBlockerExtension.isInjectionBlocked(scriptTag, language)) { return; } if (LanguageUtil.isInjectableLanguage(language)) { registrar .startInjecting(language) .addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength())) .doneInjecting(); } }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) { if (!(context instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost)context).isValidHost()) return; PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; PsiFile containingFile = context.getContainingFile(); InjectedLanguage injectedLanguage = myRegistry.getLanguageFor(host, containingFile); Language language = injectedLanguage != null ? injectedLanguage.getLanguage() : null; if (language == null) return; final ElementManipulator<PsiLanguageInjectionHost> manipulator = ElementManipulators.getManipulator(host); if (manipulator == null) return; List<Trinity<PsiLanguageInjectionHost, InjectedLanguage,TextRange>> trinities = Collections.singletonList(Trinity.create(host, injectedLanguage, manipulator.getRangeInElement(host))); InjectorUtils.registerInjection(language, trinities, containingFile, registrar); InjectorUtils.registerSupport(myRegistry.getLanguageInjectionSupport(), false, registrar); }
public static boolean registerInjectionSimple(@NotNull PsiLanguageInjectionHost host, @NotNull BaseInjection injection, @Nullable LanguageInjectionSupport support, @NotNull MultiHostRegistrar registrar) { Language language = InjectedLanguage.findLanguageById(injection.getInjectedLanguageId()); if (language == null) return false; InjectedLanguage injectedLanguage = InjectedLanguage.create(injection.getInjectedLanguageId(), injection.getPrefix(), injection.getSuffix(), false); List<TextRange> ranges = injection.getInjectedArea(host); List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list = ContainerUtil.newArrayListWithCapacity(ranges.size()); for (TextRange range : ranges) { list.add(Trinity.create(host, injectedLanguage, range)); } //if (host.getChildren().length > 0) { // host.putUserData(LanguageInjectionSupport.HAS_UNPARSABLE_FRAGMENTS, Boolean.TRUE); //} registerInjection(language, list, host.getContainingFile(), registrar); if (support != null) { registerSupport(support, true, registrar); } return !ranges.isEmpty(); }
public static void registerInjection(Language language, List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list, PsiFile containingFile, MultiHostRegistrar registrar) { // if language isn't injected when length == 0, subsequent edits will not cause the language to be injected as well. // Maybe IDEA core is caching a bit too aggressively here? if (language == null/* && (pair.second.getLength() > 0*/) { return; } boolean injectionStarted = false; for (Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange> trinity : list) { final PsiLanguageInjectionHost host = trinity.first; if (host.getContainingFile() != containingFile) continue; final TextRange textRange = trinity.third; final InjectedLanguage injectedLanguage = trinity.second; if (!injectionStarted) { registrar.startInjecting(language); injectionStarted = true; } registrar.addPlace(injectedLanguage.getPrefix(), injectedLanguage.getSuffix(), host, textRange); } if (injectionStarted) { registrar.doneInjecting(); } }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) { if (!(context instanceof PsiLanguageInjectionHost) || context instanceof PsiComment) return; if (!((PsiLanguageInjectionHost)context).isValidHost()) return; PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; boolean applicableFound = false; for (LanguageInjectionSupport support : mySupports) { if (!support.isApplicableTo(host)) continue; if (support == myInjectorSupport && applicableFound) continue; applicableFound = true; BaseInjection injection = support.findCommentInjection(host, null); if (injection == null) continue; if (!InjectorUtils.registerInjectionSimple(host, injection, support, registrar)) continue; return; } }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) { if (SCRIPT_PATTERN.accepts(host)) { final List<String> registeredLanguages = JavaFxPsiUtil.parseInjectedLanguages((XmlFile)host.getContainingFile()); for (Language language : Language.getRegisteredLanguages()) { for (String registeredLanguage : registeredLanguages) { if (StringUtil.equalsIgnoreCase(language.getID(), registeredLanguage)) { registrar.startInjecting(language) .addPlace(null, null, (PsiLanguageInjectionHost) host, TextRange.from(0, host.getTextLength() - 1)) .doneInjecting(); break; } } } } }
@Override public void getLanguagesToInject(@NotNull final MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement context) { final PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; InjectedLanguagePlaces placesRegistrar = new InjectedLanguagePlaces() { @Override public void addPlace(@NotNull Language language, @NotNull TextRange rangeInsideHost, @NonNls @Nullable String prefix, @NonNls @Nullable String suffix) { ProperTextRange.assertProperRange(rangeInsideHost); injectionPlacesRegistrar .startInjecting(language) .addPlace(prefix, suffix, host, rangeInsideHost) .doneInjecting(); } }; for (LanguageInjector injector : Extensions.getExtensions(LanguageInjector.EXTENSION_POINT_NAME)) { injector.getLanguagesToInject(host, placesRegistrar); } }
@Override @NotNull public MultiHostRegistrar startInjecting(@NotNull Language language) { escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>(); shreds = new SmartList<PsiLanguageInjectionHost.Shred>(); outChars = new StringBuilder(); if (!cleared) { clear(); throw new IllegalStateException("Seems you haven't called doneInjecting()"); } if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) { throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null"); } myLanguage = language; return this; }
public static boolean registerInjectionSimple(@NotNull PsiLanguageInjectionHost host, @NotNull BaseInjection injection, @Nullable LanguageInjectionSupport support, @NotNull MultiHostRegistrar registrar) { Language language = InjectedLanguage.findLanguageById(injection.getInjectedLanguageId()); if (language == null) return false; InjectedLanguage injectedLanguage = InjectedLanguage.create(injection.getInjectedLanguageId(), injection.getPrefix(), injection.getSuffix(), false); List<TextRange> ranges = injection.getInjectedArea(host); List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list = ContainerUtil.newArrayListWithExpectedSize(ranges.size()); for (TextRange range : ranges) { list.add(Trinity.create(host, injectedLanguage, range)); } //if (host.getChildren().length > 0) { // host.putUserData(LanguageInjectionSupport.HAS_UNPARSABLE_FRAGMENTS, Boolean.TRUE); //} registerInjection(language, list, host.getContainingFile(), registrar); if (support != null) { registerSupport(support, true, registrar); } return !ranges.isEmpty(); }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) { if (!(context instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost)context).isValidHost()) return; PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; boolean applicableFound = false; for (LanguageInjectionSupport support : mySupports) { if (!support.isApplicableTo(host)) continue; if (support == myInjectorSupport && applicableFound) continue; applicableFound = true; BaseInjection injection = support.findCommentInjection(host, null); if (injection == null) continue; if (!InjectorUtils.registerInjectionSimple(host, injection, support, registrar)) continue; return; } }
private static void processAnnotations(MultiHostRegistrar registrar, PsiLanguageInjectionHost host, PsiModifierListOwner annotationOwner) { final Pair<String, ? extends Set<String>> pair = Configuration.getInstance().getAdvancedConfiguration().getLanguageAnnotationPair(); final PsiAnnotation[] annotations = getAnnotationFrom(annotationOwner, pair, true, true); if (annotations.length > 0) { BaseInjection injection = new BaseInjection(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID); injection.setPrefix(StringUtil.notNullize(AnnotationUtilEx.calcAnnotationValue(annotations, "prefix"))); injection.setSuffix(StringUtil.notNullize(AnnotationUtilEx.calcAnnotationValue(annotations, "suffix"))); injection.setInjectedLanguageId(StringUtil.notNullize(AnnotationUtilEx.calcAnnotationValue(annotations, "value"))); LanguageInjectionSupport support = InjectorUtils.findInjectionSupport(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID); InjectorUtils.registerInjectionSimple(host, injection, support, registrar); } }
@Override public void injectLanguages(@NotNull MultiHostRegistrar multiHostRegistrar, @NotNull PsiElement element) { if (SCRIPT_PATTERN.accepts(element)) { final List<String> registeredLanguages = JavaFxPsiUtil.parseInjectedLanguages((XmlFile) element.getContainingFile()); for (Language language : Language.getRegisteredLanguages()) { for (String registeredLanguage : registeredLanguages) { if (StringUtil.equalsIgnoreCase(language.getID(), registeredLanguage)) { multiHostRegistrar.startInjecting(language) .addPlace(null, null, (PsiLanguageInjectionHost) element, TextRange.from(0, element.getTextLength() - 1)) .doneInjecting(); break; } } } } }
@Nonnull @Override public MultiHostRegistrar startInjecting(@Nonnull LanguageVersion languageVersion) { placeInfos = new SmartList<>(); if (!cleared) { clear(); throw new IllegalStateException("Seems you haven't called doneInjecting()"); } currentThread = Thread.currentThread(); if (LanguageParserDefinitions.INSTANCE.forLanguage(languageVersion.getLanguage()) == null) { throw new UnsupportedOperationException("Cannot inject language '" + languageVersion.getLanguage() + "' because it has no ParserDefinition"); } myLanguageVersion = languageVersion; return this; }
@Override @Nonnull public MultiHostRegistrar addPlace(@NonNls @Nullable String prefix, @NonNls @Nullable String suffix, @Nonnull PsiLanguageInjectionHost host, @Nonnull TextRange rangeInsideHost) { checkThreading(); if (myLanguageVersion == null) { clear(); throw new IllegalStateException("Seems you haven't called startInjecting()"); } PsiFile containingFile = PsiUtilCore.getTemplateLanguageFile(host); assert containingFile == myHostPsiFile : exceptionContext("Trying to inject into foreign file: " + containingFile, myLanguageVersion, myHostPsiFile, myHostVirtualFile, myHostDocument, placeInfos); TextRange hostTextRange = host.getTextRange(); if (!hostTextRange.contains(rangeInsideHost.shiftRight(hostTextRange.getStartOffset()))) { clear(); throw new IllegalArgumentException("rangeInsideHost must lie within host text range. rangeInsideHost:" + rangeInsideHost + "; host textRange:" + hostTextRange); } cleared = false; String nnPrefix = StringUtil.isEmpty(prefix) ? "" : prefix; // intern empty strings too to reduce gc String nnSuffix = StringUtil.isEmpty(suffix) ? "" : suffix; // intern empty strings too to reduce gc PlaceInfo info = new PlaceInfo(nnPrefix, nnSuffix, host, rangeInsideHost); placeInfos.add(info); return this; }
@Override public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) { if (!(host instanceof XmlText)) { return; } XmlTag scriptTag = ((XmlText)host).getParentTag(); if (!"script".equalsIgnoreCase(scriptTag.getLocalName())) { return; } String mimeType = scriptTag.getAttributeValue("type"); Collection<Language> languages = Language.findInstancesByMimeType(mimeType); Language language = languages.isEmpty() ? null : languages.iterator().next(); if (language != null && LanguageUtil.isInjectableLanguage(language)) { registrar .startInjecting(language) .addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength())) .doneInjecting(); } }
@Override public void injectLanguages(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) { Pair<ASTNode, ASTNode> pair = parseConditionalCommentBoundaries(host); if (pair == null) { return; } final TextRange textRange = host.getTextRange(); final int startOffset = textRange.getStartOffset(); Language language = host.getParent().getLanguage(); ASTNode conditionalStart = pair.first; ASTNode conditionalEnd = pair.second; TextRange range = new TextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset); if (range.getStartOffset() < range.getEndOffset()) { registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting(); } }
@Override @RequiredReadAction public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if(context instanceof JSSimpleLiteralExpression) { IElementType literalElementType = ((JSSimpleLiteralExpression) context).getLiteralElementType(); if(literalElementType == JSTokenTypes.REGEXP_LITERAL) { int textLength = context.getTextLength() - 1; String text = context.getText(); if(text.charAt(textLength) != '/') { textLength --; } registrar.startInjecting(RegExpLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(1, textLength)).doneInjecting(); } } }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if (context instanceof AppleScriptStringLiteralExpression) { AppleScriptCommandHandlerCall asCommand = PsiTreeUtil.getContextOfType(context, AppleScriptCommandHandlerCall.class); if (asCommand != null && asCommand.getCommandName().equalsIgnoreCase("do javascript")) { Collection<Language> javascript = Language.findInstancesByMimeType("javascript"); if (javascript.isEmpty()) return; registrar.startInjecting(javascript.iterator().next()).addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(1, context.getTextLength() - 1)).doneInjecting(); } } }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final PyInjectionUtil.InjectionResult result = registerInjection(registrar, context); if (!result.isStrict()) { InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, Boolean.TRUE); } }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final PyInjectionUtil.InjectionResult result = registerInjection(registrar, context); if (result.isInjected()) { final TemporaryPlacesRegistry registry = TemporaryPlacesRegistry.getInstance(context.getProject()); InjectorUtils.registerSupport(registry.getLanguageInjectionSupport(), false, registrar); if (!result.isStrict()) { InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, Boolean.TRUE); } } }
@Override protected PyInjectionUtil.InjectionResult registerInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final PyInjectionUtil.InjectionResult result = super.registerInjection(registrar, context); if (result == PyInjectionUtil.InjectionResult.EMPTY && context instanceof PsiComment && context instanceof PsiLanguageInjectionHost) { return registerCommentInjection(registrar, (PsiLanguageInjectionHost)context); } return result; }
protected PyInjectionUtil.InjectionResult registerInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final Language language = getInjectedLanguage(context); if (language != null) { final PsiElement element = PyInjectionUtil.getLargestStringLiteral(context); if (element != null) { registrar.startInjecting(language); final PyInjectionUtil.InjectionResult result = PyInjectionUtil.registerStringLiteralInjection(element, registrar); if (result.isInjected()) { registrar.doneInjecting(); } return result; } } return PyInjectionUtil.InjectionResult.EMPTY; }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final PsiElement contextParent = context.getParent(); if (PyInjectionUtil.getLargestStringLiteral(context) == context && contextParent instanceof PyArgumentList) { final PyExpression[] args = ((PyArgumentList)contextParent).getArguments(); int index = ArrayUtil.indexOf(args, context); PyCallExpression call = PsiTreeUtil.getParentOfType(context, PyCallExpression.class); if (call != null) { final PyExpression callee = call.getCallee(); if (callee instanceof PyReferenceExpression && canBeRegexpCall(callee)) { final PsiPolyVariantReference ref = ((PyReferenceExpression)callee).getReference(PyResolveContext.noImplicits()); if (ref != null) { final PsiElement element = ref.resolve(); if (element != null && ScopeUtil.getScopeOwner(element) instanceof PyFile && element.getContainingFile().getName().equals("re.py") && isRegexpMethod(element, index)) { final Language language = isVerbose(call) ? PythonVerboseRegexpLanguage.INSTANCE : PythonRegexpLanguage.INSTANCE; registrar.startInjecting(language); final PyInjectionUtil.InjectionResult result = PyInjectionUtil.registerStringLiteralInjection(context, registrar); if (result.isInjected()) { registrar.doneInjecting(); if (!result.isStrict()) { final PsiFile file = getInjectedFile(registrar); if (file != null) { file.putUserData(InjectedLanguageUtil.FRANKENSTEIN_INJECTION, Boolean.TRUE); } } } } } } } } }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) { if (!(context instanceof PsiLanguageInjectionHost) || !((PsiLanguageInjectionHost)context).isValidHost()) return; PsiLanguageInjectionHost host = (PsiLanguageInjectionHost)context; for (LanguageInjectionSupport support : mySupports) { if (!support.isApplicableTo(host)) continue; if (!support.useDefaultInjector(host)) continue; for (BaseInjection injection : myInjectionConfiguration.getInjections(support.getId())) { if (!injection.acceptsPsiElement(host)) continue; if (!InjectorUtils.registerInjectionSimple(host, injection, support, registrar)) continue; return; } } }
@Override public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement... operands) { if (operands.length == 0) return; final PsiFile file = operands[0].getContainingFile(); if (!(file instanceof GroovyFileBase)) return; new InjectionProcessor(myConfiguration, mySupport, operands) { @Override protected void processInjection(Language language, List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list, boolean settingsAvailable, boolean unparsable) { InjectorUtils.registerInjection(language, list, file, registrar); InjectorUtils.registerSupport(mySupport, settingsAvailable, registrar); InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable); } @Override protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) { if (getAnnotatedElementsValue().contains(methodName)) { return true; } if (!annoOnly && getXmlAnnotatedElementsValue().contains(methodName)) { return true; } return false; } }.processInjections(); }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { assert context instanceof GrLiteral; final GrLiteral literal = (GrLiteral)context; processInPlace(registrar, literal); }
public static void processInPlace(MultiHostRegistrar registrar, GrLiteral literal) { BaseInjection injection = findLanguageParams(literal, Configuration.getInstance()); if (injection != null) { LanguageInjectionSupport support = InjectorUtils.findInjectionSupport(GroovyLanguageInjectionSupport.GROOVY_SUPPORT_ID); InjectorUtils.registerInjectionSimple(literal, injection, support, registrar); } }
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final XmlAttribute attribute = (XmlAttribute)context; if (!XsltSupport.isXPathAttribute(attribute)) return; XmlAttributeValueImpl value = (XmlAttributeValueImpl)attribute.getValueElement(); if (value == null) return; ASTNode type = value.findChildByType(XmlElementType.XML_ENTITY_REF); if (type != null) return; // workaround for inability to inject into text with entity refs (e.g. IDEA-72972) TODO: fix it final XsltChecker.LanguageLevel languageLevel = XsltSupport.getXsltLanguageLevel(attribute.getContainingFile()); final TextRange[] ranges = getInjectionRanges(attribute, languageLevel); for (TextRange range : ranges) { // workaround for http://www.jetbrains.net/jira/browse/IDEA-10096 TextRange rangeInsideHost; String prefix; if (range instanceof AVTRange) { if (((AVTRange)range).myComplete) { rangeInsideHost = range.shiftRight(2).grown(-2); prefix = ""; } else { // we need to keep the "'}' expected" parse error rangeInsideHost = range.shiftRight(2).grown(-1); prefix = "{"; } } else { rangeInsideHost = range; prefix = ""; } if (value.getTextRange().contains(rangeInsideHost.shiftRight(value.getTextRange().getStartOffset()))) { registrar.startInjecting(languageLevel.getXPathVersion().getLanguage()) .addPlace(prefix, "", value, rangeInsideHost) .doneInjecting(); } } }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { if(JSGraphQLLanguageInjectionUtil.isJSGraphQLLanguageInjectionTarget(context)) { final JSStringTemplateExpression template = (JSStringTemplateExpression)context; final TextRange graphQlTextRange = JSGraphQLLanguageInjectionUtil.getGraphQLTextRange(template); if(graphQlTextRange.isEmpty()) { // all whitespace return; } registrar.startInjecting(JSGraphQLLanguage.INSTANCE); final StringBuilder sb = new StringBuilder(); final TextRange[] stringRanges = template.getStringRanges(); int stringIndex = 0; boolean insideTemplate = false; for (ASTNode astNode : template.getNode().getChildren(null)) { if(astNode.getElementType() == JSTokenTypes.BACKQUOTE) { insideTemplate = true; continue; } if(astNode.getElementType() == JSTokenTypes.STRING_TEMPLATE_PART) { registrar.addPlace(sb.toString(), "", (PsiLanguageInjectionHost) template, stringRanges[stringIndex]); stringIndex++; sb.setLength(0); } else if(insideTemplate) { sb.append(astNode.getText()); } } registrar.doneInjecting(); } }
@Override @RequiredReadAction public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { ShaderCGScript cgScript = (ShaderCGScript) context; PsiElement scriptBlock = cgScript.getScriptBlock(); if(scriptBlock == null) { return; } int startOffsetInParent = scriptBlock.getStartOffsetInParent(); registrar.startInjecting(CGLanguage.INSTANCE).addPlace(null, null, cgScript, new TextRange(startOffsetInParent, scriptBlock.getTextLength() + startOffsetInParent)).doneInjecting(); }
@Override public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement host) { if (!host.isValid() || !(host instanceof XmlText) || !HtmlUtil.isHtmlTagContainingFile(host)) { return; } XmlTag scriptTag = ((XmlText)host).getParentTag(); if (scriptTag == null || !"script".equalsIgnoreCase(scriptTag.getLocalName())) { return; } String mimeType = scriptTag.getAttributeValue("type"); Collection<Language> languages = Language.findInstancesByMimeType(mimeType); Language language; if (!languages.isEmpty()) { language = languages.iterator().next(); } else if (mimeType != null && mimeType.contains("template")) { language = StdLanguages.HTML; } else { language = StdLanguages.TEXT; } if (LanguageUtil.isInjectableLanguage(language)) { registrar .startInjecting(language) .addPlace(null, null, (PsiLanguageInjectionHost)host, TextRange.create(0, host.getTextLength())) .doneInjecting(); } }
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement host) { Pair<ASTNode, ASTNode> pair = parseConditionalCommentBoundaries(host); if (pair == null) { return; } final TextRange textRange = host.getTextRange(); final int startOffset = textRange.getStartOffset(); Language language = host.getParent().getLanguage(); ASTNode conditionalStart = pair.first; ASTNode conditionalEnd = pair.second; TextRange range = new TextRange(conditionalStart.getTextRange().getEndOffset() - startOffset, conditionalEnd.getStartOffset() - startOffset); if (range.getStartOffset() < range.getEndOffset()) { registrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost)host, range).doneInjecting(); } }