mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -61,7 +61,7 @@ public abstract class JavaTestConfigurationBase extends ModuleBasedConfiguration
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortenCommandLine(ShortenCommandLine shortenCommandLine) {
|
||||
public void setShortenCommandLine(@Nullable ShortenCommandLine shortenCommandLine) {
|
||||
myShortenCommandLine = shortenCommandLine;
|
||||
}
|
||||
|
||||
|
||||
+23
-9
@@ -9,6 +9,7 @@ import com.intellij.execution.junit.RefactoringListeners;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.util.JavaParametersUtil;
|
||||
import com.intellij.execution.util.ProgramParametersUtil;
|
||||
import com.intellij.openapi.components.BaseState;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.options.SettingsEditorGroup;
|
||||
@@ -35,14 +36,18 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
RefactoringListenerProvider, InputRedirectAware {
|
||||
|
||||
/* deprecated, but 3rd-party used variables */
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated public String MAIN_CLASS_NAME;
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated public String PROGRAM_PARAMETERS;
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated public String WORKING_DIRECTORY;
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated public boolean ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated public String ALTERNATIVE_JRE_PATH;
|
||||
/* */
|
||||
|
||||
private ShortenCommandLine myShortenCommandLine = null;
|
||||
private final InputRedirectAware.InputRedirectOptions myInputRedirectOptions = new InputRedirectOptions();
|
||||
|
||||
public ApplicationConfiguration(String name, @NotNull Project project, @NotNull ApplicationConfigurationType configurationType) {
|
||||
@@ -275,11 +280,19 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
return JavaRunConfigurationModule.getModulesForClass(getProject(), getMainClassName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void readExternal(@NotNull final Element element) {
|
||||
super.readExternal(element);
|
||||
|
||||
syncOldStateFields();
|
||||
|
||||
JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
|
||||
setShortenCommandLine(ShortenCommandLine.readShortenClasspathMethod(element));
|
||||
myInputRedirectOptions.readExternal(element);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void syncOldStateFields() {
|
||||
JvmMainMethodRunConfigurationOptions options = getOptions();
|
||||
|
||||
String workingDirectory = options.getWorkingDirectory();
|
||||
@@ -295,10 +308,12 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
WORKING_DIRECTORY = workingDirectory;
|
||||
ALTERNATIVE_JRE_PATH = options.getAlternativeJrePath();
|
||||
ALTERNATIVE_JRE_PATH_ENABLED = options.isAlternativeJrePathEnabled();
|
||||
}
|
||||
|
||||
JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element);
|
||||
setShortenCommandLine(ShortenCommandLine.readShortenClasspathMethod(element));
|
||||
myInputRedirectOptions.readExternal(element);
|
||||
@Override
|
||||
public void setState(@NotNull BaseState state) {
|
||||
super.setState(state);
|
||||
syncOldStateFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -306,19 +321,18 @@ public class ApplicationConfiguration extends ModuleBasedConfiguration<JavaRunCo
|
||||
super.writeExternal(element);
|
||||
|
||||
JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
|
||||
ShortenCommandLine.writeShortenClasspathMethod(element, myShortenCommandLine);
|
||||
myInputRedirectOptions.writeExternal(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ShortenCommandLine getShortenCommandLine() {
|
||||
return myShortenCommandLine;
|
||||
return getOptions().getShortenClasspath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortenCommandLine(ShortenCommandLine mode) {
|
||||
myShortenCommandLine = mode;
|
||||
public void setShortenCommandLine(@Nullable ShortenCommandLine mode) {
|
||||
getOptions().setShortenClasspath(mode);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+11
-5
@@ -2,26 +2,32 @@
|
||||
package com.intellij.execution.application
|
||||
|
||||
import com.intellij.execution.JvmConfigurationOptions
|
||||
import com.intellij.execution.ShortenCommandLine
|
||||
import com.intellij.util.xmlb.annotations.OptionTag
|
||||
import com.intellij.util.xmlb.annotations.XMap
|
||||
import java.util.*
|
||||
|
||||
open class JvmMainMethodRunConfigurationOptions : JvmConfigurationOptions() {
|
||||
@get:OptionTag("PROGRAM_PARAMETERS")
|
||||
open var programParameters: String? by string()
|
||||
open var programParameters by string()
|
||||
|
||||
@get:OptionTag("WORKING_DIRECTORY")
|
||||
open var workingDirectory: String? by string()
|
||||
open var workingDirectory by string()
|
||||
|
||||
@get:OptionTag("INCLUDE_PROVIDED_SCOPE")
|
||||
var includeProvidedScope: Boolean by property(false)
|
||||
var includeProvidedScope by property(false)
|
||||
|
||||
@get:OptionTag("ENABLE_SWING_INSPECTOR")
|
||||
var isSwingInspectorEnabled: Boolean by property(false)
|
||||
var isSwingInspectorEnabled by property(false)
|
||||
|
||||
@get:OptionTag("PASS_PARENT_ENVS")
|
||||
var isPassParentEnv: Boolean by property(true)
|
||||
var isPassParentEnv by property(true)
|
||||
|
||||
@get:XMap(propertyElementName = "envs", entryTagName = "env", keyAttributeName = "name")
|
||||
var env: MutableMap<String, String> by property(LinkedHashMap())
|
||||
|
||||
// see ConfigurationWithCommandLineShortener - "null if option was not selected explicitly, legacy user-local options to be used"
|
||||
// so, we cannot use NONE as default value
|
||||
@get:OptionTag(nameAttribute = "", valueAttribute = "name")
|
||||
var shortenClasspath by enum<ShortenCommandLine>()
|
||||
}
|
||||
+1
-1
@@ -238,7 +238,7 @@ public abstract class TestDiscoveryConfigurationProducer extends JavaRunConfigur
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShortenCommandLine(ShortenCommandLine mode) {
|
||||
public void setShortenCommandLine(@Nullable ShortenCommandLine mode) {
|
||||
myConfiguration.setShortenCommandLine(mode);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
// Copyright 2000-2017 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -74,6 +62,7 @@ public enum ShortenCommandLine {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void writeShortenClasspathMethod(@NotNull Element element, ShortenCommandLine shortenCommandLine) {
|
||||
if (shortenCommandLine != null) {
|
||||
element.addContent(new Element("shortenClasspath").setAttribute("name", shortenCommandLine.name()));
|
||||
|
||||
+3
-1
@@ -21,6 +21,7 @@ import com.intellij.util.SmartList;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -215,7 +216,8 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements
|
||||
myOptions = XmlSerializer.deserialize(element, getOptionsClass());
|
||||
}
|
||||
|
||||
public final void setState(@NotNull BaseState state) {
|
||||
@ApiStatus.Experimental
|
||||
public void setState(@NotNull BaseState state) {
|
||||
myOptions = (RunConfigurationOptions)state;
|
||||
}
|
||||
|
||||
|
||||
+27
-12
@@ -6,6 +6,7 @@ package com.intellij.ide.actions.searcheverywhere;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -16,7 +17,6 @@ import java.util.function.Function;
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
//todo generic? #UX-1
|
||||
public interface SearchEverywhereContributor<F> {
|
||||
|
||||
ExtensionPointName<SearchEverywhereContributorFactory<?>> EP_NAME = ExtensionPointName.create("com.intellij.searchEverywhereContributor");
|
||||
@@ -27,6 +27,7 @@ public interface SearchEverywhereContributor<F> {
|
||||
@NotNull
|
||||
String getGroupName();
|
||||
|
||||
@Nullable
|
||||
String includeNonProjectItemsText();
|
||||
|
||||
int getSortWeight();
|
||||
@@ -37,15 +38,22 @@ public interface SearchEverywhereContributor<F> {
|
||||
return false;
|
||||
}
|
||||
|
||||
default int getElementPriority(Object element, String searchPattern) {
|
||||
default int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<F> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer);
|
||||
void fetchElements(@NotNull String pattern,
|
||||
boolean everywhere,
|
||||
@Nullable SearchEverywhereContributorFilter<F> filter,
|
||||
@NotNull ProgressIndicator progressIndicator,
|
||||
@NotNull Function<Object, Boolean> consumer);
|
||||
|
||||
default ContributorSearchResult<Object> search(String pattern, boolean everywhere, SearchEverywhereContributorFilter<F> filter,
|
||||
ProgressIndicator progressIndicator, int elementsLimit) {
|
||||
@NotNull
|
||||
default ContributorSearchResult<Object> search(@NotNull String pattern,
|
||||
boolean everywhere,
|
||||
@Nullable SearchEverywhereContributorFilter<F> filter,
|
||||
@NotNull ProgressIndicator progressIndicator,
|
||||
int elementsLimit) {
|
||||
ContributorSearchResult.Builder<Object> builder = ContributorSearchResult.builder();
|
||||
fetchElements(pattern, everywhere, filter, progressIndicator, element -> {
|
||||
if (elementsLimit < 0 || builder.itemsCount() < elementsLimit) {
|
||||
@@ -61,20 +69,26 @@ public interface SearchEverywhereContributor<F> {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
default List<Object> search(String pattern, boolean everywhere, SearchEverywhereContributorFilter<F> filter,
|
||||
ProgressIndicator progressIndicator) {
|
||||
@NotNull
|
||||
default List<Object> search(@NotNull String pattern,
|
||||
boolean everywhere,
|
||||
@Nullable SearchEverywhereContributorFilter<F> filter,
|
||||
@NotNull ProgressIndicator progressIndicator) {
|
||||
List<Object> res = new ArrayList<>();
|
||||
fetchElements(pattern, everywhere, filter, progressIndicator, o -> res.add(o));
|
||||
return res;
|
||||
}
|
||||
|
||||
boolean processSelectedItem(Object selected, int modifiers, String searchText);
|
||||
boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String searchText);
|
||||
|
||||
ListCellRenderer getElementsRenderer(JList<?> list);
|
||||
@NotNull
|
||||
ListCellRenderer getElementsRenderer(@NotNull JList<?> list);
|
||||
|
||||
Object getDataForItem(Object element, String dataId);
|
||||
@Nullable
|
||||
Object getDataForItem(@NotNull Object element, @NotNull String dataId);
|
||||
|
||||
default String filterControlSymbols(String pattern) {
|
||||
@NotNull
|
||||
default String filterControlSymbols(@NotNull String pattern) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@@ -86,6 +100,7 @@ public interface SearchEverywhereContributor<F> {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static List<SearchEverywhereContributorFactory<?>> getProviders() {
|
||||
return Arrays.asList(EP_NAME.getExtensions());
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -14,7 +14,7 @@ public interface ConfigurationWithCommandLineShortener {
|
||||
/**
|
||||
* Called from UI, when user explicitly selects method to be used to shorten the command line or from the deserialization
|
||||
*/
|
||||
void setShortenCommandLine(ShortenCommandLine mode);
|
||||
void setShortenCommandLine(@Nullable ShortenCommandLine mode);
|
||||
|
||||
Project getProject();
|
||||
}
|
||||
|
||||
+12
-8
@@ -65,8 +65,8 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
private static final Logger LOG = Logger.getInstance(AbstractGotoSEContributor.class);
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<F> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer) {
|
||||
public void fetchElements(@NotNull String pattern, boolean everywhere, @Nullable SearchEverywhereContributorFilter<F> filter,
|
||||
@NotNull ProgressIndicator progressIndicator, @NotNull Function<Object, Boolean> consumer) {
|
||||
if (!isDumbModeSupported() && DumbService.getInstance(myProject).isDumb()) {
|
||||
return;
|
||||
}
|
||||
@@ -74,7 +74,9 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
String suffix = pattern.endsWith(fullMatchSearchSuffix) ? fullMatchSearchSuffix : "";
|
||||
String searchString = filterControlSymbols(pattern) + suffix;
|
||||
FilteringGotoByModel<F> model = createModel(myProject);
|
||||
model.setFilterItems(filter.getSelectedElements());
|
||||
if (filter != null) {
|
||||
model.setFilterItems(filter.getSelectedElements());
|
||||
}
|
||||
ChooseByNamePopup popup = ChooseByNamePopup.createPopup(myProject, model, (PsiElement)null);
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
@@ -95,8 +97,9 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
//todo param is unnecessary #UX-1
|
||||
protected abstract FilteringGotoByModel<F> createModel(Project project);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String filterControlSymbols(String pattern) {
|
||||
public String filterControlSymbols(@NotNull String pattern) {
|
||||
if (StringUtil.containsAnyChar(pattern, ":,;@[( #") || pattern.contains(" line ") || pattern.contains("?l=")) { // quick test if reg exp should be used
|
||||
return applyPatternFilter(pattern, patternToDetectLinesAndColumns);
|
||||
}
|
||||
@@ -119,7 +122,7 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String searchText) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String searchText) {
|
||||
if (selected instanceof PsiElement) {
|
||||
if (!((PsiElement)selected).isValid()) {
|
||||
LOG.warn("Cannot navigate to invalid PsiElement");
|
||||
@@ -143,7 +146,7 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
if (CommonDataKeys.PSI_ELEMENT.is(dataId) && element instanceof PsiElement) {
|
||||
return element;
|
||||
}
|
||||
@@ -156,8 +159,9 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ListCellRenderer getElementsRenderer(JList<?> list) {
|
||||
public ListCellRenderer getElementsRenderer(@NotNull JList<?> list) {
|
||||
return new SearchEverywherePsiRenderer(list) {
|
||||
@Override
|
||||
public String getElementText(PsiElement element) {
|
||||
@@ -172,7 +176,7 @@ public abstract class AbstractGotoSEContributor<F> implements SearchEverywhereCo
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementPriority(Object element, String searchPattern) {
|
||||
public int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return 50;
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -57,8 +57,8 @@ public class ActionSearchEverywhereContributor implements SearchEverywhereContri
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<Void> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer) {
|
||||
public void fetchElements(@NotNull String pattern, boolean everywhere, @Nullable SearchEverywhereContributorFilter<Void> filter,
|
||||
@NotNull ProgressIndicator progressIndicator, @NotNull Function<Object, Boolean> consumer) {
|
||||
if (StringUtil.isEmptyOrSpaces(pattern)) {
|
||||
return;
|
||||
}
|
||||
@@ -80,8 +80,9 @@ public class ActionSearchEverywhereContributor implements SearchEverywhereContri
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ListCellRenderer getElementsRenderer(JList<?> list) {
|
||||
public ListCellRenderer getElementsRenderer(@NotNull JList<?> list) {
|
||||
return new GotoActionModel.GotoActionListCellRenderer(myModel::getGroupName, true);
|
||||
}
|
||||
|
||||
@@ -97,7 +98,7 @@ public class ActionSearchEverywhereContributor implements SearchEverywhereContri
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
if (SetShortcutAction.SELECTED_ACTION.is(dataId)) {
|
||||
Object value = ((GotoActionModel.MatchedValue)element).value;
|
||||
if (value instanceof GotoActionModel.ActionWrapper) {
|
||||
@@ -113,7 +114,7 @@ public class ActionSearchEverywhereContributor implements SearchEverywhereContri
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String text) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String text) {
|
||||
selected = ((GotoActionModel.MatchedValue) selected).value;
|
||||
|
||||
if (selected instanceof BooleanOptionDescription) {
|
||||
|
||||
+3
-2
@@ -60,8 +60,9 @@ public class ClassSearchEverywhereContributor extends AbstractGotoSEContributor<
|
||||
return new GotoClassModel2(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String filterControlSymbols(String pattern) {
|
||||
public String filterControlSymbols(@NotNull String pattern) {
|
||||
if (pattern.indexOf('#') != -1) {
|
||||
pattern = applyPatternFilter(pattern, patternToDetectMembers);
|
||||
}
|
||||
@@ -74,7 +75,7 @@ public class ClassSearchEverywhereContributor extends AbstractGotoSEContributor<
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementPriority(Object element, String searchPattern) {
|
||||
public int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return super.getElementPriority(element, searchPattern) + 5;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ public class FileSearchEverywhereContributor extends AbstractGotoSEContributor<F
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String searchText) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String searchText) {
|
||||
if (selected instanceof PsiFile) {
|
||||
VirtualFile file = ((PsiFile)selected).getVirtualFile();
|
||||
if (file != null) {
|
||||
@@ -77,7 +77,7 @@ public class FileSearchEverywhereContributor extends AbstractGotoSEContributor<F
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
if (CommonDataKeys.PSI_FILE.is(dataId) && element instanceof PsiFile) {
|
||||
return element;
|
||||
}
|
||||
|
||||
+4
-3
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.codeStyle.MinusculeMatcher;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -51,13 +52,13 @@ public class RecentFilesSEContributor extends FileSearchEverywhereContributor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementPriority(Object element, String searchPattern) {
|
||||
public int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return super.getElementPriority(element, searchPattern) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<FileType> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer) {
|
||||
public void fetchElements(@NotNull String pattern, boolean everywhere, @Nullable SearchEverywhereContributorFilter<FileType> filter,
|
||||
@NotNull ProgressIndicator progressIndicator, @NotNull Function<Object, Boolean> consumer) {
|
||||
String searchString = filterControlSymbols(pattern);
|
||||
MinusculeMatcher matcher = NameUtil.buildMatcher("*" + searchString).build();
|
||||
List<VirtualFile> opened = Arrays.asList(FileEditorManager.getInstance(myProject).getSelectedFiles());
|
||||
|
||||
+51
-17
@@ -14,14 +14,17 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
|
||||
import com.intellij.openapi.progress.util.ProgressWindow;
|
||||
import com.intellij.openapi.progress.util.TooManyUsagesStatus;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
@@ -44,6 +47,7 @@ import com.intellij.ui.components.fields.ExtendableTextField;
|
||||
import com.intellij.ui.popup.PopupUpdateProcessor;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usages.*;
|
||||
import com.intellij.usages.impl.UsageViewManagerImpl;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.text.MatcherHolder;
|
||||
import com.intellij.util.ui.DialogUtil;
|
||||
@@ -1047,7 +1051,7 @@ public class SearchEverywhereUI extends BorderLayoutPanel implements Disposable,
|
||||
|
||||
Collection<Object> cached = contributors.stream()
|
||||
.flatMap(contributor -> myListModel.getFoundItems(contributor).stream())
|
||||
.collect(Collectors.toList());
|
||||
.collect(Collectors.toSet());
|
||||
fillUsages(cached, usages, targets);
|
||||
|
||||
Collection<SearchEverywhereContributor> contributorsForAdditionalSearch;
|
||||
@@ -1062,14 +1066,44 @@ public class SearchEverywhereUI extends BorderLayoutPanel implements Disposable,
|
||||
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
progressIndicator.start();
|
||||
TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.createFor(progressIndicator);
|
||||
|
||||
Collection<Object> foundElements = new ArrayList<>();
|
||||
int alreadyFoundCount = cached.size();
|
||||
contributorsForAdditionalSearch.forEach(contributor -> {
|
||||
if (!progressIndicator.isCanceled()) {
|
||||
//todo overflow #UX-1
|
||||
List<Object> foundElements =
|
||||
contributor.search(searchText, everywhere, myContributorFilters.get(contributor.getSearchProviderId()), progressIndicator);
|
||||
fillUsages(foundElements, usages, targets);
|
||||
try {
|
||||
contributor
|
||||
.fetchElements(searchText, everywhere, myContributorFilters.get(contributor.getSearchProviderId()), progressIndicator,
|
||||
o -> {
|
||||
if (progressIndicator.isCanceled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cached.contains(o)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foundElements.add(o);
|
||||
tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
|
||||
if (foundElements.size() + alreadyFoundCount >= UsageLimitUtil.USAGES_LIMIT &&
|
||||
tooManyUsagesStatus.switchTooManyUsagesStatus()) {
|
||||
int usageCount = foundElements.size() + alreadyFoundCount;
|
||||
UsageViewManagerImpl
|
||||
.showTooManyUsagesWarningLater(getProject(), tooManyUsagesStatus, progressIndicator,
|
||||
presentation, usageCount, null);
|
||||
return !progressIndicator.isCanceled();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
fillUsages(foundElements, usages, targets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1093,18 +1127,18 @@ public class SearchEverywhereUI extends BorderLayoutPanel implements Disposable,
|
||||
}
|
||||
|
||||
private void fillUsages(Collection<Object> foundElements, Collection<Usage> usages, Collection<PsiElement> targets) {
|
||||
foundElements.stream()
|
||||
.filter(o -> o instanceof PsiElement)
|
||||
.forEach(o -> {
|
||||
PsiElement element = (PsiElement)o;
|
||||
if (element.getTextRange() != null) {
|
||||
UsageInfo usageInfo = new UsageInfo(element);
|
||||
usages.add(new UsageInfo2UsageAdapter(usageInfo));
|
||||
}
|
||||
else {
|
||||
targets.add(element);
|
||||
}
|
||||
});
|
||||
ReadAction.run(() -> foundElements.stream()
|
||||
.filter(o -> o instanceof PsiElement)
|
||||
.forEach(o -> {
|
||||
PsiElement element = (PsiElement)o;
|
||||
if (element.getTextRange() != null) {
|
||||
UsageInfo usageInfo = new UsageInfo(element);
|
||||
usages.add(new UsageInfo2UsageAdapter(usageInfo));
|
||||
}
|
||||
else {
|
||||
targets.add(element);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void showInFindWindow(Collection<PsiElement> targets, Collection<Usage> usages, UsageViewPresentation presentation) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class SymbolSearchEverywhereContributor extends AbstractGotoSEContributor
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementPriority(Object element, String searchPattern) {
|
||||
public int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return super.getElementPriority(element, searchPattern) + 3;
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -28,6 +28,7 @@ import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
@@ -80,18 +81,18 @@ public class TopHitSEContributor implements SearchEverywhereContributor<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<Void> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer) {
|
||||
public void fetchElements(@NotNull String pattern, boolean everywhere, @Nullable SearchEverywhereContributorFilter<Void> filter,
|
||||
@NotNull ProgressIndicator progressIndicator, @NotNull Function<Object, Boolean> consumer) {
|
||||
fill(pattern, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String text) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String text) {
|
||||
if (selected instanceof BooleanOptionDescription) {
|
||||
final BooleanOptionDescription option = (BooleanOptionDescription) selected;
|
||||
option.setOptionState(!option.isOptionEnabled());
|
||||
@@ -111,8 +112,9 @@ public class TopHitSEContributor implements SearchEverywhereContributor<Void> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ListCellRenderer getElementsRenderer(JList<?> list) {
|
||||
public ListCellRenderer getElementsRenderer(@NotNull JList<?> list) {
|
||||
return new TopHitRenderer(myProject);
|
||||
}
|
||||
|
||||
|
||||
+12
-10
@@ -7,6 +7,7 @@ import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCa
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -30,7 +31,7 @@ public class MultithreadSearchTest extends LightPlatformCodeInsightFixtureTestCa
|
||||
MultithreadSearcher searcher = new MultithreadSearcher(collector, command -> alarm.addRequest(command, 0));
|
||||
|
||||
scenarios.forEach(scenario -> {
|
||||
searcher.search(scenario.contributorsAndLimits, null, false, ignrd -> null);
|
||||
searcher.search(scenario.contributorsAndLimits, "", false, ignrd -> null);
|
||||
collector.awaitFinish();
|
||||
scenario.results.forEach((contributorId, results) -> {
|
||||
List<String> values = collector.getContributorValues(contributorId);
|
||||
@@ -47,7 +48,7 @@ public class MultithreadSearchTest extends LightPlatformCodeInsightFixtureTestCa
|
||||
SESearcher searcher = new SingleThreadSearcher(collector, command -> alarm.addRequest(command, 0));
|
||||
|
||||
scenarios.forEach(scenario -> {
|
||||
searcher.search(scenario.contributorsAndLimits, null, false, ignrd -> null);
|
||||
searcher.search(scenario.contributorsAndLimits, "", false, ignrd -> null);
|
||||
collector.awaitFinish();
|
||||
scenario.results.forEach((contributorId, results) -> {
|
||||
List<String> values = collector.getContributorValues(contributorId);
|
||||
@@ -344,16 +345,16 @@ public class MultithreadSearchTest extends LightPlatformCodeInsightFixtureTestCa
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementPriority(Object element, String searchPattern) {
|
||||
public int getElementPriority(@NotNull Object element, @NotNull String searchPattern) {
|
||||
return fixedPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern,
|
||||
public void fetchElements(@NotNull String pattern,
|
||||
boolean everywhere,
|
||||
SearchEverywhereContributorFilter<Object> filter,
|
||||
ProgressIndicator progressIndicator,
|
||||
Function<Object, Boolean> consumer) {
|
||||
@Nullable SearchEverywhereContributorFilter<Object> filter,
|
||||
@NotNull ProgressIndicator progressIndicator,
|
||||
@NotNull Function<Object, Boolean> consumer) {
|
||||
boolean flag = true;
|
||||
Iterator<String> iterator = Arrays.asList(items).iterator();
|
||||
while (flag && iterator.hasNext()) {
|
||||
@@ -363,17 +364,18 @@ public class MultithreadSearchTest extends LightPlatformCodeInsightFixtureTestCa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String searchText) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String searchText) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ListCellRenderer getElementsRenderer(JList<?> list) {
|
||||
public ListCellRenderer getElementsRenderer(@NotNull JList<?> list) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.awt.Rectangle
|
||||
class ProjectFrameBounds(private val project: Project) : PersistentStateComponent<FrameInfo>, ModificationTracker {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project): ProjectFrameBounds = project.service<ProjectFrameBounds>()
|
||||
fun getInstance(project: Project) = project.service<ProjectFrameBounds>()
|
||||
}
|
||||
|
||||
// in device space
|
||||
@@ -26,7 +26,7 @@ class ProjectFrameBounds(private val project: Project) : PersistentStateComponen
|
||||
val isInFullScreen: Boolean
|
||||
get() = rawFrameInfo?.fullScreen ?: false
|
||||
|
||||
override fun getState(): FrameInfo? = rawFrameInfo
|
||||
override fun getState() = rawFrameInfo
|
||||
|
||||
override fun loadState(state: FrameInfo) {
|
||||
rawFrameInfo = state
|
||||
@@ -49,10 +49,10 @@ class ProjectFrameBounds(private val project: Project) : PersistentStateComponen
|
||||
|
||||
class FrameInfo : BaseState() {
|
||||
// flat is used due to backward compatibility
|
||||
@get:Property(flat = true) var bounds: Rectangle? by property<Rectangle>()
|
||||
@get:Attribute var extendedState: Int by property(Frame.NORMAL)
|
||||
@get:Property(flat = true) var bounds by property<Rectangle>()
|
||||
@get:Attribute var extendedState by property(Frame.NORMAL)
|
||||
|
||||
@get:Attribute var fullScreen: Boolean by property(false)
|
||||
@get:Attribute var fullScreen by property(false)
|
||||
}
|
||||
|
||||
fun WindowManagerImpl.getFrameInfoInDeviceSpace(project: Project): FrameInfo? {
|
||||
|
||||
+29
-1
@@ -4,9 +4,10 @@ package com.intellij.configurationStore.properties
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
internal abstract class ObjectStateStoredPropertyBase<T>(protected var value: T) : StoredPropertyBase<T>() {
|
||||
abstract class ObjectStateStoredPropertyBase<T>(protected var value: T) : StoredPropertyBase<T>() {
|
||||
override val jsonType: JsonSchemaType
|
||||
get() = JsonSchemaType.OBJECT
|
||||
|
||||
@@ -55,6 +56,33 @@ internal open class ObjectStoredProperty<T>(private val defaultValue: T) : Objec
|
||||
}
|
||||
}
|
||||
|
||||
class EnumStoredProperty<T : Enum<*>>(private val defaultValue: T?, val clazz: Class<T>) : ObjectStateStoredPropertyBase<T?>(defaultValue), ScalarProperty {
|
||||
override val jsonType: JsonSchemaType
|
||||
get() = JsonSchemaType.STRING
|
||||
|
||||
override fun isEqualToDefault() = value === defaultValue
|
||||
|
||||
override fun getModificationCount() = 0L
|
||||
|
||||
override fun setValue(thisRef: BaseState, property: KProperty<*>, @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") newValue: T?) {
|
||||
val v = newValue ?: defaultValue
|
||||
if (value !== v) {
|
||||
thisRef.intIncrementModificationCount()
|
||||
value = v
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun parseAndSetValue(rawValue: String?) {
|
||||
if (rawValue == null) {
|
||||
value = defaultValue
|
||||
}
|
||||
else {
|
||||
value = XmlSerializerUtil.stringToEnum(rawValue, clazz, true /* lowercase in YAML by default */) as T? ?: defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class StateObjectStoredProperty<T : BaseState?>(initialValue: T) : ObjectStateStoredPropertyBase<T>(initialValue) {
|
||||
override fun isEqualToDefault(): Boolean {
|
||||
val value = value
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
properties.add(p as StoredProperty<Any>)
|
||||
}
|
||||
|
||||
fun <T> property(): StoredPropertyBase<T?> {
|
||||
protected fun <T> property(): StoredPropertyBase<T?> {
|
||||
val result = ObjectStoredProperty<T?>(null)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -42,7 +42,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
* Value considered as default only if all properties have default values.
|
||||
* Passed instance is not used for `isDefault` check. It is just an initial value.
|
||||
*/
|
||||
fun <T : BaseState?> property(initialValue: T): StoredPropertyBase<T> {
|
||||
protected fun <T : BaseState?> property(initialValue: T): StoredPropertyBase<T> {
|
||||
val result = StateObjectStoredProperty(initialValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -51,7 +51,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
/**
|
||||
* For non-BaseState classes explicit `isDefault` must be provided, because no other way to check.
|
||||
*/
|
||||
fun <T> property(initialValue: T, isDefault: (value: T) -> Boolean): StoredPropertyBase<T> {
|
||||
protected fun <T> property(initialValue: T, isDefault: (value: T) -> Boolean): StoredPropertyBase<T> {
|
||||
val result = object : ObjectStoredProperty<T>(initialValue) {
|
||||
override fun isEqualToDefault() = isDefault(value)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
* Collection considered as default if empty. It is *your* responsibility to call `incrementModificationCount` on collection modification.
|
||||
* You cannot set value to a new collection - on set current collection is cleared and new collection is added to current.
|
||||
*/
|
||||
fun <E, C : MutableCollection<E>> property(initialValue: C): StoredPropertyBase<C> {
|
||||
protected fun <E, C : MutableCollection<E>> property(initialValue: C): StoredPropertyBase<C> {
|
||||
val result = CollectionStoredProperty(initialValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -73,7 +73,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
/**
|
||||
* Charset is an immutable, so, it is safe to use it as default value.
|
||||
*/
|
||||
fun <T : Charset> property(initialValue: T): StoredPropertyBase<T> {
|
||||
protected fun <T : Charset> property(initialValue: T): StoredPropertyBase<T> {
|
||||
val result = ObjectStoredProperty(initialValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -82,27 +82,41 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
/**
|
||||
* Enum is an immutable, so, it is safe to use it as default value.
|
||||
*/
|
||||
fun <T : Enum<*>> property(defaultValue: T): StoredPropertyBase<T> {
|
||||
protected fun <T : Enum<*>> property(defaultValue: T): StoredPropertyBase<T> {
|
||||
val result = ObjectStoredProperty(defaultValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* `null` is always normalized to null.
|
||||
*/
|
||||
protected inline fun <reified T : Enum<*>> enum(defaultValue: T? = null): StoredPropertyBase<T?> {
|
||||
return doEnum(defaultValue, T::class.java)
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
internal fun <T : Enum<*>> doEnum(defaultValue: T? = null, clazz: Class<T>): StoredPropertyBase<T?> {
|
||||
val result = EnumStoredProperty(defaultValue, clazz)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Not-null list. Initialized as SmartList.
|
||||
*/
|
||||
fun <T : Any> list(): StoredPropertyBase<MutableList<T>> {
|
||||
protected fun <T : Any> list(): StoredPropertyBase<MutableList<T>> {
|
||||
val result = ListStoredProperty<T>()
|
||||
addProperty(result)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return result as StoredPropertyBase<MutableList<T>>
|
||||
}
|
||||
|
||||
fun <K : Any, V: Any> property(value: MutableMap<K, V>): StoredPropertyBase<MutableMap<K, V>> {
|
||||
protected fun <K : Any, V: Any> property(value: MutableMap<K, V>): StoredPropertyBase<MutableMap<K, V>> {
|
||||
return map(value)
|
||||
}
|
||||
|
||||
fun <K : Any, V: Any> map(value: MutableMap<K, V> = THashMap()): StoredPropertyBase<MutableMap<K, V>> {
|
||||
protected fun <K : Any, V: Any> map(value: MutableMap<K, V> = THashMap()): StoredPropertyBase<MutableMap<K, V>> {
|
||||
val result = MapStoredProperty(value)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -111,36 +125,36 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
/**
|
||||
* Empty string is always normalized to null.
|
||||
*/
|
||||
fun property(defaultValue: String?): StoredPropertyBase<String?> = string(defaultValue)
|
||||
protected fun property(defaultValue: String?): StoredPropertyBase<String?> = string(defaultValue)
|
||||
|
||||
/**
|
||||
* Empty string is always normalized to null.
|
||||
*/
|
||||
fun string(defaultValue: String? = null): StoredPropertyBase<String?> {
|
||||
protected fun string(defaultValue: String? = null): StoredPropertyBase<String?> {
|
||||
val result = NormalizedStringStoredProperty(defaultValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
fun property(defaultValue: Int = 0): StoredPropertyBase<Int> {
|
||||
protected fun property(defaultValue: Int = 0): StoredPropertyBase<Int> {
|
||||
val result = IntStoredProperty(defaultValue, null)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
fun property(defaultValue: Long = 0): StoredPropertyBase<Long> {
|
||||
protected fun property(defaultValue: Long = 0): StoredPropertyBase<Long> {
|
||||
val result = LongStoredProperty(defaultValue, null)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
fun property(defaultValue: Float = 0f, valueNormalizer: ((value: Float) -> Float)? = null): StoredPropertyBase<Float> {
|
||||
protected fun property(defaultValue: Float = 0f, valueNormalizer: ((value: Float) -> Float)? = null): StoredPropertyBase<Float> {
|
||||
val result = FloatStoredProperty(defaultValue, valueNormalizer)
|
||||
addProperty(result)
|
||||
return result
|
||||
}
|
||||
|
||||
fun property(defaultValue: Boolean = false): StoredPropertyBase<Boolean> {
|
||||
protected fun property(defaultValue: Boolean = false): StoredPropertyBase<Boolean> {
|
||||
val result = ObjectStoredProperty(defaultValue)
|
||||
addProperty(result)
|
||||
return result
|
||||
@@ -217,26 +231,8 @@ abstract class BaseState : SerializationFilter, ModificationTracker {
|
||||
}
|
||||
}
|
||||
|
||||
fun getProperties() = properties
|
||||
}
|
||||
|
||||
// move buildJsonSchema and other such functions from BaseState to exclude from completion
|
||||
// internal usage only
|
||||
@ApiStatus.Experimental
|
||||
fun buildJsonSchema(state: BaseState, builder: StringBuilder) {
|
||||
val properties = state.getProperties()
|
||||
// todo object definition
|
||||
for (property in properties) {
|
||||
builder.jsonEscapedString(property.name!!).append(':').append('{')
|
||||
builder.jsonEscapedString("type").append(':').jsonEscapedString(property.jsonType.jsonName)
|
||||
builder.append('}')
|
||||
if (property !== properties.last()) {
|
||||
builder.append(',')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.jsonEscapedString(value: String): StringBuilder {
|
||||
append('"').append(value).append('"')
|
||||
return this
|
||||
// internal usage only
|
||||
@Suppress("FunctionName")
|
||||
@ApiStatus.Experimental
|
||||
fun __getProperties() = properties
|
||||
}
|
||||
@@ -255,20 +255,8 @@ public final class XmlSerializerImpl {
|
||||
accessor.setShort(host, Short.parseShort(value));
|
||||
}
|
||||
else if (valueClass.isEnum()) {
|
||||
Object deserializedValue = null;
|
||||
for (Object enumConstant : valueClass.getEnumConstants()) {
|
||||
if (enumConstant.toString().equals(value)) {
|
||||
deserializedValue = enumConstant;
|
||||
}
|
||||
}
|
||||
if (deserializedValue == null) {
|
||||
for (Object enumConstant : valueClass.getEnumConstants()) {
|
||||
if (enumConstant.toString().equalsIgnoreCase(value)) {
|
||||
deserializedValue = enumConstant;
|
||||
}
|
||||
}
|
||||
}
|
||||
accessor.set(host, deserializedValue);
|
||||
//noinspection unchecked
|
||||
accessor.set(host, XmlSerializerUtil.stringToEnum(value, (Class<? extends Enum<?>>)valueClass, false));
|
||||
}
|
||||
else if (Date.class.isAssignableFrom(valueClass)) {
|
||||
try {
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,4 +35,22 @@ public class XmlSerializerUtil {
|
||||
public static List<MutableAccessor> getAccessors(@NotNull Class<?> aClass) {
|
||||
return BeanBinding.getAccessors(aClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object stringToEnum(@NotNull String value, @NotNull Class<? extends Enum<?>> valueClass, boolean isAlwaysIgnoreCase) {
|
||||
Enum<?>[] enumConstants = valueClass.getEnumConstants();
|
||||
if (!isAlwaysIgnoreCase) {
|
||||
for (Object enumConstant : enumConstants) {
|
||||
if (enumConstant.toString().equals(value)) {
|
||||
return enumConstant;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Object enumConstant : enumConstants) {
|
||||
if (enumConstant.toString().equalsIgnoreCase(value)) {
|
||||
return enumConstant;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +76,24 @@ internal class JsonObjectBuilder(private val builder: StringBuilder) {
|
||||
}
|
||||
|
||||
fun rawMap(key: CharSequence, build: (StringBuilder) -> Unit) {
|
||||
mapOrArray('{', '}', key, build)
|
||||
}
|
||||
|
||||
fun rawArray(key: CharSequence, build: (StringBuilder) -> Unit) {
|
||||
mapOrArray('[', ']', key, build)
|
||||
}
|
||||
|
||||
private fun mapOrArray(openChar: Char, closeChar: Char, key: CharSequence, build: (StringBuilder) -> Unit) {
|
||||
builder
|
||||
.appendCommaIfNeed()
|
||||
.jsonEscapedString(key)
|
||||
.append(':')
|
||||
.append('{')
|
||||
.append(openChar)
|
||||
.append('\n')
|
||||
build(builder)
|
||||
builder
|
||||
.append('\n')
|
||||
.append('}')
|
||||
.append(closeChar)
|
||||
}
|
||||
|
||||
fun rawBuilder(key: CharSequence, child: JsonObjectBuilder) {
|
||||
|
||||
+29
-2
@@ -1,8 +1,9 @@
|
||||
package com.intellij.configurationScript
|
||||
|
||||
import com.intellij.configurationStore.properties.EnumStoredProperty
|
||||
import com.intellij.execution.configurations.ConfigurationFactory
|
||||
import com.intellij.execution.configurations.ConfigurationType
|
||||
import com.intellij.openapi.components.buildJsonSchema
|
||||
import com.intellij.openapi.components.BaseState
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.ReflectionUtil
|
||||
@@ -175,12 +176,38 @@ internal class RunConfigurationJsonSchemaGenerator {
|
||||
if (description != null) {
|
||||
"description" toUnescaped description
|
||||
}
|
||||
rawMap("properties") { buildJsonSchema(state, it) }
|
||||
map("properties") { buildJsonSchema(state, this) }
|
||||
}
|
||||
"additionalProperties" to false
|
||||
}
|
||||
}
|
||||
|
||||
// move buildJsonSchema and other such functions from BaseState to exclude from completion
|
||||
private fun buildJsonSchema(state: BaseState, builder: JsonObjectBuilder) {
|
||||
val properties = state.__getProperties()
|
||||
// todo object definition
|
||||
for (property in properties) {
|
||||
builder.map(property.name!!) {
|
||||
"type" to property.jsonType.jsonName
|
||||
if (property is EnumStoredProperty<*>) {
|
||||
describeEnum(property)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun JsonObjectBuilder.describeEnum(property: EnumStoredProperty<*>) {
|
||||
rawArray("enum") { stringBuilder ->
|
||||
val enumConstants = property.clazz.enumConstants
|
||||
for (enum in enumConstants) {
|
||||
stringBuilder.append('"').append(enum.toString().toLowerCase()).append('"')
|
||||
if (enum !== enumConstants.last()) {
|
||||
stringBuilder.append(',')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns null if id is not valid
|
||||
internal fun rcTypeIdToPropertyName(configurationType: ConfigurationType): CharSequence? {
|
||||
val result = idToPropertyName(configurationType.tag, configurationType, null) ?: return null
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ internal class RunConfigurationListReader(private val processor: (factory: Confi
|
||||
|
||||
private fun readRc(optionsClass: Class<out BaseState>, node: MappingNode, factory: ConfigurationFactory) {
|
||||
val state = ReflectionUtil.newInstance(optionsClass)
|
||||
val properties = state.getProperties()
|
||||
val properties = state.__getProperties()
|
||||
for (tuple in node.value) {
|
||||
val valueNode = tuple.valueNode
|
||||
val key = (tuple.keyNode as ScalarNode).value
|
||||
|
||||
@@ -119,7 +119,7 @@ class ConfigurationFileTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun parse(@Language("YAML") data: String, isTemplatesOnly: Boolean = false): List<Any> {
|
||||
internal fun parse(@Language("YAML") data: String, isTemplatesOnly: Boolean = false): List<Any> {
|
||||
val list = SmartList<Any>()
|
||||
parseConfigurationFile(data.trimIndent().reader(), isTemplatesOnly) { _, state ->
|
||||
list.add(state)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.intellij.configurationScript
|
||||
|
||||
import com.intellij.execution.ShortenCommandLine
|
||||
import com.intellij.execution.application.JvmMainMethodRunConfigurationOptions
|
||||
import com.intellij.testFramework.ProjectRule
|
||||
import com.intellij.testFramework.assertions.Assertions.assertThat
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Test
|
||||
|
||||
class PropertyValueReaderTest {
|
||||
companion object {
|
||||
@JvmField
|
||||
@ClassRule
|
||||
val projectRule = ProjectRule()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `enum`() {
|
||||
val result = parse("""
|
||||
runConfigurations:
|
||||
jvmMainMethod:
|
||||
shortenClasspath: MANIFEST
|
||||
""")
|
||||
val options = JvmMainMethodRunConfigurationOptions()
|
||||
options.shortenClasspath = ShortenCommandLine.MANIFEST
|
||||
assertThat(result).containsExactly(options)
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -72,8 +72,8 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchElements(String pattern, boolean everywhere, SearchEverywhereContributorFilter<Language> filter,
|
||||
ProgressIndicator progressIndicator, Function<Object, Boolean> consumer) {
|
||||
public void fetchElements(@NotNull String pattern, boolean everywhere, @Nullable SearchEverywhereContributorFilter<Language> filter,
|
||||
@NotNull ProgressIndicator progressIndicator, @NotNull Function<Object, Boolean> consumer) {
|
||||
if (myProject == null || DumbService.getInstance(myProject).isDumb() || pattern.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -82,20 +82,21 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processSelectedItem(Object selected, int modifiers, String searchText) {
|
||||
public boolean processSelectedItem(@NotNull Object selected, int modifiers, @NotNull String searchText) {
|
||||
if (selected instanceof Navigatable) {
|
||||
((Navigatable)selected).navigate(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ListCellRenderer getElementsRenderer(JList<?> list) {
|
||||
public ListCellRenderer getElementsRenderer(@NotNull JList<?> list) {
|
||||
return new NavigationItemListCellRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDataForItem(Object element, String dataId) {
|
||||
public Object getDataForItem(@NotNull Object element, @NotNull String dataId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user