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
}
}
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();
}
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());
}
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());
}
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);
}
}
Aggregations