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

The following examples show how to use com.intellij.lang.Language#is() . 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: SoyFileViewProvider.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@Override
protected PsiFile createFile(@NotNull Language lang) {
  ParserDefinition parserDefinition = getDefinition(lang);
  if (parserDefinition == null) {
    return null;
  }

  if (lang.is(TEMPLATE_DATA_LANGUAGE)) {
    PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
    file.setContentElementType(TEMPLATE_DATA_ELEMENT_TYPE);
    return file;
  } else if (lang.isKindOf(BASE_LANGUAGE)) {
    return parserDefinition.createFile(this);
  } else {
    return null;
  }
}
 
Example 2
Source File: IndentCalculator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
String getIndentString(@Nullable Language language, @Nonnull SemanticEditorPosition currPosition) {
  String baseIndent = getBaseIndent(currPosition);
  Document document = myEditor.getDocument();
  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
  if (file != null) {
    CommonCodeStyleSettings.IndentOptions fileOptions = CodeStyle.getIndentOptions(file);
    CommonCodeStyleSettings.IndentOptions options =
            !fileOptions.isOverrideLanguageOptions() && language != null && !(language.is(file.getLanguage()) || language.is(Language.ANY)) ? CodeStyle.getLanguageSettings(file, language)
                    .getIndentOptions() : fileOptions;
    if (options != null) {
      return baseIndent + new IndentInfo(0, indentToSize(myIndent, options), 0, false).generateNewWhiteSpace(options);
    }
  }
  return null;
}
 
Example 3
Source File: LanguageSubstitutors.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void processLanguageSubstitution(@Nonnull final VirtualFile file,
                                                @Nonnull Language originalLang,
                                                @Nonnull final Language substitutedLang) {
  if (file instanceof VirtualFileWindow) {
    // Injected files are created with substituted language, no need to reparse:
    //   com.intellij.psi.impl.source.tree.injected.MultiHostRegistrarImpl#doneInjecting
    return;
  }
  Language prevSubstitutedLang = SUBSTITUTED_LANG_KEY.get(file);
  final Language prevLang = ObjectUtil.notNull(prevSubstitutedLang, originalLang);
  if (!prevLang.is(substitutedLang)) {
    if (file.replace(SUBSTITUTED_LANG_KEY, prevSubstitutedLang, substitutedLang)) {
      if (prevSubstitutedLang == null) {
        return; // no need to reparse for the first language substitution
      }
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
      }
      file.putUserData(REPARSING_SCHEDULED, true);
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (file.replace(REPARSING_SCHEDULED, true, null)) {
            LOG.info("Reparsing " + file.getPath() + " because of language substitution " +
                     prevLang.getID() + "->" + substitutedLang.getID());
            FileContentUtilCore.reparseFiles(file);
          }
        }
      }, ModalityState.defaultModalityState());
    }
  }
}
 
Example 4
Source File: BreadcrumbsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static BreadcrumbsProvider getInfoProvider(@Nonnull Language language) {
  List<BreadcrumbsProvider> providers = BreadcrumbsProvider.EP_NAME.getExtensionList();
  while (language != null) {
    for (BreadcrumbsProvider provider : providers) {
      Language supported = provider.getLanguage();
      if (language.is(supported)) {
        return provider;
      }
    }
    language = language.getBaseLanguage();
  }
  return null;
}
 
Example 5
Source File: TemplateLanguageErrorFilter.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean isKnownSubLanguage(final @Nonnull Language language) {
  for (Language knownLanguage : knownLanguageSet) {
    if (language.is(knownLanguage)) {
      return true;
    }
  }
  return false;
}