From eb4537ef312fc0111213315324104449aa309dea Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 9 Oct 2012 12:51:12 +0400 Subject: [PATCH] idea settings test --- .../options/colors/ColorAndFontOptions.java | 11 +- .../psi/impl/PsiDocumentManagerImpl.java | 105 +++++++++++------- .../testFramework/LightPlatformTestCase.java | 22 +++- .../testFramework/PlatformTestCase.java | 2 +- .../impl/HeavyIdeaTestFixtureImpl.java | 2 +- .../configurable/VcsManagerConfigurable.java | 19 ++++ 6 files changed, 110 insertions(+), 51 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java index b0459f9e3ef7..7d501968c38f 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java @@ -62,6 +62,7 @@ import com.intellij.util.diff.FilesTooBigForDiffException; import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -934,6 +935,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract } @Override + @NotNull public String getHelpTopic() { return "reference.settingsdialog.IDE.editor.colors"; } @@ -1165,7 +1167,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract private boolean mySubInitInvoked = false; private final ColorAndFontPanelFactory myFactory; - private InnerSearchableConfigurable(final ColorAndFontPanelFactory factory) { + private InnerSearchableConfigurable(@NotNull ColorAndFontPanelFactory factory) { myFactory = factory; } @@ -1280,6 +1282,11 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract public Set processListOptions() { return createPanel().processListOptions(); } - } + @NonNls + @Override + public String toString() { + return "Color And Fonts for "+getDisplayName(); + } + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java index 6740f388b45c..df4538caed28 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/PsiDocumentManagerImpl.java @@ -115,12 +115,12 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void beforeWriteActionStart(Object action) { - documentCommitThread.disable("Write action started: "+ action); + documentCommitThread.disable("Write action started: " + action); } @Override public void writeActionFinished(Object action) { - documentCommitThread.enable("Write action finished: "+action); + documentCommitThread.enable("Write action finished: " + action); } }, myProject); documentCommitThread.enable("project open"); @@ -141,7 +141,8 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } @Override - public void initComponent() { } + public void initComponent() { + } @Override public void disposeComponent() { @@ -151,7 +152,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @Nullable public PsiFile getPsiFile(@NotNull Document document) { final PsiFile userData = document.getUserData(HARD_REF_TO_PSI); - if(userData != null) return userData; + if (userData != null) return userData; PsiFile psiFile = getCachedPsiFile(document); if (psiFile != null) return psiFile; @@ -161,7 +162,12 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec if (ApplicationManager.getApplication().isUnitTestMode()) { Collection projects = ProjectLocator.getInstance().getProjectsForFile(virtualFile); - LOG.assertTrue(projects.isEmpty() || projects.contains(myProject), "Trying to get PSI for an alien project. VirtualFile=" + virtualFile + ";\n myProject=" + myProject+";\n projects returned: "+projects); + LOG.assertTrue(projects.isEmpty() || projects.contains(myProject), "Trying to get PSI for an alien project. VirtualFile=" + + virtualFile + + ";\n myProject=" + + myProject + + ";\n projects returned: " + + projects); } psiFile = getPsiFile(virtualFile); @@ -175,10 +181,11 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec public static void cachePsi(@NotNull Document document, @NotNull PsiFile file) { document.putUserData(HARD_REF_TO_PSI, file); } + @Override public PsiFile getCachedPsiFile(@NotNull Document document) { final PsiFile userData = document.getUserData(HARD_REF_TO_PSI); - if(userData != null) return userData; + if (userData != null) return userData; final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); if (virtualFile == null || !virtualFile.isValid()) return null; @@ -234,7 +241,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @Override public Document getCachedDocument(@NotNull PsiFile file) { - if(!file.isPhysical()) return null; + if (!file.isPhysical()) return null; VirtualFile vFile = file.getViewProvider().getVirtualFile(); return FileDocumentManager.getInstance().getCachedDocument(vFile); } @@ -264,7 +271,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } private final Map actionsWhenAllDocumentsAreCommitted = new LinkedHashMap(); //accessed from EDT only - private static final Object PERFORM_ALWAYS_KEY = new Object(){ + private static final Object PERFORM_ALWAYS_KEY = new Object() { @Override @NonNls public String toString() { @@ -272,8 +279,10 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } }; - /** Schedules action to be executed when all documents are committed. - * @return true if action has been run immediately, or false if action was scheduled for execution later. + /** + * Schedules action to be executed when all documents are committed. + * + * @return true if action has been run immediately, or false if action was scheduled for execution later. */ @Override public boolean performWhenAllCommitted(@NotNull final Runnable action) { @@ -304,11 +313,12 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec /** * Cancel previously registered action and schedules (new) action to be executed when all documents are committed. - * @param key the (unique) id of the action. - * @param action The action to be executed after automatic commit. - * This action will overwrite any action which was registered under this key earlier. - * The action will be executed in EDT. - * @return true if action has been run immediately, or false if action was scheduled for execution later. + * + * @param key the (unique) id of the action. + * @param action The action to be executed after automatic commit. + * This action will overwrite any action which was registered under this key earlier. + * The action will be executed in EDT. + * @return true if action has been run immediately, or false if action was scheduled for execution later. */ public boolean cancelAndRunWhenAllCommitted(@NonNls @NotNull Object key, @NotNull final Runnable action) { ApplicationManager.getApplication().assertIsDispatchThread(); @@ -406,7 +416,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @Override public void visitElement(PsiElement element) { if (!element.isValid()) { - LOG.error("Commit to '"+psiFile.getVirtualFile()+"' lead to invalid element: "+element+ "; Reason: '"+reason+"'"); + LOG.error("Commit to '" + psiFile.getVirtualFile() + "' lead to invalid element: " + element + "; Reason: '" + reason + "'"); } } }); @@ -428,7 +438,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec finally { myIsCommitInProgress = false; } - assert !myUncommittedDocuments.contains(document) : "Document :"+ document; + assert !myUncommittedDocuments.contains(document) : "Document :" + document; } }); } @@ -453,7 +463,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec List keys = new ArrayList(actionsWhenAllDocumentsAreCommitted.keySet()); for (Object key : keys) { Runnable action = actionsWhenAllDocumentsAreCommitted.remove(key); - myDocumentCommitThread.log("Running after commit runnable: ",null, false, key, action); + myDocumentCommitThread.log("Running after commit runnable: ", null, false, key, action); action.run(); } } @@ -486,12 +496,13 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @Override public void commitAndRunReadAction(@NotNull final Runnable runnable) { final Application application = ApplicationManager.getApplication(); - if (SwingUtilities.isEventDispatchThread()){ + if (SwingUtilities.isEventDispatchThread()) { commitAllDocuments(); runnable.run(); } - else{ - LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed(), "Don't call commitAndRunReadAction inside ReadAction, it will cause a deadlock otherwise."); + else { + LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed(), + "Don't call commitAndRunReadAction inside ReadAction, it will cause a deadlock otherwise."); final Semaphore s1 = new Semaphore(); final Semaphore s2 = new Semaphore(); @@ -501,11 +512,11 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec new Runnable() { @Override public void run() { - if (myUncommittedDocuments.isEmpty()){ + if (myUncommittedDocuments.isEmpty()) { runnable.run(); committed[0] = true; } - else{ + else { s1.down(); s2.down(); final Runnable commitRunnable = new Runnable() { @@ -528,7 +539,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } ); - if (!committed[0]){ + if (!committed[0]) { s1.waitFor(); application.runReadAction( new Runnable() { @@ -564,7 +575,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec if (doc instanceof DocumentWindow) doc = ((DocumentWindow)doc).getDelegate(); final PostprocessReformattingAspect component = myProject.getComponent(PostprocessReformattingAspect.class); final FileViewProvider viewProvider = getCachedViewProvider(doc); - if(viewProvider != null) component.doPostponedFormatting(viewProvider); + if (viewProvider != null) component.doPostponedFormatting(viewProvider); } private void fireDocumentCreated(@NotNull Document document, PsiFile file) { @@ -607,6 +618,7 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } private final Key TEMP_TREE_IN_DOCUMENT_KEY = Key.create("TEMP_TREE_IN_DOCUMENT_KEY"); + void clearTreeHardRef(@NotNull Document document) { document.putUserData(TEMP_TREE_IN_DOCUMENT_KEY, null); } @@ -637,14 +649,14 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec continue; } - if (file instanceof PsiFileImpl){ + if (file instanceof PsiFileImpl) { myIsCommitInProgress = true; - try{ + try { PsiFileImpl psiFile = (PsiFileImpl)file; // tree should be initialized and be kept until commit document.putUserData(TEMP_TREE_IN_DOCUMENT_KEY, psiFile.calcTreeElement()); } - finally{ + finally { myIsCommitInProgress = false; } } @@ -675,7 +687,14 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec if (textBlock.isLocked()) continue; textBlock.documentChanged(event); - assert file instanceof PsiFileImpl || "mock.file".equals(file.getName()) && ApplicationManager.getApplication().isUnitTestMode() : event + "; file="+file+"; allFiles="+files+"; viewProvider="+viewProvider; + assert file instanceof PsiFileImpl || "mock.file".equals(file.getName()) && ApplicationManager.getApplication().isUnitTestMode() : + event + + "; file=" + + file + + "; allFiles=" + + files + + "; viewProvider=" + + viewProvider; commitNecessary = true; } @@ -695,14 +714,14 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE); } - if (commitNecessary && fromRefresh){ + if (commitNecessary && fromRefresh) { commitDocument(document); } // avoid documents piling up during batch processing if (FileDocumentManagerImpl.areTooManyDocumentsInTheQueue(myUncommittedDocuments)) { if (ApplicationManager.getApplication().isUnitTestMode()) { try { - LOG.error("Too many uncommitted documents for "+myProject + ":\n"+myUncommittedDocuments); + LOG.error("Too many uncommitted documents for " + myProject + ":\n" + myUncommittedDocuments); } finally { clearUncommitedDocuments(); @@ -712,9 +731,11 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec } } - private boolean isRelevant(FileViewProvider viewProvider) { + private boolean isRelevant(@NotNull FileViewProvider viewProvider) { VirtualFile virtualFile = viewProvider.getVirtualFile(); - return !virtualFile.getFileType().isBinary() && viewProvider.getManager() == myPsiManager && !myPsiManager.getProject().isDisposed() && !myProject.isDefault(); + return !virtualFile.getFileType().isBinary() && + viewProvider.getManager() == myPsiManager && + !myPsiManager.getProject().isDisposed(); } public static boolean checkConsistency(PsiFile psiFile, Document document) { @@ -733,16 +754,16 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @NonNls String error = "File '" + psiFile.getName() + "' text mismatch after reparse. " + "File length=" + fileText.length + "; Doc length=" + documentLength + "\n"; int i = 0; - for(; i < documentLength; i++){ - if (i >= fileText.length){ + for (; i < documentLength; i++) { + if (i >= fileText.length) { error += "editorText.length > psiText.length i=" + i + "\n"; break; } - if (i >= editorText.length()){ + if (i >= editorText.length()) { error += "editorText.length > psiText.length i=" + i + "\n"; break; } - if (editorText.charAt(i) != fileText[i]){ + if (editorText.charAt(i) != fileText[i]) { error += "first unequal char i=" + i + "\n"; break; } @@ -766,15 +787,15 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec if (document instanceof DocumentWindow) { error += "doc: '" + document.getText() + "'\n"; - error += "psi: '" + psiFile.getText() + "'\n"; + error += "psi: '" + psiFile.getText() + "'\n"; error += "ast: '" + psiFile.getNode().getText() + "'\n"; - error += psiFile.getLanguage()+"\n"; + error += psiFile.getLanguage() + "\n"; PsiElement context = InjectedLanguageManager.getInstance(psiFile.getProject()).getInjectionHost(psiFile); if (context != null) { - error += "context: " + context +"; text: '" + context.getText() + "'\n"; + error += "context: " + context + "; text: '" + context.getText() + "'\n"; error += "context file: " + context.getContainingFile() + "\n"; } - error += "document window ranges: " + Arrays.asList(((DocumentWindow)document).getHostRanges())+"\n"; + error += "document window ranges: " + Arrays.asList(((DocumentWindow)document).getHostRanges()) + "\n"; } LOG.error(error); //document.replaceString(0, documentLength, psiFile.getText()); @@ -806,6 +827,6 @@ public class PsiDocumentManagerImpl extends PsiDocumentManager implements Projec @NonNls @Override public String toString() { - return super.toString() + " for the project "+myProject + "."; + return super.toString() + " for the project " + myProject + "."; } } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 45b9392229b3..805522d0eeed 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -58,6 +58,7 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ex.ProjectEx; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.project.impl.ProjectImpl; +import com.intellij.openapi.project.impl.ProjectManagerImpl; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.*; import com.intellij.openapi.startup.StartupManager; @@ -343,7 +344,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx(); projectManagerEx.openTestProject(ourProject); - ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(getProject())).clearUncommitedDocuments(); + clearUncommittedDocuments(getProject()); for (LocalInspectionTool tool : localInspectionTools) { enableInspectionTool(availableInspectionTools, new LocalInspectionToolWrapper(tool)); @@ -532,8 +533,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da throw IdeaLogger.ourErrorsOccurred; } } - PsiDocumentManagerImpl documentManager = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(project); - documentManager.clearUncommitedDocuments(); + PsiDocumentManagerImpl documentManager = clearUncommittedDocuments(project); ((HintManagerImpl)HintManager.getInstance()).cleanup(); DocumentCommitThread.getInstance().clearQueue(); @@ -560,12 +560,24 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da checkEditorsReleased(); } if (isLight(project)) { - ((ProjectImpl)project) - .setTemporarilyDisposed(true); // mark temporarily as disposed so that rogue component trying to access it will fail + // mark temporarily as disposed so that rogue component trying to access it will fail + ((ProjectImpl)project).setTemporarilyDisposed(true); documentManager.clearUncommitedDocuments(); } } + public static PsiDocumentManagerImpl clearUncommittedDocuments(@NotNull Project project) { + PsiDocumentManagerImpl documentManager = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(project); + documentManager.clearUncommitedDocuments(); + + ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance(); + if (projectManager.isDefaultProjectInitialized()) { + Project defaultProject = projectManager.getDefaultProject(); + ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(defaultProject)).clearUncommitedDocuments(); + } + return documentManager; + } + public static void checkEditorsReleased() throws Exception { CompositeException result = new CompositeException(); final Editor[] allEditors = EditorFactory.getInstance().getAllEditors(); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index a6a7c4ddabb6..fbbb7b484725 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -223,7 +223,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro setUpJdk(); - ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(getProject())).clearUncommitedDocuments(); + LightPlatformTestCase.clearUncommittedDocuments(getProject()); runStartupActivities(); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java index da2a9b94c33e..9d4c5e8e801a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java @@ -162,7 +162,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu sm.runPostStartupActivities(); ProjectManagerEx.getInstanceEx().openTestProject(myProject); - ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myProject)).clearUncommitedDocuments(); + LightPlatformTestCase.clearUncommittedDocuments(myProject); } }.execute().throwException(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java index f97b39e5c884..c13fd7857562 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsManagerConfigurable.java @@ -83,14 +83,17 @@ public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstra myMappings = null; } + @Override public String getDisplayName() { return VcsBundle.message("version.control.main.configurable.name"); } + @Override public String getHelpTopic() { return "project.propVCSSupport.Mappings"; } + @Override @NotNull public String getId() { return getDefaultConfigurableIdValue(this); @@ -102,6 +105,7 @@ public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstra return helpTopic == null ? configurable.getClass().getName() : helpTopic; } + @Override protected Configurable[] buildConfigurables() { myGeneralPanel = new VcsGeneralConfigurationPanel(myProject){ @Override @@ -152,6 +156,7 @@ public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstra private void addListenerToGeneralPanel() { myMappings.addVcsListener(new ModuleVcsListener() { + @Override public void activeVcsSetChanged(Collection activeVcses) { myGeneralPanel.updateAvailableOptions(activeVcses); } @@ -168,43 +173,57 @@ public class VcsManagerConfigurable extends SearchableConfigurable.Parent.Abstra }; return new SearchableConfigurable(){ + @Override @Nls public String getDisplayName() { return vcs.getDisplayName(); } + @Override public String getHelpTopic() { return delegate.getValue().getHelpTopic(); } + @Override public JComponent createComponent() { return delegate.getValue().createComponent(); } + @Override public boolean isModified() { return delegate.getValue().isModified(); } + @Override public void apply() throws ConfigurationException { delegate.getValue().apply(); } + @Override public void reset() { delegate.getValue().reset(); } + @Override public void disposeUIResources() { delegate.getValue().disposeUIResources(); } + @Override @NotNull public String getId() { return "vcs." + getDisplayName(); } + @Override public Runnable enableSearch(String option) { return null; } + + @Override + public String toString() { + return "VcsConfigurable for "+vcs.getDisplayName(); + } }; }