Java Code Examples for com.intellij.lang.Language#findLanguageByID()

The following examples show how to use com.intellij.lang.Language#findLanguageByID() . 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: XmlSqlTplMultiHostInjector.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
    public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement psiElement) {
        String productCode = INSTANCE.getBuild().getProductCode();
        if (NutzCons.IDEA_VERSION.equals(productCode)) {
            final Language SQL_LANGUAGE = Language.findLanguageByID("SQL");
            if (DomUtil.isNutzSqlFile(psiElement.getContainingFile())) {
                if (psiElement instanceof XmlTag) {
                    XmlTag tag = (XmlTag) psiElement;
                    if (SQL_TAG.equals(tag.getName())) {
                        registrarInjecting(SQL_LANGUAGE, registrar, DomUtil.findXmlTexts(psiElement.getChildren()), null, null);
                    }
//                else if (EXP_TAG.equals(tag.getName())) {
//                    registrarInjecting(XMLLanguage.INSTANCE, registrar, DomUtil.findXmlTexts(psiElement.getChildren()), "<!--", "-->");
//                }
                }
            }
        }
    }
 
Example 2
Source File: TemplateLanguageErrorFilter.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected TemplateLanguageErrorFilter(
  final @Nonnull TokenSet templateExpressionStartTokens,
  final @Nonnull Class templateFileViewProviderClass,
  final @Nonnull String... knownSubLanguageNames)
{
  myTemplateExpressionStartTokens = TokenSet.create(templateExpressionStartTokens.getTypes());
  myTemplateFileViewProviderClass = templateFileViewProviderClass;

  List<String> knownSubLanguageList = new ArrayList<String>(Arrays.asList(knownSubLanguageNames));
  knownSubLanguageList.add("JavaScript");
  knownSubLanguageList.add("CSS");
  knownLanguageSet = new HashSet<Language>();
  for (String name : knownSubLanguageList) {
    final Language language = Language.findLanguageByID(name);
    if (language != null) {
      knownLanguageSet.add(language);
    }
  }
}
 
Example 3
Source File: InspectionManagerEx.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static SuppressIntentionAction[] getSuppressActions(@Nonnull InspectionToolWrapper toolWrapper) {
  final InspectionProfileEntry tool = toolWrapper.getTool();
  if (tool instanceof CustomSuppressableInspectionTool) {
    return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null);
  }
  final List<LocalQuickFix> actions = new ArrayList<LocalQuickFix>(Arrays.asList(tool.getBatchSuppressActions(null)));
  if (actions.isEmpty()) {
    final Language language = Language.findLanguageByID(toolWrapper.getLanguage());
    if (language != null) {
      final List<InspectionSuppressor> suppressors = LanguageInspectionSuppressors.INSTANCE.allForLanguage(language);
      for (InspectionSuppressor suppressor : suppressors) {
        final SuppressQuickFix[] suppressActions = suppressor.getSuppressActions(null, tool.getShortName());
        Collections.addAll(actions, suppressActions);
      }
    }
  }
  return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function<LocalQuickFix, SuppressIntentionAction>() {
    @Override
    public SuppressIntentionAction fun(final LocalQuickFix fix) {
      return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix);
    }
  });
}
 
Example 4
Source File: TaskUtils.java    From JHelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static PsiElement generateCPP(Project project, TaskData taskData) {
	VirtualFile parent = FileUtils.findOrCreateByRelativePath(project.getBaseDir(), FileUtils.getDirectory(taskData.getCppPath()));
	PsiDirectory psiParent = PsiManager.getInstance(project).findDirectory(parent);
	if (psiParent == null) {
		throw new NotificationException("Couldn't open parent directory as PSI");
	}

	Language objC = Language.findLanguageByID("ObjectiveC");
	if (objC == null) {
		throw new NotificationException("Language not found");
	}

	PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(
			FileUtils.getFilename(taskData.getCppPath()),
			objC,
			getTaskContent(project, taskData.getClassName())
	);
	if (file == null) {
		throw new NotificationException("Couldn't generate file");
	}
	return ApplicationManager.getApplication().runWriteAction(
			(Computable<PsiElement>) () -> psiParent.add(file)
	);

}
 
Example 5
Source File: SQLInjector.java    From dbunit-extractor with MIT License 6 votes vote down vote up
@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();
            }
        }
    }
}
 
Example 6
Source File: NutzJavaSqlMultiHostInjector.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement psiElement) {
    String productCode = INSTANCE.getBuild().getProductCode();
    if (NutzCons.IDEA_VERSION.equals(productCode)) {
        //旗舰版才支持该功能
        final Language SQL_LANGUAGE = Language.findLanguageByID("SQL");
        if (psiElement.getParent() != null && psiElement.getParent().getParent() != null) {
            PsiElement parent = psiElement.getParent().getParent().getParent();
            if (parent != null && parent instanceof PsiAnnotation) {
                String qualifiedName = ((PsiAnnotation) parent).getQualifiedName();
                if (NutzCons.SQLS.contains(qualifiedName)) {
                    registrar.startInjecting(SQL_LANGUAGE);
                    registrar.addPlace(null, null, (PsiLanguageInjectionHost) psiElement, ElementManipulators.getValueTextRange(psiElement));
                    registrar.doneInjecting();
                }
            }
        }
    }
}
 
Example 7
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
private EditorHighlighter createHighlighter(EditorColorsScheme settings) {
    Language language = Language.findLanguageByID("JSON");
    if (language == null) {
        language = Language.ANY;
    }
    return new LexerEditorHighlighter(PlainTextSyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null), settings);
}
 
Example 10
Source File: InspectionsFilter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean matches(final Tools tools) {
  if (myShowOnlyCleanupInspections && !tools.getTool().isCleanupTool()) {
    return false;
  }

  if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != tools.isEnabled()) {
    return false;
  }

  if (myAvailableOnlyForAnalyze != isAvailableOnlyForAnalyze(tools)) {
    return false;
  }

  if (!mySuitableSeverities.isEmpty()) {
    boolean suitable = false;
    for (final ScopeToolState state : tools.getTools()) {
      if (mySuitableInspectionsStates != null && mySuitableInspectionsStates != state.isEnabled()) {
        continue;
      }
      if (mySuitableSeverities.contains(tools.getDefaultState().getLevel().getSeverity())) {
        suitable = true;
        break;
      }
    }
    if (!suitable) {
      return false;
    }
  }

  if(mySuitableLanguages.isEmpty()) {
    return true;
  }
  final String languageId = tools.getDefaultState().getTool().getLanguage();
  Language language  = languageId == null ? null : Language.findLanguageByID(languageId);
  return language != null && mySuitableLanguages.contains(language);
}
 
Example 11
Source File: CommonCodeStyleSettingsManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void readExternal(@Nonnull Element element) throws InvalidDataException {
  synchronized (this) {
    initCommonSettingsMap();
    for (Element commonSettingsElement : element.getChildren(COMMON_SETTINGS_TAG)) {
      final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
      if (!StringUtil.isEmpty(languageId)) {
        Language target = Language.findLanguageByID(languageId);
        boolean isKnownLanguage = target != null;
        if (isKnownLanguage) {
          final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(target);
          if (provider != null) {
            CommonCodeStyleSettings settings = safelyGetDefaults(provider);
            if (settings != null) {
              settings.readExternal(commonSettingsElement);
              init(settings, target);
            }
          }
          else {
            isKnownLanguage = false;
          }
        }
        if (!isKnownLanguage) {
          myUnknownSettingsMap.put(languageId, JDOMUtil.internElement(commonSettingsElement));
        }
      }
    }
    initNonReadSettings();
  }
}
 
Example 12
Source File: FileElementInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
PsiElement restoreElement(@Nonnull SmartPointerManagerImpl manager) {
  Language language = Language.findLanguageByID(myLanguageId);
  if (language == null) return null;
  PsiFile file = SelfElementInfo.restoreFileFromVirtual(myVirtualFile, myProject, language);
  return file != null && file.getClass().getName().equals(myFileClassName) ? file : null;
}
 
Example 13
Source File: Identikit.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public PsiElement findPsiElement(@Nonnull PsiFile file, int startOffset, int endOffset) {
  Language fileLanguage = Language.findLanguageByID(myFileLanguageId);
  if (fileLanguage == null) return null;   // plugin has been unloaded
  Language actualLanguage = fileLanguage != Language.ANY ? fileLanguage : file.getViewProvider().getBaseLanguage();
  PsiFile actualLanguagePsi = file.getViewProvider().getPsi(actualLanguage);
  if (actualLanguagePsi == null) {
    return null; // the file has changed its language or dialect, so we can't restore
  }
  return findInside(actualLanguagePsi, startOffset, endOffset);
}
 
Example 14
Source File: ParameterLanguageInjector.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
public Language getLanguage() {
    return Language.findLanguageByID(this.language);
}
 
Example 15
Source File: CachedAnnotators.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<Annotator> initialValue(@Nonnull String languageId) {
  Language language = Language.findLanguageByID(languageId);
  return language == null ? ContainerUtil.<Annotator>emptyList() : LanguageAnnotators.INSTANCE.allForLanguage(language);
}
 
Example 16
Source File: LanguagePointerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected Language compute() {
  return Language.findLanguageByID(myId);
}
 
Example 17
Source File: Identikit.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Language getFileLanguage() {
  return Language.findLanguageByID(myFileLanguageId);
}
 
Example 18
Source File: XExpressionState.java    From consulo with Apache License 2.0 4 votes vote down vote up
public XExpression toXExpression() {
  checkConverted();
  return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguage), myCustomInfo);
}
 
Example 19
Source File: PostfixTemplatesChildConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nls
@Override
public String getDisplayName() {
  Language languageByID = Language.findLanguageByID(myExtensionPoint.getKey());
  return languageByID == null ? myExtensionPoint.getKey() : languageByID.getDisplayName();
}
 
Example 20
Source File: FluidConfig.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@NotNull
public static Language getCommenterLanguage() {
    final Language id = Language.findLanguageByID(getStringPropertyValue(COMMENTER_LANGUAGE_ID));
    return id == null ? HTMLLanguage.INSTANCE : id;
}