Java Code Examples for com.intellij.lang.Language.getBaseLanguage()

The following are Jave code examples for showing how to use getBaseLanguage() of the com.intellij.lang.Language class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: intellij-ce-playground   File: LanguageFolding.java   Source Code and License Vote up 6 votes
@Override
public FoldingBuilder forLanguage(@NotNull Language l) {
  FoldingBuilder cached = l.getUserData(getLanguageCache());
  if (cached != null) return cached;

  List<FoldingBuilder> extensions = forKey(l);
  FoldingBuilder result;
  if (extensions.isEmpty()) {

    Language base = l.getBaseLanguage();
    if (base != null) {
      result = forLanguage(base);
    }
    else {
      result = getDefaultImplementation();
    }
  }
  else {
    return extensions.size() == 1 ? extensions.get(0) : new CompositeFoldingBuilder(extensions);
  }

  l.putUserData(getLanguageCache(), result);
  return result;
}
 
Example 2
Project: intellij-ce-playground   File: CommentByBlockCommentHandler.java   Source Code and License Vote up 6 votes
@Nullable
public static Commenter getCommenter(final PsiFile file, final Editor editor,
                                     final Language lineStartLanguage, final Language lineEndLanguage) {

  final FileViewProvider viewProvider = file.getViewProvider();

  for (MultipleLangCommentProvider provider : MultipleLangCommentProvider.EP_NAME.getExtensions()) {
    if (provider.canProcess(file, viewProvider)) {
      return provider.getLineCommenter(file, editor, lineStartLanguage, lineEndLanguage);
    }
  }

  final Language fileLanguage = file.getLanguage();
  Language lang = lineStartLanguage == null || LanguageCommenters.INSTANCE.forLanguage(lineStartLanguage) == null ||
                  fileLanguage.getBaseLanguage() == lineStartLanguage // file language is a more specific dialect of the line language
                  ? fileLanguage
                  : lineStartLanguage;

  if (viewProvider instanceof TemplateLanguageFileViewProvider &&
      lang == ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage()) {
    lang = viewProvider.getBaseLanguage();
  }

  return LanguageCommenters.INSTANCE.forLanguage(lang);
}
 
Example 3
Project: intellij-ce-playground   File: CompletionContributor.java   Source Code and License Vote up 5 votes
@NotNull
@Override
protected List<CompletionContributor> buildExtensions(@NotNull String stringKey, @NotNull Language key) {
  Set<String> allowed = new THashSet<String>();
  while (key != null) {
    allowed.add(keyToString(key));
    key = key.getBaseLanguage();
  }
  allowed.add("any");
  return buildExtensions(allowed);
}
 
Example 4
Project: intellij-ce-playground   File: CommonCodeStyleSettingsManager.java   Source Code and License Vote up 5 votes
/**
 * Attempts to get language-specific common settings from <code>LanguageCodeStyleSettingsProvider</code>.
 *
 * @param lang The language to get settings for.
 * @return If the provider for the language exists and is able to create language-specific default settings
 *         (<code>LanguageCodeStyleSettingsProvider.getDefaultCommonSettings()</code> doesn't return null)
 *         returns the instance of settings for this language. Otherwise returns the instance of parent settings
 *         shared between several languages.
 */
public CommonCodeStyleSettings getCommonSettings(@Nullable Language lang) {
  Map<Language, CommonCodeStyleSettings> commonSettingsMap = getCommonSettingsMap();
  CommonCodeStyleSettings settings = commonSettingsMap.get(lang);
  while (settings == null && lang != null) {
    lang = lang.getBaseLanguage();
    settings = commonSettingsMap.get(lang);
  }
  if (settings != null) {
    return settings;
  }
  return myParentSettings;
}
 
Example 5
Project: intellij-ce-playground   File: HtmlUtil.java   Source Code and License Vote up 5 votes
public static boolean supportsXmlTypedHandlers(PsiFile file) {
  Language language = file.getLanguage();
  while (language != null) {
    if ("JavaScript".equals(language.getID())) return true;
    language = language.getBaseLanguage();
  }

  return false;
}