コード例 #1
0
  private static boolean doChooseLanguageToInject(Editor editor, final Processor<String> onChosen) {
    final String[] langIds = InjectedLanguage.getAvailableLanguageIDs();
    Arrays.sort(langIds);

    final JList list = new JBList(langIds);
    list.setCellRenderer(
        new ListCellRendererWrapper<String>(list.getCellRenderer()) {
          @Override
          public void customize(
              JList list, String value, int index, boolean selected, boolean hasFocus) {
            final Language language = InjectedLanguage.findLanguageById(value);
            assert language != null;
            final FileType ft = language.getAssociatedFileType();
            setIcon(ft != null ? ft.getIcon() : EmptyIcon.ICON_16);
            setText(
                language.getDisplayName() + (ft != null ? " (" + ft.getDescription() + ")" : ""));
          }
        });
    new PopupChooserBuilder(list)
        .setItemChoosenCallback(
            new Runnable() {
              public void run() {
                final String string = (String) list.getSelectedValue();
                onChosen.process(string);
              }
            })
        .setFilteringEnabled(new Function.Self<Object, String>())
        .createPopup()
        .showInBestPositionFor(editor);
    return true;
  }
コード例 #2
0
 public static List<Injectable> getAllInjectables() {
   Language[] languages = InjectedLanguage.getAvailableLanguages();
   List<Injectable> list = new ArrayList<Injectable>();
   for (Language language : languages) {
     list.add(Injectable.fromLanguage(language));
   }
   list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
   Collections.sort(list);
   return list;
 }
コード例 #3
0
 private static void invokeImpl(Project project, Editor editor, PsiFile file, String languageId) {
   final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
   if (host == null) return;
   if (defaultFunctionalityWorked(host, languageId)) return;
   final Language language = InjectedLanguage.findLanguageById(languageId);
   try {
     for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
       if (support.addInjectionInPlace(language, host)) return;
     }
     TemporaryPlacesRegistry.getInstance(project)
         .getLanguageInjectionSupport()
         .addInjectionInPlace(language, host);
   } finally {
     FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
   }
 }