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

The following are Jave code examples for showing how to use findLanguageByID() 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: educational-plugin   File: EduRemoteCourseModuleBuilder.java   Source Code and License Vote up 6 votes
@Nullable
@Override
public Module commitModule(@NotNull Project project, @Nullable ModifiableModuleModel model) {
  Module module = super.commitModule(project, model);
  if (module == null) {
    return null;
  }
  String languageName = myCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language == null) {
    return module;
  }
  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  if (configurator == null) {
    return module;
  }
  configurator.configureModule(module);
  return module;
}
 
Example 2
Project: educational-plugin   File: EduRemoteCourseModuleBuilder.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
  throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  String languageName = myCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language != null) {
    EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
    if (configurator != null) {
      Project project = baseModule.getProject();
      myGenerator.setSelectedCourse(myCourse);
      myGenerator.generateProject(project, project.getBaseDir());
      Course course = StudyTaskManager.getInstance(project).getCourse();
      if (course == null) {
        LOG.info("failed to generate course");
        return baseModule;
      }
      configurator.createCourseModuleContent(moduleModel, project, course, getModuleFileDirectory());
    }
  }
  return baseModule;
}
 
Example 3
Project: educational-plugin   File: EduCustomCourseModuleBuilder.java   Source Code and License Vote up 6 votes
@Nullable
@Override
public Module commitModule(@NotNull Project project, @Nullable ModifiableModuleModel model) {
  Module module = super.commitModule(project, model);
  if (module == null) {
    return null;
  }
  String languageName = mySelectedCourse.getLanguageID();
  Language language = Language.findLanguageByID(languageName);
  if (language == null) {
    return module;
  }
  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
  if (configurator == null) {
    return module;
  }
  configurator.configureModule(module);
  return module;
}
 
Example 4
Project: educational-plugin   File: EduCustomCourseModuleBuilder.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public Module createModule(@NotNull ModifiableModuleModel moduleModel)
  throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException {
  Module baseModule = super.createModule(moduleModel);
  if (mySelectedCourse != null) {
    String languageName = mySelectedCourse.getLanguageID();
    Language language = Language.findLanguageByID(languageName);
    if (language != null) {
      EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
      if (configurator != null) {
        myGenerator.setSelectedCourse(mySelectedCourse);
        Project project = baseModule.getProject();
        myGenerator.generateProject(project, project.getBaseDir());
        Course course = StudyTaskManager.getInstance(project).getCourse();
        if (course == null) {
          LOG.info("failed to generate course");
          return baseModule;
        }
        configurator.createCourseModuleContent(moduleModel, project, course, getModuleFileDirectory());
      }
    }
  }
  return baseModule;
}
 
Example 5
Project: intellij-ce-playground   File: MyTestInjector.java   Source Code and License Vote up 6 votes
public void injectAll(Disposable parent) {
  injectVariousStuffEverywhere(parent, myPsiManager);

  Project project = myPsiManager.getProject();
  Language ql = Language.findLanguageByID("JPAQL");
  Language js = Language.findLanguageByID("JavaScript");
  registerForStringVarInitializer(parent, project, ql, "ql", null, null);
  registerForStringVarInitializer(parent, project, ql, "qlPrefixed", "xxx", null);
  registerForStringVarInitializer(parent, project, js, "js", null, null);
  registerForStringVarInitializer(parent, project, js, "jsSeparated", " + ", " + 'separator'");
  registerForStringVarInitializer(parent, project, js, "jsBrokenPrefix", "xx ", "");

  registerForStringVarInitializer(parent, project, Language.findLanguageByID("Oracle"), "oracle", null, null);

  registerForParameterValue(parent, project, Language.findLanguageByID("Groovy"), "groovy");
  registerForStringVarInitializer(parent, project, JavaLanguage.INSTANCE, "java", "", "");
}
 
Example 6
Project: intellij-ce-playground   File: InspectionEngine.java   Source Code and License Vote up 6 votes
@Nullable("null means not specified")
private static Set<String> getDialectIdsSpecifiedForTool(@NotNull LocalInspectionToolWrapper wrapper) {
  String langId = wrapper.getLanguage();
  if (langId == null) {
    return null;
  }
  Language language = Language.findLanguageByID(langId);
  Set<String> result;
  if (language != null) {
    List<Language> dialects = language.getDialects();
    boolean applyToDialects = wrapper.applyToDialects();
    result = applyToDialects && !dialects.isEmpty() ? new THashSet<String>(1 + dialects.size()) : new SmartHashSet<String>();
    result.add(langId);
    if (applyToDialects) {
      for (Language dialect : dialects) {
        result.add(dialect.getID());
      }
    }
  }
  else {
    // unknown language in plugin.xml, ignore
    result = Collections.singleton(langId);
  }
  return result;
}
 
Example 7
Project: intellij-ce-playground   File: InspectionManagerEx.java   Source Code and License Vote up 6 votes
@Nullable
public static SuppressIntentionAction[] getSuppressActions(@NotNull 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, toolWrapper.getID());
        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 8
Project: intellij-ce-playground   File: TemplateLanguageErrorFilter.java   Source Code and License Vote up 6 votes
protected TemplateLanguageErrorFilter(
  @NotNull final TokenSet templateExpressionStartTokens,
  @NotNull final Class templateFileViewProviderClass,
  @NotNull final 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 9
Project: intellij-ce-playground   File: PostfixTemplatesCheckboxTree.java   Source Code and License Vote up 6 votes
public void initTree(@NotNull MultiMap<String, PostfixTemplate> langToTemplates) {
  myRoot.removeAllChildren();
  for (Map.Entry<String, Collection<PostfixTemplate>> entry : langToTemplates.entrySet()) {
    String id = entry.getKey();
    Language language = Language.findLanguageByID(id);
    String langName = language != null ? language.getDisplayName() : id;  
    CheckedTreeNode langNode = new CheckedTreeNode(langName);
    myRoot.add(langNode);
    for (PostfixTemplate template : entry.getValue()) {
      CheckedTreeNode templateNode = new PostfixTemplateCheckedTreeNode(template, langName);
      langNode.add(templateNode);
    }
  }

  myModel.nodeStructureChanged(myRoot);
  TreeUtil.expandAll(this);
  setSelectionRow(0);
}
 
Example 10
Project: intellij-ce-playground   File: FindDialog.java   Source Code and License Vote up 6 votes
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
  final Component editorComponent = inputComboBox.getEditor().getEditorComponent();

  if (editorComponent instanceof EditorTextField) {
    boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable();
    FileType fileType = PlainTextFileType.INSTANCE;
    if (isRegexp) {
      Language regexpLanguage = Language.findLanguageByID("RegExp");
      if (regexpLanguage != null) {
        LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType();
        if (regexpFileType != null) {
          fileType = regexpFileType;
        }
      }
    }
    String fileName = isRegexp ? "a.regexp" : "a.txt";
    final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true);

    ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
  }
}
 
Example 11
Project: educational-plugin   File: EduCCModuleBuilder.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) {
  ModuleWizardStep javaSettingsStep =
    ProjectWizardStepFactory.getInstance().createJavaSettingsStep(settingsStep, this, Conditions.alwaysTrue());
  Function<JTextField, String> getValue = JTextComponent::getText;
  getWizardInputField("ccname", "", "Name:", myPanel.getNameField(), getValue).addToSettings(settingsStep);
  getWizardInputField("ccauthor", "", "Author:", myPanel.getAuthorField(), getValue).addToSettings(settingsStep);

  myLanguageComboBox.removeAllItems();
  for (LanguageExtensionPoint extension : Extensions.<LanguageExtensionPoint>getExtensions(EduPluginConfigurator.EP_NAME, null)) {
    String languageId = extension.getKey();
    Language language = Language.findLanguageByID(languageId);
    if (language == null) {
      LOG.info("Language with id " + languageId + " not found");
      continue;
    }
    myLanguageComboBox.addItem(new LanguageWrapper(language));
  }
  getWizardInputField("cclang", "", "Language:", myLanguageComboBox, comboBox -> (String) comboBox.getSelectedItem())
    .addToSettings(settingsStep);
  JTextArea descriptionField = myPanel.getDescriptionField();
  descriptionField.setRows(4);
  descriptionField.setBorder(null);
  descriptionField.invalidate();
  JBScrollPane scrollPane = new JBScrollPane(descriptionField);
  scrollPane.setMinimumSize(scrollPane.getUI().getPreferredSize(descriptionField));
  getWizardInputField("ccdescr", "", "Description:", scrollPane, pane -> descriptionField.getText()).addToSettings(settingsStep);
  return javaSettingsStep;
}
 
Example 12
Project: mule-intellij-plugins   File: MuleLanguageInjector.java   Source Code and License Vote up 5 votes
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 13
Project: mule-intellij-plugins   File: MuleLanguageInjector.java   Source Code and License Vote up 5 votes
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 14
Project: intellij-ce-playground   File: CommonCodeStyleSettingsManager.java   Source Code and License Vote up 5 votes
@Override
public void readExternal(@NotNull Element element) throws InvalidDataException {
  synchronized (this) {
    initCommonSettingsMap();
    final List list = element.getChildren(COMMON_SETTINGS_TAG);
    for (Object o : list) {
      final Element commonSettingsElement = (Element)o;
      final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
      if (languageId != null && !languageId.isEmpty()) {
        Language target = Language.findLanguageByID(languageId);
        boolean isKnownLanguage = target != null;
        if (isKnownLanguage) {
          final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(target);
          if (provider != null) {
            CommonCodeStyleSettings settings = provider.getDefaultCommonSettings();
            if (settings != null) {
              settings.readExternal(commonSettingsElement);
              init(settings, target);
            }
          }
          else {
            isKnownLanguage = false;
          }
        }
        if (!isKnownLanguage) {
          myUnknownSettingsMap.put(languageId, (Content)commonSettingsElement.clone());
        }
      }
    }
    initNonReadSettings();
  }
}
 
Example 15
Project: intellij-ce-playground   File: XExpressionState.java   Source Code and License Vote up 5 votes
@Nullable
public XExpression toXExpression() {
  checkConverted();
  // old versions may have empty expressions serialized
  if (StringUtil.isEmptyOrSpaces(myExpression)) {
    return null;
  }
  return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguage), myCustomInfo);
}
 
Example 16
Project: intellij-ce-playground   File: LocalInspectionsPass.java   Source Code and License Vote up 5 votes
@NotNull
List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
  List<LocalInspectionToolWrapper> enabled = new ArrayList<LocalInspectionToolWrapper>();
  final InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(getFile());
  InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers);
  for (InspectionToolWrapper toolWrapper : toolWrappers) {
    ProgressManager.checkCanceled();
    if (!profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), getFile())) continue;
    LocalInspectionToolWrapper wrapper = null;
    if (toolWrapper instanceof LocalInspectionToolWrapper) {
      wrapper = (LocalInspectionToolWrapper)toolWrapper;
    }
    else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
      final GlobalInspectionToolWrapper globalInspectionToolWrapper = (GlobalInspectionToolWrapper)toolWrapper;
      wrapper = globalInspectionToolWrapper.getSharedLocalInspectionToolWrapper();
    }
    if (wrapper == null) continue;
    String language = wrapper.getLanguage();
    if (language != null && Language.findLanguageByID(language) == null) {
      continue; // filter out at least unknown languages
    }
    if (myIgnoreSuppressed && SuppressionUtil.inspectionResultSuppressed(getFile(), wrapper.getTool())) {
      continue;
    }
    enabled.add(wrapper);
  }
  return enabled;
}
 
Example 17
Project: intellij-ce-playground   File: RestFileViewProvider.java   Source Code and License Vote up 5 votes
@Override
@NotNull
public Set<Language> getLanguages() {
  if (myLanguages == null) {
    myLanguages = Sets.newConcurrentHashSet();
    myLanguages.add(getBaseLanguage());
    Language djangoTemplateLanguage = Language.findLanguageByID("DjangoTemplate");
    if (djangoTemplateLanguage != null) {
      myLanguages.add(djangoTemplateLanguage);
    }
    myLanguages.add(getTemplateDataLanguage());
  }
  return myLanguages;
}
 
Example 18
Project: intellij-ce-playground   File: HtmlDocumentationProvider.java   Source Code and License Vote up 5 votes
@Nullable
private DocumentationProvider getStyleProvider() {
  if (myStyleProvider == null) {
    Language cssLanguage = Language.findLanguageByID("CSS");
    if (cssLanguage != null) {
      myStyleProvider = LanguageDocumentation.INSTANCE.forLanguage(cssLanguage);
    }
  }
  return myStyleProvider;
}
 
Example 19
Project: educational-plugin   File: Course.java   Source Code and License Vote up 4 votes
public Language getLanguageById() {
  return Language.findLanguageByID(getLanguageID());
}
 
Example 20
Project: intellij-ce-playground   File: DefaultHighlightVisitor.java   Source Code and License Vote up 4 votes
@NotNull
@Override
public Collection<Annotator> initialValue(@NotNull String languageId) {
  Language language = Language.findLanguageByID(languageId);
  return language == null ? ContainerUtil.<Annotator>emptyList() : LanguageAnnotators.INSTANCE.allForLanguage(language);
}
 
Example 21
Project: intellij-ce-playground   File: CCUtils.java   Source Code and License Vote up 4 votes
@Nullable
public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) {
  Language language = Language.findLanguageByID(course.getLanguage());
  return language == null ? null : CCLanguageManager.INSTANCE.forLanguage(language);
}
 
Example 22
Project: intellij-ce-playground   File: Course.java   Source Code and License Vote up 4 votes
public Language getLanguageById() {
  return Language.findLanguageByID(myLanguage);
}
 
Example 23
Project: intellij-ce-playground   File: XPath2Language.java   Source Code and License Vote up 4 votes
XPath2Language() {
    super(Language.findLanguageByID(XPathLanguage.ID), ID);
}