use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class StatisticsManagerImpl method enableStatistics.
@TestOnly
public void enableStatistics(@NotNull Disposable parentDisposable) {
myTestingStatistics = true;
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
synchronized (LOCK) {
Collections.fill(myUnits, null);
}
myTestingStatistics = false;
}
});
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CodeInsightTestUtil method doIntentionTest.
@TestOnly
public static void doIntentionTest(@NotNull final CodeInsightTestFixture fixture, @NonNls final String action, @NotNull final String before, @NotNull final String after) {
fixture.configureByFile(before);
List<IntentionAction> availableIntentions = fixture.getAvailableIntentions();
final IntentionAction intentionAction = findIntentionByText(availableIntentions, action);
if (intentionAction == null) {
Assert.fail("Action not found: " + action + " in place: " + fixture.getElementAtCaret() + " among " + availableIntentions);
}
fixture.launchAction(intentionAction);
fixture.checkResultByFile(after, false);
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CodeInsightTestUtil method doInlineRename.
@TestOnly
public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, @NotNull Editor editor, PsiElement elementAtCaret) {
Project project = editor.getProject();
TemplateManagerImpl templateManager = (TemplateManagerImpl) TemplateManager.getInstance(project);
try {
templateManager.setTemplateTesting(true);
handler.doRename(elementAtCaret, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
TemplateState state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
final TextRange range = state.getCurrentVariableRange();
assert range != null;
final Editor finalEditor = editor;
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
}
}.execute().throwException();
state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
state.gotoEnd(false);
} finally {
templateManager.setTemplateTesting(false);
}
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CodeInsightTestUtil method gotoImplementation.
@NotNull
@TestOnly
public static GotoTargetHandler.GotoData gotoImplementation(Editor editor, PsiFile file) {
GotoTargetHandler.GotoData data = new GotoImplementationHandler().getSourceAndTargetElements(editor, file);
if (data.listUpdaterTask != null) {
JBList list = new JBList();
CollectionListModel model = new CollectionListModel(new ArrayList());
list.setModel(model);
list.setModel(new NameFilteringListModel(list, Function.ID, Condition.FALSE, String::new));
JBPopup popup = new ComponentPopupBuilderImpl(list, null).createPopup();
data.listUpdaterTask.init((AbstractPopup) popup, list, new Ref<>());
data.listUpdaterTask.queue();
try {
while (!data.listUpdaterTask.isFinished()) {
UIUtil.dispatchAllInvocationEvents();
}
} finally {
Disposer.dispose(popup);
}
}
return data;
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class ThreadTracker method checkLeak.
@TestOnly
public void checkLeak() throws AssertionError {
NettyUtil.awaitQuiescenceOfGlobalEventExecutor(100, TimeUnit.SECONDS);
ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
try {
if (myDefaultProjectInitialized != ((ProjectManagerImpl) ProjectManager.getInstance()).isDefaultProjectInitialized())
return;
Collection<Thread> after = new THashSet<>(getThreads());
after.removeAll(before);
for (final Thread thread : after) {
if (thread == Thread.currentThread())
continue;
ThreadGroup group = thread.getThreadGroup();
if (group != null && "system".equals(group.getName()))
continue;
if (isWellKnownOffender(thread))
continue;
if (!thread.isAlive())
continue;
if (thread.getStackTrace().length == 0) {
thread.interrupt();
if (new WaitFor(10000) {
@Override
protected boolean condition() {
return !thread.isAlive();
}
}.isConditionRealized()) {
continue;
}
}
StackTraceElement[] stackTrace = thread.getStackTrace();
if (stackTrace.length == 0) {
// ignore threads with empty stack traces for now. Seems they are zombies unwilling to die.
continue;
}
if (isIdleApplicationPoolThread(thread, stackTrace)) {
continue;
}
@SuppressWarnings("NonConstantStringShouldBeStringBuffer") String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
for (final StackTraceElement stackTraceElement : stackTrace) {
trace += " at " + stackTraceElement + "\n";
}
trace += "---\n";
Assert.fail(trace);
}
} finally {
before.clear();
}
}
Aggregations