mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (warnings; typos; formatting)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// 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.ide.actions;
|
||||
|
||||
import com.intellij.featureStatistics.FeatureUsageTracker;
|
||||
@@ -51,9 +50,9 @@ import static com.intellij.openapi.keymap.KeymapUtil.getActiveKeymapShortcuts;
|
||||
|
||||
public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
@Override
|
||||
public void gotoActionPerformed(@NotNull final AnActionEvent e) {
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
final Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
|
||||
public void gotoActionPerformed(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
|
||||
Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.action");
|
||||
@@ -76,20 +75,20 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
|
||||
@NotNull
|
||||
private static ChooseByNamePopup createPopup(@Nullable Project project,
|
||||
@NotNull final GotoActionModel model,
|
||||
@NotNull GotoActionModel model,
|
||||
String initialText,
|
||||
int initialIndex,
|
||||
final Component component,
|
||||
final AnActionEvent event) {
|
||||
Component component,
|
||||
AnActionEvent event) {
|
||||
ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
|
||||
if (oldPopup != null) {
|
||||
oldPopup.close(false);
|
||||
}
|
||||
final Disposable disposable = Disposer.newDisposable();
|
||||
Disposable disposable = Disposer.newDisposable();
|
||||
ShortcutSet altEnterShortcutSet = getActiveKeymapShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
|
||||
KeymapManager km = KeymapManager.getInstance();
|
||||
Keymap activeKeymap = km != null ? km.getActiveKeymap() : null;
|
||||
final ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {
|
||||
ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {
|
||||
private boolean myPaintInternalInfo;
|
||||
|
||||
@Override
|
||||
@@ -220,14 +219,14 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
if (project != null) {
|
||||
project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, popup);
|
||||
}
|
||||
|
||||
popup.addMouseClickListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(@NotNull MouseEvent me) {
|
||||
Object element = popup.getSelectionByPoint(me.getPoint());
|
||||
if (element instanceof GotoActionModel.MatchedValue) {
|
||||
if (processOptionInplace(((GotoActionModel.MatchedValue)element).value, popup, component, event)) {
|
||||
me.consume();
|
||||
}
|
||||
if (element instanceof GotoActionModel.MatchedValue &&
|
||||
processOptionInplace(((GotoActionModel.MatchedValue)element).value, popup, component, event)) {
|
||||
me.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -245,6 +244,7 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
}
|
||||
}
|
||||
}).registerCustomShortcutSet(altEnterShortcutSet, popup.getTextField(), disposable);
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
@@ -271,38 +271,34 @@ public class GotoActionAction extends GotoActionBase implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
public static void openOptionOrPerformAction(@NotNull Object element,
|
||||
final String enteredText,
|
||||
@Nullable final Project project,
|
||||
Component component) {
|
||||
public static void openOptionOrPerformAction(@NotNull Object element, String enteredText, @Nullable Project project, Component component) {
|
||||
if (element instanceof OptionDescription) {
|
||||
OptionDescription optionDescription = (OptionDescription)element;
|
||||
final String configurableId = optionDescription.getConfigurableId();
|
||||
String configurableId = optionDescription.getConfigurableId();
|
||||
Disposable disposable = project != null ? project : ApplicationManager.getApplication();
|
||||
TransactionGuard guard = TransactionGuard.getInstance();
|
||||
if (optionDescription.hasExternalEditor()) {
|
||||
guard.submitTransactionLater(disposable, () -> optionDescription.invokeInternalEditor());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
guard.submitTransactionLater(disposable, () -> ShowSettingsUtilImpl.showSettingsDialog(project, configurableId, enteredText));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().invokeLater(() -> IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(
|
||||
() -> performAction(element, component, null)));
|
||||
ApplicationManager.getApplication().invokeLater(
|
||||
() -> IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(
|
||||
() -> performAction(element, component, null)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void performAction(Object element, @Nullable final Component component, @Nullable final AnActionEvent e) {
|
||||
public static void performAction(@NotNull Object element, @Nullable Component component, @Nullable AnActionEvent e) {
|
||||
performAction(element, component, e, null);
|
||||
}
|
||||
|
||||
public static void performAction(Object element,
|
||||
@Nullable final Component component,
|
||||
@Nullable final AnActionEvent e,
|
||||
@Nullable final Runnable callback) {
|
||||
private static void performAction(Object element, @Nullable Component component, @Nullable AnActionEvent e, @Nullable Runnable callback) {
|
||||
// element could be AnAction (SearchEverywhere)
|
||||
if (component == null) return;
|
||||
final AnAction action = element instanceof AnAction ? (AnAction)element : ((GotoActionModel.ActionWrapper)element).getAction();
|
||||
AnAction action = element instanceof AnAction ? (AnAction)element : ((GotoActionModel.ActionWrapper)element).getAction();
|
||||
TransactionGuard.getInstance().submitTransactionLater(ApplicationManager.getApplication(), () -> {
|
||||
DataManager instance = DataManager.getInstance();
|
||||
DataContext context = instance != null ? instance.getDataContext(component) : DataContext.EMPTY_CONTEXT;
|
||||
|
||||
@@ -732,7 +732,7 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myMessagePool.clearFatals();
|
||||
myMessagePool.clearErrors();
|
||||
doOKAction();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,13 @@
|
||||
/*
|
||||
* 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.diagnostic;
|
||||
|
||||
import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
|
||||
import com.intellij.util.concurrency.AppExecutorUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.apache.log4j.Category;
|
||||
import org.apache.log4j.Priority;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -31,102 +16,81 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MessagePool {
|
||||
private static final int MAX_POOL_SIZE_FOR_FATALS = 100;
|
||||
|
||||
private final List<AbstractMessage> myIdeFatals = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
private final List<MessagePoolListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
private final MessageGrouper myFatalsGrouper;
|
||||
|
||||
MessagePool(int maxGroupSize, int timeout) {
|
||||
myFatalsGrouper = new MessageGrouper(timeout, maxGroupSize);
|
||||
}
|
||||
private static final int MAX_POOL_SIZE = 100;
|
||||
private static final int MAX_GROUP_SIZE = 20;
|
||||
private static final int GROUP_TIME_SPAN_MS = 1000;
|
||||
|
||||
private static class MessagePoolHolder {
|
||||
private static final MessagePool ourInstance = new MessagePool(20, 1000);
|
||||
private static final MessagePool ourInstance = new MessagePool();
|
||||
}
|
||||
|
||||
public static MessagePool getInstance() {
|
||||
return MessagePoolHolder.ourInstance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LogMessage addIdeFatalMessage(final IdeaLoggingEvent aEvent) {
|
||||
Object data = aEvent.getData();
|
||||
final LogMessage message = data instanceof LogMessage ? (LogMessage)data : new LogMessage(aEvent);
|
||||
if (myIdeFatals.size() < MAX_POOL_SIZE_FOR_FATALS) {
|
||||
if (myFatalsGrouper.addToGroup(message)) {
|
||||
return message;
|
||||
}
|
||||
} else if (myIdeFatals.size() == MAX_POOL_SIZE_FOR_FATALS) {
|
||||
private final List<AbstractMessage> myErrors = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final List<MessagePoolListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final MessageGrouper myGrouper = new MessageGrouper();
|
||||
|
||||
private MessagePool() { }
|
||||
|
||||
public void addIdeFatalMessage(@NotNull IdeaLoggingEvent event) {
|
||||
Object data = event.getData();
|
||||
LogMessage message = data instanceof LogMessage ? (LogMessage)data : new LogMessage(event);
|
||||
if (myErrors.size() < MAX_POOL_SIZE) {
|
||||
myGrouper.addToGroup(message);
|
||||
}
|
||||
else if (myErrors.size() == MAX_POOL_SIZE) {
|
||||
String msg = DiagnosticBundle.message("error.monitor.too.many.errors");
|
||||
LogMessage tooMany = new LogMessage(new LoggingEvent(msg, Category.getRoot(), Priority.ERROR, null, new TooManyErrorsException()));
|
||||
myFatalsGrouper.addToGroup(tooMany);
|
||||
return tooMany;
|
||||
myGrouper.addToGroup(new LogMessage(new LoggingEvent(msg, LogManager.getRootLogger(), Level.ERROR, null, new TooManyErrorsException())));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<AbstractMessage> getFatalErrors(boolean aIncludeReadMessages, boolean aIncludeSubmittedMessages) {
|
||||
public List<AbstractMessage> getFatalErrors(boolean includeReadMessages, boolean includeSubmittedMessages) {
|
||||
List<AbstractMessage> result = new ArrayList<>();
|
||||
for (AbstractMessage each : myIdeFatals) {
|
||||
if (!each.isRead() && !each.isSubmitted()) {
|
||||
result.add(each);
|
||||
}
|
||||
else if ((each.isRead() && aIncludeReadMessages) || (each.isSubmitted() && aIncludeSubmittedMessages)) {
|
||||
result.add(each);
|
||||
for (AbstractMessage message : myErrors) {
|
||||
if ((!message.isRead() && !message.isSubmitted()) ||
|
||||
(message.isRead() && includeReadMessages) ||
|
||||
(message.isSubmitted() && includeSubmittedMessages)) {
|
||||
result.add(message);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void clearFatals() {
|
||||
for (AbstractMessage fatal : myIdeFatals) {
|
||||
fatal.setRead(true); // expire notifications
|
||||
public void clearErrors() {
|
||||
for (AbstractMessage message : myErrors) {
|
||||
message.setRead(true); // expire notifications
|
||||
}
|
||||
|
||||
myIdeFatals.clear();
|
||||
notifyListenersClear();
|
||||
myErrors.clear();
|
||||
notifyPoolCleared();
|
||||
}
|
||||
|
||||
public void addListener(MessagePoolListener aListener) {
|
||||
myListeners.add(aListener);
|
||||
public void addListener(MessagePoolListener listener) {
|
||||
myListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(MessagePoolListener aListener) {
|
||||
myListeners.remove(aListener);
|
||||
public void removeListener(MessagePoolListener listener) {
|
||||
myListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyListenersAdd() {
|
||||
for (MessagePoolListener messagePoolListener : myListeners) {
|
||||
messagePoolListener.newEntryAdded();
|
||||
}
|
||||
private void notifyEntryAdded() {
|
||||
myListeners.forEach(MessagePoolListener::newEntryAdded);
|
||||
}
|
||||
|
||||
private void notifyListenersClear() {
|
||||
for (MessagePoolListener messagePoolListener : myListeners) {
|
||||
messagePoolListener.poolCleared();
|
||||
}
|
||||
private void notifyPoolCleared() {
|
||||
myListeners.forEach(MessagePoolListener::poolCleared);
|
||||
}
|
||||
|
||||
void notifyListenersRead() {
|
||||
for (MessagePoolListener messagePoolListener : myListeners) {
|
||||
messagePoolListener.entryWasRead();
|
||||
}
|
||||
private void notifyEntryRead() {
|
||||
myListeners.forEach(MessagePoolListener::entryWasRead);
|
||||
}
|
||||
|
||||
private class MessageGrouper implements Runnable {
|
||||
private final int myTimeOut;
|
||||
private final int myMaxGroupSize;
|
||||
private final List<AbstractMessage> myMessages = new ArrayList<>();
|
||||
private Future<?> myAlarm = CompletableFuture.completedFuture(null);
|
||||
|
||||
public MessageGrouper(int timeout, int maxGroupSize) {
|
||||
myTimeOut = timeout;
|
||||
myMaxGroupSize = maxGroupSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (myMessages) {
|
||||
if (myMessages.size() > 0) {
|
||||
@@ -136,36 +100,30 @@ public class MessagePool {
|
||||
}
|
||||
|
||||
private void post() {
|
||||
AbstractMessage message;
|
||||
if (myMessages.size() == 1) {
|
||||
message = myMessages.get(0);
|
||||
} else {
|
||||
message = new GroupedLogMessage(new ArrayList<>(myMessages));
|
||||
}
|
||||
message.setOnReadCallback(() -> notifyListenersRead());
|
||||
AbstractMessage message = myMessages.size() == 1 ? myMessages.get(0) : new GroupedLogMessage(new ArrayList<>(myMessages));
|
||||
message.setOnReadCallback(() -> notifyEntryRead());
|
||||
myMessages.clear();
|
||||
myIdeFatals.add(message);
|
||||
notifyListenersAdd();
|
||||
myErrors.add(message);
|
||||
notifyEntryAdded();
|
||||
}
|
||||
|
||||
public boolean addToGroup(@NotNull AbstractMessage message) {
|
||||
boolean result = myMessages.isEmpty();
|
||||
synchronized(myMessages) {
|
||||
private void addToGroup(@NotNull AbstractMessage message) {
|
||||
synchronized (myMessages) {
|
||||
myMessages.add(message);
|
||||
if (myMessages.size() >= myMaxGroupSize) {
|
||||
if (myMessages.size() >= MAX_GROUP_SIZE) {
|
||||
post();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
myAlarm.cancel(false);
|
||||
myAlarm = AppExecutorUtil.getAppScheduledExecutorService().schedule(this, myTimeOut, TimeUnit.MILLISECONDS);
|
||||
myAlarm = AppExecutorUtil.getAppScheduledExecutorService().schedule(this, GROUP_TIME_SPAN_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TooManyErrorsException extends Exception {
|
||||
TooManyErrorsException() {
|
||||
private TooManyErrorsException() {
|
||||
super(DiagnosticBundle.message("error.monitor.too.many.errors"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +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.testGuiFramework.impl
|
||||
|
||||
import com.intellij.diagnostic.MessagePool
|
||||
@@ -226,19 +212,17 @@ class GuiTestRule : TestRule {
|
||||
}
|
||||
|
||||
inner class FatalErrorsFlusher : ExternalResource() {
|
||||
|
||||
override fun after() {
|
||||
try {
|
||||
val executorService = AppExecutorUtil.getAppExecutorService()
|
||||
//wait 10 second for the termination of all
|
||||
if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) executorService.shutdownNow()
|
||||
MessagePool.getInstance().clearFatals()
|
||||
MessagePool.getInstance().clearErrors()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
//TODO: log it
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun findWelcomeFrame(): WelcomeFrameFixture {
|
||||
|
||||
Reference in New Issue
Block a user