mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Diagnostics for non-physical files in code style preview
This commit is contained in:
+5
-1
@@ -74,10 +74,14 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
|
||||
/**
|
||||
* Allows to customize PSI file creation for a language settings preview panel.
|
||||
* <p>
|
||||
* <b>IMPORTANT</b>: The created file must be a non-physical one with PSI events disabled. For more information see
|
||||
* {@link com.intellij.psi.PsiFileFactory#createFileFromText(String, Language, CharSequence, boolean, boolean)} where
|
||||
* {@code eventSystemEnabled} parameter must be {@code false}
|
||||
*
|
||||
* @param project current project
|
||||
* @param text code sample to demonstrate formatting settings (see {@link #getCodeSample(LanguageCodeStyleSettingsProvider.SettingsType)}
|
||||
* @return a PSI file instance with given text, or null for use
|
||||
* @return a PSI file instance with given text, or null for default implementation using provider's language.
|
||||
*/
|
||||
@Nullable
|
||||
public PsiFile createFileFromText(final Project project, final String text) {
|
||||
|
||||
+10
-2
@@ -308,8 +308,16 @@ public abstract class CodeStyleAbstractPanel implements Disposable {
|
||||
protected PsiFile createFileFromText(Project project, String text) {
|
||||
Language language = getDefaultLanguage();
|
||||
if (language != null) {
|
||||
final PsiFile file = LanguageCodeStyleSettingsProvider.createFileFromText(language, project, text);
|
||||
if (file != null) return file;
|
||||
LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(language);
|
||||
if (provider != null) {
|
||||
final PsiFile file = provider.createFileFromText(project, text);
|
||||
if (file != null) {
|
||||
if (file.isPhysical()) {
|
||||
LOG.error(provider.getClass() + " creates a physical file with PSI events enabled");
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return PsiFileFactory.getInstance(project).createFileFromText(
|
||||
"a." + getFileExt(), getFileType(), text, LocalTimeCounter.currentTime(), false
|
||||
|
||||
+13
-1
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
@@ -45,6 +44,19 @@ public class CodeSamplesCorrectnessTest extends LightPlatformCodeInsightFixtureT
|
||||
mySettingValues = SettingsType.values();
|
||||
}
|
||||
|
||||
public void testNonPhysicalFiles() {
|
||||
LanguageCodeStyleSettingsProvider[] providers = LanguageCodeStyleSettingsProvider.EP_NAME.getExtensions();
|
||||
for (LanguageCodeStyleSettingsProvider provider : providers) {
|
||||
List<CodeSampleInfo> samplesToTest = getSamplesToTest(provider);
|
||||
for (CodeSampleInfo sampleInfo : samplesToTest) {
|
||||
PsiFile file = provider.createFileFromText(getProject(), sampleInfo.codeSample);
|
||||
if (file != null) {
|
||||
assertFalse(provider.getClass() + " must not create a physical file with psi events enabled", file.isPhysical());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testAllCodeStylePreviewSamplesValid() {
|
||||
LanguageCodeStyleSettingsProvider[] providers = LanguageCodeStyleSettingsProvider.EP_NAME.getExtensions();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user