private List<CodeSampleInfo> getSamplesToTest(@NotNull LanguageCodeStyleSettingsProvider provider) { Set<String> processedSamples = ContainerUtil.newHashSet(); List<CodeSampleInfo> sampleInfos = ContainerUtil.newArrayList(); for (SettingsType setting : mySettingValues) { String sample = provider.getCodeSample(setting); if (StringUtil.isEmpty(sample) || processedSamples.contains(sample)) { continue; } processedSamples.add(sample); sampleInfos.add(new CodeSampleInfo(setting, sample)); } return sampleInfos; }
@Override public boolean setPanelLanguage(Language language) { boolean languageProviderFound = false; for (LanguageCodeStyleSettingsProvider provider : Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME)) { if (provider.getLanguage().is(language)) { resetDefaultNames(); provider.customizeSettings(this, getSettingsType()); languageProviderFound = true; break; } } if (!languageProviderFound) return false; myLanguage = language; setSkipPreviewHighlighting(true); try { onLanguageChange(language); } finally { setSkipPreviewHighlighting(false); } updatePreview(true); return true; }
@NotNull @Override protected FileType getFileType() { if (myLanguage != null) { FileType assocType = myLanguage.getAssociatedFileType(); if (assocType != null) { return assocType; } } Language[] langs = LanguageCodeStyleSettingsProvider.getLanguagesWithCodeStyleSettings(); if (langs.length > 0) { myLanguage = langs[0]; FileType type = langs[0].getAssociatedFileType(); if (type != null) return type; } return StdFileTypes.JAVA; }
@Override protected void customizeSettings() { LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(JavaLanguage.INSTANCE); if (provider != null) { provider.customizeSettings(this, getSettingsType()); } }
public void testAllCodeStylePreviewSamplesValid() { LanguageCodeStyleSettingsProvider[] providers = LanguageCodeStyleSettingsProvider.EP_NAME.getExtensions(); for (LanguageCodeStyleSettingsProvider provider : providers) { List<CodeSampleInfo> samplesToTest = getSamplesToTest(provider); processCodeSamples(provider, samplesToTest); } Assert.assertTrue(formReport(myErrorReports), myErrorReports.isEmpty()); }
private void processCodeSamples(@NotNull LanguageCodeStyleSettingsProvider provider, @NotNull List<CodeSampleInfo> samples) { for (CodeSampleInfo sample : samples) { Collection<PsiErrorElement> errorReports = getErrorsForText(provider, sample.codeSample); if (errorReports.isEmpty()) { continue; } CodeErrorReport report = new CodeErrorReport(sample, provider.getLanguage(), errorReports); myErrorReports.add(report); } }
@NotNull private Collection<PsiErrorElement> getErrorsForText(@NotNull LanguageCodeStyleSettingsProvider provider, @NotNull String sample) { PsiFile file = provider.createFileFromText(getProject(), sample); if (file == null) { Language language = provider.getLanguage(); LanguageFileType type = language.getAssociatedFileType(); if (type == null) return ContainerUtil.newArrayList(); file = myFixture.configureByText(type, sample); } return PsiTreeUtil.collectElementsOfType(file, PsiErrorElement.class); }
@Override protected String getPreviewText() { if (getDefaultLanguage() == null) return ""; String sample = LanguageCodeStyleSettingsProvider.getCodeSample(getDefaultLanguage(), getSettingsType()); if (sample == null) return ""; return sample; }
@Override protected void customizeSettings() { resetDefaultNames(); LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(JavaLanguage.INSTANCE); if (provider != null) { provider.customizeSettings(this, getSettingsType()); } }
public GeneralCodeStylePanel(CodeStyleSettings settings) { super(settings); final List<FileTypeIndentOptionsProvider> indentOptionsProviders = Arrays.asList(Extensions.getExtensions(FileTypeIndentOptionsProvider.EP_NAME)); Collections.sort(indentOptionsProviders, new Comparator<FileTypeIndentOptionsProvider>() { @Override public int compare(FileTypeIndentOptionsProvider p1, FileTypeIndentOptionsProvider p2) { Language lang1 = getLanguage(p1.getFileType()); if (lang1 == null) return -1; Language lang2 = getLanguage(p2.getFileType()); if (lang2 == null) return 1; DisplayPriority priority1 = LanguageCodeStyleSettingsProvider.getDisplayPriority(lang1); DisplayPriority priority2 = LanguageCodeStyleSettingsProvider.getDisplayPriority(lang2); if (priority1.equals(priority2)) { return lang1.getDisplayName().compareTo(lang2.getDisplayName()); } return priority1.compareTo(priority2); } }); myLineSeparatorCombo.addItem(SYSTEM_DEPENDANT_STRING); myLineSeparatorCombo.addItem(UNIX_STRING); myLineSeparatorCombo.addItem(WINDOWS_STRING); myLineSeparatorCombo.addItem(MACINTOSH_STRING); addPanelToWatch(myPanel); myRightMarginSpinner.setModel(new SpinnerNumberModel(settings.RIGHT_MARGIN, 1, 1000000, 1)); myIndentOptionsEditor = new SmartIndentOptionsEditor(); myDefaultIndentOptionsPanel.add(myIndentOptionsEditor.createPanel(), BorderLayout.CENTER); }
protected void customizeSettings() { for (LanguageCodeStyleSettingsProvider provider : Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME)) { if (provider.usesSharedPreview()) { resetDefaultNames(); provider.customizeSettings(this, getSettingsType()); } } }
@Override protected String getPreviewText() { if (myLanguage == null) return ""; String sample = LanguageCodeStyleSettingsProvider.getCodeSample(myLanguage, getSettingsType()); if (sample == null) return ""; return sample; }
@Override protected void installPreviewPanel(final JPanel previewPanel) { if (getSettingsType() != LanguageCodeStyleSettingsProvider.SettingsType.LANGUAGE_SPECIFIC) { tabbedPane = new JBTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); Language[] langs = LanguageCodeStyleSettingsProvider.getLanguagesWithSharedPreview(); if (langs.length == 0) return; for (Language lang : langs) { tabbedPane.addTab(getTabName(lang), createDummy()); } tabbedPane.setComponentAt(0, getEditor().getComponent()); myLangSelectionIndex = 0; if (myLanguage == null) { setPanelLanguage(langs[0]); } else { updatePreview(true); } tabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { onTabSelection((JTabbedPane)e.getSource()); } }); previewPanel.add(tabbedPane, BorderLayout.CENTER); previewPanel.addAncestorListener(new AncestorListenerAdapter() { @Override public void ancestorAdded(AncestorEvent event) { selectCurrentLanguageTab(); } }); } else { // If settings are language-specific previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER); updatePreview(true); } }
private void onTabSelection(JTabbedPane tabs) { int i = tabs.getSelectedIndex(); tabs.setComponentAt(myLangSelectionIndex, createDummy()); tabs.setComponentAt(i, getEditor().getComponent()); myLangSelectionIndex = i; String selectionTitle = tabs.getTitleAt(i); Language lang = LanguageCodeStyleSettingsProvider.getLanguage(selectionTitle); if (lang != null && getLanguageSelector() != null) { getLanguageSelector().setLanguage(lang); } }
private void customizeSettings() { setAllOptionsVisible(false); LanguageCodeStyleSettingsProvider settingsProvider = LanguageCodeStyleSettingsProvider.forLanguage(myLanguage); if (settingsProvider != null) { // TODO<rv> Only commenter settings should be used, move from WRAPPING_AND_BRACES settingsProvider.customizeSettings(this, LanguageCodeStyleSettingsProvider.SettingsType.WRAPPING_AND_BRACES_SETTINGS); settingsProvider.customizeSettings(this, LanguageCodeStyleSettingsProvider.SettingsType.COMMENTER_SETTINGS); } myCommenterPanel.setVisible( myLineCommentAtFirstColumnCb.isVisible() || myLineCommentAddSpaceCb.isVisible() || myBlockCommentAtFirstJBCheckBox.isVisible()); }
public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull LanguageCodeStyleSettingsProvider.SettingsType settingsType) { if (consumer == null) throw new IllegalArgumentException("Argument 0 for @NotNull parameter of org/livescriptidea/formatter/LiveScriptLanguageCodeStyleSettingsProvider.customizeSettings must not be null"); if (settingsType == null) throw new IllegalArgumentException("Argument 1 for @NotNull parameter of org/livescriptidea/formatter/LiveScriptLanguageCodeStyleSettingsProvider.customizeSettings must not be null"); if (settingsType == LanguageCodeStyleSettingsProvider.SettingsType.SPACING_SETTINGS) { consumer.showStandardOptions(STANDARD_SPACING_OPTIONS); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "SPACE_BEFORE_PROPERTY_COLON", "Before property name-value separator ':'", CodeStyleSettingsCustomizable.SPACES_OTHER, new Object[0]); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "SPACE_AFTER_PROPERTY_COLON", "After property name-value separator ':'", CodeStyleSettingsCustomizable.SPACES_OTHER, new Object[0]); consumer.renameStandardOption("SPACE_WITHIN_ARRAY_INITIALIZER_BRACES", "Array initializer brackets"); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "SPACE_WITHIN_INDEX_BRACKETS", "Array index brackets", CodeStyleSettingsCustomizable.SPACES_WITHIN, new Object[0]); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "SPACE_WITHIN_RANGE_BRACKETS", "Range brackets", CodeStyleSettingsCustomizable.SPACES_WITHIN, new Object[0]); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "SPACE_WITHIN_OBJECT_BRACES", "Object braces", CodeStyleSettingsCustomizable.SPACES_WITHIN, new Object[0]); } else if (settingsType == LanguageCodeStyleSettingsProvider.SettingsType.WRAPPING_AND_BRACES_SETTINGS) { consumer.showStandardOptions(STANDARD_WRAPPING_OPTIONS); consumer.renameStandardOption("ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE", "New line after '['"); consumer.renameStandardOption("ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE", "Place ']' on new line"); consumer.renameStandardOption("METHOD_PARAMETERS_WRAP", "Function declaration parameters"); consumer.renameStandardOption("CALL_PARAMETERS_WRAP", "Function call arguments inside parenthesis"); consumer.showCustomOption(LiveScriptCodeStyleSettings.class, "ALIGN_FUNCTION_BODY", "Align function body", CodeStyleSettingsCustomizable.SPACES_OTHER, new Object[0]); } else if (settingsType == LanguageCodeStyleSettingsProvider.SettingsType.BLANK_LINES_SETTINGS) { consumer.showStandardOptions(STANDARD_BLANK_LINES_OPTIONS); } }
protected void initTabs(CodeStyleSettings settings) { LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(getDefaultLanguage()); addIndentOptionsTab(settings); if ((provider != null) && (!provider.usesSharedPreview())) { addSpacesTab(settings); addWrappingAndBracesTab(settings); addBlankLinesTab(settings); } }
@Override public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() { return LanguageCodeStyleSettingsProvider.SettingsType.LANGUAGE_SPECIFIC; }
@Override public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() { return LanguageCodeStyleSettingsProvider.SettingsType.WRAPPING_AND_BRACES_SETTINGS; }
@Override public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() { return LanguageCodeStyleSettingsProvider.SettingsType.SPACING_SETTINGS; }
protected void customizeSettings() { LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(getDefaultLanguage()); if (provider != null) { provider.customizeSettings(this, getSettingsType()); } }
@Override protected PsiFile createFileFromText(final Project project, final String text) { final PsiFile file = LanguageCodeStyleSettingsProvider.createFileFromText(getDefaultLanguage(), project, text); return file != null ? file : super.createFileFromText(project, text); }
@Override protected int getRightMargin() { if (getDefaultLanguage() == null) return -1; return LanguageCodeStyleSettingsProvider.getRightMargin(getDefaultLanguage(), getSettingsType()); }
@Override protected String getFileExt() { String fileExt = LanguageCodeStyleSettingsProvider.getFileExt(getDefaultLanguage()); if (fileExt != null) return fileExt; return super.getFileExt(); }
@Override public LanguageCodeStyleSettingsProvider.SettingsType getSettingsType() { return LanguageCodeStyleSettingsProvider.SettingsType.BLANK_LINES_SETTINGS; }
@Override public boolean hasSettingsPage() { return LanguageCodeStyleSettingsProvider.getLanguagesWithSharedPreview().length != 0; }
@Override protected PsiFile createFileFromText(final Project project, final String text) { final PsiFile file = LanguageCodeStyleSettingsProvider.createFileFromText(myLanguage, project, text); return file != null ? file : super.createFileFromText(project, text); }
@Override protected int getRightMargin() { if (myLanguage == null) return -1; return LanguageCodeStyleSettingsProvider.getRightMargin(myLanguage, getSettingsType()); }
@Override protected String getFileExt() { String fileExt = LanguageCodeStyleSettingsProvider.getFileExt(myLanguage); if (fileExt != null) return fileExt; return super.getFileExt(); }
private static String getTabName(Language language) { String tabName = LanguageCodeStyleSettingsProvider.getLanguageName(language); if (tabName == null) tabName = language.getDisplayName(); return tabName; }
@Override public String getCodeSample(LanguageCodeStyleSettingsProvider.SettingsType settingsType) { return BuckFileUtil.getSampleBuckFile(); }