diff --git a/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContext.java b/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContext.java index 74f1be7b8108..d6b2645f224a 100644 --- a/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContext.java +++ b/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -92,6 +92,16 @@ public abstract class ConfigurationFromContext { return true; } + /** + * Checks if this configuration should replace another one, that is if the other should be discarded. + * + * @see RunConfigurationProducer#shouldReplace(ConfigurationFromContext, ConfigurationFromContext) + * @return true if the other configuration should be discarded, false otherwise. + */ + public boolean shouldReplace(ConfigurationFromContext other) { + return false; + } + /** * Checks if this configuration was created by the specified producer. * @@ -117,9 +127,15 @@ public abstract class ConfigurationFromContext { if (!configuration1.isPreferredTo(configuration2)) { return 1; } + if (configuration2.shouldReplace(configuration1)) { + return 1; + } if (!configuration2.isPreferredTo(configuration1)) { return -1; } + if (configuration1.shouldReplace(configuration2)) { + return -1; + } return 0; } }; diff --git a/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContextImpl.java b/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContextImpl.java index dce85e0e7c9a..8487f91efdeb 100644 --- a/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContextImpl.java +++ b/platform/lang-api/src/com/intellij/execution/actions/ConfigurationFromContextImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -55,6 +55,11 @@ public class ConfigurationFromContextImpl extends ConfigurationFromContext { return myConfigurationProducer.isPreferredConfiguration(this, other); } + @Override + public boolean shouldReplace(ConfigurationFromContext other) { + return myConfigurationProducer.shouldReplace(this, other); + } + @Override public boolean isProducedBy(Class producerClass) { return producerClass.isInstance(myConfigurationProducer); diff --git a/platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java b/platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java index 7290b83516aa..711588a4aa6b 100644 --- a/platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java +++ b/platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java @@ -119,11 +119,28 @@ public abstract class RunConfigurationProducer { * @param other a configuration created by another producer. * @return true if the configuration created by this producer is at least as good as the other one; false if this configuration * should be discarded and the other one should be used instead. + * @see #shouldReplace(ConfigurationFromContext, ConfigurationFromContext) */ public boolean isPreferredConfiguration(ConfigurationFromContext self, ConfigurationFromContext other) { return true; } + /** + * When two configurations are created from the same context by two different producers, checks if the configuration created by + * this producer should replace the other one, that is if the other one should be discarded. + * + *

This is the same relationship as {@link #isPreferredConfiguration(ConfigurationFromContext, ConfigurationFromContext)} but + * specified from the "replacement" side. + * + * @param self a configuration created by this producer. + * @param other a configuration created by another producer. + * @return true if the other configuration should be discarded, false otherwise. + * @see #isPreferredConfiguration(ConfigurationFromContext, ConfigurationFromContext) + */ + public boolean shouldReplace(ConfigurationFromContext self, ConfigurationFromContext other) { + return false; + } + /** * Called before a configuration created from context by this producer is first executed. Can be used to show additional UI for * customizing the created configuration. diff --git a/platform/lang-api/src/com/intellij/execution/impl/ConfigurationFromContextWrapper.java b/platform/lang-api/src/com/intellij/execution/impl/ConfigurationFromContextWrapper.java index 69acb5463c7b..621113a4b8dc 100644 --- a/platform/lang-api/src/com/intellij/execution/impl/ConfigurationFromContextWrapper.java +++ b/platform/lang-api/src/com/intellij/execution/impl/ConfigurationFromContextWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -61,4 +61,10 @@ public class ConfigurationFromContextWrapper extends ConfigurationFromContext { return other instanceof ConfigurationFromContextWrapper && myProducer.compareTo(((ConfigurationFromContextWrapper) other).myProducer) < 0; } + + @Override + public boolean shouldReplace(ConfigurationFromContext other) { + return other instanceof ConfigurationFromContextWrapper && + myProducer.compareTo(((ConfigurationFromContextWrapper) other).myProducer) > 0; + } }