mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
EA-1469039 IJPL-101036 diff: better mocking in UnifiedImaginaryEditor
GitOrigin-RevId: 21a077ad656db3277ac84487560ed1050291d1fd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f17e10ca2b
commit
c796e05468
@@ -79,6 +79,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
@@ -1613,6 +1616,7 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase implements EditorD
|
||||
}
|
||||
|
||||
private class UnifiedImaginaryEditor extends ImaginaryEditor {
|
||||
private static final Set<String> ourReportedMockMethods = ContainerUtil.newConcurrentSet();
|
||||
private static boolean ourDisableImaginaryEditor = false;
|
||||
|
||||
private final Side mySide;
|
||||
@@ -1629,6 +1633,19 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase implements EditorD
|
||||
return new UnsupportedOperationException("Not implemented. UnifiedDiffViewer.UnifiedImaginaryEditor will be disabled.");
|
||||
}
|
||||
|
||||
protected void warnMockImplementation(@NotNull String methodName) {
|
||||
if (ourReportedMockMethods.add(methodName)) {
|
||||
String message = "Method is not applicable. Consider using 'editor instanceOf ImaginaryEditor'";
|
||||
if (ApplicationManager.getApplication().isInternal() ||
|
||||
ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
LOG.error(message);
|
||||
}
|
||||
else {
|
||||
LOG.warn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFile getVirtualFile() {
|
||||
return FileDocumentManager.getInstance().getFile(getDocument());
|
||||
@@ -1705,5 +1722,74 @@ public class UnifiedDiffViewer extends ListenerDiffViewerBase implements EditorD
|
||||
public @NotNull FoldingModel getFoldingModel() {
|
||||
return new EmptyFoldingModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasHeaderComponent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable JComponent getHeaderComponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComponent(@Nullable JComponent header) {
|
||||
warnMockImplementation("setHeaderComponent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLineHeight() {
|
||||
warnMockImplementation("getLineHeight");
|
||||
return myEditor.getLineHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LogicalPosition visualToLogicalPosition(@NotNull VisualPosition visiblePos) {
|
||||
warnMockImplementation("visualToLogicalPosition");
|
||||
return new LogicalPosition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LogicalPosition xyToLogicalPosition(@NotNull Point p) {
|
||||
warnMockImplementation("xyToLogicalPosition");
|
||||
return new LogicalPosition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull VisualPosition logicalToVisualPosition(@NotNull LogicalPosition logicalPos) {
|
||||
warnMockImplementation("logicalToVisualPosition");
|
||||
return new VisualPosition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull VisualPosition xyToVisualPosition(@NotNull Point p) {
|
||||
warnMockImplementation("xyToVisualPosition");
|
||||
return new VisualPosition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull VisualPosition xyToVisualPosition(@NotNull Point2D p) {
|
||||
warnMockImplementation("xyToVisualPosition");
|
||||
return new VisualPosition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Point logicalPositionToXY(@NotNull LogicalPosition pos) {
|
||||
warnMockImplementation("logicalPositionToXY");
|
||||
return new Point(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Point visualPositionToXY(@NotNull VisualPosition visible) {
|
||||
warnMockImplementation("visualPositionToXY");
|
||||
return new Point(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Point2D visualPositionToPoint2D(@NotNull VisualPosition pos) {
|
||||
warnMockImplementation("visualPositionToPoint2D");
|
||||
return new Point(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,10 @@ public class ImaginaryEditor extends UserDataHolderBase implements Editor {
|
||||
|
||||
@Override
|
||||
public int logicalPositionToOffset(@NotNull LogicalPosition pos) {
|
||||
throw notImplemented();
|
||||
int line = MathUtil.clamp(pos.line, 0, myDocument.getLineCount());
|
||||
int startOffset = myDocument.getLineStartOffset(line);
|
||||
int endOffset = myDocument.getLineEndOffset(line);
|
||||
return MathUtil.clamp(startOffset + pos.column, startOffset, endOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.MarkupModelEx;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.editor.impl.ImaginaryEditor;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -110,7 +111,7 @@ public final class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
|
||||
int caretOffset = myEditor.getCaretModel().getOffset();
|
||||
importUnambiguousImports();
|
||||
if (isImportHintEnabled()) {
|
||||
if (isImportHintEnabled() && !(myEditor instanceof ImaginaryEditor)) {
|
||||
List<HighlightInfo> visibleHighlights = getVisibleHighlights(myVisibleRange, myProject, myEditor, hasDirtyTextRange);
|
||||
// sort by distance to the caret
|
||||
visibleHighlights.sort(Comparator.comparingInt(info -> Math.abs(info.getActualStartOffset() - caretOffset)));
|
||||
|
||||
Reference in New Issue
Block a user