Search in sources :

Example 41 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class NettyUtil method awaitQuiescenceOfGlobalEventExecutor.

@TestOnly
public static void awaitQuiescenceOfGlobalEventExecutor(long timeout, @NotNull TimeUnit unit) {
    try {
        @NotNull GlobalEventExecutor executor = GlobalEventExecutor.INSTANCE;
        executor.awaitInactivity(timeout, unit);
    } catch (InterruptedException ignored) {
    } catch (IllegalStateException ignored) {
    // thread did not start
    }
}
Also used : GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) NotNull(org.jetbrains.annotations.NotNull) TestOnly(org.jetbrains.annotations.TestOnly)

Example 42 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class EditorTestUtil method configureSoftWraps.

/**
   * Configures given editor to wrap at given width, assuming characters are of given width
   *
   * @return whether any actual wraps of editor contents were created as a result of turning on soft wraps
   */
@TestOnly
public static boolean configureSoftWraps(Editor editor, final int visibleWidth, final int charWidthInPixels) {
    editor.getSettings().setUseSoftWraps(true);
    SoftWrapModelImpl model = (SoftWrapModelImpl) editor.getSoftWrapModel();
    model.setSoftWrapPainter(new SoftWrapPainter() {

        @Override
        public int paint(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) {
            return charWidthInPixels;
        }

        @Override
        public int getDrawingHorizontalOffset(@NotNull Graphics g, @NotNull SoftWrapDrawingType drawingType, int x, int y, int lineHeight) {
            return charWidthInPixels;
        }

        @Override
        public int getMinDrawingWidth(@NotNull SoftWrapDrawingType drawingType) {
            return charWidthInPixels;
        }

        @Override
        public boolean canUse() {
            return true;
        }

        @Override
        public void reinit() {
        }
    });
    model.reinitSettings();
    SoftWrapApplianceManager applianceManager = model.getApplianceManager();
    applianceManager.setWidthProvider(new SoftWrapApplianceManager.VisibleAreaWidthProvider() {

        @Override
        public int getVisibleAreaWidth() {
            return visibleWidth;
        }
    });
    model.setEditorTextRepresentationHelper(new DefaultEditorTextRepresentationHelper(editor) {

        @Override
        public int charWidth(int c, int fontType) {
            return charWidthInPixels;
        }
    });
    setEditorVisibleSizeInPixels(editor, visibleWidth, 1000);
    applianceManager.registerSoftWrapIfNecessary();
    return !model.getRegisteredSoftWraps().isEmpty();
}
Also used : SoftWrapPainter(com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter) DefaultEditorTextRepresentationHelper(com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper) SoftWrapDrawingType(com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType) SoftWrapModelImpl(com.intellij.openapi.editor.impl.SoftWrapModelImpl) SoftWrapApplianceManager(com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager) TestOnly(org.jetbrains.annotations.TestOnly)

Example 43 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class InspectionTestUtil method runTool.

@TestOnly
public static void runTool(@NotNull InspectionToolWrapper toolWrapper, @NotNull final AnalysisScope scope, @NotNull final GlobalInspectionContextForTests globalContext) {
    final String shortName = toolWrapper.getShortName();
    final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
    if (key == null) {
        HighlightDisplayKey.register(shortName);
    }
    globalContext.doInspections(scope);
    do {
        UIUtil.dispatchAllInvocationEvents();
    } while (!globalContext.isFinished());
}
Also used : HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) TestOnly(org.jetbrains.annotations.TestOnly)

Example 44 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class DaemonCodeAnalyzerImpl method getFileLevelHighlights.

@Override
@NotNull
@TestOnly
public List<HighlightInfo> getFileLevelHighlights(@NotNull Project project, @NotNull PsiFile file) {
    VirtualFile vFile = file.getViewProvider().getVirtualFile();
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    return Arrays.stream(manager.getEditors(vFile)).map(fileEditor -> fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS)).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Storage(com.intellij.openapi.components.Storage) EdtExecutorService(com.intellij.util.concurrency.EdtExecutorService) PowerSaveMode(com.intellij.ide.PowerSaveMode) UIUtil(com.intellij.util.ui.UIUtil) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) NamedScopeManager(com.intellij.psi.search.scope.packageSet.NamedScopeManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) ModalityState(com.intellij.openapi.application.ModalityState) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) AutoPopupController(com.intellij.codeInsight.AutoPopupController) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) ApplicationInfoImpl(com.intellij.openapi.application.impl.ApplicationInfoImpl) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) State(com.intellij.openapi.components.State) Disposer(com.intellij.openapi.util.Disposer) BackgroundEditorHighlighter(com.intellij.codeHighlighting.BackgroundEditorHighlighter) Logger(com.intellij.openapi.diagnostic.Logger) TextEditor(com.intellij.openapi.fileEditor.TextEditor) RangeMarker(com.intellij.openapi.editor.RangeMarker) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) java.util.concurrent(java.util.concurrent) IntentionHintComponent(com.intellij.codeInsight.intention.impl.IntentionHintComponent) TextEditorImpl(com.intellij.openapi.fileEditor.impl.text.TextEditorImpl) TextRange(com.intellij.openapi.util.TextRange) com.intellij.codeInsight.daemon(com.intellij.codeInsight.daemon) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Collectors(java.util.stream.Collectors) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) PsiDocumentManagerBase(com.intellij.psi.impl.PsiDocumentManagerBase) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) FileLevelIntentionComponent(com.intellij.codeInsight.intention.impl.FileLevelIntentionComponent) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) java.util(java.util) NonNls(org.jetbrains.annotations.NonNls) ThreadDumper(com.intellij.diagnostic.ThreadDumper) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Project(com.intellij.openapi.project.Project) TextEditorProvider(com.intellij.openapi.fileEditor.impl.text.TextEditorProvider) Key(com.intellij.openapi.util.Key) AsyncEditorLoader(com.intellij.openapi.fileEditor.impl.text.AsyncEditorLoader) FileType(com.intellij.openapi.fileTypes.FileType) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) RefreshQueueImpl(com.intellij.openapi.vfs.newvfs.RefreshQueueImpl) TestOnly(org.jetbrains.annotations.TestOnly) StoragePathMacros(com.intellij.openapi.components.StoragePathMacros) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) HintManager(com.intellij.codeInsight.hint.HintManager) Element(org.jdom.Element) HeavyProcessLatch(com.intellij.util.io.storage.HeavyProcessLatch) DependencyValidationManager(com.intellij.packageDependencies.DependencyValidationManager) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class DaemonCodeAnalyzerImpl method waitInOtherThread.

@TestOnly
private boolean waitInOtherThread(int millis, boolean canChangeDocument) throws Throwable {
    Disposable disposable = Disposer.newDisposable();
    // last hope protection against PsiModificationTrackerImpl.incCounter() craziness (yes, Kotlin)
    myProject.getMessageBus().connect(disposable).subscribe(PsiModificationTracker.TOPIC, () -> {
        throw new IllegalStateException("You must not perform PSI modifications from inside highlighting");
    });
    if (!canChangeDocument) {
        myProject.getMessageBus().connect(disposable).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonListenerAdapter() {

            @Override
            public void daemonCancelEventOccurred(@NotNull String reason) {
                throw new IllegalStateException("You must not cancel daemon inside highlighting test: " + reason);
            }
        });
    }
    try {
        Future<Boolean> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
            try {
                return myPassExecutorService.waitFor(millis);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        });
        return future.get();
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) 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