Cleanup (formatting)

This commit is contained in:
Roman Shevchenko
2019-03-04 13:33:10 +01:00
parent 5f91010c09
commit d714d4bab2
4 changed files with 41 additions and 19 deletions
@@ -26,6 +26,8 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.ReflectionUtil;
import com.intellij.util.SmartList;
import com.intellij.util.StartUpMeasurer;
import com.intellij.util.StartUpMeasurer.Activities;
import com.intellij.util.StartUpMeasurer.Phases;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusFactory;
@@ -79,14 +81,19 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
return null;
}
protected final void init(@NotNull List<? extends IdeaPluginDescriptor> plugins, @Nullable ProgressIndicator indicator, @Nullable Runnable componentsRegistered, boolean isNeededToMeasure) {
StartUpMeasurer.MeasureToken totalMeasureToken = isNeededToMeasure ? StartUpMeasurer.start(measureTokenNamePrefix() + StartUpMeasurer.Phases.INITIALIZE_COMPONENTS_SUFFIX) : null;
protected final void init(@NotNull List<? extends IdeaPluginDescriptor> plugins,
@Nullable ProgressIndicator indicator,
@Nullable Runnable componentsRegistered,
boolean isNeededToMeasure) {
StartUpMeasurer.MeasureToken totalMeasureToken =
isNeededToMeasure ? StartUpMeasurer.start(measureTokenNamePrefix() + Phases.INITIALIZE_COMPONENTS_SUFFIX) : null;
final Application app = ApplicationManager.getApplication();
boolean headless = app == null || app.isHeadlessEnvironment();
String measureTokenNamePrefix = StringUtil.notNullize(measureTokenNamePrefix());
StartUpMeasurer.MeasureToken measureToken = isNeededToMeasure ? StartUpMeasurer.start(measureTokenNamePrefix + StartUpMeasurer.Phases.REGISTER_COMPONENTS_SUFFIX) : null;
StartUpMeasurer.MeasureToken measureToken =
isNeededToMeasure ? StartUpMeasurer.start(measureTokenNamePrefix + Phases.REGISTER_COMPONENTS_SUFFIX) : null;
int componentConfigCount = 0;
for (IdeaPluginDescriptor plugin : plugins) {
for (ComponentConfig config : getMyComponentConfigsFromDescriptor(plugin)) {
@@ -109,14 +116,14 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
myComponentConfigCount = componentConfigCount;
if (componentsRegistered != null) {
measureToken = isNeededToMeasure ? totalMeasureToken.startChild(measureTokenNamePrefix + StartUpMeasurer.Phases.COMPONENTS_REGISTERED_CALLBACK_SUFFIX) : null;
measureToken = isNeededToMeasure ? totalMeasureToken.startChild(measureTokenNamePrefix + Phases.COMPONENTS_REGISTERED_CALLBACK_SUFFIX) : null;
componentsRegistered.run();
if (measureToken != null) {
measureToken.end();
}
}
measureToken = isNeededToMeasure ? totalMeasureToken.startChild(measureTokenNamePrefix + StartUpMeasurer.Phases.CREATE_COMPONENTS_SUFFIX) : null;
measureToken = isNeededToMeasure ? totalMeasureToken.startChild(measureTokenNamePrefix + Phases.CREATE_COMPONENTS_SUFFIX) : null;
createComponents(indicator);
if (measureToken != null) {
measureToken.end();
@@ -220,7 +227,9 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
}
@TestOnly
public void registerComponentImplementation(@NotNull Class<?> componentKey, @NotNull Class<?> componentImplementation, boolean shouldBeRegistered) {
public void registerComponentImplementation(@NotNull Class<?> componentKey,
@NotNull Class<?> componentImplementation,
boolean shouldBeRegistered) {
MutablePicoContainer picoContainer = getPicoContainer();
ComponentConfigComponentAdapter adapter = (ComponentConfigComponentAdapter)picoContainer.unregisterComponent(componentKey);
if (shouldBeRegistered) LOG.assertTrue(adapter != null);
@@ -256,7 +265,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
List<T> result = null;
// we must use instances only from our adapter (could be service or extension point or something else)
for (ComponentAdapter componentAdapter : ((DefaultPicoContainer)getPicoContainer()).getComponentAdapters()) {
if (componentAdapter instanceof ComponentConfigComponentAdapter && ReflectionUtil.isAssignable(baseClass, componentAdapter.getComponentImplementation())) {
if (componentAdapter instanceof ComponentConfigComponentAdapter &&
ReflectionUtil.isAssignable(baseClass, componentAdapter.getComponentImplementation())) {
//noinspection unchecked
T instance = (T)((ComponentConfigComponentAdapter)componentAdapter).myInitializedComponentInstance;
if (instance != null) {
@@ -419,7 +429,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
BaseComponent loadedComponent = myNameToComponent.get(componentName);
// component may have been already loaded by PicoContainer, so fire error only if components are really different
if (!instance.equals(loadedComponent)) {
String errorMessage = "Component name collision: " + componentName + " " + (loadedComponent == null ? "null" : loadedComponent.getClass()) + " and " + instance.getClass();
String errorMessage = "Component name collision: " + componentName +
' ' + (loadedComponent == null ? "null" : loadedComponent.getClass()) + " and " + instance.getClass();
PluginException.logPluginError(LOG, errorMessage, null, instance.getClass());
}
}
@@ -453,7 +464,9 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
}
@Override
public Object getComponentInstance(@NotNull PicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException, ProcessCanceledException {
public Object getComponentInstance(@NotNull PicoContainer picoContainer)
throws PicoInitializationException, PicoIntrospectionException, ProcessCanceledException {
Object instance = myInitializedComponentInstance;
// getComponent could be called during some component.dispose() call, in this case we don't attempt to instantiate component
if (instance != null || myDisposed) {
@@ -469,7 +482,8 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
}
// if it will be module component, then get rid of such component instead of measurement
StartUpMeasurer.MeasureToken measureToken = StartUpMeasurer.start(ComponentManagerImpl.this instanceof Application ? StartUpMeasurer.Activities.APP_COMPONENT : StartUpMeasurer.Activities.PROJECT_COMPONENT);
boolean appComponent = ComponentManagerImpl.this instanceof Application;
StartUpMeasurer.MeasureToken measureToken = StartUpMeasurer.start(appComponent ? Activities.APP_COMPONENT : Activities.PROJECT_COMPONENT);
instance = super.getComponentInstance(picoContainer);
if (myInitializing) {
@@ -520,4 +534,4 @@ public abstract class ComponentManagerImpl extends UserDataHolderBase implements
return "ComponentConfigAdapter[" + getComponentKey() + "]: implementation=" + getComponentImplementation() + ", plugin=" + myPluginId;
}
}
}
}
@@ -15,7 +15,8 @@ public final class StartUpMeasurer {
public static final long MEASURE_THRESHOLD = TimeUnit.MILLISECONDS.toNanos(10);
// Use constants for better overview of existing phases (and preserve consistent naming).
// `what + noun` is used as scheme for name to make analyzing easier (to visually group - `components loading/initialization/etc`, not to put common part of name to end of).
// `what + noun` is used as scheme for name to make analyzing easier (to visually group - `components loading/initialization/etc`,
// not to put common part of name to end of).
// It is not serves only display purposes - it is IDs. Visualizer and another tools to analyze data uses phase IDs,
// so, any changes must be discussed across all involved and reflected in changelog (see `format-changelog.md`).
public static final class Phases {
@@ -182,4 +183,4 @@ public final class StartUpMeasurer {
end(null);
}
}
}
}
@@ -89,7 +89,8 @@ public class StartupManagerImpl extends StartupManagerEx {
public synchronized void registerPostStartupActivity(@NotNull Runnable runnable) {
checkNonDefaultProject();
LOG.assertTrue(!myPostStartupActivitiesPassed, "Registering post-startup activity that will never be run:" +
" disposed=" + myProject.isDisposed() + "; open=" + myProject.isOpen() + "; passed=" + myStartupActivitiesPassed);
" disposed=" + myProject.isDisposed() + "; open=" + myProject.isOpen() +
"; passed=" + myStartupActivitiesPassed);
(DumbService.isDumbAware(runnable) ? myDumbAwarePostStartupActivities : myNotDumbAwarePostStartupActivities).add(runnable);
}
@@ -156,7 +157,8 @@ public class StartupManagerImpl extends StartupManagerEx {
if (duration > 100 && !app.isUnitTestMode()) {
boolean edt = app.isDispatchThread();
if (edt && uiFreezeWarned.compareAndSet(false, true)) {
LOG.info("Some post-startup activities freeze UI for noticeable time. Please consider making them DumbAware to do them in background under modal progress, or just making them faster to speed up project opening.");
LOG.info("Some post-startup activities freeze UI for noticeable time. Please consider making them DumbAware to run them in background" +
" under modal progress, or just making them faster to speed up project opening.");
}
LOG.info(extension.getClass().getSimpleName() + " run in " + duration + "ms " + (edt ? "on UI thread" : "under project opening modal progress"));
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.PlatformUtils;
import com.intellij.util.StartUpMeasurer;
import com.intellij.util.StartUpMeasurer.Activities;
import com.intellij.util.io.storage.HeavyProcessLatch;
import com.intellij.util.pico.AssignableToComponentAdapter;
import com.intellij.util.pico.CachingConstructorInjectionComponentAdapter;
@@ -43,7 +44,9 @@ import java.util.function.Consumer;
public final class ServiceManagerImpl implements Disposable {
private static final Logger LOG = Logger.getInstance(ServiceManagerImpl.class);
static void registerServices(@NotNull List<ServiceDescriptor> services, @NotNull IdeaPluginDescriptor pluginDescriptor, @NotNull ComponentManagerEx componentManager) {
static void registerServices(@NotNull List<ServiceDescriptor> services,
@NotNull IdeaPluginDescriptor pluginDescriptor,
@NotNull ComponentManagerEx componentManager) {
MutablePicoContainer picoContainer = (MutablePicoContainer)componentManager.getPicoContainer();
for (ServiceDescriptor descriptor : services) {
// Allow to re-define service implementations in plugins.
@@ -97,7 +100,8 @@ public final class ServiceManagerImpl implements Disposable {
return result;
}
public static void processAllImplementationClasses(@NotNull ComponentManagerImpl componentManager, @NotNull BiPredicate<? super Class<?>, ? super PluginDescriptor> processor) {
public static void processAllImplementationClasses(@NotNull ComponentManagerImpl componentManager,
@NotNull BiPredicate<? super Class<?>, ? super PluginDescriptor> processor) {
@SuppressWarnings("unchecked")
Collection<ComponentAdapter> adapters = componentManager.getPicoContainer().getComponentAdapters();
if (adapters.isEmpty()) {
@@ -228,7 +232,8 @@ public final class ServiceManagerImpl implements Disposable {
@NotNull
private Object createAndInitialize(@NotNull PicoContainer container) {
// if it will be module service, then get rid of such component instead of measurement
StartUpMeasurer.MeasureToken measureToken = StartUpMeasurer.start(myComponentManager instanceof Application ? StartUpMeasurer.Activities.APP_SERVICE : StartUpMeasurer.Activities.PROJECT_SERVICE);
boolean appComponent = myComponentManager instanceof Application;
StartUpMeasurer.MeasureToken measureToken = StartUpMeasurer.start(appComponent ? Activities.APP_SERVICE : Activities.PROJECT_SERVICE);
Object instance = getDelegate().getComponentInstance(container);
if (instance instanceof Disposable) {
Disposer.register(myComponentManager, (Disposable)instance);
@@ -276,4 +281,4 @@ public final class ServiceManagerImpl implements Disposable {
return "ServiceComponentAdapter(descriptor=" + myDescriptor + ", pluginDescriptor=" + myPluginDescriptor + ")";
}
}
}
}