@Override public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) { if (!(host instanceof XmlText)) return; final XmlText xmlText = (XmlText)host; if (!MavenPluginParamInfo.isSimpleText(xmlText)) return; MavenPluginParamInfo.ParamInfoList infoList = MavenPluginParamInfo.getParamInfoList(xmlText); for (MavenPluginParamInfo.ParamInfo info : infoList) { Language language = info.getLanguage(); if (language == null) { MavenParamLanguageProvider provider = info.getLanguageProvider(); if (provider != null) { language = provider.getLanguage(xmlText, infoList.getDomCfg()); } } if (language != null) { injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix()); return; } } }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces) { if (host.getLanguage().isKindOf(JavaScriptLanguage) && host.getClass().getSimpleName().equals(TEMPLATE_STRING)) { String hostText = host.getText(); if (!hostText.contains("${") && hostText.startsWith(prefix) && hostText.endsWith(suffix)) { injectedLanguagePlaces.addPlace( GraphQLLanguage.INSTANCE, new TextRange( prefix.length(), hostText.length() - suffix.length() ), null, null); } } }
@Override public void getLanguagesToInject( @NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { // we accept only PHP literal expressions, such as docBlocks and string for PointcutBuilder->method('<expr>') if (!(host instanceof StringLiteralExpression)) { return; } StringLiteralExpression literalExpression = (StringLiteralExpression) host; boolean enableInjection = CodePattern.isInsideAnnotation(literalExpression, GO_AOP_ANNOTATION); enableInjection |= CodePattern.isInsidePointcutBuilderMethod(literalExpression); if (enableInjection) { TextRange rangeInsideHost = new TextRange(1, Math.max(literalExpression.getTextLength()-1, 1)); injectionPlacesRegistrar.addPlace(PointcutQueryLanguage.INSTANCE, rangeInsideHost, null, null); } }
@Override public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces places) { final boolean isSelectQuery = host.getText().trim().toUpperCase().startsWith("SELECT"); final boolean isDataSetFile = host.getContainingFile().getText().startsWith("<dataset>"); if (isDataSetFile && isSelectQuery) { final Language language = Language.findLanguageByID("SQL"); if (language != null) { try { places.addPlace(language, TextRange.from(0, host.getTextLength()), null, null); } catch (Throwable e) { e.printStackTrace(); } } } }
@Override public void getLanguagesToInject( @NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar ) { final PsiElement hostParent = host.getParent(); if (host instanceof ImpexStringImpl) { final String hostString = StringUtil.unquoteString(host.getText()).toLowerCase(); if (StringUtil.trim(hostString).startsWith("select ")) { registerInjectionPlace(injectionPlacesRegistrar, host); } } if (hostParent != null) { if (hostParent.getParent() instanceof PsiMethodCallExpressionImpl) { final PsiMethodCallExpressionImpl callExpression = (PsiMethodCallExpressionImpl) hostParent.getParent(); final PsiMethod method = callExpression.resolveMethod(); if (method != null) { final PsiClass containingClass = method.getContainingClass(); if (containingClass != null && "FlexibleSearchService".equals(containingClass.getName()) && "search".equals(method.getName())) { registerInjectionPlace(injectionPlacesRegistrar, host); } } } } }
@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); } } } } }
private void injectLanguage(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces, String scriptingName) { final Language requiredLanguage = Language.findLanguageByID(scriptingName); if (requiredLanguage != null) { final TextRange range = TextRange.from(0, host.getTextRange().getLength()); injectedLanguagePlaces.addPlace(requiredLanguage, range, null, null); } }
private boolean tryInjectLanguage(@NotNull String langPrefix, @NotNull String languageId, @NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces) { if (isExpectedLocalName(langPrefix, host)) { injectLanguage(langPrefix, languageId, host, injectedLanguagePlaces); return true; } return false; }
private void injectLanguage(String langPrefix, @NotNull String languageId, @NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces) { // Find the required Language final Language requiredLanguage = Language.findLanguageByID(languageId); if (requiredLanguage == null) { return; } final TextRange textRange = ((XmlAttributeValue) host).getValueTextRange(); final int length = getLanguagePrefix(langPrefix).length() + 1; final TextRange expressionTextRange = TextRange.from(length, textRange.getLength() - length); injectedLanguagePlaces.addPlace(requiredLanguage, expressionTextRange, null, null); }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { if (!(host instanceof CupJavaImpl) || !(settings.ENABLE_JAVA_INJECTION)) { return; } final CupJavaImpl cupJavaCode = (CupJavaImpl) host; final String text = cupJavaCode.getText(); if (!(text.startsWith(PREFIX) && text.endsWith(SUFFIX))) { return; } injectionPlacesRegistrar.addPlace(JavaLanguage.INSTANCE, new TextRange(SUFFIX.length(), text.length() - SUFFIX.length()), "public class Dummy { public void dummyMethod(){", "}}"); }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { Iterator it = myInjectionConfiguration.getInjections("fusion").iterator(); while(it.hasNext()) { BaseInjection injection = (BaseInjection) it.next(); if (injection.acceptsPsiElement(host)) { Language language = InjectedLanguage.findLanguageById(injection.getInjectedLanguageId()); if (language != null) { injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getTextLength()), "", ""); } } } }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { if (!(host instanceof XmlAttributeValue)) { return; } String valueText = ((XmlAttributeValue)host).getValue(); if (valueText.length() <= PREFIX_BINDING_EXPR.length() || !valueText.startsWith(PREFIX_BINDING_EXPR)) { return; } PsiElement parent = host.getParent(); if (!(parent instanceof XmlAttribute)) return; GenericAttributeValue element = DomManager.getDomManager(host.getProject()).getDomElement((XmlAttribute)parent); if (element == null || !(element.getParent() instanceof AndroidDomElement)) return; // Parser only parses the expression, not the prefix '@{' or the suffix '}'. Extract the start/end index of the expression. String unescapedValue = host.getText(); int startIndex = unescapedValue.indexOf(PREFIX_BINDING_EXPR.charAt(0)) + PREFIX_BINDING_EXPR.length(); int endIndex; if (valueText.endsWith("}")) { endIndex = unescapedValue.lastIndexOf('}'); } else { if (host.getNode().getLastChildNode().getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) { endIndex = host.getLastChild().getStartOffsetInParent(); } else { endIndex = unescapedValue.length(); } } injectionPlacesRegistrar.addPlace(DbLanguage.INSTANCE, TextRange.from(startIndex, endIndex-startIndex), null, null); }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { if(ApplicationManager.getApplication().isUnitTestMode()) { // intellij unit test env doesn't properly support language injection in combination with formatter tests, so skip injection in that case return; } if (host instanceof PsiComment && host.getLanguage() == JSGraphQLEndpointLanguage.INSTANCE) { injectionPlacesRegistrar.addPlace(JSGraphQLEndpointDocLanguage.INSTANCE, TextRange.create(0, host.getTextLength()), "", ""); } }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { if (host instanceof HaxeRegularExpression) { final String text = host.getText(); final TextRange textRange = new TextRange(text.indexOf('/') + 1, text.lastIndexOf('/')); injectionPlacesRegistrar.addPlace(RegExpLanguage.INSTANCE, textRange, null, null); } }
@Override public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) { if (host instanceof RestLine) { int start = 0; int end = host.getTextLength() - 1; final String text = host.getText(); final List<String> strings = StringUtil.split(text, "\n", false); boolean gotExample = false; int currentPosition = 0; boolean endsWithSlash = false; for (String string : strings) { final String trimmedString = string.trim(); if (!trimmedString.startsWith(">>>") && !trimmedString.startsWith("...") && gotExample && start < end) { gotExample = false; if (!endsWithSlash) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } if (endsWithSlash) { endsWithSlash = false; injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, getEndOffset(currentPosition, string)), null, null); } if (trimmedString.startsWith(">>>")) { if (trimmedString.endsWith("\\")) endsWithSlash = true; if (!gotExample) start = currentPosition; gotExample = true; end = getEndOffset(currentPosition, string); } else if (trimmedString.startsWith("...") && gotExample) { if (trimmedString.endsWith("\\")) endsWithSlash = true; end = getEndOffset(currentPosition, string); } currentPosition += string.length(); } if (gotExample && start < end) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } }
@Override public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) { if (!(host instanceof PyStringLiteralExpression)) { return; } final Module module = ModuleUtilCore.findModuleForPsiElement(host); if (module == null || !PyDocumentationSettings.getInstance(module).isAnalyzeDoctest()) return; final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(host, PyDocStringOwner.class); if (docStringOwner != null && host.equals(docStringOwner.getDocStringExpression())) { int start = 0; int end = host.getTextLength() - 1; final String text = host.getText(); final Pair<String,String> quotes = PythonStringUtil.getQuotes(text); final List<String> strings = StringUtil.split(text, "\n", false); boolean gotExample = false; int currentPosition = 0; int maxPosition = text.length(); boolean endsWithSlash = false; for (String string : strings) { final String trimmedString = string.trim(); if (!trimmedString.startsWith(">>>") && !trimmedString.startsWith("...") && gotExample && start < end) { gotExample = false; if (!endsWithSlash) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } final String closingQuote = quotes == null ? text.substring(0, 1) : quotes.second; if (endsWithSlash && !trimmedString.endsWith("\\")) { endsWithSlash = false; injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, getEndOffset(currentPosition, string, maxPosition, closingQuote)), null, null); } if (trimmedString.startsWith(">>>")) { if (trimmedString.endsWith("\\")) endsWithSlash = true; if (!gotExample) start = currentPosition; gotExample = true; end = getEndOffset(currentPosition, string, maxPosition, closingQuote); } else if (trimmedString.startsWith("...") && gotExample) { if (trimmedString.endsWith("\\")) endsWithSlash = true; end = getEndOffset(currentPosition, string, maxPosition, closingQuote); } currentPosition += string.length(); } if (gotExample && start < end) injectionPlacesRegistrar.addPlace(PyDocstringLanguageDialect.getInstance(), TextRange.create(start, end), null, null); } }
@Override public void getLanguagesToInject(PsiLanguageInjectionHost psiLanguageInjectionHost, InjectedLanguagePlaces injectedLanguagePlaces) { //TODO: implement language injector }
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost _host, @NotNull InjectedLanguagePlaces registrar) { if (_host instanceof JFlexJavaCode) { if (!settings.ENABLED_EMBED_JAVA) return; JFlexJavaCode host = (JFlexJavaCode) _host; assert host.getContainingFile() instanceof JFlexPsiFile; JFlexPsiFile file = (JFlexPsiFile) host.getContainingFile(); JFlexJavaCode importSection = file.getImports(); //processing imports and package section if (importSection == host) { registrar.addPlace(StdLanguages.JAVA, new TextRange(0, host.getTextLength()), null, "\npublic class a{}"); return; } StringBuilder prefix = new StringBuilder(); //let's add some imports and package statements from flex file header if (importSection != null) { prefix.append(importSection.getText()); } String classnamestr = DEFCLASS; JFlexElement classname = file.getClassname(); if (classname != null) { classnamestr = classname.getText(); } String returntypestr = DEFTYPE; JFlexElement returntype = file.getReturnType(); if (returntype != null) { returntypestr = returntype.getText(); } StringBuilder implementedstr = new StringBuilder(); JFlexElement[] implemented = file.getImplementedInterfaces(); //what a lousy piece of code. if (implemented.length > 0) { implementedstr.append(" implements "); for (int i = 0; i < implemented.length; i++) { JFlexElement jFlexElement = implemented[i]; implementedstr.append(jFlexElement.getText()); if (i < implemented.length - 1) { implementedstr.append(","); } } } prefix.append("\npublic class ").append(classnamestr).append(implementedstr.toString()).append("{"); StringBuilder suffix = new StringBuilder(); if (host.isMatchAction()) { prefix.append("public ").append(returntypestr).append(" yylex(){"); suffix.append("}}"); } else { suffix.append("}"); } registrar.addPlace(StdLanguages.JAVA, new TextRange(0, host.getTextLength()), prefix.toString(), suffix.toString()); } }
@Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost psiElement, @NotNull InjectedLanguagePlaces injectedLanguagePlaces) { //TODO add language support within HTML at all places }