Search in sources :

Example 21 with TestOnly

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;
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 22 with TestOnly

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);
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TestOnly(org.jetbrains.annotations.TestOnly)

Example 23 with TestOnly

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) EditorWindow(com.intellij.injected.editor.EditorWindow) TestOnly(org.jetbrains.annotations.TestOnly)

Example 24 with TestOnly

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;
}
Also used : NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) GotoTargetHandler(com.intellij.codeInsight.navigation.GotoTargetHandler) GotoImplementationHandler(com.intellij.codeInsight.navigation.GotoImplementationHandler) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) CollectionListModel(com.intellij.ui.CollectionListModel) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ComponentPopupBuilderImpl(com.intellij.ui.popup.ComponentPopupBuilderImpl) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with TestOnly

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();
    }
}
Also used : WaitFor(com.intellij.util.WaitFor) THashSet(gnu.trove.THashSet) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

TestOnly (org.jetbrains.annotations.TestOnly)56 Disposable (com.intellij.openapi.Disposable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 Application (com.intellij.openapi.application.Application)4 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 THashSet (gnu.trove.THashSet)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 CollectionListModel (com.intellij.ui.CollectionListModel)2 THashMap (gnu.trove.THashMap)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 Pass (com.intellij.codeHighlighting.Pass)1 AutoPopupController (com.intellij.codeInsight.AutoPopupController)1 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1