From dfa3ef17fbd82f80eaf17f09c4584d8173629c4b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 27 Mar 2014 16:01:48 +0100 Subject: [PATCH] Cleanup (arrangement; formatting) --- .../ProjectOpenProcessorBase.java | 63 ++++++++----------- .../project/impl/ProjectManagerImpl.java | 20 +++--- .../PlatformProjectOpenProcessor.java | 5 +- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/java/idea-ui/src/com/intellij/projectImport/ProjectOpenProcessorBase.java b/java/idea-ui/src/com/intellij/projectImport/ProjectOpenProcessorBase.java index a7bb76be7d18..8afa3ba0981c 100644 --- a/java/idea-ui/src/com/intellij/projectImport/ProjectOpenProcessorBase.java +++ b/java/idea-ui/src/com/intellij/projectImport/ProjectOpenProcessorBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 12-Jul-2007 - */ package com.intellij.projectImport; import com.intellij.CommonBundle; @@ -38,13 +33,11 @@ import com.intellij.openapi.roots.CompilerProjectExtension; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; -import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,8 +48,11 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; +/** + * @author anna + * @since 12-Jul-2007 + */ public abstract class ProjectOpenProcessorBase extends ProjectOpenProcessor { - private final T myBuilder; protected ProjectOpenProcessorBase(@NotNull final T builder) { @@ -176,16 +172,14 @@ public abstract class ProjectOpenProcessorBase e existingName = "'" + projectFile.getName() + "'"; pathToOpen = projectFilePath; } - int result = Messages.showYesNoCancelDialog(projectToClose, - IdeBundle.message("project.import.open.existing", - existingName, - projectFile.getParent(), - virtualFile.getName()), - IdeBundle.message("title.open.project"), - IdeBundle.message("project.import.open.existing.openExisting"), - IdeBundle.message("project.import.open.existing.reimport"), - CommonBundle.message("button.cancel"), - Messages.getQuestionIcon()); + int result = Messages.showYesNoCancelDialog( + projectToClose, + IdeBundle.message("project.import.open.existing", existingName, projectFile.getParent(), virtualFile.getName()), + IdeBundle.message("title.open.project"), + IdeBundle.message("project.import.open.existing.openExisting"), + IdeBundle.message("project.import.open.existing.reimport"), + CommonBundle.message("button.cancel"), + Messages.getQuestionIcon()); if (result == Messages.CANCEL) return null; shouldOpenExisting = result == Messages.YES; } @@ -195,13 +189,7 @@ public abstract class ProjectOpenProcessorBase e try { projectToOpen = ProjectManagerEx.getInstanceEx().loadProject(pathToOpen); } - catch (IOException e) { - return null; - } - catch (JDOMException e) { - return null; - } - catch (InvalidDataException e) { + catch (Exception e) { return null; } } @@ -214,15 +202,20 @@ public abstract class ProjectOpenProcessorBase e projectToOpen.save(); - ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override public void run() { Sdk jdk = wizardContext.getProjectJdk(); - if (jdk != null) NewProjectUtil.applyJdkToProject(projectToOpen, jdk); + if (jdk != null) { + NewProjectUtil.applyJdkToProject(projectToOpen, jdk); + } - final String projectDirPath = wizardContext.getProjectFileDirectory(); - CompilerProjectExtension.getInstance(projectToOpen).setCompilerOutputUrl(getUrl( - StringUtil.endsWithChar(projectDirPath, '/') ? projectDirPath + "classes" : projectDirPath + "/classes")); + String projectDirPath = wizardContext.getProjectFileDirectory(); + String path = StringUtil.endsWithChar(projectDirPath, '/') ? projectDirPath + "classes" : projectDirPath + "/classes"; + CompilerProjectExtension extension = CompilerProjectExtension.getInstance(projectToOpen); + if (extension != null) { + extension.setCompilerOutputUrl(getUrl(path)); + } } }); @@ -246,9 +239,7 @@ public abstract class ProjectOpenProcessorBase e try { path = FileUtil.resolveShortWindowsName(path); } - catch (IOException e) { - //file doesn't exist - } - return VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)); + catch (IOException ignored) { } + return VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index 90cbffe3d96b..df20c0734be5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -86,11 +86,10 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt public static final int CURRENT_FORMAT_VERSION = 4; private static final Key> LISTENERS_IN_PROJECT_KEY = Key.create("LISTENERS_IN_PROJECT_KEY"); - @NonNls private static final String ELEMENT_DEFAULT_PROJECT = "defaultProject"; + private static final String ELEMENT_DEFAULT_PROJECT = "defaultProject"; @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) private ProjectImpl myDefaultProject; // Only used asynchronously in save and dispose, which itself are synchronized. - @SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"}) private Element myDefaultProjectRootElement; // Only used asynchronously in save and dispose, which itself are synchronized. @@ -107,8 +106,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt private final Alarm myChangedFilesAlarm = new Alarm(); private final List> myChangedApplicationFiles = new ArrayList>(); private final AtomicInteger myReloadBlockCount = new AtomicInteger(0); - @SuppressWarnings("FieldCanBeLocal") private final Map myProjects = new WeakHashMap(); - private static final int MAX_LEAKY_PROJECTS = 42; private final ProgressManager myProgressManager; private volatile boolean myDefaultProjectWasDisposed = false; @@ -126,8 +123,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt myProgressManager = progressManager; Application app = ApplicationManager.getApplication(); MessageBus messageBus = app.getMessageBus(); - MessageBusConnection connection = messageBus.connect(app); - connection.subscribe(StateStorage.STORAGE_TOPIC, new StateStorage.Listener() { + + messageBus.connect(app).subscribe(StateStorage.STORAGE_TOPIC, new StateStorage.Listener() { @Override public void storageFileChanged(@NotNull final VirtualFileEvent event, @NotNull final StateStorage storage) { VirtualFile file = event.getFile(); @@ -136,8 +133,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } } }); - final ProjectManagerListener busPublisher = messageBus.syncPublisher(TOPIC); + final ProjectManagerListener busPublisher = messageBus.syncPublisher(TOPIC); addProjectManagerListener( new ProjectManagerListener() { @Override @@ -191,6 +188,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt registerExternalProjectFileListener(virtualFileManager); } + @Override + public void initComponent() { } + @Override public void disposeComponent() { ApplicationManager.getApplication().assertWriteAccessAllowed(); @@ -203,11 +203,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } } - @Override - public void initComponent() { - } - private static final boolean LOG_PROJECT_LEAKAGE_IN_TESTS = false; + private static final int MAX_LEAKY_PROJECTS = 42; + @SuppressWarnings("FieldCanBeLocal") private final Map myProjects = new WeakHashMap(); @Override @Nullable diff --git a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java index fe35f5067a21..4fd433b2e70b 100644 --- a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java +++ b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -163,12 +163,13 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor { for (ProjectOpenProcessor processor : ProjectOpenProcessor.EXTENSION_POINT_NAME.getExtensions()) { processor.refreshProjectFiles(projectDir); } - + project = projectManager.convertAndLoadProject(baseDir.getPath()); if (project == null) { WelcomeFrame.showIfNoProjectOpened(); return null; } + final Module[] modules = ModuleManager.getInstance(project).getModules(); if (modules.length > 0) { runConfigurators = false;