diff --git a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF index 90baf9c1bee..64aa00f691e 100644 --- a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF @@ -31,6 +31,7 @@ Export-Package: org.eclipse.jface, org.eclipse.jface.viewers, org.eclipse.jface.viewers.deferred, org.eclipse.jface.viewers.internal;x-friends:="org.eclipse.ui.tests,org.eclipse.jface.tests", + org.eclipse.jface.viewers.m3, org.eclipse.jface.widgets, org.eclipse.jface.window, org.eclipse.jface.wizard, diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java index 0f7f8be7c5e..043068ed885 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java @@ -1414,6 +1414,7 @@ void preservingSelection(Runnable updateCode, boolean reveal) { @Override public void refresh() { + org.eclipse.jface.viewers.m3.M3Viewers.flush(this); Control control = getControl(); if (control != null) { control.setRedraw(false); @@ -1449,6 +1450,7 @@ public void refresh() { * @since 2.0 */ public void refresh(boolean updateLabels) { + org.eclipse.jface.viewers.m3.M3Viewers.flush(this); refresh(getRoot(), updateLabels); } @@ -1465,6 +1467,7 @@ public void refresh(boolean updateLabels) { * the element */ public void refresh(final Object element) { + org.eclipse.jface.viewers.m3.M3Viewers.flush(this); preservingSelection(() -> internalRefresh(element)); } @@ -1488,6 +1491,7 @@ public void refresh(final Object element) { * @since 2.0 */ public void refresh(final Object element, final boolean updateLabels) { + org.eclipse.jface.viewers.m3.M3Viewers.flush(this); preservingSelection(() -> internalRefresh(element, updateLabels)); } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java index 88a47bcd2a5..8e9c66c447f 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java @@ -74,21 +74,21 @@ public class TreeViewer extends AbstractTreeViewer { private static final MethodHandle SWT_TREE_EXPAND_TO_LEVEL = - swtTreeOperation("expandToLevel", int.class); + swtTreeOperation("expandToLevel", int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_EXPAND_ITEM_TO_LEVEL = - swtTreeOperation("expandToLevel", TreeItem.class, int.class); + swtTreeOperation("expandToLevel", TreeItem.class, int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_COLLAPSE_TO_LEVEL = - swtTreeOperation("collapseToLevel", int.class); + swtTreeOperation("collapseToLevel", int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_COLLAPSE_ITEM_TO_LEVEL = - swtTreeOperation("collapseToLevel", TreeItem.class, int.class); + swtTreeOperation("collapseToLevel", TreeItem.class, int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_EXPAND_SELECTION_TO_LEVEL = - swtTreeOperation("expandSelectionToLevel", int.class); + swtTreeOperation("expandSelectionToLevel", int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_COLLAPSE_SELECTION_TO_LEVEL = - swtTreeOperation("collapseSelectionToLevel", int.class); + swtTreeOperation("collapseSelectionToLevel", int.class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_GET_EXPANDED_ITEMS = - swtTreeQuery("getExpandedItems", TreeItem[].class); + swtTreeQuery("getExpandedItems", TreeItem[].class); //$NON-NLS-1$ private static final MethodHandle SWT_TREE_SET_EXPANDED_ITEMS = - swtTreeOperation("setExpandedItems", TreeItem[].class); + swtTreeOperation("setExpandedItems", TreeItem[].class); //$NON-NLS-1$ private static MethodHandle swtTreeOperation(String name, Class... parameterTypes) { try { @@ -119,7 +119,7 @@ private static boolean invokeSwtTreeOperation(MethodHandle operation, Object... } catch (RuntimeException | Error failure) { throw failure; } catch (Throwable failure) { - throw new IllegalStateException("Unable to invoke SWT Tree bulk operation", failure); + throw new IllegalStateException("Unable to invoke SWT Tree bulk operation", failure); //$NON-NLS-1$ } } @@ -132,7 +132,7 @@ private static Object invokeSwtTreeQuery(MethodHandle operation, Object... argum } catch (RuntimeException | Error failure) { throw failure; } catch (Throwable failure) { - throw new IllegalStateException("Unable to invoke SWT Tree state query", failure); + throw new IllegalStateException("Unable to invoke SWT Tree state query", failure); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewSpec.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewSpec.java new file mode 100644 index 00000000000..09d5037ed9a --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewSpec.java @@ -0,0 +1,350 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.viewers.m3; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +/** + * A view spec of the view template (brief rule 27, + * {@code docs/m3/view-template/VIEW_TEMPLATE.md}): one small declarative file + * next to the view, {@code .m3view}, that names the view's change + * source adapter, its lane schema, grouping, sort, filters, counts and + * presentation. The template turns a spec into the view's lane model, delta + * wiring and viewer setup, so that converting a view means writing a spec, not + * view code. + *

+ * Format: {@code key=value} lines; {@code #} starts a comment (a whole line, or + * after whitespace at the end of a line); blank lines are ignored. Keys: + *

+ * + * Any other key is an error, so a typo never passes silently. Instances are + * immutable. + * + * @since 3.43 (M3 enhanced API) + */ +public final class M3ViewSpec { + + /** The change-source adapter ids of the template (VIEW_TEMPLATE.md, "Adapters needed"). */ + public static final Set ADAPTERS = Set.of("markers", "resources", "java-elements", "pde-model", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + "search-results", "emf-notifications", "debug-events", "team-sync", "observables", "console-document"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + + /** Lane types. */ + public enum LaneType { + /** 64-bit integer (ids, times). */ + LONG, + /** 32-bit integer. */ + INT, + /** small integer (severity, kinds). */ + BYTE, + /** interned string: a label id. */ + LABEL, + /** image id. */ + IMAGE, + /** state bits. */ + BITS + } + + /** + * One lane of the schema. + * + * @param name the lane name + * @param type the lane type + */ + public record Lane(String name, LaneType type) { + } + + /** + * One sort key. + * + * @param lane the lane name + * @param descending whether the order is reversed + */ + public record SortKey(String lane, boolean descending) { + } + + private static final Set KEYS = Set.of("view.id", "element", "source", "lanes", "group", "sort", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + "filters", "counts", "presentation", "label"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + private static final Set PRESENTATIONS = Set.of("tree", "table", "flat"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static final Set BUILT_IN_FILTERS = Set.of("scope", "text"); //$NON-NLS-1$ //$NON-NLS-2$ + private static final String NONE = "none"; //$NON-NLS-1$ + + private final String viewId; + private final String element; + private final String source; + private final List lanes; + private final List groups; + private final List sort; + private final List filters; + private final List counts; + private final List presentations; + private final String label; + + private M3ViewSpec(Map v) { + viewId = v.get("view.id"); //$NON-NLS-1$ + element = v.get("element"); //$NON-NLS-1$ + source = v.get("source"); //$NON-NLS-1$ + lanes = lanes(v.get("lanes")); //$NON-NLS-1$ + groups = split(v.getOrDefault("group", NONE), "\\|"); //$NON-NLS-1$ //$NON-NLS-2$ + sort = sort(v.getOrDefault("sort", "")); //$NON-NLS-1$ //$NON-NLS-2$ + filters = split(v.getOrDefault("filters", ""), ","); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + counts = split(v.getOrDefault("counts", ""), ","); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + presentations = split(v.getOrDefault("presentation", "tree"), "\\|"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + label = v.get("label"); //$NON-NLS-1$ + } + + /** + * Parses a spec. + * + * @param text the spec text + * @return the spec + * @throws IllegalArgumentException naming the line of the first error + */ + public static M3ViewSpec parse(String text) { + Map values = new LinkedHashMap<>(); + String[] lines = text.split("\\R", -1); //$NON-NLS-1$ + for (int i = 0; i < lines.length; i++) { + String line = stripComment(lines[i]).strip(); + if (line.isEmpty()) { + continue; + } + int eq = line.indexOf('='); + if (eq <= 0) { + throw error(i, "expected key=value: " + line); //$NON-NLS-1$ + } + String key = line.substring(0, eq).strip(); + if (!KEYS.contains(key)) { + throw error(i, "unknown key: " + key); //$NON-NLS-1$ + } + if (values.put(key, line.substring(eq + 1).strip()) != null) { + throw error(i, "duplicate key: " + key); //$NON-NLS-1$ + } + } + for (String required : new String[] { "view.id", "element", "source", "lanes" }) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + if (values.get(required) == null || values.get(required).isEmpty()) { + throw new IllegalArgumentException("missing key: " + required); //$NON-NLS-1$ + } + } + M3ViewSpec spec = new M3ViewSpec(values); + spec.validate(); + return spec; + } + + /** + * Loads {@code .m3view} next to a view class. + * + * @param viewClass the view class; its loader reads the spec + * @return the spec + * @throws IOException when the spec cannot be read + * @throws IllegalArgumentException when it is not a valid spec + */ + public static M3ViewSpec load(Class viewClass) throws IOException { + String name = viewClass.getSimpleName() + ".m3view"; //$NON-NLS-1$ + try (InputStream in = viewClass.getResourceAsStream(name)) { + if (in == null) { + throw new IOException("no spec " + name + " next to " + viewClass.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + } + return parse(new String(in.readAllBytes(), StandardCharsets.UTF_8)); + } + } + + /* a '#' at the start of a line, or after whitespace, starts a comment ('#' inside a value stays) */ + private static String stripComment(String line) { + for (int i = 0; i < line.length(); i++) { + if (line.charAt(i) == '#' && (i == 0 || Character.isWhitespace(line.charAt(i - 1)))) { + return line.substring(0, i); + } + } + return line; + } + + private static IllegalArgumentException error(int line, String message) { + return new IllegalArgumentException("line " + (line + 1) + ": " + message); //$NON-NLS-1$ //$NON-NLS-2$ + } + + private static List split(String value, String separator) { + List out = new ArrayList<>(); + for (String part : value.split(separator)) { + String p = part.strip(); + if (!p.isEmpty()) { + out.add(p); + } + } + return Collections.unmodifiableList(out); + } + + private static List lanes(String value) { + List out = new ArrayList<>(); + for (String part : split(value, ",")) { //$NON-NLS-1$ + int colon = part.indexOf(':'); + if (colon <= 0) { + throw new IllegalArgumentException("lane without a type: " + part); //$NON-NLS-1$ + } + String type = part.substring(colon + 1).strip().toUpperCase(Locale.ROOT); + try { + out.add(new Lane(part.substring(0, colon).strip(), LaneType.valueOf(type))); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("unknown lane type: " + part, e); //$NON-NLS-1$ + } + } + return Collections.unmodifiableList(out); + } + + private static List sort(String value) { + List out = new ArrayList<>(); + for (String part : split(value, ",")) { //$NON-NLS-1$ + String[] words = part.split("\\s+"); //$NON-NLS-1$ + if (words.length > 2 || words.length == 2 && !"desc".equals(words[1]) && !"asc".equals(words[1])) { //$NON-NLS-1$ //$NON-NLS-2$ + throw new IllegalArgumentException("sort key must be ' [asc|desc]': " + part); //$NON-NLS-1$ + } + out.add(new SortKey(words[0], words.length == 2 && "desc".equals(words[1]))); //$NON-NLS-1$ + } + return Collections.unmodifiableList(out); + } + + private void validate() { + if (!ADAPTERS.contains(source)) { + throw new IllegalArgumentException("unknown source adapter: " + source + " (known: " + ADAPTERS + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + for (String p : presentations) { + if (!PRESENTATIONS.contains(p)) { + throw new IllegalArgumentException("unknown presentation: " + p); //$NON-NLS-1$ + } + } + for (String g : groups) { + if (!NONE.equals(g)) { + requireLane(g, "group"); //$NON-NLS-1$ + } + } + for (SortKey k : sort) { + requireLane(k.lane(), "sort"); //$NON-NLS-1$ + } + for (String f : filters) { + if (!BUILT_IN_FILTERS.contains(f)) { + requireLane(f, "filters"); //$NON-NLS-1$ + } + } + for (String c : counts) { + requireLane(c, "counts"); //$NON-NLS-1$ + } + for (int i = 0; i < lanes.size(); i++) { + for (int j = i + 1; j < lanes.size(); j++) { + if (lanes.get(i).name().equals(lanes.get(j).name())) { + throw new IllegalArgumentException("duplicate lane: " + lanes.get(i).name()); //$NON-NLS-1$ + } + } + } + } + + private void requireLane(String name, String key) { + if (lane(name) == null) { + throw new IllegalArgumentException(key + " names an undeclared lane: " + name); //$NON-NLS-1$ + } + } + + /** + * @param name a lane name + * @return the lane, or {@code null} + */ + public Lane lane(String name) { + for (Lane l : lanes) { + if (l.name().equals(name)) { + return l; + } + } + return null; + } + + /** @return the view id */ + public String viewId() { + return viewId; + } + + /** @return the element type */ + public String element() { + return element; + } + + /** @return the change-source adapter id */ + public String source() { + return source; + } + + /** @return the lanes, in declaration order */ + public List lanes() { + return lanes; + } + + /** @return the grouping alternatives, the default first ({@code none} = flat) */ + public List groups() { + return groups; + } + + /** @return the sort keys in order */ + public List sort() { + return sort; + } + + /** @return the filter lanes ({@code scope} and {@code text} built in) */ + public List filters() { + return filters; + } + + /** @return the counted lanes */ + public List counts() { + return counts; + } + + /** @return the presentations, the default first */ + public List presentations() { + return presentations; + } + + /** @return the label provider the view reuses, or {@code null} */ + public String label() { + return label; + } + + @Override + public String toString() { + return "M3ViewSpec[" + viewId + " source=" + source + " lanes=" + lanes.size() + " group=" + groups + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + } +} diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewerDelta.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewerDelta.java new file mode 100644 index 00000000000..53ef6b2b793 --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3ViewerDelta.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.viewers.m3; + +import java.util.Arrays; + +/** + * A change to the elements shown by a structured viewer, expressed as a + * sequence of operations: add (at an index or in comparator order), remove, + * update (labels) and refresh (structure of one subtree). A view that receives + * an event stream (resource deltas, marker deltas, model events) translates + * each event into a delta and hands it to {@link M3Viewers#apply} or + * {@link M3Viewers#post}, instead of refreshing the whole viewer. + *

+ * The operations are kept in lanes (one array per field, no object per + * operation) and applied in the order they were added. Consecutive operations + * of the same kind are applied as one batch call to the viewer. + *

+ *

+ * This class is not thread-safe; build a delta on one thread, then pass it on. + *

+ * + * @since 3.43 (M3 enhanced API) + */ +public final class M3ViewerDelta { + + /** Operation kind: add an element under a parent. */ + public static final byte ADD = 1; + /** Operation kind: remove an element. */ + public static final byte REMOVE = 2; + /** Operation kind: update the labels of an element. */ + public static final byte UPDATE = 3; + /** Operation kind: refresh the structure below an element (or the input). */ + public static final byte REFRESH = 4; + + private byte[] kinds = new byte[8]; + private Object[] elements = new Object[8]; + private Object[] parents = new Object[8]; + private int[] indexes = new int[8]; + private String[][] properties = new String[8][]; + private int size; + + /** + * Adds {@code element} as a child of {@code parent}. + * + * @param parent the parent element or tree path; for tables and lists the + * input (it is ignored there) + * @param element the new element + * @param index the position among the parent's children, or -1 to let the + * viewer place it (comparator order, else the end) + * @return this delta + */ + public M3ViewerDelta add(Object parent, Object element, int index) { + return push(ADD, element, parent, index, null); + } + + /** + * Removes {@code element} from the viewer. + * + * @param element the element (or tree path) that left the model + * @return this delta + */ + public M3ViewerDelta remove(Object element) { + return push(REMOVE, element, null, -1, null); + } + + /** + * Updates the labels of {@code element}. + * + * @param element the element whose presentation changed + * @param properties the changed properties, or {@code null} for all (see + * {@code StructuredViewer.update(Object, String[])}) + * @return this delta + */ + public M3ViewerDelta update(Object element, String[] properties) { + return push(UPDATE, element, null, -1, properties); + } + + /** + * Refreshes the structure below {@code element}: the fallback for changes + * the source cannot express as adds and removes. + * + * @param element the element (or tree path) to refresh, or {@code null} for + * the whole viewer + * @return this delta + */ + public M3ViewerDelta refresh(Object element) { + return push(REFRESH, element, null, -1, null); + } + + /** + * Appends the operations of {@code other} to this delta, so that deltas + * posted in a burst are applied as one. + * + * @param other the later delta + * @return this delta + */ + public M3ViewerDelta append(M3ViewerDelta other) { + for (int i = 0; i < other.size; i++) { + push(other.kinds[i], other.elements[i], other.parents[i], other.indexes[i], other.properties[i]); + } + return this; + } + + /** @return the number of operations */ + public int size() { + return size; + } + + /** @return whether the delta has no operation */ + public boolean isEmpty() { + return size == 0; + } + + /** + * @param i the operation index + * @return the kind of operation {@code i}: {@link #ADD}, {@link #REMOVE}, + * {@link #UPDATE} or {@link #REFRESH} + */ + public byte kind(int i) { + check(i); + return kinds[i]; + } + + /** + * @param i the operation index + * @return the element of operation {@code i} + */ + public Object element(int i) { + check(i); + return elements[i]; + } + + /** + * @param i the operation index + * @return the parent of an {@link #ADD}, else {@code null} + */ + public Object parent(int i) { + check(i); + return parents[i]; + } + + /** + * @param i the operation index + * @return the index of an {@link #ADD}, else -1 + */ + public int index(int i) { + check(i); + return indexes[i]; + } + + /** + * @param i the operation index + * @return the properties of an {@link #UPDATE}, else {@code null} + */ + public String[] properties(int i) { + check(i); + return properties[i]; + } + + private void check(int i) { + if (i < 0 || i >= size) { + throw new IndexOutOfBoundsException(i); + } + } + + private M3ViewerDelta push(byte kind, Object element, Object parent, int index, String[] props) { + if (element == null && kind != REFRESH) { + throw new IllegalArgumentException("element must not be null"); //$NON-NLS-1$ + } + if (size == kinds.length) { + int capacity = size << 1; + kinds = Arrays.copyOf(kinds, capacity); + elements = Arrays.copyOf(elements, capacity); + parents = Arrays.copyOf(parents, capacity); + indexes = Arrays.copyOf(indexes, capacity); + properties = Arrays.copyOf(properties, capacity); + } + kinds[size] = kind; + elements[size] = element; + parents[size] = parent; + indexes[size] = index; + properties[size] = props; + size++; + return this; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder("M3ViewerDelta["); //$NON-NLS-1$ + for (int i = 0; i < size; i++) { + b.append(i == 0 ? "" : ", ").append(switch (kinds[i]) { //$NON-NLS-1$ //$NON-NLS-2$ + case ADD -> "add"; //$NON-NLS-1$ + case REMOVE -> "remove"; //$NON-NLS-1$ + case UPDATE -> "update"; //$NON-NLS-1$ + default -> "refresh"; //$NON-NLS-1$ + }).append(' ').append(elements[i]); + } + return b.append(']').toString(); + } +} diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java new file mode 100644 index 00000000000..6fe5e0f7dcf --- /dev/null +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/M3Viewers.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.viewers.m3; + +import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.jface.viewers.AbstractListViewer; +import org.eclipse.jface.viewers.AbstractTableViewer; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + +/** + * Entry points that apply {@link M3ViewerDelta}s to structured viewers: the + * event stream of a view becomes deltas, never a whole-viewer refresh. + *
    + *
  • {@link #apply} applies a delta now, on the UI thread, with consecutive + * operations of one kind batched into one viewer call;
  • + *
  • {@link #post} queues a delta from any thread. Deltas posted in a burst + * are merged and applied once, after {@code delayMillis} without a newer post + * (superseding-generation debounce), and at the latest after four delays;
  • + *
  • {@link #flush} applies a queued delta at once. The viewers call it + * before every {@code refresh}, so a refresh never runs ahead of queued + * deltas.
  • + *
+ * Supported viewers: {@link AbstractTreeViewer}, {@link AbstractTableViewer}, + * {@link AbstractListViewer}. Any other structured viewer is refreshed at the + * first operation (the stock behaviour). + * + * @since 3.43 (M3 enhanced API) + */ +public final class M3Viewers { + + private static final Logger LOG = Logger.getLogger(M3Viewers.class.getName()); + private static final String KEY = "org.eclipse.jface.viewers.m3.M3Viewers.queue"; //$NON-NLS-1$ + + /** Batches of at least this many operations run with redraw off. */ + static final int REDRAW_BATCH = 64; + + /** Whether any delta was ever posted; until then {@link #flush} returns at once. */ + private static volatile boolean posted; + + private M3Viewers() { + } + + /** + * Applies {@code delta} to {@code viewer} now. Must run on the viewer's UI + * thread. + * + * @param viewer the viewer + * @param delta the delta; it is not changed + */ + public static void apply(StructuredViewer viewer, M3ViewerDelta delta) { + Control control = viewer.getControl(); + if (control == null || control.isDisposed() || delta.isEmpty()) { + return; + } + if (!(viewer instanceof AbstractTreeViewer || viewer instanceof AbstractTableViewer + || viewer instanceof AbstractListViewer)) { + viewer.refresh(); + return; + } + boolean bulk = delta.size() >= REDRAW_BATCH; + if (bulk) { + control.setRedraw(false); + } + try { + for (int i = 0; i < delta.size();) { + i = run(viewer, delta, i); + } + } finally { + if (bulk && !control.isDisposed()) { + control.setRedraw(true); + } + } + } + + /* applies the run of operations starting at i; returns the index after it */ + private static int run(StructuredViewer viewer, M3ViewerDelta delta, int i) { + byte kind = delta.kind(i); + int end = i + 1; + switch (kind) { + case M3ViewerDelta.ADD -> { + if (delta.index(i) >= 0) { + insert(viewer, delta.parent(i), delta.element(i), delta.index(i)); + return end; + } + while (end < delta.size() && delta.kind(end) == M3ViewerDelta.ADD && delta.index(end) < 0 + && delta.parent(end) == delta.parent(i)) { + end++; + } + add(viewer, delta.parent(i), elements(delta, i, end)); + } + case M3ViewerDelta.REMOVE -> { + while (end < delta.size() && delta.kind(end) == M3ViewerDelta.REMOVE) { + end++; + } + remove(viewer, elements(delta, i, end)); + } + case M3ViewerDelta.UPDATE -> { + while (end < delta.size() && delta.kind(end) == M3ViewerDelta.UPDATE + && Arrays.equals(delta.properties(end), delta.properties(i))) { + end++; + } + viewer.update(elements(delta, i, end), delta.properties(i)); + } + default -> { + if (delta.element(i) == null) { + viewer.refresh(); + } else { + viewer.refresh(delta.element(i)); + } + } + } + return end; + } + + private static Object[] elements(M3ViewerDelta delta, int from, int to) { + Object[] result = new Object[to - from]; + for (int k = from; k < to; k++) { + result[k - from] = delta.element(k); + } + return result; + } + + private static void insert(StructuredViewer viewer, Object parent, Object element, int index) { + if (viewer instanceof AbstractTreeViewer tree) { + tree.insert(parent, element, index); + } else if (viewer instanceof AbstractTableViewer table) { + table.insert(element, index); + } else { + ((AbstractListViewer) viewer).insert(element, index); + } + } + + private static void add(StructuredViewer viewer, Object parent, Object[] elements) { + if (viewer instanceof AbstractTreeViewer tree) { + tree.add(parent, elements); + } else if (viewer instanceof AbstractTableViewer table) { + table.add(elements); + } else { + ((AbstractListViewer) viewer).add(elements); + } + } + + private static void remove(StructuredViewer viewer, Object[] elements) { + if (viewer instanceof AbstractTreeViewer tree) { + tree.remove(elements); + } else if (viewer instanceof AbstractTableViewer table) { + table.remove(elements); + } else { + ((AbstractListViewer) viewer).remove(elements); + } + } + + /** The queue of one viewer: the merged pending delta and the generation of the latest post. */ + private static final class Queue { + final StructuredViewer viewer; + M3ViewerDelta pending; + long generation; + long firstPost; + + Queue(StructuredViewer viewer) { + this.viewer = viewer; + } + } + + /** + * Queues {@code delta} for {@code viewer}; it may be called from any thread. + * Deltas posted within {@code delayMillis} of each other are merged; the + * merged delta is applied on the UI thread after {@code delayMillis} without + * a newer post, and at the latest {@code 4 * delayMillis} after the first. + * + * @param viewer the viewer + * @param delta the delta; the caller must not change it afterwards + * @param delayMillis the debounce delay, 0 or more + */ + public static void post(StructuredViewer viewer, M3ViewerDelta delta, int delayMillis) { + Control control = viewer.getControl(); + if (control == null || control.isDisposed() || delta.isEmpty()) { + return; + } + posted = true; + Display display = control.getDisplay(); + display.asyncExec(() -> enqueue(viewer, delta, Math.max(0, delayMillis))); + } + + /* UI thread */ + private static void enqueue(StructuredViewer viewer, M3ViewerDelta delta, int delayMillis) { + Control control = viewer.getControl(); + if (control == null || control.isDisposed()) { + return; + } + Queue queue = (Queue) control.getData(KEY); + if (queue == null) { + queue = new Queue(viewer); + control.setData(KEY, queue); + } + long now = System.currentTimeMillis(); + if (queue.pending == null) { + queue.pending = new M3ViewerDelta().append(delta); + queue.firstPost = now; + } else { + queue.pending.append(delta); + } + long generation = ++queue.generation; + Queue q = queue; + long overdue = q.firstPost + 4L * delayMillis - now; + int wait = (int) Math.max(0, Math.min(delayMillis, overdue)); + control.getDisplay().timerExec(wait, () -> { + if (q.generation == generation || System.currentTimeMillis() >= q.firstPost + 4L * delayMillis) { + drain(q); + } + }); + } + + private static void drain(Queue queue) { + M3ViewerDelta delta = queue.pending; + queue.pending = null; + if (delta == null) { + return; + } + try { + apply(queue.viewer, delta); + } catch (RuntimeException e) { + LOG.log(Level.WARNING, "viewer delta failed; refreshing the viewer", e); //$NON-NLS-1$ + Control control = queue.viewer.getControl(); + if (control != null && !control.isDisposed()) { + queue.viewer.refresh(); + } + } + } + + /** + * Applies the delta queued for {@code viewer}, if any, now. The viewers call + * this before every refresh. Must run on the UI thread. + * + * @param viewer the viewer + */ + public static void flush(StructuredViewer viewer) { + if (!posted) { + return; + } + Control control = viewer.getControl(); + if (control == null || control.isDisposed() || control.getDisplay().getThread() != Thread.currentThread()) { + return; + } + if (control.getData(KEY) instanceof Queue queue && queue.pending != null) { + queue.generation++; + drain(queue); + } + } + + /** + * Schedules a refresh of {@code viewer} through the same debounce: a burst + * of calls refreshes once. + * + * @param viewer the viewer + * @param delayMillis the debounce delay + */ + public static void refreshLater(StructuredViewer viewer, int delayMillis) { + post(viewer, new M3ViewerDelta().refresh(null), delayMillis); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java index 6959b89fdb6..ebf742da883 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java @@ -11,7 +11,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Stefan Winkler - Bug 537099 - * Hitesh Soliwal (Synexia) - M3 marker delta path hooks (docs/m3/markers-view) + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -213,6 +213,10 @@ int getTotalMarkerCount() { * @return int */ static int getTotalMarkerCount(Markers markers) { + M3MarkerLanes lanes = markers.m3; + if (lanes != null) { + return lanes.size(); + } MarkerSupportItem[] elements = markers.getElements(); if (elements.length == 0 || elements[0].isConcrete()) { return elements.length; @@ -234,6 +238,16 @@ boolean isBuilding() { return building || markerListener.isReceivingChange(); } + /** + * Whether a clean rebuild is running, without the change listener's receiving flag that + * {@link #isBuilding()} adds: the delta path asks from inside resourceChanged (M3MarkerDeltas). + * + * @return whether a clean rebuild is running + */ + boolean m3Building() { + return building; + } + /** * Update the flag that indicates if the markers are building/changing */ @@ -611,6 +625,9 @@ public void propertyChange(PropertyChangeEvent event) { } } if (needsUpdate) { + if (M3MarkerDeltas.scopeChanged(CachedMarkerBuilder.this)) { + return; + } scheduleUpdate(); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java index 427f98cfb22..0d78988246a 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java @@ -16,6 +16,7 @@ * Andrey Loskutov - Bug 446864, 466927 * Mickael Istria (Red Hat Inc.) - Bug 486901 * Patrik Suzzi - Bug 489250 + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -951,6 +952,19 @@ public boolean getSortAscending() { * @return String */ private String getStatusMessage(Markers markers, Integer[] counts) { + M3MarkerLanes m3Lanes = markers.m3; + if (m3Lanes != null && m3Lanes.isFlat() && getSearchFilter() == null) { + // flat lane model: the counts come from the lanes, no entry per marker (same messages as below) + int m3Total = m3Lanes.size(); + int m3Shown = applyMarkerLimit(m3Total); + if (counts[0].intValue() == 0 && counts[1].intValue() == 0) { + return m3Shown >= m3Total ? NLS.bind(MarkerMessages.filter_itemsMessage, m3Total) + : NLS.bind(MarkerMessages.filter_matchedMessage, m3Shown, m3Total); + } + String m3Message = formatSummaryBreakdown(counts); + return m3Shown >= m3Total ? m3Message + : NLS.bind(MarkerMessages.problem_filter_matchedMessage, m3Message, m3Shown, m3Total); + } String status = MarkerSupportInternalUtilities.EMPTY_STRING; int totalCount = CachedMarkerBuilder.getTotalMarkerCount(markers); int filteredCount = 0; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LabelTable.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LabelTable.java new file mode 100644 index 00000000000..9f7e9f9481d --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LabelTable.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import java.text.CollationKey; +import java.text.Collator; +import java.util.Arrays; + +/** + * Interned labels of the marker lanes: each distinct string (message, + * location, resource name, path, type name) is stored once and named by an + * {@code int} id; a reference count per id frees it when no marker uses it. + * The collation key of a label is computed once, on the first comparison that + * needs it, so a sort by description costs one key per distinct message, not + * one per marker (stock rotates a per-update map of keys, MarkerEntry.java:76). + *

+ * Lookup is an open-addressing {@code int[]} table over the ids (no map entry + * objects). Not thread-safe. + *

+ */ +public final class M3LabelTable { + + private final Collator collator; + private String[] text = new String[16]; + private CollationKey[] keys = new CollationKey[16]; + private int[] refs = new int[16]; + private int[] free = new int[16]; + private int freeCount; + private int count; + private int live; + private int[] table = new int[32]; + + /** + * @param collator the collator of the description sort (MarkerEntry's) + */ + public M3LabelTable(Collator collator) { + this.collator = collator; + } + + /** + * Interns a label and counts one more reference to it. + * + * @param label the label, not {@code null} + * @return its id + */ + public int acquire(String label) { + int mask = table.length - 1; + int h = label.hashCode(); + int i = mix(h) & mask; + while (table[i] != 0) { + int id = table[i] - 1; + if (text[id].equals(label)) { + refs[id]++; + return id; + } + i = (i + 1) & mask; + } + int id = freeCount > 0 ? free[--freeCount] : count++; + if (id == text.length) { + int capacity = id << 1; + text = Arrays.copyOf(text, capacity); + keys = Arrays.copyOf(keys, capacity); + refs = Arrays.copyOf(refs, capacity); + } + text[id] = label; + keys[id] = null; + refs[id] = 1; + live++; + table[i] = id + 1; + if (live << 1 > table.length) { + rehash(table.length << 1); + } + return id; + } + + /** + * Counts one reference less; the label is freed at zero. + * + * @param id a label id + */ + public void release(int id) { + if (--refs[id] > 0) { + return; + } + String label = text[id]; + text[id] = null; + keys[id] = null; + live--; + if (freeCount == free.length) { + free = Arrays.copyOf(free, freeCount << 1); + } + free[freeCount++] = id; + // remove from the table and re-place the rest of the cluster (linear probing) + int mask = table.length - 1; + int i = mix(label.hashCode()) & mask; + while (table[i] != id + 1) { + i = (i + 1) & mask; + } + table[i] = 0; + for (int j = (i + 1) & mask; table[j] != 0; j = (j + 1) & mask) { + int other = table[j] - 1; + table[j] = 0; + place(other); + } + } + + /** + * @param id a label id + * @return the label + */ + public String text(int id) { + return text[id]; + } + + /** + * @param id a label id + * @return the number of markers that use it + */ + public int references(int id) { + return refs[id]; + } + + /** @return the number of distinct labels in use */ + public int size() { + return live; + } + + /** + * Compares two labels by their collation keys (the order of + * {@code MarkerDescriptionField}); an empty label sorts as the empty key. + * + * @param a a label id + * @param b a label id + * @return the collation order + */ + public int collate(int a, int b) { + if (a == b) { + return 0; + } + return key(a).compareTo(key(b)); + } + + /** + * Compares two labels by {@link String#compareTo(String)}. + * + * @param a a label id + * @param b a label id + * @return the code-unit order + */ + public int compare(int a, int b) { + return a == b ? 0 : text[a].compareTo(text[b]); + } + + private CollationKey key(int id) { + CollationKey key = keys[id]; + if (key == null) { + key = collator.getCollationKey(text[id]); + keys[id] = key; + } + return key; + } + + private void rehash(int capacity) { + table = new int[capacity]; + for (int id = 0; id < count; id++) { + if (text[id] != null) { + place(id); + } + } + } + + private void place(int id) { + int mask = table.length - 1; + int i = mix(text[id].hashCode()) & mask; + while (table[i] != 0) { + i = (i + 1) & mask; + } + table[i] = id + 1; + } + + private static int mix(int h) { + return h * 0x9E3779B9 ^ (h >>> 16); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LongSet.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LongSet.java index c6025b73133..8e3dca6c56d 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LongSet.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3LongSet.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.ui.internal.views.markers; +import java.util.function.LongConsumer; + /** * A set of marker ids: one {@code long[]} open-addressing lane with linear * probing (power-of-two capacity, load at most one half). No boxing, no entry @@ -21,8 +23,9 @@ */ final class M3LongSet { - private final long[] keys; - private final int shift; + private long[] keys; + private int shift; + private int size; private boolean zero; /** @@ -48,6 +51,9 @@ void add(long id) { i = (i + 1) & mask; } keys[i] = id; + if (++size << 1 > keys.length) { + grow(); + } } boolean contains(long id) { @@ -63,6 +69,42 @@ boolean contains(long id) { return false; } + /** + * @param action receives every id of the set + */ + void forEach(LongConsumer action) { + if (zero) { + action.accept(0); + } + for (long id : keys) { + if (id != 0) { + action.accept(id); + } + } + } + + /** @return whether no id was added */ + boolean isEmpty() { + return size == 0 && !zero; + } + + /* doubles the table once it is half full (sets that accumulate, e.g. while the view is hidden) */ + private void grow() { + long[] old = keys; + keys = new long[old.length << 1]; + shift--; + int mask = keys.length - 1; + for (long id : old) { + if (id != 0) { + int i = slot(id); + while (keys[i] != 0) { + i = (i + 1) & mask; + } + keys[i] = id; + } + } + } + private int slot(long id) { return (int) ((id * 0x9E3779B97F4A7C15L) >>> shift); } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerCategory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerCategory.java new file mode 100644 index 00000000000..33d61a5ec50 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerCategory.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +/** + * The facade of one category of the lane model ({@link M3MarkerLanes}): it + * answers counts and the highest severity from lane counters and materializes + * entries only for the window the viewer shows ({@link #window(int)}) or when + * an API asks for every child ({@link #getChildren()}). It lives as long as its + * category: marker deltas patch it in place instead of creating a new one. + */ +final class M3MarkerCategory extends MarkerCategory { + + private final Markers owner; + private final M3MarkerLanes lanes; + /** The category in the lanes; set by the lanes right after construction. */ + M3MarkerLanes.Category lane; + + private String shownPattern; + private int shownGeneration = -1; + private int shownCount; + + M3MarkerCategory(Markers owner, M3MarkerLanes lanes, String name) { + super(owner, 0, -1, name); + this.owner = owner; + this.lanes = lanes; + } + + /** Every child: an API asks for all of them (selection of the category, copy, the search box). */ + @Override + MarkerSupportItem[] getChildren() { + return lanes.children(lane); + } + + @Override + int getChildrenCount() { + return lane.order.size(); + } + + /** + * The rows the viewer shows. + * + * @param limit the marker limit, or a negative value for none + * @return the entries of the window, in order + */ + MarkerEntry[] window(int limit) { + return lanes.window(lane, limit); + } + + @Override + int getHighestSeverity() { + return lanes.highestSeverity(lane); + } + + @Override + int getShownChildrenCount() { + ExtendedMarkersView view = owner.getBuilder().getView(); + // the search text is a lane (M3MarkerLanes.applyText): what stock counts over every child + return view.applyMarkerLimit(lanes.matching(lane)); + } + + @Override + void clearCache() { + shownGeneration = -1; + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java index 06e5eb265ed..9b228dd9446 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Set; @@ -36,11 +35,13 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.m3.M3ViewerDelta; +import org.eclipse.jface.viewers.m3.M3Viewers; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.views.markers.MarkerItem; +import org.eclipse.ui.internal.m3.M3PartVisibility; import org.eclipse.ui.views.markers.internal.MarkerGroup; import org.eclipse.ui.views.markers.internal.MarkerGroupingEntry; @@ -49,25 +50,27 @@ *

* The original view answers every marker change with a clean rebuild: a new * {@link MarkerEntry} for every marker in scope, every filter evaluated again, - * every category regrouped and sorted, and the whole tree refreshed. This class - * consumes the {@link IMarkerDelta}s of the resource change event instead: + * every category regrouped and sorted, and the whole tree refreshed. In M3 mode + * the model is {@link M3MarkerLanes} and this class feeds it the + * {@link IMarkerDelta}s of each resource change event: *

*
    *
  1. {@link #offer} records the applicable deltas by marker id (lanes, merged - * per id) and schedules one debounced job; a newer clean rebuild supersedes - * them (generation counter);
  2. - *
  3. the job (worker thread) creates entries only for added or changed - * markers, evaluates the filters for them only and finds their category;
  4. - *
  5. {@link #apply} (UI thread) patches the model with one merge pass per - * category (references only, no attribute reads for unchanged markers) and - * patches the tree: rows inside a category's shown window are removed, - * inserted or relabelled; outside the window only the category label (its - * count) and the title counts change.
  6. + * per id) and schedules one debounced job; a clean rebuild supersedes them + * (generation counter); + *
  7. the job (worker thread) reads keys, filters and categories of the changed + * markers only (one attribute lookup per marker);
  8. + *
  9. one {@code asyncExec} applies them on the UI thread: each changed marker + * leaves and re-enters its category's order (O(log n) compares, at most one + * block of slots moved), the counters follow, and the tree is patched inside + * the shown windows only, through one {@link M3ViewerDelta}. Outside a window + * only the category label (its count) and the title change.
  10. *
- * Anything the delta path does not cover falls back to the original clean - * rebuild: flat (ungrouped) presentation, an active search text, filters with - * a resource scope, more than {@link #MAX_PENDING} pending deltas, or an error. - * Design: {@code docs/m3/markers-view/DESIGN.md}. + * The original clean rebuild still runs for the first input and for changes of + * filters, grouping, sorting or scope, and when the view is in a state the lanes + * do not cover (flat presentation, an active search text, a resource scope, + * more than {@link #MAX_PENDING} pending deltas, an error). Design: + * {@code docs/m3/markers-view/DESIGN.md}, {@code FALLBACKS_TO_DELTAS.md}. */ final class M3MarkerDeltas { @@ -77,7 +80,7 @@ final class M3MarkerDeltas { /** Whether the delta path is on: {@code -Dorg.eclipse.ui.ide.markers.mode=viewport}. */ static final boolean ENABLED = "viewport".equals(System.getProperty(PROPERTY)); //$NON-NLS-1$ - /** Above this many pending deltas a clean rebuild is cheaper. */ + /** Above this many pending deltas a clean rebuild runs instead (to be measured, FALLBACKS_TO_DELTAS.md). */ static final int MAX_PENDING = 50_000; /** The debounce of the original update scheduler (MarkerUpdateScheduler.SHORT_DELAY), kept for the delta job. */ @@ -87,6 +90,13 @@ final class M3MarkerDeltas { private static final Map BY_BUILDER = new WeakHashMap<>(); private static final byte NONE = 0; + /** Counters for the differential and the benchmark: see {@link #counters()}. */ + private static final int[] COUNTERS = new int[4]; + private static final int APPLIED = 0; + private static final int FALLBACKS = 1; + private static final int BUILDS = 2; + private static final int SHOWN = 3; + private final MarkersChangeListener listener; private final CachedMarkerBuilder builder; private final Job job; @@ -94,7 +104,6 @@ final class M3MarkerDeltas { /* pending deltas: lanes indexed by slot, plus an open-addressing id -> slot+1 table */ private long[] ids = new long[16]; private byte[] kinds = new byte[16]; - private int[] oldSeverities = new int[16]; private IMarker[] markers = new IMarker[16]; private int size; private int[] table = new int[32]; @@ -106,6 +115,131 @@ private M3MarkerDeltas(MarkersChangeListener listener, CachedMarkerBuilder build job = Job.create("M3 marker deltas", this::prepare); //$NON-NLS-1$ job.setSystem(true); job.setPriority(Job.SHORT); + scopeJob = Job.create("M3 marker scope", this::diffScope); //$NON-NLS-1$ + scopeJob.setSystem(true); + scopeJob.setPriority(Job.SHORT); + } + + /* ---------------------------------------------------------------- scope and filter changes */ + + private final Job scopeJob; + private int knownLimit = Integer.MIN_VALUE; + + /** + * The shown set may have changed without any marker change: the selection + * (resource-scoped filters), a working set, or the filters themselves + * (MarkerContentGenerator.requestMarkerUpdate, CachedMarkerBuilder's working + * set listener). Stock answers with a clean rebuild and a full refresh. In M3 + * mode one job gathers the markers the filters now select, diffs their ids + * against the lanes (two-pointer merge of sorted id arrays) and applies only + * the markers that entered or left, as one delta: an unchanged result makes + * no update at all (the "contentChanged() == false" answer of Bug 296695). + * + * @param builder the view's builder + * @return {@code true} when the change is taken; {@code false} to run the + * original clean rebuild + */ + static boolean scopeChanged(CachedMarkerBuilder builder) { + if (!ENABLED) { + return false; + } + M3MarkerDeltas deltas; + synchronized (BY_BUILDER) { + deltas = BY_BUILDER.computeIfAbsent(builder, b -> new M3MarkerDeltas(b.getMarkerListener(), b)); + } + return deltas.acceptScope(); + } + + private synchronized boolean acceptScope() { + MarkerContentGenerator generator = builder.getGenerator(); + if (!ready() || generator == null) { + return false; + } + int limit = generator.isMarkerLimitsEnabled() ? generator.getMarkerLimits() : -1; + if (knownLimit != Integer.MIN_VALUE && limit != knownLimit) { + knownLimit = limit; + return false; // the limit changed: every window changes, the clean rebuild refreshes them all + } + knownLimit = limit; + scopeJob.schedule(DEBOUNCE_MILLIS); + return true; + } + + /* worker thread: gather what the filters select now, diff against the lanes */ + private IStatus diffScope(IProgressMonitor monitor) { + long gen; + synchronized (this) { + gen = generation; + } + MarkerContentGenerator generator = builder.getGenerator(); + M3MarkerLanes lanes = builder.getMarkers().m3; + if (generator == null || lanes == null) { + return Status.OK_STATUS; + } + try { + long[] shown = lanes.liveIds(); + List selected = new ArrayList<>(); + if (!generator.generateMarkerEntries(selected, monitor) || stale(gen)) { + return Status.OK_STATUS; + } + MarkerEntry[] entries = selected.toArray(new MarkerEntry[0]); + Arrays.sort(entries, (a, b) -> Long.compare(a.getMarker().getId(), b.getMarker().getId())); + List changes = new ArrayList<>(); + MarkerGroup group = builder.getCategoryGroup(); + int i = 0; + int j = 0; + while (i < shown.length || j < entries.length) { + long left = i < shown.length ? shown[i] : Long.MAX_VALUE; + long right = j < entries.length ? entries[j].getMarker().getId() : Long.MAX_VALUE; + if (left == right) { + i++; + j++; // shown before and after: the marker deltas keep it current + } else if (left < right) { + changes.add(new M3MarkerLanes.Change().set(left, null, null, null, null)); + i++; + } else { + MarkerEntry entry = entries[j++]; + IMarker marker = entry.getMarker(); + try { + MarkerGroupingEntry key = group == null ? null + : group.findGroupValue(marker.getType(), marker); + changes.add(new M3MarkerLanes.Change().set(right, marker, + M3MarkerKeys.read(marker, lanes.needsType(), null), key, entry)); + } catch (CoreException e) { + // deleted since the gather: its REMOVED delta follows; stock skips it too + } + } + } + if (changes.isEmpty()) { + return Status.OK_STATUS; // the shown set did not change: no update at all + } + Display.getDefault().asyncExec(() -> { + try { + apply(gen, changes); + } catch (RuntimeException e) { + fallback(e); + } + }); + } catch (RuntimeException e) { + fallback(e); + } + return Status.OK_STATUS; + } + + /** + * The counters the differential and the benchmark read: deltas applied + * through the lanes, fallbacks to a clean rebuild, clean rebuilds started, + * window patches applied when a hidden view showed again. + * + * @return {@code "applied= fallbacks= builds= shown-patches="} + */ + static synchronized String counters() { + return "applied=" + COUNTERS[APPLIED] + " fallbacks=" + COUNTERS[FALLBACKS] + " builds=" + COUNTERS[BUILDS] //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + " shown-patches=" + COUNTERS[SHOWN]; //$NON-NLS-1$ + } + + private static synchronized void count(int counter) { + COUNTERS[counter]++; } /** @@ -128,6 +262,26 @@ static boolean offer(MarkersChangeListener listener, IResourceChangeEvent event, return deltas.accept(event, types); } + /** + * The view's search text changed (MarkerPatternFilter.setPattern, called by + * the FilteredTree refresh job on the UI thread before its viewer refresh): + * the lanes recompute their hits, so the windows the refresh reads are the + * matching rows first, then the limit, as stock computes them. + * + * @param view the view + * @param filter the active search filter, or {@code null} for none + */ + static void textChanged(ExtendedMarkersView view, MarkerPatternFilter filter) { + if (!ENABLED || view == null || view.isDisposed()) { + return; + } + TreeViewer viewer = view.getViewer(); + Object input = viewer == null ? null : viewer.getInput(); + if (input instanceof Markers markers && markers.m3 != null) { + markers.m3.applyText(filter); + } + } + /** * A clean rebuild is starting: pending and prepared deltas are dropped, as the * rebuild reads the markers afresh. @@ -138,6 +292,7 @@ static void supersede(CachedMarkerBuilder builder) { if (!ENABLED) { return; } + count(BUILDS); M3MarkerDeltas deltas; synchronized (BY_BUILDER) { deltas = BY_BUILDER.get(builder); @@ -148,13 +303,46 @@ static void supersede(CachedMarkerBuilder builder) { } /** - * Whether categories are sorted completely, not only their shown window: the - * delta path inserts by binary search. + * Builds the lane model of a clean rebuild from the gathered entries (the + * entries the filters selected); they are not kept. * - * @return {@code true} when the delta path is on + * @param model the view's model + * @param entries the selected entries + * @param monitor the rebuild's monitor + * @return the lanes, or {@code null} when the view is in a state the lanes + * do not cover or the rebuild was cancelled */ - static boolean fullSort() { - return ENABLED; + static M3MarkerLanes build(Markers model, Collection entries, IProgressMonitor monitor) { + CachedMarkerBuilder builder = model.getBuilder(); + M3MarkerLanes lanes = M3MarkerLanes.create(model, builder.getComparator()); + if (lanes == null) { + return null; + } + MarkerGroup group = builder.getCategoryGroup(); + M3MarkerLanes.Change change = new M3MarkerLanes.Change(); + M3MarkerKeys keys = null; + int i = 0; + for (MarkerEntry entry : entries) { + if ((++i & 4095) == 0 && monitor.isCanceled()) { + return null; + } + IMarker marker = entry.getMarker(); + if (marker == null) { + continue; + } + try { + MarkerGroupingEntry key = group == null ? null : group.findGroupValue(marker.getType(), marker); + keys = M3MarkerKeys.read(marker, lanes.needsType(), keys); + lanes.add(change.set(keys.id, marker, keys, key, entry)); + } catch (CoreException e) { + entry.checkIfMarkerStale(); // stock skips a stale marker when grouping (Markers.groupMarkerEntries) + } + } + lanes.finishBuild(); + // the search text as a lane: a hit per slot, before the viewer reads any window + ExtendedMarkersView view = builder.getView(); + lanes.applyText(view == null || view.isDisposed() ? null : view.getSearchFilter()); + return lanes; } private synchronized boolean accept(IResourceChangeEvent event, Set types) { @@ -164,36 +352,35 @@ private synchronized boolean accept(IResourceChangeEvent event, Set type } for (IMarkerDelta delta : event.findMarkerDeltas(null, true)) { if (types.contains(delta.getType())) { - add(delta.getId(), (byte) delta.getKind(), delta.getMarker(), - delta.getKind() == IResourceDelta.ADDED ? -2 : delta.getAttribute(IMarker.SEVERITY, -1)); + add(delta.getId(), (byte) delta.getKind(), delta.getMarker()); } } if (size > MAX_PENDING) { clear(); + count(FALLBACKS); return false; } job.schedule(DEBOUNCE_MILLIS); return true; } - /* the model is built and the view state is one the delta path covers */ + /* the lane model is built and the view state is one the delta path covers */ private boolean ready() { - if (builder.isBuilding() || !builder.isShowingHierarchy() || builder.getGenerator() == null) { + // m3Building, not isBuilding: isBuilding also reports the listener receiving the very event offered here + if (builder.m3Building() || builder.getGenerator() == null + || builder.getMarkers().m3 == null) { return false; } ExtendedMarkersView view = listener.getView(); - if (view == null || view.isDisposed() || view.getSearchFilter() != null) { - return false; - } - for (MarkerFieldFilterGroup group : builder.getGenerator().getEnabledFilters()) { - if (group.getScope() != MarkerFieldFilterGroup.ON_ANY) { - return false; - } - } - return true; + // A resource scope needs no fallback for marker deltas: MarkerContentGenerator.select evaluates every + // group's selectByScope against the current selection for each changed marker, which is exactly the + // membership a clean rebuild computes (gather under computeResources, then select). Selection and + // working-set changes are scope changes, handled apart (FALLBACKS_TO_DELTAS.md, Bug 296695). + // the search text is a lane too (M3MarkerLanes.applyText), so it is no fallback state any more + return view != null && !view.isDisposed(); } - private void add(long id, byte kind, IMarker marker, int oldSeverity) { + private void add(long id, byte kind, IMarker marker) { int slot = find(id); if (slot < 0) { grow(); @@ -201,7 +388,6 @@ private void add(long id, byte kind, IMarker marker, int oldSeverity) { ids[slot] = id; kinds[slot] = kind; markers[slot] = marker; - oldSeverities[slot] = oldSeverity; index(id, slot); return; } @@ -210,7 +396,6 @@ private void add(long id, byte kind, IMarker marker, int oldSeverity) { kinds[slot] = kind == IResourceDelta.REMOVED ? NONE : IResourceDelta.ADDED; } else if (before == NONE) { kinds[slot] = kind; - oldSeverities[slot] = oldSeverity; } else { kinds[slot] = (byte) (kind == IResourceDelta.REMOVED ? IResourceDelta.REMOVED : IResourceDelta.CHANGED); } @@ -257,7 +442,6 @@ private void grow() { ids = Arrays.copyOf(ids, capacity); kinds = Arrays.copyOf(kinds, capacity); markers = Arrays.copyOf(markers, capacity); - oldSeverities = Arrays.copyOf(oldSeverities, capacity); } } @@ -268,19 +452,12 @@ private synchronized void clear() { size = 0; } - /** One prepared change: the marker, its new entry (or null when it leaves the view) and its category. */ - private record Change(long id, byte kind, MarkerEntry entry, String category, MarkerGroupingEntry key, - int oldSeverity) { - } - - /* worker thread: entries, filters and categories for the changed markers only */ + /* worker thread: keys, filters and categories for the changed markers only */ private IStatus prepare(IProgressMonitor monitor) { long gen; - List changes = new ArrayList<>(); long[] batchIds; byte[] batchKinds; IMarker[] batchMarkers; - int[] batchSeverities; int n; synchronized (this) { gen = generation; @@ -288,38 +465,31 @@ private IStatus prepare(IProgressMonitor monitor) { batchIds = Arrays.copyOf(ids, n); batchKinds = Arrays.copyOf(kinds, n); batchMarkers = Arrays.copyOf(markers, n); - batchSeverities = Arrays.copyOf(oldSeverities, n); Arrays.fill(markers, 0, size, null); Arrays.fill(table, 0); size = 0; } + List changes = new ArrayList<>(n); try { MarkerContentGenerator generator = builder.getGenerator(); - if (generator == null) { + M3MarkerLanes lanes = builder.getMarkers().m3; + if (generator == null || lanes == null) { return Status.OK_STATUS; } IResource[] selected = generator.getSelectedResources(); Collection filters = generator.getEnabledFilters(); MarkerGroup group = builder.getCategoryGroup(); + ExtendedMarkersView view = listener.getView(); + MarkerPatternFilter text = view == null || view.isDisposed() ? null : view.getSearchFilter(); + int textGen = lanes.textGeneration(); for (int i = 0; i < n; i++) { - byte kind = batchKinds[i]; - if (kind == NONE) { - continue; + if ((i & 4095) == 4095 && stale(gen)) { + return Status.OK_STATUS; } - IMarker marker = batchMarkers[i]; - MarkerEntry entry = null; - MarkerGroupingEntry key = null; - if (kind != IResourceDelta.REMOVED && marker.exists()) { - MarkerEntry candidate = new MarkerEntry(marker); - if (MarkerContentGenerator.select(candidate, selected, filters)) { - entry = candidate; - key = group.findGroupValue(marker.getType(), marker); - } - candidate.clearCache(); + if (batchKinds[i] != NONE) { + changes.add(prepareOne(batchIds[i], batchKinds[i], batchMarkers[i], lanes, selected, filters, + group, text, textGen)); } - String category = entry == null ? null - : group.getMarkerField().getValue(entry); - changes.add(new Change(batchIds[i], kind, entry, category, key, batchSeverities[i])); } } catch (CoreException | RuntimeException e) { fallback(e); @@ -336,289 +506,260 @@ private IStatus prepare(IProgressMonitor monitor) { return Status.OK_STATUS; } + /* one changed marker: its keys and category when it is (still) selected by the filters, else it leaves */ + private static M3MarkerLanes.Change prepareOne(long id, byte kind, IMarker marker, M3MarkerLanes lanes, + IResource[] selected, Collection filters, MarkerGroup group, + MarkerPatternFilter text, int textGen) throws CoreException { + M3MarkerLanes.Change change = new M3MarkerLanes.Change().set(id, marker, null, null, null); + if (kind == IResourceDelta.REMOVED || !marker.exists()) { + return change; + } + MarkerEntry candidate = new MarkerEntry(marker); + if (!MarkerContentGenerator.select(candidate, selected, filters)) { + return change; + } + MarkerGroupingEntry key = group == null ? null : group.findGroupValue(marker.getType(), marker); + candidate.clearCache(); + change.set(id, marker, M3MarkerKeys.read(marker, lanes.needsType(), null), key, candidate); + // the search text: the same test stock's PatternFilter runs on every child, for this row only + change.textHit = text == null || text.matches(candidate); + change.textGeneration = textGen; + return change; + } + + private synchronized boolean stale(long gen) { + return gen != generation; + } + private void fallback(Exception e) { LOG.log(Level.WARNING, "marker delta path failed, rebuilding the view", e); //$NON-NLS-1$ + count(FALLBACKS); clear(); builder.getUpdateScheduler().scheduleUpdate(); } - /* UI thread: patch the model with one merge pass, then the tree rows inside the shown windows */ - private void apply(long gen, List changes) { - synchronized (this) { - if (gen != generation) { - return; - } + /* UI thread: patch the lanes, then the tree rows inside the shown windows */ + private void apply(long gen, List changes) { + if (stale(gen)) { + return; } ExtendedMarkersView view = listener.getView(); - if (view == null || view.isDisposed() || builder.isBuilding() || !ready()) { + if (view == null || view.isDisposed() || !ready()) { return; } - Markers model = builder.getMarkers(); - MarkerCategory[] oldCategories; - MarkerCategory[] newCategories; - synchronized (model) { - oldCategories = model.getCategories(); - Patch patch = new Patch(model, changes); - if (!patch.build()) { - fallback(new IllegalStateException("marker delta does not fit the model")); //$NON-NLS-1$ - return; - } - newCategories = patch.categories; - model.m3Replace(patch.entries, newCategories, patch.counts); - Markers clone = builder.getClonedMarkers(); - if (clone != model) { - clone.m3Replace(patch.entries, newCategories, patch.counts); + M3MarkerLanes lanes = builder.getMarkers().m3; + // a search text typed after this batch was prepared: re-evaluate its hits here (UI thread, few rows) + MarkerPatternFilter text = lanes.textFilter(); + int textGen = lanes.textGeneration(); + for (M3MarkerLanes.Change c : changes) { + if (c.keys != null && c.textGeneration != textGen) { + c.textHit = text == null || c.item instanceof MarkerSupportItem item && text.matches(item); + c.textGeneration = textGen; } } - patchTree(view, oldCategories, newCategories, changes); - view.updateTitle(); + M3LongSet changed = new M3LongSet(changes.size()); + for (M3MarkerLanes.Change c : changes) { + changed.add(c.id); + } + List touched = lanes.apply(changes); + count(APPLIED); + if (visibility == null) { + visibility = M3PartVisibility.watch(view, () -> shown(view)); + } + if (visibility.isHidden()) { + // hidden viewport (brief rule 24): the lanes stay current, the tree does no native work; the touched + // categories and changed markers accumulate for one window patch when the view shows again + hide(lanes, touched, changed); + visibility.markDirty(); + view.updateTitle(); + return; + } + if (view.getActiveViewerInputClone().m3 == lanes) { + patchTree(view, lanes, touched, changed); + } // else a rebuilt model waits for its UI update, which refreshes the tree from these lanes + finishPatch(view, lanes); } - /** The model patch: new entry array, categories and counts from the old ones and the changes. */ - private final class Patch { - final Markers model; - final List changes; - MarkerEntry[] entries; - MarkerCategory[] categories; - Integer[] counts; - - Patch(Markers model, List changes) { - this.model = model; - this.changes = changes; - } - - boolean build() { - MarkerEntry[] old = model.getMarkerEntryArray(); - MarkerCategory[] oldCategories = model.getCategories(); - Integer[] oldCounts = model.getMarkerCounts(); - int[] counts4 = { oldCounts[0].intValue(), oldCounts[1].intValue(), oldCounts[2].intValue(), - oldCounts[3].intValue() }; - // one pass: which old positions leave (removed or changed markers) - M3LongSet changedIds = new M3LongSet(changes.size()); - for (Change c : changes) { - changedIds.add(c.id); - } - boolean[] leaving = new boolean[old.length]; - int left = 0; - for (int i = 0; i < old.length; i++) { - IMarker marker = old[i].getMarker(); - if (marker != null && changedIds.contains(marker.getId())) { - leaving[i] = true; - left++; - } - } - for (Change c : changes) { - if (c.oldSeverity != -2 && c.kind != IResourceDelta.ADDED) { - // counted before only when it was in the view; the scan above found it there - if (wasShown(old, leaving, c.id)) { - counts4[countIndex(c.oldSeverity)]--; - } - } - if (c.entry != null) { - Object severity = c.entry.getAttributeValue(IMarker.SEVERITY); - counts4[countIndex(severity instanceof Integer s ? s.intValue() : -1)]++; - } + /* what UIUpdateJob does after its refresh, and the title */ + private static void finishPatch(ExtendedMarkersView view, M3MarkerLanes lanes) { + // UIUpdateJob: with no saved state, a single category is recorded for expansion + if (view.getBuilder().isShowingHierarchy() && view.getCategoriesToExpand().isEmpty()) { + M3MarkerCategory[] categories = lanes.categories(); + if (categories.length == 1) { + view.getCategoriesToExpand().add(categories[0].getDescription()); } - // group the arriving entries by category name, each group sorted - Comparator order = builder.getComparator().getFieldsComparator(); - List names = new ArrayList<>(); - List> arriving = new ArrayList<>(); - List keys = new ArrayList<>(); - for (Change c : changes) { - if (c.entry == null) { - continue; - } - int at = names.indexOf(c.category); - if (at < 0) { - names.add(c.category); - keys.add(c.key); - arriving.add(new ArrayList<>()); - at = names.size() - 1; - } - arriving.get(at).add(c.entry); - } - for (List list : arriving) { - list.sort(order); - } - // category order: existing categories keep their order; new ones go by the group comparator - MarkerGroup group = builder.getCategoryGroup(); - Comparator categoryOrder = group.getEntriesComparator(); - List orderNames = new ArrayList<>(); - List orderKeys = new ArrayList<>(); - for (MarkerCategory category : oldCategories) { - orderNames.add(category.getName()); - orderKeys.add(keyOf(old, category, leaving, keys, names)); - } - for (int i = 0; i < names.size(); i++) { - if (!orderNames.contains(names.get(i))) { - MarkerGroupingEntry key = keys.get(i); - int at = 0; - while (at < orderKeys.size() && orderKeys.get(at) != null - && categoryOrder.compare(orderKeys.get(at), key) <= 0) { - at++; - } - orderNames.add(at, names.get(i)); - orderKeys.add(at, key); - } - } - int total = old.length - left; - for (List list : arriving) { - total += list.size(); - } - entries = new MarkerEntry[total]; - List made = new ArrayList<>(); - int out = 0; - for (String name : orderNames) { - MarkerCategory before = categoryNamed(oldCategories, name); - int at = names.indexOf(name); - List in = at < 0 ? List.of() : arriving.get(at); - int start = out; - int i = before == null ? 0 : before.start; - int end = before == null ? -1 : before.end; - int j = 0; - while (i <= end || j < in.size()) { - while (i <= end && leaving[i]) { - i++; - } - if (i > end) { - while (j < in.size()) { - entries[out++] = in.get(j++); - } - break; - } - if (j < in.size() && order.compare(in.get(j), old[i]) < 0) { - entries[out++] = in.get(j++); - } else { - entries[out++] = old[i++]; - } - } - if (out > start) { - made.add(new MarkerCategory(model, start, out - 1, name)); - } - } - if (out != total) { - return false; - } - categories = made.toArray(new MarkerCategory[0]); - counts = new Integer[] { Integer.valueOf(counts4[0]), Integer.valueOf(counts4[1]), - Integer.valueOf(counts4[2]), Integer.valueOf(counts4[3]) }; - return true; - } - - private boolean wasShown(MarkerEntry[] old, boolean[] leaving, long id) { - for (int i = 0; i < old.length; i++) { - if (leaving[i] && old[i].getMarker() != null && old[i].getMarker().getId() == id) { - return true; - } - } - return false; } + view.reexpandCategories(); + view.updateTitle(); + view.updateStatusLine(view.getViewer().getStructuredSelection()); + } - /* the grouping key of an existing category, from an entry that stays (its attributes are unchanged) */ - private MarkerGroupingEntry keyOf(MarkerEntry[] old, MarkerCategory category, boolean[] leaving, - List keys, List names) { - int at = names.indexOf(category.getName()); - if (at >= 0) { - return keys.get(at); - } - for (int i = category.start; i <= category.end; i++) { - IMarker marker = old[i].getMarker(); - if (!leaving[i] && marker != null) { - try { - return builder.getCategoryGroup().findGroupValue(marker.getType(), marker); - } catch (CoreException e) { - return null; - } - } + /* the coalesced dirty window of a hidden view: O(changed) ids and the touched categories */ + private M3MarkerLanes hiddenLanes; + private List hiddenTouched; + private M3LongSet hiddenChanged; + private M3PartVisibility visibility; + + private void hide(M3MarkerLanes lanes, List touched, M3LongSet changed) { + if (hiddenLanes != lanes) { + hiddenLanes = lanes; + hiddenTouched = new ArrayList<>(); + hiddenChanged = new M3LongSet(64); + } + for (M3MarkerLanes.Category c : touched) { + if (!hiddenTouched.contains(c)) { + hiddenTouched.add(c); } - return null; } + changed.forEach(hiddenChanged::add); } - /** Severity to the index of {@link Markers#getMarkerCounts()}: errors, warnings, infos, others. */ - static int countIndex(int severity) { - return switch (severity) { - case IMarker.SEVERITY_ERROR -> 0; - case IMarker.SEVERITY_WARNING -> 1; - case IMarker.SEVERITY_INFO -> 2; - default -> 3; - }; + /* the view shows again: one window patch against the current lanes */ + private void shown(ExtendedMarkersView view) { + M3MarkerLanes lanes = hiddenLanes; + List touched = hiddenTouched; + M3LongSet changed = hiddenChanged; + hiddenLanes = null; + hiddenTouched = null; + hiddenChanged = null; + if (lanes == null || view.isDisposed() || builder.getMarkers().m3 != lanes + || view.getActiveViewerInputClone().m3 != lanes) { + return; // nothing hidden, or a clean rebuild replaced the lanes: its UI update refreshes the tree + } + count(SHOWN); + patchTree(view, lanes, touched, changed); + finishPatch(view, lanes); } - private static MarkerCategory categoryNamed(MarkerCategory[] categories, String name) { - for (MarkerCategory category : categories) { - if (category.getName().equals(name)) { - return category; - } + /** + * @param view a markers view + * @return the number of window patches applied on show after a hidden + * period with changes (tests and the bench), or -1 when the view is + * not watched + */ + static int hiddenPatches(ExtendedMarkersView view) { + synchronized (BY_BUILDER) { + M3MarkerDeltas deltas = BY_BUILDER.get(view.getBuilder()); + return deltas == null || deltas.visibility == null ? -1 : deltas.visibility.patches(); } - return null; } - /* the tree patch: categories added/removed; per expanded category only the rows of its shown window */ - private void patchTree(ExtendedMarkersView view, MarkerCategory[] oldCategories, MarkerCategory[] newCategories, - List changes) { + /* the tree patch: categories removed and added; per touched category its label and the rows of its window */ + private static void patchTree(ExtendedMarkersView view, M3MarkerLanes lanes, + List touched, M3LongSet changed) { TreeViewer viewer = view.getViewer(); Object input = viewer.getInput(); - M3LongSet changed = new M3LongSet(changes.size()); - for (Change c : changes) { - changed.add(c.id); + M3ViewerDelta delta = new M3ViewerDelta(); + if (lanes.isFlat()) { + M3MarkerLanes.Category flat = lanes.flatCategory(); + if (flat != null) { + patchRows(delta, lanes, flat, input, viewer.getTree().getItems(), limit(view), changed); + } + if (!delta.isEmpty()) { + ((MarkersTreeViewer) viewer).m3PreservingSelection(() -> M3Viewers.apply(viewer, delta)); + } + return; } - for (MarkerCategory before : oldCategories) { - if (categoryNamed(newCategories, before.getName()) == null) { - viewer.remove(before); + for (M3MarkerLanes.Category c : touched) { + if (lanes.indexOf(c) < 0 && viewer.testFindItem(c.facade) != null) { + delta.remove(c.facade); } } - int limit = view.getGenerator().isMarkerLimitsEnabled() ? view.getGenerator().getMarkerLimits() : -1; - for (int c = 0; c < newCategories.length; c++) { - MarkerCategory category = newCategories[c]; - MarkerCategory before = categoryNamed(oldCategories, category.getName()); - if (before == null) { - viewer.insert(input, category, c); + M3MarkerCategory[] categories = lanes.categories(); + List expand = new ArrayList<>(); + for (int i = 0; i < categories.length; i++) { + M3MarkerCategory category = categories[i]; + if (contains(touched, category) && viewer.testFindItem(category) == null) { + delta.add(input, category, i); if (view.getCategoriesToExpand().contains(category.getName())) { - viewer.setExpandedState(category, true); + expand.add(category); } - continue; } - viewer.update(category, null); - Widget widget = viewer.testFindItem(category); - if (!(widget instanceof TreeItem item) || !item.getExpanded()) { + } + int limit = limit(view); + for (M3MarkerLanes.Category c : touched) { + if (lanes.indexOf(c) < 0) { continue; } - patchWindow(viewer, category, item, limit, changed); + Widget widget = viewer.testFindItem(c.facade); + if (widget instanceof TreeItem item) { + delta.update(c.facade, null); + patchWindow(delta, lanes, c, item, limit, changed); + } + } + if (delta.isEmpty()) { + return; + } + ((MarkersTreeViewer) viewer).m3PreservingSelection(() -> M3Viewers.apply(viewer, delta)); + for (M3MarkerCategory category : expand) { + viewer.setExpandedState(category, true); } } - /* rows of one expanded category: remove rows that left the window, insert rows that entered it */ - private static void patchWindow(TreeViewer viewer, MarkerCategory category, TreeItem item, int limit, - M3LongSet changed) { - MarkerSupportItem[] all = category.getChildren(); - int shown = limit > 0 ? Math.min(limit, all.length) : all.length; - M3LongSet next = new M3LongSet(shown); - for (int i = 0; i < shown; i++) { - IMarker marker = ((MarkerEntry) all[i]).getMarker(); - if (marker != null) { - next.add(marker.getId()); + private static boolean contains(List touched, M3MarkerCategory category) { + for (M3MarkerLanes.Category c : touched) { + if (c.facade == category) { + return true; } } - List gone = new ArrayList<>(); - M3LongSet kept = new M3LongSet(shown); - for (Item child : item.getItems()) { - if (child.getData() instanceof MarkerEntry entry && entry.getMarker() != null) { + return false; + } + + /** + * MarkerViewerContentProvider.getLimitedChildren: the marker limit. + * + * @param view the view + * @return the limit, or -1 for none + */ + static int limit(ExtendedMarkersView view) { + MarkerContentGenerator generator = view.getGenerator(); + int limit = generator.getMarkerLimits(); + return generator.isMarkerLimitsEnabled() && limit > 0 ? limit : -1; + } + + /* + * Rows of one category whose items exist (expanded once): rows that left the + * window or changed are removed, rows that entered it (or changed) are inserted + * at their window index, in increasing order. + */ + private static void patchWindow(M3ViewerDelta delta, M3MarkerLanes lanes, M3MarkerLanes.Category c, + TreeItem item, int limit, M3LongSet changed) { + Item[] rows = item.getItems(); + if (rows.length == 0 || rows.length == 1 && rows[0].getData() == null) { + return; // never expanded: the content provider gives the window on expansion + } + patchRows(delta, lanes, c, c.facade, rows, limit, changed); + } + + /* + * The rows under one parent (a category item, or the tree itself in the flat presentation) against the + * category's window: O(window), whatever the size of the category. + */ + private static void patchRows(M3ViewerDelta delta, M3MarkerLanes lanes, M3MarkerLanes.Category c, + Object parent, Item[] rows, int limit, M3LongSet changed) { + int[] next = lanes.windowSlots(c, limit); + M3LongSet nextIds = new M3LongSet(next.length); + for (int slot : next) { + nextIds.add(lanes.id(slot)); + } + M3LongSet kept = new M3LongSet(rows.length); + for (Item row : rows) { + if (row.getData() instanceof MarkerEntry entry && entry.getMarker() != null) { long id = entry.getMarker().getId(); - if (changed.contains(id) || !next.contains(id)) { - gone.add(entry); + if (changed.contains(id) || !nextIds.contains(id)) { + delta.remove(entry); + int slot = lanes.find(id); + if (slot >= 0 && !nextIds.contains(id)) { + lanes.releaseFacade(slot); + } } else { kept.add(id); } } } - if (!gone.isEmpty()) { - viewer.remove(gone.toArray()); - } - for (int i = 0; i < shown; i++) { - MarkerEntry entry = (MarkerEntry) all[i]; - if (entry.getMarker() == null || !kept.contains(entry.getMarker().getId())) { - viewer.insert(category, entry, i); + for (int j = 0; j < next.length; j++) { + if (!kept.contains(lanes.id(next[j]))) { + delta.add(parent, lanes.facade(next[j]), j); } } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerKeys.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerKeys.java new file mode 100644 index 00000000000..e797c974de9 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerKeys.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.osgi.util.NLS; +import org.eclipse.osgi.util.TextProcessor; +import org.eclipse.ui.views.markers.MarkerField; +import org.eclipse.ui.views.markers.MarkerViewUtil; +import org.eclipse.ui.views.markers.internal.MarkerMessages; +import org.eclipse.ui.views.markers.internal.MarkerType; +import org.eclipse.ui.views.markers.internal.MarkerTypesModel; + +/** + * The sort keys of one marker, read with one attribute lookup + * ({@link IMarker#getAttributes(String[])}: one element-tree lookup, where a + * {@link MarkerEntry} pays one per attribute, ui#4404), and the field kinds the + * lane comparator knows. + *

+ * Every key equals what the stock field reads through a {@link MarkerEntry}: + *

+ *
    + *
  • severity: {@code getAttributeValue(SEVERITY, -1)} + * (MarkerSupportInternalUtilities.getSeverity);
  • + *
  • message: {@code getAttributeValue(MESSAGE, Unknown)}, compared by + * collation key (MarkerDescriptionField);
  • + *
  • resource: {@code TextProcessor.process(NAME_ATTRIBUTE or resource name)} + * (MarkerResourceField);
  • + *
  • path: the container path of the resource (MarkerEntry.computePath);
  • + *
  • location and line (MarkerLocationField), id (MarkerIDField), creation + * time (MarkerCreationTimeField), type label (MarkerTypeField).
  • + *
+ */ +final class M3MarkerKeys { + + /** Field kind: a field the lanes cannot answer; the lane model is not used. */ + static final byte UNKNOWN = 0; + /** Field kind: severity descending, then description (both severity-and-description fields). */ + static final byte SEVERITY_DESCRIPTION = 1; + /** Field kind: description. */ + static final byte DESCRIPTION = 2; + /** Field kind: resource name. */ + static final byte RESOURCE = 3; + /** Field kind: container path. */ + static final byte PATH = 4; + /** Field kind: location, then line. */ + static final byte LOCATION = 5; + /** Field kind: marker id. */ + static final byte ID = 6; + /** Field kind: creation time. */ + static final byte CREATED = 7; + /** Field kind: marker type label. */ + static final byte TYPE = 8; + + private static final String[] ATTRIBUTES = { IMarker.SEVERITY, IMarker.MESSAGE, IMarker.LOCATION, + IMarker.LINE_NUMBER, MarkerViewUtil.NAME_ATTRIBUTE }; + + long id; + int severity; + String message; + String location; + int line; + String resource; + String path; + long created; + String type; + + private M3MarkerKeys() { + } + + /** + * @param field a sort field of the view + * @return its kind; {@link #UNKNOWN} for a field whose compare the lanes do + * not reproduce (any class other than these exact ones) + */ + static byte kindOf(MarkerField field) { + Class c = field.getClass(); + if (c == MarkerProblemSeverityAndMessageField.class || c == MarkerSeverityAndDescriptionField.class) { + return SEVERITY_DESCRIPTION; + } + if (c == MarkerDescriptionField.class) { + return DESCRIPTION; + } + if (c == MarkerResourceField.class) { + return RESOURCE; + } + if (c == MarkerPathField.class) { + return PATH; + } + if (c == MarkerLocationField.class) { + return LOCATION; + } + if (c == MarkerIDField.class) { + return ID; + } + if (c == MarkerCreationTimeField.class) { + return CREATED; + } + if (c == MarkerTypeField.class) { + return TYPE; + } + return UNKNOWN; + } + + /** + * Reads the keys of a marker. + * + * @param marker the marker + * @param needType whether the type label is needed (a TYPE sort field) + * @param into the keys to fill (a clean rebuild reuses one), or {@code null} for new keys + * @return its keys + * @throws CoreException when the marker no longer exists + */ + static M3MarkerKeys read(IMarker marker, boolean needType, M3MarkerKeys into) throws CoreException { + M3MarkerKeys k = into != null ? into : new M3MarkerKeys(); + Object[] v = marker.getAttributes(ATTRIBUTES); + IResource resource = marker.getResource(); + k.id = marker.getId(); + k.severity = v[0] instanceof Integer i ? i.intValue() : -1; + k.message = v[1] == null ? MarkerSupportInternalUtilities.UNKNOWN_ATRRIBTE_VALUE_STRING : v[1].toString(); + k.location = v[2] == null ? MarkerItemDefaults.LOCATION_DEFAULT : v[2].toString(); + k.line = v[3] instanceof Integer i ? i.intValue() : -1; + k.resource = TextProcessor.process(v[4] == null ? resource.getName() : v[4].toString()); + k.path = path(resource); + k.created = marker.getCreationTime(); + k.type = needType ? typeLabel(marker) : null; + return k; + } + + /* MarkerEntry.getMarkerTypeName */ + private static String typeLabel(IMarker marker) throws CoreException { + MarkerType type = MarkerTypesModel.getInstance().getType(marker.getType()); + return type == null ? NLS.bind(MarkerMessages.FieldMessage_WrongType, marker.toString()) : type.getLabel(); + } + + /* MarkerEntry.getPath(IResource) */ + private static String path(IResource resource) { + IPath full = resource.getFullPath(); + if (full.segmentCount() - 1 <= 0) { + return MarkerItemDefaults.PATH_DEFAULT; + } + return full.removeLastSegments(1).removeTrailingSeparator().toString(); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerLanes.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerLanes.java new file mode 100644 index 00000000000..ba30b658e34 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerLanes.java @@ -0,0 +1,902 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import java.text.Collator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.ui.views.markers.MarkerField; +import org.eclipse.ui.views.markers.MarkerItem; +import org.eclipse.ui.views.markers.internal.MarkerGroup; +import org.eclipse.ui.views.markers.internal.MarkerGroupingEntry; + +/** + * The one model of a markers view in M3 mode: every shown marker is a slot in + * a set of lanes (id, marker handle, severity, interned message, location, + * resource name and path, line, creation time, category). Each category keeps + * its slots in sort order ({@link M3SlotOrder}); counts per severity are lane + * counters. A {@link MarkerEntry} exists only for a slot an API asks for (the + * rows the viewer shows, a selection, Quick Fix) and is parent-owned by its + * category. + *

+ * Built once by a clean rebuild (first input, filter, grouping or sort + * changes), then patched by marker deltas on the UI thread + * ({@link #apply(List)}). Design: {@code docs/m3/markers-view/DESIGN.md} and + * {@code FALLBACKS_TO_DELTAS.md}. + *

+ */ +final class M3MarkerLanes { + + /** + * One prepared change: a marker leaves the view ({@code keys == null}) or is + * (re)placed with its keys and grouping. A clean rebuild reuses one instance + * for every marker. + */ + static final class Change { + long id; + IMarker marker; + M3MarkerKeys keys; + MarkerGroupingEntry group; + /** The entry the filters saw; it names a category the first time one is needed. */ + MarkerItem item; + /** Whether the view's search text keeps the row (true without a search text). */ + boolean textHit = true; + /** The lanes' text generation the hit was computed for. */ + int textGeneration; + + Change set(long markerId, IMarker m, M3MarkerKeys k, MarkerGroupingEntry g, MarkerItem i) { + id = markerId; + marker = m; + keys = k; + group = g; + item = i; + textHit = true; + textGeneration = 0; + return this; + } + } + + /** One category: its grouping key, its slots in order, its counters and its facade. */ + static final class Category { + /** Stable id: the value of the category lane (positions shift, ids do not). */ + final int id; + final MarkerGroupingEntry key; + final M3MarkerCategory facade; + M3SlotOrder order; + /** Counts by severity bucket (errors, warnings, infos, others) and of severities above error. */ + final int[] buckets = new int[4]; + int aboveError; + /* slots collected by a clean rebuild, sorted once by finishBuild */ + int[] pending; + int pendingSize; + + Category(int id, MarkerGroupingEntry key, M3MarkerCategory facade, M3SlotOrder order) { + this.id = id; + this.key = key; + this.facade = facade; + this.order = order; + } + } + + private static final Collator COLLATOR = Collator.getInstance(); + + private final Markers owner; + private final Comparator categoryOrder; + private final MarkerField categoryField; + private final M3LabelTable labels = new M3LabelTable(COLLATOR); + private byte[] kinds; + private boolean[] descending; + private boolean needType; + + /* lanes, by slot */ + private byte[] state = new byte[64]; + private long[] ids = new long[64]; + private IMarker[] markers = new IMarker[64]; + private int[] category = new int[64]; + private int[] severity = new int[64]; + private int[] message = new int[64]; + private int[] location = new int[64]; + private int[] line = new int[64]; + private int[] resource = new int[64]; + private int[] path = new int[64]; + private long[] created = new long[64]; + private int[] type = new int[64]; + private MarkerEntry[] facades = new MarkerEntry[64]; + /* the view's search text (MarkerPatternFilter): one hit bit per slot, meaningful while textFilter != null */ + private long[] textHits = new long[1]; + private MarkerPatternFilter textFilter; + private int textGeneration; + private int slots; + private int[] free = new int[16]; + private int freeCount; + private int live; + /* marker id -> slot + 1, open addressing */ + private int[] table = new int[128]; + + private final List categories = new ArrayList<>(); + private Category[] byId = new Category[8]; + private int nextCategoryId; + private M3MarkerCategory[] categoryArray; + private final int[] counts = new int[4]; + private Integer[] countsArray; + private int generation; + + private M3MarkerLanes(Markers owner, Comparator categoryOrder, MarkerField categoryField) { + this.owner = owner; + this.categoryOrder = categoryOrder; + this.categoryField = categoryField; + } + + /** + * @param owner the model of the view + * @param comparator the view's sort + * @return an empty lane model, or {@code null} when the view uses a field + * or a presentation the lanes do not answer (flat presentation, a + * field of another class): the stock model is used then + */ + static M3MarkerLanes create(Markers owner, MarkerComparator comparator) { + CachedMarkerBuilder builder = owner.getBuilder(); + if (!M3MarkerDeltas.ENABLED) { + return null; + } + MarkerGroup group = builder.getCategoryGroup(); + // flat presentation (no grouping): one implicit category without a tree item (FALLBACKS_TO_DELTAS.md) + M3MarkerLanes lanes = group == null ? new M3MarkerLanes(owner, null, null) + : new M3MarkerLanes(owner, group.getEntriesComparator(), group.getMarkerField()); + return lanes.compile(comparator) ? lanes : null; + } + + /** @return whether the view is flat: the rows are the tree's top-level items */ + boolean isFlat() { + return categoryOrder == null; + } + + /** @return the implicit category of the flat presentation, or {@code null} before the first row */ + Category flatCategory() { + return categories.isEmpty() ? null : categories.get(0); + } + + /** + * The shown rows of the flat presentation. + * + * @param limit the marker limit, or a negative value for none + * @return the entries of the window, in order + */ + MarkerEntry[] flatWindow(int limit) { + Category c = flatCategory(); + return c == null ? new MarkerEntry[0] : window(c, limit); + } + + /** + * Markers.getElements: the categories, or every row of the flat presentation + * (an API asks for all of them). + * + * @return the elements + */ + MarkerSupportItem[] elements() { + if (!isFlat()) { + return categories(); + } + Category c = flatCategory(); + return c == null ? new MarkerEntry[0] : children(c); + } + + /* the comparator's fields as lane kinds; false when one is unknown */ + private boolean compile(MarkerComparator comparator) { + MarkerField[] fields = comparator.getFields(); + byte[] k = new byte[fields.length]; + boolean[] d = new boolean[fields.length]; + boolean type = false; + for (int i = 0; i < fields.length; i++) { + k[i] = M3MarkerKeys.kindOf(fields[i]); + if (k[i] == M3MarkerKeys.UNKNOWN) { + return false; + } + type |= k[i] == M3MarkerKeys.TYPE; + d[i] = comparator.descendingFields.contains(fields[i]); + } + kinds = k; + descending = d; + needType = type; + return true; + } + + /** @return whether the sort keys include the type label */ + boolean needsType() { + return needType; + } + + /* ---------------------------------------------------------------- build */ + + /** + * Adds a marker during a clean rebuild; {@link #finishBuild()} sorts. + * + * @param change the marker, its keys and category + */ + void add(Change change) { + if (find(change.id) >= 0) { + return; // the same marker found through two scopes + } + int slot = allocate(change.id); + write(slot, change); + Category c = categoryFor(change); + category[slot] = c.id; + count(slot, c, 1); + if (c.pending == null) { + c.pending = new int[64]; + } else if (c.pendingSize == c.pending.length) { + c.pending = Arrays.copyOf(c.pending, c.pendingSize << 1); + } + c.pending[c.pendingSize++] = slot; + } + + /** Sorts every category once, at the end of a clean rebuild. */ + void finishBuild() { + M3SlotOrder.SlotComparator order = comparator(kinds, descending); + for (Category c : categories) { + M3SlotOrder o = new M3SlotOrder(order); + if (c.pending != null) { + o.sortAndFill(c.pending, c.pendingSize); + } + c.pending = null; + c.pendingSize = 0; + c.order = o; + } + changed(); + } + + /** + * Sorts again with the view's current sort (the user changed it). Builds + * the new orders aside and swaps them in. + * + * @param comparator the view's sort + * @return {@code false} when the new sort uses a field the lanes do not + * answer + */ + synchronized boolean resort(MarkerComparator comparator) { + if (!compile(comparator)) { + return false; + } + M3SlotOrder.SlotComparator order = comparator(kinds, descending); + M3SlotOrder[] next = new M3SlotOrder[categories.size()]; + for (int i = 0; i < next.length; i++) { + M3SlotOrder old = categories.get(i).order; + int[] members = new int[Math.max(1, old.size())]; + int n = old.head(old.size(), members); + next[i] = new M3SlotOrder(order); + next[i].sortAndFill(members, n); + } + for (int i = 0; i < next.length; i++) { + categories.get(i).order = next[i]; + } + Arrays.fill(facades, null); + changed(); + return true; + } + + /* ---------------------------------------------------------------- delta */ + + /** + * Applies prepared changes on the UI thread. + * + * @param changes the changes, merged per marker + * @return the categories that were touched, created or emptied (an emptied + * category has an empty order and is no longer in + * {@link #categories()}) + */ + synchronized List apply(List changes) { + List touched = new ArrayList<>(); + for (Change change : changes) { + int slot = find(change.id); + if (slot >= 0) { + Category before = byId[category[slot]]; + before.order.remove(slot); + count(slot, before, -1); + mark(touched, before); + release(slot); + if (change.keys == null) { + freeSlot(slot); + continue; + } + } else if (change.keys == null) { + continue; + } else { + slot = allocate(change.id); + } + write(slot, change); + Category c = categoryFor(change); + category[slot] = c.id; + c.order.insert(slot); + count(slot, c, 1); + mark(touched, c); + } + dropEmpty(); + changed(); + return touched; + } + + private static void mark(List touched, Category c) { + for (Category t : touched) { + if (t == c) { + return; + } + } + touched.add(c); + } + + /* remove categories that lost their last slot */ + private void dropEmpty() { + if (isFlat()) { + return; // the implicit category stays, empty or not + } + for (int i = categories.size() - 1; i >= 0; i--) { + Category c = categories.get(i); + if (c.order.size() == 0) { + categories.remove(i); + byId[c.id] = null; + } + } + } + + /* the category of a change: found by the group's comparator (TreeMap equality), else created in order */ + private Category categoryFor(Change change) { + if (isFlat()) { + return categories.isEmpty() ? newCategory(0, null, null) : categories.get(0); + } + int lo = 0; + int hi = categories.size() - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = categoryOrder.compare(categories.get(mid).key, change.group); + if (c < 0) { + lo = mid + 1; + } else if (c > 0) { + hi = mid - 1; + } else { + return categories.get(mid); + } + } + // stock names a category after its first entry (Markers.groupIntoCategories) + return newCategory(lo, change.group, categoryField.getValue(change.item)); + } + + /* a category at position lo; the flat presentation's implicit category has no facade (rows have no parent) */ + private Category newCategory(int lo, MarkerGroupingEntry key, String name) { + int id = nextCategoryId++; + M3MarkerCategory facade = name == null ? null : new M3MarkerCategory(owner, this, name); + Category created = new Category(id, key, facade, new M3SlotOrder(comparator(kinds, descending))); + if (facade != null) { + facade.lane = created; + } + categories.add(lo, created); + if (id == byId.length) { + byId = Arrays.copyOf(byId, id << 1); + } + byId[id] = created; + return created; + } + + /* ---------------------------------------------------------------- lanes */ + + private int allocate(long id) { + int slot; + if (freeCount > 0) { + slot = free[--freeCount]; + } else { + slot = slots++; + if (slot == ids.length) { + grow(slot << 1); + } + } + ids[slot] = id; + state[slot] = 1; + live++; + if (live << 1 > table.length) { + rehash(table.length << 1); + } else { + put(id, slot); + } + return slot; + } + + private void freeSlot(int slot) { + unput(ids[slot]); + state[slot] = 0; + markers[slot] = null; + category[slot] = -1; + live--; + if (freeCount == free.length) { + free = Arrays.copyOf(free, freeCount << 1); + } + free[freeCount++] = slot; + } + + private void write(int slot, Change change) { + M3MarkerKeys k = change.keys; + markers[slot] = change.marker; + severity[slot] = k.severity; + message[slot] = labels.acquire(k.message); + location[slot] = labels.acquire(k.location); + line[slot] = k.line; + resource[slot] = labels.acquire(k.resource); + path[slot] = labels.acquire(k.path); + created[slot] = k.created; + type[slot] = k.type == null ? -1 : labels.acquire(k.type); + setTextHit(slot, change.textHit); + facades[slot] = null; + } + + /* the labels of a slot that leaves or changes */ + private void release(int slot) { + labels.release(message[slot]); + labels.release(location[slot]); + labels.release(resource[slot]); + labels.release(path[slot]); + if (type[slot] >= 0) { + labels.release(type[slot]); + } + facades[slot] = null; + } + + private void count(int slot, Category c, int delta) { + int b = bucket(severity[slot]); + counts[b] += delta; + c.buckets[b] += delta; + if (severity[slot] > IMarker.SEVERITY_ERROR) { + c.aboveError += delta; + } + } + + /** Severity to the index of {@link Markers#getMarkerCounts()}: errors, warnings, infos, others. */ + static int bucket(int severity) { + return switch (severity) { + case IMarker.SEVERITY_ERROR -> 0; + case IMarker.SEVERITY_WARNING -> 1; + case IMarker.SEVERITY_INFO -> 2; + default -> 3; + }; + } + + private void grow(int capacity) { + state = Arrays.copyOf(state, capacity); + ids = Arrays.copyOf(ids, capacity); + markers = Arrays.copyOf(markers, capacity); + category = Arrays.copyOf(category, capacity); + severity = Arrays.copyOf(severity, capacity); + message = Arrays.copyOf(message, capacity); + location = Arrays.copyOf(location, capacity); + line = Arrays.copyOf(line, capacity); + resource = Arrays.copyOf(resource, capacity); + path = Arrays.copyOf(path, capacity); + created = Arrays.copyOf(created, capacity); + type = Arrays.copyOf(type, capacity); + facades = Arrays.copyOf(facades, capacity); + } + + /* id table */ + + /** + * @param id a marker id + * @return its slot, or -1 + */ + int find(long id) { + int mask = table.length - 1; + for (int i = hash(id) & mask; table[i] != 0; i = (i + 1) & mask) { + if (ids[table[i] - 1] == id) { + return table[i] - 1; + } + } + return -1; + } + + private void put(long id, int slot) { + int mask = table.length - 1; + int i = hash(id) & mask; + while (table[i] != 0) { + i = (i + 1) & mask; + } + table[i] = slot + 1; + } + + private void unput(long id) { + int mask = table.length - 1; + int i = hash(id) & mask; + while (ids[table[i] - 1] != id) { + i = (i + 1) & mask; + } + table[i] = 0; + for (int j = (i + 1) & mask; table[j] != 0; j = (j + 1) & mask) { + int slot = table[j] - 1; + table[j] = 0; + put(ids[slot], slot); + } + } + + private void rehash(int capacity) { + table = new int[capacity]; + for (int s = 0; s < slots; s++) { + if (state[s] != 0) { + put(ids[s], s); + } + } + } + + private static int hash(long id) { + return (int) ((id ^ (id >>> 32)) * 0x9E3779B97F4A7C15L >>> 32); + } + + /* ---------------------------------------------------------------- order */ + + private M3SlotOrder.SlotComparator comparator(byte[] k, boolean[] d) { + return (a, b) -> compare(a, b, k, d); + } + + /* MarkerComparator.compareFields over the lanes; ties end by marker id, then slot (a total order) */ + private int compare(int a, int b, byte[] k, boolean[] d) { + if (a == b) { + return 0; + } + for (int i = 0; i < k.length; i++) { + int c = compareField(k[i], a, b); + if (c != 0) { + return d[i] ? -c : c; + } + } + int c = Long.compare(ids[a], ids[b]); + return c != 0 ? c : Integer.compare(a, b); + } + + private int compareField(byte kind, int a, int b) { + switch (kind) { + case M3MarkerKeys.SEVERITY_DESCRIPTION: + int c = Integer.compare(severity[b], severity[a]); + return c != 0 ? c : labels.collate(message[a], message[b]); + case M3MarkerKeys.DESCRIPTION: + return labels.collate(message[a], message[b]); + case M3MarkerKeys.RESOURCE: + return labels.compare(resource[a], resource[b]); + case M3MarkerKeys.PATH: + return labels.compare(path[a], path[b]); + case M3MarkerKeys.LOCATION: + String la = labels.text(location[a]); + String lb = labels.text(location[b]); + int e = Boolean.compare(la.isEmpty(), lb.isEmpty()); + if (e != 0) { + return e; + } + e = labels.compare(location[a], location[b]); + return e != 0 ? e : Integer.compare(line[a], line[b]); + case M3MarkerKeys.ID: + return Long.compare(ids[a], ids[b]); + case M3MarkerKeys.CREATED: + return Long.compare(created[a], created[b]); + case M3MarkerKeys.TYPE: + return labels.compare(type[a], type[b]); + default: + throw new IllegalStateException("unknown field kind " + kind); //$NON-NLS-1$ + } + } + + /* ---------------------------------------------------------------- answers */ + + private void changed() { + generation++; + categoryArray = null; + countsArray = null; + } + + /** @return the generation, increased by every change of the model */ + int generation() { + return generation; + } + + /** @return the categories in order (cached until the next change) */ + M3MarkerCategory[] categories() { + M3MarkerCategory[] a = categoryArray; + if (a == null) { + a = new M3MarkerCategory[isFlat() ? 0 : categories.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = categories.get(i).facade; + } + categoryArray = a; + } + return a; + } + + /** @return the counts: errors, warnings, infos, others (O(1), lane counters) */ + Integer[] counts() { + Integer[] a = countsArray; + if (a == null) { + a = new Integer[] { Integer.valueOf(counts[0]), Integer.valueOf(counts[1]), Integer.valueOf(counts[2]), + Integer.valueOf(counts[3]) }; + countsArray = a; + } + return a; + } + + /** @return the number of markers in the categories */ + int size() { + return live; + } + + /** + * A consistent snapshot of the shown marker ids (any thread; the UI thread + * applies changes under the same lock). + * + * @return the ids, sorted ascending + */ + synchronized long[] liveIds() { + long[] out = new long[live]; + int k = 0; + for (int s = 0; s < slots; s++) { + if (state[s] != 0) { + out[k++] = ids[s]; + } + } + Arrays.sort(out); + return out; + } + + /** @return the number of distinct labels (heap evidence) */ + int labelCount() { + return labels.size(); + } + + /** + * @param c a category + * @return its number of markers + */ + static int size(Category c) { + return c.order.size(); + } + + /** + * The facade of a slot, created on first request and kept while the slot + * stays in a shown window. + * + * @param slot a slot + * @return its entry + */ + MarkerEntry facade(int slot) { + MarkerEntry e = facades[slot]; + if (e == null) { + e = new MarkerEntry(markers[slot]); + e.setCategory(byId[category[slot]].facade); + facades[slot] = e; + } + return e; + } + + /** + * Drops the facade of a slot that left every shown window. + * + * @param slot a slot + */ + void releaseFacade(int slot) { + facades[slot] = null; + } + + /** + * The first rows of a category: the shown window. + * + * @param c a category + * @param limit the marker limit, or a negative value for none + * @return the entries of the window, in order + */ + MarkerEntry[] window(Category c, int limit) { + int[] head = windowSlots(c, limit); + MarkerEntry[] out = new MarkerEntry[head.length]; + for (int i = 0; i < head.length; i++) { + out[i] = facade(head[i]); + } + return out; + } + + /** + * The slots of a category's window. + * + * @param c a category + * @param limit the marker limit, or a negative value for none + * @return the slots, in order + */ + int[] windowSlots(Category c, int limit) { + int size = c.order.size(); + if (textFilter == null) { + int n = limit < 0 ? size : Math.min(limit, size); + int[] head = new int[n]; + c.order.head(n, head); + return head; + } + // a search text: the matching rows first, then the limit (MarkerViewerContentProvider.getLimitedChildren) + int max = limit < 0 ? size : Math.min(limit, size); + int[] head = new int[max]; + int n = 0; + for (int i = 0; i < size && n < max; i++) { + int slot = c.order.get(i); + if (textHit(slot)) { + head[n++] = slot; + } + } + return n == max ? head : Arrays.copyOf(head, n); + } + + /** + * The search text of the view as a lane: a hit bit per slot. Called on the + * UI thread when the text changes (MarkerPatternFilter.setPattern, before + * the viewer refresh that follows typing) and by a clean rebuild after + * {@link #finishBuild()}. + * + * @param filter the active search filter, or {@code null} for none + */ + void applyText(MarkerPatternFilter filter) { + textGeneration++; + textFilter = filter; + if (filter == null) { + return; + } + for (int s = 0; s < slots; s++) { + if (state[s] != 0) { + MarkerEntry e = facades[s]; + if (e == null) { + e = new MarkerEntry(markers[s]); + e.setCategory(byId[category[s]].facade); + } + setTextHit(s, filter.matches(e)); + } + } + } + + /** The active search filter, or {@code null}. */ + MarkerPatternFilter textFilter() { + return textFilter; + } + + /** Increases on every {@link #applyText}. */ + int textGeneration() { + return textGeneration; + } + + /** Whether the search text keeps a slot; every slot without a search text. */ + boolean textHit(int slot) { + return textFilter == null || (textHits[slot >>> 6] & (1L << (slot & 63))) != 0; + } + + void setTextHit(int slot, boolean hit) { + int word = slot >>> 6; + if (word >= textHits.length) { + textHits = Arrays.copyOf(textHits, Math.max(word + 1, textHits.length << 1)); + } + if (hit) { + textHits[word] |= 1L << (slot & 63); + } else { + textHits[word] &= ~(1L << (slot & 63)); + } + } + + /** + * The rows of a category the search text keeps (all of them without a + * search text): what stock counts with MarkerPatternFilter over every child. + * + * @param c a category + * @return the matching row count + */ + int matching(Category c) { + int size = c.order.size(); + if (textFilter == null) { + return size; + } + int m = 0; + for (int i = 0; i < size; i++) { + if (textHit(c.order.get(i))) { + m++; + } + } + return m; + } + + /** + * Every row of a category (an API asks for all of them: selection of a + * category, copy, the search box). Facades of rows outside the windows are + * not kept. + * + * @param c a category + * @return the entries in order + */ + MarkerEntry[] children(Category c) { + int n = c.order.size(); + int[] all = new int[n]; + c.order.head(n, all); + MarkerEntry[] out = new MarkerEntry[n]; + for (int i = 0; i < n; i++) { + MarkerEntry e = facades[all[i]]; + if (e == null) { + e = new MarkerEntry(markers[all[i]]); + e.setCategory(c.facade); + } + out[i] = e; + } + return out; + } + + /** + * MarkerCategory.getHighestSeverity from the counters: the first child's + * order matters only when a severity above error exists, then the rows are + * scanned like stock does. + * + * @param c a category + * @return the highest severity, at least info + */ + int highestSeverity(Category c) { + if (c.aboveError == 0) { + if (c.buckets[0] > 0) { + return IMarker.SEVERITY_ERROR; + } + return c.buckets[1] > 0 ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_INFO; + } + int highest = 0; + int n = c.order.size(); + for (int i = 0; i < n; i++) { + int s = severity[c.order.get(i)]; + if (s > highest) { + highest = s; + } + if (highest == IMarker.SEVERITY_ERROR) { + return highest; + } + } + return highest; + } + + /** + * @param marker a marker + * @return its entry, or {@code null} when it is not shown + */ + MarkerEntry item(IMarker marker) { + int slot = find(marker.getId()); + if (slot < 0 || !marker.equals(markers[slot])) { + return null; + } + return facade(slot); + } + + /** + * @param id a marker id + * @return the marker of the slot that holds it, or {@code null} + */ + IMarker marker(long id) { + int slot = find(id); + return slot < 0 ? null : markers[slot]; + } + + /** + * @param slot a slot + * @return its marker id + */ + long id(int slot) { + return ids[slot]; + } + + /** + * @param c a category + * @return its index in {@link #categories()}, or -1 once dropped + */ + int indexOf(Category c) { + return categories.indexOf(c); + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3SlotOrder.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3SlotOrder.java new file mode 100644 index 00000000000..01e4526eb9c --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3SlotOrder.java @@ -0,0 +1,326 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.views.markers; + +import java.util.Arrays; + +/** + * The rows of one category in sort order: an order-statistic list of + * {@code int} slots kept as sorted blocks of at most {@link #BLOCK} slots. + *

+ * Insert and remove cost a binary search over the blocks, a binary search in + * one block and one {@code arraycopy} of at most {@link #BLOCK} ints, whatever + * the size of the category: a marker change never moves the other rows of a + * category of 10^6 markers. {@link #get(int)} and {@link #indexOf(int)} walk + * the block lengths (n / {@link #BLOCK} additions). Catalogue: order-statistic + * list over blocked sorted arrays (rule 21). + *

+ *

+ * The comparator must be a total order on the slots it is given: it returns 0 + * only for the same slot. Not thread-safe. + *

+ */ +public final class M3SlotOrder { + + /** Compares two slots by the lanes of the model that owns them. */ + @FunctionalInterface + public interface SlotComparator { + /** + * @param a a slot + * @param b a slot + * @return negative, zero (same slot only) or positive + */ + int compare(int a, int b); + } + + /** The longest block; a full block splits in two halves. */ + static final int BLOCK = 1024; + + private final SlotComparator order; + private int[][] blocks = new int[4][]; + private int[] lengths = new int[4]; + private int blockCount; + private int size; + + /** + * @param order the total order of the slots + */ + public M3SlotOrder(SlotComparator order) { + this.order = order; + } + + /** @return the number of slots */ + public int size() { + return size; + } + + /** + * @param index a position, 0 to {@code size() - 1} + * @return the slot at {@code index} + */ + public int get(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException(index); + } + int b = 0; + while (index >= lengths[b]) { + index -= lengths[b++]; + } + return blocks[b][index]; + } + + /** + * Copies the first slots in order. + * + * @param limit the most slots to copy + * @param out receives the slots; at least {@code min(limit, size())} long + * @return the number of slots copied + */ + public int head(int limit, int[] out) { + int n = Math.min(limit, size); + int copied = 0; + for (int b = 0; copied < n; b++) { + int take = Math.min(lengths[b], n - copied); + System.arraycopy(blocks[b], 0, out, copied, take); + copied += take; + } + return copied; + } + + /** + * @param slot a slot + * @return its position, or -1 when it is not in the list + */ + public int indexOf(int slot) { + int b = blockOf(slot); + if (b == blockCount) { + return -1; + } + int i = search(blocks[b], lengths[b], slot); + if (i < 0) { + return -1; + } + int index = i; + for (int k = 0; k < b; k++) { + index += lengths[k]; + } + return index; + } + + /** + * Inserts a slot at its sorted position. + * + * @param slot a slot that is not in the list + * @return its position + */ + public int insert(int slot) { + if (blockCount == 0) { + blocks[0] = new int[BLOCK]; + blocks[0][0] = slot; + lengths[0] = 1; + blockCount = 1; + size = 1; + return 0; + } + int b = blockOf(slot); + if (b == blockCount) { + b--; // after every slot: the end of the last block + } + int[] block = blocks[b]; + int i = search(block, lengths[b], slot); + if (i >= 0) { + throw new IllegalArgumentException("slot already present: " + slot); //$NON-NLS-1$ + } + i = -i - 1; + if (lengths[b] == BLOCK) { + split(b); + if (i > lengths[b]) { + i -= lengths[b]; + b++; + } + block = blocks[b]; + } + System.arraycopy(block, i, block, i + 1, lengths[b] - i); + block[i] = slot; + lengths[b]++; + size++; + int index = i; + for (int k = 0; k < b; k++) { + index += lengths[k]; + } + return index; + } + + /** + * Removes a slot. The lanes the comparator reads must still hold the values + * the slot was inserted with. + * + * @param slot a slot + * @return its former position, or -1 when it was not in the list + */ + public int remove(int slot) { + int b = blockOf(slot); + if (b == blockCount) { + return -1; + } + int[] block = blocks[b]; + int i = search(block, lengths[b], slot); + if (i < 0) { + return -1; + } + int index = i; + for (int k = 0; k < b; k++) { + index += lengths[k]; + } + System.arraycopy(block, i + 1, block, i, lengths[b] - i - 1); + lengths[b]--; + size--; + if (lengths[b] == 0) { + dropBlock(b); + } + return index; + } + + /** + * Replaces the contents with slots that are already sorted. + * + * @param sorted the slots in order + * @param n how many of them + */ + public void fill(int[] sorted, int n) { + int count = (n + BLOCK / 2 - 1) / (BLOCK / 2); + blocks = new int[Math.max(4, count)][]; + lengths = new int[blocks.length]; + blockCount = 0; + for (int from = 0; from < n; from += BLOCK / 2) { + int len = Math.min(BLOCK / 2, n - from); + int[] block = new int[BLOCK]; + System.arraycopy(sorted, from, block, 0, len); + blocks[blockCount] = block; + lengths[blockCount++] = len; + } + size = n; + } + + /** + * Sorts the slots with the comparator (a stable merge sort over {@code int}, + * no boxing) and replaces the contents with them. + * + * @param slots the slots; reordered in place + * @param n how many of them + */ + public void sortAndFill(int[] slots, int n) { + sort(slots, n, order); + fill(slots, n); + } + + /** + * Sorts {@code slots[0, n)} with {@code order}: a stable merge sort over + * {@code int} with one scratch array. + * + * @param slots the slots; reordered in place + * @param n how many of them + * @param order the order + */ + static void sort(int[] slots, int n, SlotComparator order) { + if (n < 2) { + return; + } + int[] scratch = new int[n]; + int[] from = slots; + int[] to = scratch; + for (int run = 1; run < n; run <<= 1) { + for (int lo = 0; lo < n; lo += run << 1) { + int mid = Math.min(lo + run, n); + int hi = Math.min(lo + (run << 1), n); + int i = lo; + int j = mid; + int k = lo; + while (i < mid && j < hi) { + to[k++] = order.compare(from[j], from[i]) < 0 ? from[j++] : from[i++]; + } + while (i < mid) { + to[k++] = from[i++]; + } + while (j < hi) { + to[k++] = from[j++]; + } + } + int[] t = from; + from = to; + to = t; + } + if (from != slots) { + System.arraycopy(from, 0, slots, 0, n); + } + } + + /* the first block whose last slot is not before slot; blockCount when slot sorts after all */ + private int blockOf(int slot) { + int lo = 0; + int hi = blockCount - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + if (order.compare(blocks[mid][lengths[mid] - 1], slot) < 0) { + lo = mid + 1; + } else { + hi = mid - 1; + } + } + return lo; + } + + /* binary search in one block: the index, or -(insertion point) - 1 */ + private int search(int[] block, int length, int slot) { + int lo = 0; + int hi = length - 1; + while (lo <= hi) { + int mid = (lo + hi) >>> 1; + int c = order.compare(block[mid], slot); + if (c < 0) { + lo = mid + 1; + } else if (c > 0) { + hi = mid - 1; + } else { + return mid; + } + } + return -lo - 1; + } + + private void split(int b) { + if (blockCount == blocks.length) { + blocks = Arrays.copyOf(blocks, blockCount << 1); + lengths = Arrays.copyOf(lengths, blockCount << 1); + } + System.arraycopy(blocks, b + 1, blocks, b + 2, blockCount - b - 1); + System.arraycopy(lengths, b + 1, lengths, b + 2, blockCount - b - 1); + int half = lengths[b] >>> 1; + int[] right = new int[BLOCK]; + System.arraycopy(blocks[b], half, right, 0, lengths[b] - half); + blocks[b + 1] = right; + lengths[b + 1] = lengths[b] - half; + lengths[b] = half; + blockCount++; + } + + private void dropBlock(int b) { + System.arraycopy(blocks, b + 1, blocks, b, blockCount - b - 1); + System.arraycopy(lengths, b + 1, lengths, b, blockCount - b - 1); + blockCount--; + blocks[blockCount] = null; + lengths[blockCount] = 0; + } +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java index 0d7777b1ca3..c7d71276736 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -132,6 +133,9 @@ CachedMarkerBuilder getBuilder() { * If attached to a builder, request marker update. */ void requestMarkerUpdate() { + if (builder != null && M3MarkerDeltas.scopeChanged(builder)) { + return; + } if (builder != null) { builder.scheduleUpdate(0L); } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java index 580225befd9..db570fd039f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerPatternFilter.java @@ -46,6 +46,8 @@ class MarkerPatternFilter extends PatternFilter { public void setPattern(String patternString) { this.patternString = patternString; super.setPattern(patternString); + // M3 mode: the search text is a lane of the view's model, recomputed before the refresh that follows + M3MarkerDeltas.textChanged(view, isFilterEmpty() ? null : this); } /** diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerViewerContentProvider.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerViewerContentProvider.java index c173096d129..54a10df2cb2 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerViewerContentProvider.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerViewerContentProvider.java @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) ******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -48,6 +49,10 @@ public void dispose() { @Override public Object[] getChildren(Object parentElement) { + if (parentElement instanceof M3MarkerCategory category) { + // the lanes answer with the search text applied before the limit (M3MarkerLanes.windowSlots) + return category.window(M3MarkerDeltas.limit(markersView)); + } if (parentElement instanceof MarkerSupportItem markerItem) { MarkerSupportItem[] children = markerItem.getChildren(); return getLimitedChildren(children); @@ -57,6 +62,9 @@ public Object[] getChildren(Object parentElement) { @Override public Object[] getElements(Object inputElement) { + if (inputElement instanceof Markers markers && markers.m3 != null && markers.m3.isFlat()) { + return markers.m3.flatWindow(M3MarkerDeltas.limit(markersView)); + } //use clone return getLimitedChildren(((Markers) input).getElements()); } @@ -120,6 +128,9 @@ public Object getParent(Object element) { @Override public boolean hasChildren(Object element) { + if (element instanceof M3MarkerCategory category) { + return category.getChildrenCount() > 0; + } return element instanceof MarkerSupportItem markerItem ? markerItem.getChildren().length > 0 : false; } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java index 535f3cc207c..35d2e4a4d77 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java @@ -11,7 +11,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Mickael Istria (Red Hat Inc.) - Bug 486901 - * Hitesh Soliwal (Synexia) - M3 marker delta path hooks (docs/m3/markers-view) + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) ******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -66,6 +66,12 @@ class Markers { this.builder = builder; } + /** + * The lane model in M3 mode (M3MarkerLanes, docs/m3/markers-view/PROBLEMS_VIEW.md); {@code null} while + * the entry array is the model. + */ + volatile M3MarkerLanes m3; + /** * Update with newly collected markers * @@ -84,6 +90,15 @@ synchronized boolean updateWithNewMarkers(Collection markerEntries, markerToEntryMap = null; } markerCounts = null; + if (M3MarkerDeltas.ENABLED) { + m3 = sortAndGroup ? M3MarkerDeltas.build(this, markerEntries, monitor) : null; + if (m3 != null) { + categories = m3.categories(); + markerEntryArray = EMPTY_ENTRY_ARRAY; + markerCounts = m3.counts(); + return !monitor.isCanceled(); + } + } if (markerEntries.isEmpty()) { categories = EMPTY_CATEGORY_ARRAY; markerEntryArray = EMPTY_ENTRY_ARRAY; @@ -142,6 +157,15 @@ private synchronized boolean sortAndMakeCategories(IProgressMonitor monitor) { } synchronized boolean sortMarkerEntries(IProgressMonitor monitor) { + M3MarkerLanes lanes = m3; + if (lanes != null) { + if (lanes.resort(builder.getComparator())) { + return true; + } + m3 = null; + builder.scheduleUpdate(); + return false; + } if (monitor.isCanceled()) { return false; } @@ -202,9 +226,6 @@ synchronized boolean sortMarkerEntries(IProgressMonitor monitor) { * get marker limit to show, if any. */ private int getShowingLimit(int available) { - if (M3MarkerDeltas.fullSort()) { - return available; - } boolean limitsEnabled = builder.getGenerator().isMarkerLimitsEnabled(); if(!limitsEnabled) { return available; @@ -296,6 +317,10 @@ private Map groupMarkerEntries(MarkerEntry[] entri * [errors,warnings,infos,others] */ Integer[] getMarkerCounts() { + M3MarkerLanes lanes = m3; + if (lanes != null) { + return lanes.counts(); + } if (markerCounts == null) { markerCounts = getMarkerCounts(markerEntryArray); } @@ -329,6 +354,10 @@ static Integer[] getMarkerCounts(MarkerEntry[] entries) { * @return {@link MarkerItem} */ public synchronized MarkerItem getMarkerItem(IMarker marker) { + M3MarkerLanes lanes = m3; + if (lanes != null) { + return lanes.item(marker); + } if (markerToEntryMap == null) { markerToEntryMap = new HashMap<>(); for (MarkerEntry markerEntry : markerEntryArray) { @@ -352,6 +381,10 @@ MarkerEntry[] getMarkerEntryArray() { * @return Returns the categories. */ MarkerCategory[] getCategories() { + M3MarkerLanes lanes = m3; + if (lanes != null) { + return lanes.categories(); + } return categories; } @@ -359,6 +392,10 @@ MarkerCategory[] getCategories() { * @return MarkerSupportItem[] */ public MarkerSupportItem[] getElements() { + M3MarkerLanes lanes = m3; + if (lanes != null) { + return lanes.elements(); + } if (builder.isShowingHierarchy()) { return categories; } @@ -372,26 +409,15 @@ CachedMarkerBuilder getBuilder() { return builder; } - /** - * Replaces the model in one step with the result of a marker delta patch - * (M3MarkerDeltas; docs/m3/markers-view/DESIGN.md). - * - * @param entries the entries, grouped by category - * @param newCategories the categories over {@code entries} - * @param counts the counts: errors, warnings, infos, others - */ - synchronized void m3Replace(MarkerEntry[] entries, MarkerCategory[] newCategories, Integer[] counts) { - markerEntryArray = entries; - categories = newCategories; - markerCounts = counts; - markerToEntryMap = null; - } - /** * Use clone where thread safety is concerned. The method is non-blocking. */ Markers getClone() { Markers markers = new Markers(builder); + markers.m3 = m3; + if (markers.m3 != null) { + return markers; + } if (!inChange) { markers.markerEntryArray = markerEntryArray.clone(); markers.categories = categories.clone(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersChangeListener.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersChangeListener.java index 873ef831c0f..5c6a63cbb0f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersChangeListener.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersChangeListener.java @@ -10,7 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Hitesh Soliwal (Synexia) - M3 marker delta path hooks (docs/m3/markers-view) + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) ******************************************************************************/ package org.eclipse.ui.internal.views.markers; diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersTreeViewer.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersTreeViewer.java index 0a1aa02e89b..70eaeb731d1 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersTreeViewer.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersTreeViewer.java @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Hitesh Soliwal (Synexia) - M3 lane model and marker delta hooks (docs/m3/markers-view) *******************************************************************************/ package org.eclipse.ui.internal.views.markers; @@ -57,6 +58,16 @@ public void removeAndClearAll() { unmapAllElements(); } + /** + * Runs a window patch of the lane model (M3MarkerDeltas) the way refresh does: the selection is kept, and + * selection listeners hear only of a selection that changed. + * + * @param patch the patch + */ + void m3PreservingSelection(Runnable patch) { + preservingSelection(patch); + } + @Override protected void doUpdateItem(Item item, Object element) { super.doUpdateItem(item, element); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ProblemsView.m3view b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ProblemsView.m3view new file mode 100644 index 00000000000..10f05a875be --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ProblemsView.m3view @@ -0,0 +1,15 @@ +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# View template spec of the Problems view (brief rule 27, docs/m3/view-template/VIEW_TEMPLATE.md). The lanes are those +# of M3MarkerLanes; the sort is the Problems view's default MarkerComparator (severity and description, resource, +# path, location, id, creation time). +view.id=org.eclipse.ui.views.ProblemView +element=IMarker +source=markers +lanes=id:long, severity:byte, message:label, resource:label, path:label, location:label, line:int, created:long, type:label, category:int +group=severity|type|none +sort=severity desc, message, resource, path, location, line, id, created +filters=scope, severity, type, text +counts=severity +presentation=tree|flat +label=MarkerColumnLabelProvider diff --git a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF index d78d2f6ab88..ebf00e4fd7e 100644 --- a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF @@ -58,6 +58,7 @@ Export-Package: org.eclipse.e4.ui.workbench.addons.perspectiveswitcher;x-interna org.eclipse.ui.internal.keys.model;x-internal:=true, org.eclipse.ui.internal.layout;x-friends:="org.eclipse.ui.intro", org.eclipse.ui.internal.menus;x-friends:="org.eclipse.ui", + org.eclipse.ui.internal.m3;x-internal:=true, org.eclipse.ui.internal.misc;x-friends:="org.eclipse.ui.ide", org.eclipse.ui.internal.model;x-internal:=true, org.eclipse.ui.internal.operations;x-internal:=true, diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/m3/M3PartVisibility.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/m3/M3PartVisibility.java new file mode 100644 index 00000000000..a5d6a5fccf9 --- /dev/null +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/m3/M3PartVisibility.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.m3; + +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; + +/** + * The hidden state of a view's viewport, driven by the workbench (brief rule + * 24, "Hidden viewports"): {@link IPartListener2#partHidden} hides it (behind + * another tab, in a minimized or inactive stack), {@link IPartListener2#partVisible} + * shows it. + *

+ * While the part is hidden, the view keeps applying model deltas to its lanes + * but does no tree work: it calls {@link #markDirty()} instead (O(1), the view + * keeps its own coalesced dirty window). When the part becomes visible again, + * the {@code onShown} callback runs once, inside the visibility event and + * before the first paint, so the view applies ONE window patch against the + * current model and the tree paints once. The one helper every view uses + * (docs/m3/markers-view/REFERENCE_TREE_VIEW.md). + *

+ * Must be created and used on the UI thread. + */ +public final class M3PartVisibility implements IPartListener2 { + + private final IWorkbenchPart part; + private final IWorkbenchPage page; + private final Runnable onShown; + private boolean hidden; + private boolean dirty; + private int patches; + + private M3PartVisibility(IWorkbenchPart part, Runnable onShown) { + this.part = part; + this.page = part.getSite().getPage(); + this.onShown = onShown; + this.hidden = !page.isPartVisible(part); + } + + /** + * Starts watching a part; the watch ends when the part closes. + * + * @param part the view + * @param onShown applies the view's one window patch; runs only when a + * change arrived while the part was hidden + * @return the watch + */ + public static M3PartVisibility watch(IWorkbenchPart part, Runnable onShown) { + M3PartVisibility watch = new M3PartVisibility(part, onShown); + watch.page.addPartListener(watch); + return watch; + } + + /** @return whether the part is hidden: deltas must not touch its tree */ + public boolean isHidden() { + return hidden; + } + + /** A delta changed the model while the part was hidden: patch once when it shows. */ + public void markDirty() { + dirty = true; + } + + /** @return whether a patch is pending for the next show */ + public boolean isDirty() { + return dirty; + } + + /** @return how many window patches ran on show (tests: one per hidden period with changes) */ + public int patches() { + return patches; + } + + /** Stops watching. */ + public void dispose() { + page.removePartListener(this); + } + + @Override + public void partHidden(IWorkbenchPartReference ref) { + if (ref.getPart(false) == part) { + hidden = true; + } + } + + @Override + public void partVisible(IWorkbenchPartReference ref) { + if (ref.getPart(false) != part) { + return; + } + hidden = false; + if (dirty) { + dirty = false; + patches++; + onShown.run(); + } + } + + @Override + public void partClosed(IWorkbenchPartReference ref) { + if (ref.getPart(false) == part) { + dispose(); + } + } +} diff --git a/docs/m3/jface-viewport/ALGORITHM_CATALOGUE.tsv b/docs/m3/jface-viewport/ALGORITHM_CATALOGUE.tsv new file mode 100644 index 00000000000..c12b17ac6ee --- /dev/null +++ b/docs/m3/jface-viewport/ALGORITHM_CATALOGUE.tsv @@ -0,0 +1,7 @@ +id operation problem_category candidates_compared chosen why complexity measurement date +JV-1 first row of each selected element (A1, A4) hashing / open addressing linear equals scan per element (stock, O(n*k)); HashMap (boxing, Entry per row); open-addressing first-index table (M3FirstIndex) M3FirstIndex no Entry or Integer objects; one Object[] + two int[] lanes; Fibonacci hashing of the comparer hash; first occurrence kept by insertion order O(n + k) time, O(n) lanes pending: M3ViewerBench table.setSelection10 / table.refresh.sel10 stock vs viewport (bench/stock-r1.tsv: stock 10^4 refresh.sel10 2188 ms vs refresh 564 ms) 2026-10-19 +JV-2 row of a widget item (A2) hashing / identity Table.indexOf per item (native linear scan); IdentityHashMap (Entry per item); M3IdentityIndex lanes M3IdentityIndex identity only (no equals calls on items); built once per remove call when k >= 8 O(n + k) pending: table.remove1pct stock vs viewport 2026-10-19 +JV-3 disposal of stale child items (A3) two pointers arraycopy per disposed item (stock, O(n*d)); two-pointer compaction two-pointer compaction same dispose and disassociate order as stock; one pass O(n) pending: tree.flat.filter10 stock vs viewport 2026-10-19 +JV-4 marker delta ids (Markers leaf) hashing / open addressing on long HashSet (boxing); long[] open addressing (M3LongSet); sorted long[] + binary search M3LongSet no boxing; 0 id handled by a flag; built per patch sized to the delta O(1) per lookup pending (markers measurement round) 2026-10-19 +JV-5 merge of arriving entries into a sorted category (Markers leaf) merge / binary search re-sort the category (stock: partial heap sort O(n log k)); binary-search insert per arriving entry (O(k log n) compares + O(k n) moves); one merge pass of the sorted arrivals (O(n + k) moves, O(k log k + n) compares) one merge pass compares against the stock comparator only where arrivals interleave; moves are a single sequential copy O(n + k log k) pending 2026-10-19 +JV-6 debounce of change bursts superseding generation timerExec per event (stock FilteredTree refreshJob 200 ms); generation counter + one job (donors: jsonviewer TreeFilterControl, TV_5.0 ViewerFilterUI) generation counter one pending job per view; a clean rebuild supersedes all pending deltas; the worker checks the generation before applying O(1) per event n/a 2026-10-19 diff --git a/docs/m3/jface-viewport/DELTA_GATE.tsv b/docs/m3/jface-viewport/DELTA_GATE.tsv new file mode 100644 index 00000000000..5732db9f37b --- /dev/null +++ b/docs/m3/jface-viewport/DELTA_GATE.tsv @@ -0,0 +1,7 @@ +view site call reachable_from status justification_or_plan evidence +Problems (markers views) ExtendedMarkersView.java:510 viewer.setInput(builder.getMarkers()) createPartControl (initial input) JUSTIFIED initial input, once per view instance source@4e7fb8d720 +Problems (markers views) UIUpdateJob.java:104 viewer.refresh(true) MarkerUpdateJob/SortingJob -> scheduleUIUpdate; partVisible with pending change flags JUSTIFIED (user actions) / FAIL (fallback states) M3 mode: marker deltas never reach it while the view is grouped, unsearched and unscoped (M3MarkerDeltas.apply patches the window; the bench counts UI update jobs per delta: delta1/100/10000-full-refreshes). Still reached by: first build (initial input), filter, grouping, sort, scope and limit changes (user actions), and the four fallbacks of FALLBACKS_TO_DELTAS.md (search text, resource scope, flat presentation, >50k pending deltas), which stay FAIL until each is a delta or is measured and justified S:/m3-scratch/jface/eclipse/markers-results.tsv (delta*-full-refreshes, diff-edits-full-refreshes) +Problems (markers views) MarkersChangeListener.java:resourceChanged -> MarkerUpdateScheduler.scheduleUpdate clean rebuild (gatherMarkers, new MarkerEntry per marker) IResourceChangeListener PASS (M3 mode, covered states) / FAIL (fallback states) M3MarkerDeltas.offer takes the deltas first; the rebuild runs only when ready() is false (building, flat, search text, resource scope, no lanes) or >50k pending bench rows delta*-rebuilds and diff-edits-rebuilds +Problems (markers views) MarkerContentGenerator.updateSelectedResource -> requestMarkerUpdate clean rebuild on selection change (resource-scoped filters) ISelectionListener FAIL Bug 296695: scope set-diff of sorted resource-id arrays, FALLBACKS_TO_DELTAS.md section 2 (next leaf) source +Problems (markers views) CachedMarkerBuilder.java:597,611 (WorkingSetListener) group.refresh() then scheduleUpdate() IPropertyChangeListener (working sets) FAIL same scope set-diff as above source +dialogs of the markers views FiltersConfigurationDialog.java:177,546,687,710; TypesConfigurationArea.java:462-463; ViewerColumnsDialog.java:242,280,400-509; QuickFixPage.java:224,264,370 setInput/refresh of dialog-local viewers user edits inside modal dialogs JUSTIFIED dialog-local lists of filters, marker types, columns and resolutions (tens of rows), rebuilt on the user's own edit; no model listener reaches them source diff --git a/docs/m3/jface-viewport/OPTIMIZATION_LEDGER.tsv b/docs/m3/jface-viewport/OPTIMIZATION_LEDGER.tsv new file mode 100644 index 00000000000..cd49c94af1c --- /dev/null +++ b/docs/m3/jface-viewport/OPTIMIZATION_LEDGER.tsv @@ -0,0 +1,48 @@ +leaf operation size before after unit method catalogue_id commit evidence_path +JV-R3 jface viewer mode original->viewport (same build) table.add1pct.sorted 10000 99 130 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.add1pct.sorted 100000 1573 1537 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.filter50 10000 416 511 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.filter50 100000 28174 timeout>60000 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.getSelection.sel10 10000 1 1 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.getSelection.sel10 100000 20 25 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh.sel10.hash 10000 374 482 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh.sel10.hash 100000 17389 4750 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh.sel10 10000 448 571 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh.sel10 100000 21869 19731 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh 10000 295 267 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.refresh 100000 3876 15669 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.remove1pct 10000 100 105 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.remove1pct 100000 2756 3011 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.reveal.last 10000 8 9 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.reveal.last 100000 35 22 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.setInput 10000 499 717 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.setInput 100000 5056 22588 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.setSelection10 10000 57 17 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.setSelection10 100000 17299 513 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.sort 10000 343 477 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.sort 100000 5362 8142 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.update1pct 10000 8 8 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) table.update1pct 100000 1370 1323 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.collapseAll 10000 461 424 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.collapseAll 100000 3786 4608 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.expandAll 10000 755 1144 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.expandAll 100000 7966 8753 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.getExpandedElements 10000 53 56 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.getExpandedElements 100000 599 689 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.refresh 10000 230 213 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.2level.refresh 100000 1995 2060 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.filter10 10000 2915 4020 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.filter10 100000 timeout timeout>60000 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.refresh 10000 327 198 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.refresh 100000 timeout timeout>60000 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.setInput 10000 7144 12166 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.setInput 100000 timeout timeout>60000 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.setSelection10 10000 42273 45172 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) tree.flat.setSelection10 100000 timeout timeout>60000 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.refresh 10000 14 13 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.refresh 100000 29 19 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.setInput 10000 37 25 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.setInput 100000 31 37 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.setSelection1pct 10000 1208 1361 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 jface viewer mode original->viewport (same build) vtable.lazy.setSelection1pct 100000 27215 23044 ms one JVM per op and size, single run, 3 desktop slots busy (contention): inconclusive, needs median of 5 on quiet slots - 6f00b8d9ee S:/m3-scratch/jface/bench/cand-orig-r3.tsv vs cand-vp-r3.tsv +JV-R3 note table.setInput, table.refresh, table.filter50 100000 - - - source check: viewport mode changes only M3ViewerPaths.removeRows/selectRows (AbstractTableViewer.java:744,895); setInput, refresh and filter take the same code in both modes (CustomHashtable uses M3ViewerMap in both), so the r3 differences are run-to-run contention, not a viewport-mode regression - f52d18dcc8 bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java diff --git a/docs/m3/jface-viewport/PROBLEMS_VIEW.md b/docs/m3/jface-viewport/PROBLEMS_VIEW.md new file mode 100644 index 00000000000..cd783f488b1 --- /dev/null +++ b/docs/m3/jface-viewport/PROBLEMS_VIEW.md @@ -0,0 +1,93 @@ +# Problems view on one lane model and deltas + +Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + +User, 2026-10-20: "next target is the Problems view and then all the platform UI using same viewport and DOOPS", +"all delta based view", and "problems view is the example of how a tree view should [work] with all its api". +Branch `m3/jface-viewport-20261019` (hsoliwal/eclipse.platform.ui). The mode is on with +`-Dorg.eclipse.ui.ide.markers.mode=viewport`. Without it, every hook is inert and the view is stock. + +## 1. What stock does on one marker change + +`MarkersChangeListener` looks at the marker deltas only to decide "relevant or not", then drops them. A clean +rebuild follows: `gatherMarkers` creates a `new MarkerEntry` for every marker in scope and evaluates every filter for +each one. The view then regroups (a `TreeMap` per update), partially sorts every category, clones the arrays, and +runs `viewer.refresh(true)`. The scheduler can delay this by up to 10 s (`MarkerUpdateScheduler.LONG_DELAY`). Each +`MarkerEntry` carries a `ConcurrentHashMap` attribute cache, and the collation keys live in two static maps. +docs/m3/markers-view/INVENTORY.tsv and UPSTREAM_DEFECTS.tsv give the file:line evidence (ui#4404, #4301, #4304, +#4469). + +## 2. The one model: `M3MarkerLanes` + +| lane | type | content | +|---|---|---| +| `ids` | `long[]` | marker id. The open-addressing `int[]` table maps id to slot, with no `HashMap` (replaces `Markers.markerToEntryMap`) | +| `markers` | `IMarker[]` | the resource layer's handle. It is needed for the facades and the APIs | +| `severity`, `line` | `int[]` | attribute values, read once by `M3MarkerKeys.read`: one `getAttributes(String[])`, so one element-tree lookup per marker | +| `message`, `location`, `resource`, `path`, `type` | `int[]` | label ids in `M3LabelTable`: interned and reference counted. A collation key is computed once per distinct message | +| `created` | `long[]` | creation time | +| `category` | `int[]` | stable category id | +| `facades` | `MarkerEntry[]` | set only for slots in a shown window. Everything else is null | + +- **Categories.** Each category keeps its slots in sort order in an `M3SlotOrder`. This is an order-statistic list + of sorted `int` blocks of at most 1024 slots. Insert and remove cost O(log n) compares plus one `arraycopy` of at + most one block. `get(i)` and `head(k)` walk the block lengths. Categories are ordered by the group's entries + comparator, with `TreeMap` equality, as in stock. +- **Sort.** The lane comparator reproduces `MarkerComparator.compareFields` for the known field classes: + severity-and-description, description, resource, path, location, id, creation time and type. It honours the + descending fields, and ends ties on the marker id, which gives a total order. A view that uses any other field + class does not get lanes and stays stock. +- **Counts.** Per severity bucket, per view and per category, as `int` counters. The title, the status line and the + category labels are O(1) (ui#4404). +- **Facades** are `MarkerEntry` objects, created only for an API that asks: the rows the viewer shows (the + content provider's window), a selection, Quick Fix, properties, copy, and the search box. `Markers` answers + `getCategories`, `getElements`, `getMarkerCounts`, `getMarkerItem`, `getClone` and `sortMarkerEntries` from the + lanes. The content provider asks the category for its window, not for all of its children. + +## 3. Deltas end to end: `M3MarkerDeltas` + +1. `offer` (resource change thread) merges the `IMarkerDelta`s by marker id into lanes and schedules one job + (150 ms debounce). A clean rebuild supersedes it (generation counter). +2. `prepare` (worker) reads the keys of the changed markers only, evaluates the filters on one transient facade per + changed marker (the filter API asks for a `MarkerItem`), and finds the category. +3. `apply` (one `asyncExec`) runs `M3MarkerLanes.apply`: each changed marker leaves and re-enters its category's + order, and the counters follow. The tree patch (`patchTree`) then builds one `M3ViewerDelta`: categories removed + and added, a label update per touched category, and for each category whose rows exist, the rows that left the + window or changed (removed) and the rows that entered it (inserted at their window index). It is applied through + `M3Viewers.apply` inside `preservingSelection`, the same selection contract as `refresh`. Rows outside every + window cause no tree work at all. +4. **Hidden view** (brief rule 24): while the part is hidden, `apply` updates the lanes only and accumulates the + touched categories and changed ids. On `partVisible` it applies one window patch (`M3PartVisibility`, see + REFERENCE_TREE_VIEW.md; SWT.PartVisible is the coming source of truth). + +## 4. Still a clean rebuild (DELTA_GATE.tsv) + +These still rebuild: the first input; filter, grouping, sort, scope and limit changes (user actions); and the +fallbacks of docs/m3/markers-view/FALLBACKS_TO_DELTAS.md. Search text, a resource scope (Bug 296695 set-diff), more +than 50,000 pending deltas, and errors are open. The flat presentation is being closed with one implicit category. + +## 5. Proof + +- Differential: the bench bundle (docs/m3/markers-view/bench-bundle) runs a seeded script of marker edits. The + edits are severity, message, line, add and delete. The script continues with a resize sweep, a column sweep and a + hidden sweep (minimize, 10^4 changes, restore), and logs the view's answers after every step: title, categories, + rows, expansion and selection. Stock and M3 logs must be identical (`markers_round.sh`). +- Counters per measured delta and per phase: UI update jobs (full refreshes), clean rebuilds, `M3MarkerDeltas` + counters (applied, fallbacks, builds, shown-patches), and paints and item changes while hidden. +- Measurements: deltas of 1, 100 and 10^4 markers at 10^4, 10^5 and 10^6 markers. Time to title, bytes allocated by + all threads, process CPU, retained heap after GC, and class histogram. These are recorded in + OPTIMIZATION_LEDGER.tsv. +- Headless tests: `M3MarkerLanesAlgorithmsTest` (M3SlotOrder and M3LabelTable against reference structures). JaCoCo + on the bench runs (`COVER=1`) covers the lane model, the delta path and the viewer delta API. + +## 6. Files + +- `bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/`: `M3MarkerLanes`, `M3MarkerCategory`, + `M3MarkerKeys`, `M3SlotOrder`, `M3LabelTable`, `M3MarkerDeltas`, `M3LongSet`. The hooks in `Markers`, + `CachedMarkerBuilder`, `MarkersChangeListener`, `MarkerViewerContentProvider`, `MarkersTreeViewer` and + `ExtendedMarkersView` come from the recipe docs/m3/markers-view/recipe (apply_recipe.sh, idempotent). +- `bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/m3/`: `M3ViewerDelta`, `M3Viewers`. +- `bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/m3/M3PartVisibility.java`. +- Harness: docs/m3/markers-view/tools (`build_overlay.sh`, `run_markers.sh`, `markers_round.sh`, + `run_headless_tests.sh`). diff --git a/docs/m3/jface-viewport/UPSTREAM_DEFECTS.tsv b/docs/m3/jface-viewport/UPSTREAM_DEFECTS.tsv new file mode 100644 index 00000000000..55d43aed1f2 --- /dev/null +++ b/docs/m3/jface-viewport/UPSTREAM_DEFECTS.tsv @@ -0,0 +1,2 @@ +id component path stock_behaviour cause_file_line m3_behaviour status evidence +JV-1 JFace TreeViewer (non-virtual, with and without hash lookup) refresh() after the content provider dropped many root children (differential op model-shrink+refresh) SWTException "Widget is disposed" from Widget.getData in AbstractTreeViewer.updateChildren (stock 3.40 line 2952) called by internalRefreshStruct/TreeViewer.internalRefreshStruct/refresh; the refresh aborts and the tree is left half updated (same stack shape as ui#3728, which reports it for virtual trees) AbstractTreeViewer.updateChildren (stock jar 3.40.0 :2952; fork original mode :3112 identical behaviour) viewport mode does not throw and continues; every answer before the failing step equals stock (14 of 16 tree logs end at the stock exception, 0 mismatches before it) open: minimal reproducer and upstream issue to file S:/m3-scratch/jface/diff/la4/viewport.defects (seeds 0-7, 60 steps) diff --git a/docs/m3/jface-viewport/evidence/DELTA_CENSUS_20261020.tsv b/docs/m3/jface-viewport/evidence/DELTA_CENSUS_20261020.tsv new file mode 100644 index 00000000000..373bbc525c8 --- /dev/null +++ b/docs/m3/jface-viewport/evidence/DELTA_CENSUS_20261020.tsv @@ -0,0 +1,126 @@ +repo module pattern main test +platform.ui bundles/org.eclipse.ui.workbench jface_refresh_all 48 0 +platform.ui bundles/org.eclipse.search jface_refresh_all 9 0 +platform.ui examples/org.eclipse.jface.snippets jface_refresh_all 12 0 +platform.ui tests/org.eclipse.jface.tests jface_refresh_all 0 42 +platform.ui bundles/org.eclipse.ui.navigator jface_refresh_all 7 0 +platform.ui bundles/org.eclipse.jface jface_refresh_all 6 0 +platform.ui bundles/org.eclipse.ui.views.properties.tabbed jface_refresh_all 9 0 +platform.ui bundles/org.eclipse.ui.navigator.resources jface_refresh_all 6 0 +platform.ui bundles/org.eclipse.ui.ide jface_refresh_all 37 0 +platform.ui bundles/org.eclipse.ui.views.log jface_refresh_all 2 0 +platform.ui bundles/org.eclipse.text.quicksearch jface_refresh_all 4 0 +platform.ui bundles/org.eclipse.e4.ui.dialogs jface_refresh_all 4 0 +platform.ui bundles/org.eclipse.e4.ui.workbench.renderers.swt jface_refresh_all 2 0 +platform.ui bundles/org.eclipse.ui.workbench jface_setInput 76 0 +platform.ui bundles/org.eclipse.search jface_setInput 7 0 +platform.ui tests/org.eclipse.ui.tests jface_setInput 0 1 +platform.ui examples/org.eclipse.jface.snippets jface_setInput 66 0 +platform.ui tests/org.eclipse.jface.tests jface_setInput 0 99 +platform.ui bundles/org.eclipse.ui.navigator jface_setInput 5 0 +platform.ui bundles/org.eclipse.ui.views jface_setInput 3 0 +platform.ui bundles/org.eclipse.jface jface_setInput 4 0 +platform.ui bundles/org.eclipse.jface.text jface_setInput 6 0 +platform.ui bundles/org.eclipse.ui.views.properties.tabbed jface_setInput 9 0 +platform.ui bundles/org.eclipse.ui.navigator.resources jface_setInput 3 0 +platform.ui bundles/org.eclipse.ui.ide jface_setInput 32 0 +platform.ui bundles/org.eclipse.ui.views.log jface_setInput 1 0 +platform.ui bundles/org.eclipse.ui.ide.application jface_setInput 1 0 +platform.ui bundles/org.eclipse.text.quicksearch jface_setInput 2 0 +platform.ui bundles/org.eclipse.e4.ui.workbench.renderers.swt jface_setInput 3 0 +platform.ui bundles/org.eclipse.ui.workbench swt_removeAll 22 0 +platform.ui bundles/org.eclipse.search swt_removeAll 5 0 +platform.ui bundles/org.eclipse.ui.navigator swt_removeAll 1 0 +platform.ui bundles/org.eclipse.jface swt_removeAll 14 0 +platform.ui bundles/org.eclipse.jface.text swt_removeAll 3 0 +platform.ui bundles/org.eclipse.ui.views.properties.tabbed swt_removeAll 1 0 +platform.ui bundles/org.eclipse.ui.ide swt_removeAll 9 0 +platform.ui bundles/org.eclipse.e4.ui.workbench.renderers.swt swt_removeAll 1 0 +platform.ui bundles/org.eclipse.ui.workbench swt_clearAll 1 0 +platform.ui bundles/org.eclipse.jface swt_clearAll 9 0 +platform.ui bundles/org.eclipse.jface.text swt_clearAll 1 0 +platform.ui bundles/org.eclipse.jface swt_setItemCount0 2 0 +platform team jface_refresh_all 43 0 +platform debug jface_refresh_all 66 1 +platform terminal jface_refresh_all 4 0 +platform runtime jface_refresh_all 5 0 +platform ua jface_refresh_all 20 0 +platform ant jface_refresh_all 14 0 +platform resources jface_refresh_all 1 0 +platform update jface_refresh_all 1 0 +platform team jface_setInput 91 5 +platform debug jface_setInput 79 133 +platform terminal jface_setInput 1 0 +platform runtime jface_setInput 6 0 +platform ua jface_setInput 38 4 +platform platform jface_setInput 1 0 +platform ant jface_setInput 23 2 +platform resources jface_setInput 15 0 +platform team swt_removeAll 22 0 +platform debug swt_removeAll 4 0 +platform terminal swt_removeAll 1 0 +platform runtime swt_removeAll 2 0 +platform ua swt_removeAll 1 1 +platform ant swt_removeAll 10 0 +platform resources swt_removeAll 1 0 +platform debug swt_clearAll 5 0 +platform terminal swt_clearAll 3 2 +platform debug swt_setItemCount0 1 0 +swt bundles/org.eclipse.swt.tools jface_refresh_all 1 0 +swt bundles/org.eclipse.swt.tools swt_removeAll 6 0 +nebula widgets/treemapper jface_refresh_all 2 0 +nebula widgets/timeline jface_refresh_all 1 0 +nebula widgets/xviewer jface_refresh_all 16 2 +nebula examples/org.eclipse.nebula.snippets jface_refresh_all 1 0 +nebula widgets/grid jface_refresh_all 1 0 +nebula widgets/compositetable jface_refresh_all 1 0 +nebula widgets/ganttchart jface_refresh_all 0 1 +nebula widgets/treemapper jface_setInput 3 1 +nebula widgets/timeline jface_setInput 1 0 +nebula widgets/geomap jface_setInput 2 1 +nebula widgets/cdatetime jface_setInput 1 0 +nebula widgets/richtext jface_setInput 3 0 +nebula widgets/pshelf jface_setInput 1 0 +nebula widgets/gallery jface_setInput 0 2 +nebula widgets/tablecombo jface_setInput 8 1 +nebula widgets/pagination jface_setInput 2 0 +nebula widgets/xviewer jface_setInput 29 0 +nebula examples/org.eclipse.nebula.snippets jface_setInput 26 2 +nebula widgets/timeline swt_removeAll 5 0 +nebula widgets/radiogroup swt_removeAll 2 0 +nebula widgets/geomap swt_removeAll 1 0 +nebula widgets/collapsiblebuttons swt_removeAll 1 0 +nebula widgets/pshelf swt_removeAll 1 0 +nebula widgets/gallery swt_removeAll 2 3 +nebula widgets/visualization swt_removeAll 2 0 +nebula widgets/tablecombo swt_removeAll 2 1 +nebula widgets/ctreecombo swt_removeAll 2 0 +nebula widgets/opal swt_removeAll 2 0 +nebula widgets/calendarcombo swt_removeAll 9 0 +nebula widgets/xviewer swt_removeAll 1 0 +nebula examples/org.eclipse.nebula.snippets swt_removeAll 1 0 +nebula widgets/grid swt_removeAll 3 3 +nebula widgets/ganttchart swt_removeAll 0 1 +nebula widgets/gallery swt_clearAll 3 1 +nebula widgets/tablecombo swt_clearAll 2 0 +nebula widgets/ctreecombo swt_clearAll 6 0 +nebula widgets/grid swt_clearAll 2 8 +nebula widgets/gallery swt_setItemCount0 0 2 +nebula widgets/ctreecombo swt_setItemCount0 1 0 +nebula examples/org.eclipse.nebula.snippets swt_setItemCount0 1 0 +nebula widgets/grid swt_setItemCount0 0 1 +gef-classic org.eclipse.gef jface_refresh_all 8 0 +gef-classic org.eclipse.zest.tests jface_setInput 0 3 +gef-classic org.eclipse.gef jface_setInput 13 0 +gef-classic org.eclipse.gef swt_removeAll 2 0 +gef-classic org.eclipse.draw2d.tests swt_removeAll 0 2 +gef-classic org.eclipse.zest.core swt_removeAll 2 0 +gef-classic org.eclipse.gef gef_refreshChildren 21 0 +m3jdk21-desktop src/java.desktop/share/classes/javax swt_removeAll 27 0 +m3jdk21-desktop src/java.desktop/share/classes/javax swing_tableDataChanged 1 0 +m3jdk21-desktop src/java.desktop/share/classes/sun swing_tableDataChanged 1 0 +m3jdk21-desktop src/java.desktop/share/classes/javax swing_tableStructureChanged 4 0 +m3jdk21-desktop src/java.desktop/share/classes/sun swing_tableStructureChanged 2 0 +m3jdk21-desktop src/java.desktop/share/classes/javax swing_treeStructure 7 0 +m3jdk21-desktop src/java.desktop/share/classes/javax swing_contentsChanged 11 0 +m3jdk21-desktop src/java.desktop/share/classes/sun swing_contentsChanged 2 0 diff --git a/docs/m3/jface-viewport/recipe/META-INF/rewrite/m3-jface-viewport.yml b/docs/m3/jface-viewport/recipe/META-INF/rewrite/m3-jface-viewport.yml index 7b6b7320940..66f9f086f6c 100644 --- a/docs/m3/jface-viewport/recipe/META-INF/rewrite/m3-jface-viewport.yml +++ b/docs/m3/jface-viewport/recipe/META-INF/rewrite/m3-jface-viewport.yml @@ -38,3 +38,9 @@ recipeList: parameterCount: 2 position: METHOD_START statements: "\t\tif (M3ViewerPaths.selectListRows(this, in, reveal, listMap)) {\n\t\t\treturn;\n\t\t}" + # M3Viewers: a refresh never runs ahead of deltas queued with M3Viewers.post (flush first) + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.jface.viewers.StructuredViewer] + methodName: refresh + position: METHOD_START + statements: "\t\torg.eclipse.jface.viewers.m3.M3Viewers.flush(this);" diff --git a/docs/m3/jface-viewport/tools/TreeViewerNonNlsRecipe.java b/docs/m3/jface-viewport/tools/TreeViewerNonNlsRecipe.java new file mode 100644 index 00000000000..25a12e24861 --- /dev/null +++ b/docs/m3/jface-viewport/tools/TreeViewerNonNlsRecipe.java @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: EPL-2.0 +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HexFormat; +import java.util.List; + +/** + * Fail-closed, idempotent Eclipse NLS annotation recipe for the exact TreeViewer preimage. + * Source literals and method bodies are unchanged; only //\u0024NON-NLS-1\u0024 comments are added. + */ +public final class TreeViewerNonNlsRecipe { + private static final String ORIGINAL_GIT_BLOB = + "88a47bcd2a5f57ebae1fe71bde045daa1637122c"; + private static final String MARKER = " //$NON-NLS-1$"; + private static final List EXACT_EXPRESSIONS = List.of( + "swtTreeOperation(\"expandToLevel\", int.class);", + "swtTreeOperation(\"expandToLevel\", TreeItem.class, int.class);", + "swtTreeOperation(\"collapseToLevel\", int.class);", + "swtTreeOperation(\"collapseToLevel\", TreeItem.class, int.class);", + "swtTreeOperation(\"expandSelectionToLevel\", int.class);", + "swtTreeOperation(\"collapseSelectionToLevel\", int.class);", + "swtTreeQuery(\"getExpandedItems\", TreeItem[].class);", + "swtTreeOperation(\"setExpandedItems\", TreeItem[].class);", + "throw new IllegalStateException(\"Unable to invoke SWT Tree bulk operation\", failure);", + "throw new IllegalStateException(\"Unable to invoke SWT Tree state query\", failure);"); + + private TreeViewerNonNlsRecipe() {} + + public static String apply(final String source) { + String result = java.util.Objects.requireNonNull(source, "source"); + for (String expression : EXACT_EXPRESSIONS) { + final int first = result.indexOf(expression); + if (first < 0 || result.indexOf(expression, first + 1) >= 0) { + throw new IllegalArgumentException("NLS_EXPECTED_EXACTLY_ONE:" + expression); + } + final int after = first + expression.length(); + if (result.startsWith(MARKER, after)) { + continue; + } + if (after < result.length() + && result.charAt(after) != '\n' + && result.charAt(after) != '\r') { + throw new IllegalArgumentException("NLS_UNEXPECTED_SUFFIX:" + expression); + } + result = result.substring(0, after) + MARKER + result.substring(after); + } + return result; + } + + private static String blobSha1(final byte[] bytes) { + try { + final MessageDigest digest = MessageDigest.getInstance("SHA-1"); + digest.update(("blob " + bytes.length + "\u0000").getBytes(StandardCharsets.US_ASCII)); + digest.update(bytes); + return HexFormat.of().formatHex(digest.digest()); + } catch (NoSuchAlgorithmException unavailable) { + throw new IllegalStateException("GIT_SHA1_UNAVAILABLE", unavailable); + } + } + + public static void main(final String[] args) throws IOException { + if (args.length != 2 || (!args[0].equals("--apply") && !args[0].equals("--check"))) { + throw new IllegalArgumentException("usage: TreeViewerNonNlsRecipe --apply|--check path"); + } + final Path path = Path.of(args[1]).toAbsolutePath().normalize(); + final byte[] original = Files.readAllBytes(path); + final String source = new String(original, StandardCharsets.UTF_8); + final String changed = apply(source); + if (!changed.equals(apply(changed))) { + throw new IllegalStateException("NLS_RECIPE_NOT_FIXED_POINT"); + } + if (args[0].equals("--apply")) { + if (!blobSha1(original).equals(ORIGINAL_GIT_BLOB)) { + throw new IllegalStateException("NLS_SOURCE_PREIMAGE_DRIFT"); + } + Files.writeString(path, changed, StandardCharsets.UTF_8); + } else if (!source.equals(changed)) { + throw new IllegalStateException("NLS_RECIPE_NOT_APPLIED"); + } + System.out.println("sourceSha1=" + blobSha1(original)); + System.out.println("postimageSha1=" + blobSha1(changed.getBytes(StandardCharsets.UTF_8))); + System.out.println("annotations=" + EXACT_EXPRESSIONS.size()); + System.out.println("fixedPoint=true"); + } +} diff --git a/docs/m3/jface-viewport/tools/build_jface.sh b/docs/m3/jface-viewport/tools/build_jface.sh index 03335951620..afb90692ac9 100644 --- a/docs/m3/jface-viewport/tools/build_jface.sh +++ b/docs/m3/jface-viewport/tools/build_jface.sh @@ -24,6 +24,6 @@ for side in cand stock; do if [ $side = cand ]; then JF="$OUT/cand/classes"; else JF="$STOCK_JFACE"; fi rm -rf "$OUT/$side/tests" && mkdir -p "$OUT/$side/tests" "$J" --release 21 -encoding UTF-8 -nowarn -proc:none -g -cp "$JF;$SWT_JAR;$DEPS;$JUNIT" \ - -d "$OUT/$side/tests" $(ls "$T"/*.java | grep -v -E "${M3_TEST_EXCLUDE_REGEX:-^$}") 2>&1 | grep -E "error" | head -20 || true + -d "$OUT/$side/tests" $(if [ $side = stock ]; then grep -L -E "org.eclipse.jface.(internal.m3|viewers.m3)" "$T"/*.java; else ls "$T"/*.java; fi) 2>&1 | grep -E "error" | head -20 || true echo "$side test classes: $(find "$OUT/$side/tests" -name '*.class' | wc -l)" done diff --git a/docs/m3/jface-viewport/tools/run_differential.sh b/docs/m3/jface-viewport/tools/run_differential.sh index 371f9b5bfea..98d708c12e3 100644 --- a/docs/m3/jface-viewport/tools/run_differential.sh +++ b/docs/m3/jface-viewport/tools/run_differential.sh @@ -5,7 +5,7 @@ # hidden desktop. Usage: run_differential.sh [steps] (COVER=1 adds JaCoCo) . "$(dirname "$0")/jface_env.sh" if [ "$1" != --inner ]; then - . "$(dirname "$0")/snapshot.sh"; snapshot "$OUT/runs/diff-$2" + . "$(dirname "$0")/snapshot.sh"; snapshot "$OUT/runs/diff-$1" exec bash C:/m3-superset/tools/ui_lock.sh jface-viewport bash "$0" --inner "$@" fi shift @@ -19,7 +19,21 @@ for side in stock original viewport; do -Djface.viewer.mode=$MODE $AGENT -cp "$(cygpath -w "$T");$(cygpath -w "$JF");$(cygpath -w "$SWT_JAR");$(deps)" \ org.eclipse.jface.tests.viewers.m3.M3ViewerDifferential "$(cygpath -w "$D/$side")" "$FIRST" "$COUNT" "$STEPS" done -for side in original viewport; do - n=$(ls "$D/stock" 2>/dev/null | wc -l); m=$(ls "$D/$side" 2>/dev/null | wc -l) - if [ "$n" -gt 0 ] && diff -rq "$D/stock" "$D/$side" > "$D/$side.diff" 2>&1; then echo "$side vs stock: IDENTICAL ($m/$n logs)"; else echo "$side vs stock: $(wc -l < "$D/$side.diff") differing logs ($m/$n)"; fi -done +# A log that differs only after a step where stock threw (the driver records " exception ..." and ends the script) +# is a stock defect, not a mismatch, when every line before that step is identical: the defect goes to +# UPSTREAM_DEFECTS.tsv. Anything else that differs is a mismatch. +compare() { # compare : prints the summary line, writes .diff (mismatches) and .defects + local side=$1 same=0 defect=0 bad=0 f s + : > "${D:?}/$side.diff"; : > "${D:?}/$side.defects" + for f in $(ls "$D/stock"); do + if cmp -s "$D/stock/$f" "$D/$side/$f"; then same=$((same + 1)); continue; fi + s=$(grep -n -m1 '^[0-9]* exception ' "$D/stock/$f" | cut -d: -f1) + if [ -n "$s" ] && [ -f "$D/$side/$f" ] && cmp -s <(head -n $((s - 1)) "$D/stock/$f") <(head -n $((s - 1)) "$D/$side/$f"); then + defect=$((defect + 1)); echo "stock-defect $f line $s: $(sed -n "${s}p" "$D/stock/$f" | cut -c1-160)" >> "$D/$side.defects" + else + bad=$((bad + 1)); echo "$f" >> "$D/$side.diff" + fi + done + echo "$side vs stock: $bad mismatches ($same identical, $defect identical up to a stock exception; $(ls "$D/$side" | wc -l)/$(ls "$D/stock" | wc -l) logs)" +} +for side in original viewport; do compare $side; done diff --git a/docs/m3/jface-viewport/tools/run_headless_tests.sh b/docs/m3/jface-viewport/tools/run_headless_tests.sh new file mode 100644 index 00000000000..a7cec043c2f --- /dev/null +++ b/docs/m3/jface-viewport/tools/run_headless_tests.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# Headless JUnit 5 tests of the M3 lanes (no Display), with JaCoCo, after build_jface.sh. +# Usage: run_headless_tests.sh ... +. "$(dirname "$0")/jface_env.sh" +EXEC=$1; shift +SEL=(); for c in "$@"; do SEL+=(--select-class "org.eclipse.jface.tests.viewers.m3.$c"); done +mkdir -p "$OUT/coverage"; DEST=$(cygpath -w "$OUT/coverage/$EXEC.exec"); rm -f "$OUT/coverage/$EXEC.exec" +deps() { echo "$DEPS" | tr ';' '\n' | while read -r d; do printf '%s;' "$(cygpath -w "$d")"; done; } +"$JAVA_HOME/bin/java" -Xmx512m -Djava.io.tmpdir=$(cygpath -w "$OUT/tmp") ${JAVA_OPTS:-} \ + "-javaagent:$(cygpath -w "$JACOCO_AGENT")=destfile=$DEST,includes=org.eclipse.jface.*" \ + -jar "$(cygpath -w "$JUNIT")" execute --disable-banner --details=tree --details-theme=ascii \ + -cp "$(cygpath -w "$OUT/cand/tests");$(cygpath -w "$OUT/cand/classes");$(cygpath -w "$SWT_JAR");$(deps)" "${SEL[@]}" 2>&1 \ + | sed 's/\x1b\[[0-9;]*m//g' | grep -E "tests (successful|failed)|\[X\]|=>|Exception" | head -${TAILN:-30} diff --git a/docs/m3/jface-viewport/tools/run_ui_tests.sh b/docs/m3/jface-viewport/tools/run_ui_tests.sh new file mode 100644 index 00000000000..7cc496d33cc --- /dev/null +++ b/docs/m3/jface-viewport/tools/run_ui_tests.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# JUnit 5 UI tests of the M3 classes on the hidden desktop, with JaCoCo. Usage: run_ui_tests.sh ... +. "$(dirname "$0")/jface_env.sh" +if [ "$1" != --inner ]; then + . "$(dirname "$0")/snapshot.sh"; snapshot "$OUT/runs/ui-$1" + exec bash C:/m3-superset/tools/ui_lock.sh jface-viewport bash "$0" --inner "$@" +fi +shift +EXEC=$1; shift; RUN=$OUT/runs/ui-$EXEC +SEL=(); for c in "$@"; do SEL+=(--select-class "org.eclipse.jface.tests.viewers.m3.$c"); done +mkdir -p "$OUT/coverage"; rm -f "$OUT/coverage/$EXEC.exec" +deps() { echo "$DEPS" | tr ';' '\n' | while read -r d; do printf '%s;' "$(cygpath -w "$d")"; done; } +bash C:/m3-superset/tools/hidden_java.sh 900 "$OUT/$EXEC.log" -Xmx1g -Djava.io.tmpdir=$(cygpath -w "$OUT/tmp") ${JAVA_OPTS:-} \ + "-javaagent:$(cygpath -w "$JACOCO_AGENT")=destfile=$(cygpath -w "$OUT/coverage/$EXEC.exec"),includes=org.eclipse.jface.*" \ + -jar "$(cygpath -w "$JUNIT")" execute --disable-banner --details=tree --details-theme=ascii \ + -cp "$(cygpath -w "$RUN/cand-tests");$(cygpath -w "$RUN/cand-classes");$(cygpath -w "$SWT_JAR");$(deps)" "${SEL[@]}" +sed 's/\x1b\[[0-9;]*m//g' "$OUT/$EXEC.log" | grep -E "tests (successful|failed)|\[X\]|=>|Exception" | head -${TAILN:-40} diff --git a/docs/m3/markers-view/FALLBACKS_TO_DELTAS.md b/docs/m3/markers-view/FALLBACKS_TO_DELTAS.md new file mode 100644 index 00000000000..98cda4477f7 --- /dev/null +++ b/docs/m3/markers-view/FALLBACKS_TO_DELTAS.md @@ -0,0 +1,82 @@ +# Problems view: closing the clean-rebuild fallbacks (Bug 296695 and the rest) + +Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + +User, 2026-10-20: "next target is the Problems view and then all the platform UI using same viewport and DOOPS", +"all delta based view", and (pasting the Bug 296695 comment from MarkerContentGenerator) TV_5.0 and the x86core +JSON viewer "might provide useful tips on how to debounce and keep the UI interactive". + +## Where the delta path stands + +`M3MarkerDeltas` (commit d435632489) answers marker add/change/remove with lanes, a debounced job and a per-category +merge. It still falls back to the original clean rebuild (`gatherMarkers` -> `new MarkerEntry` per marker -> regroup -> +sort -> `setInput`) in four cases. Rule 24 (delta-only views) needs each one closed or justified with a measurement. + +## What Bug 296695 says, and why deltas make it unnecessary + +`MarkerContentGenerator.updateSelectedResource` calls `requestMarkerUpdate()` (a full rebuild) on every selection +change that a resource-scoped filter cares about. The commented-out `contentChanged()` and its note record that +Eclipse never found a safe way to tell whether the content actually changed. Its suggestion was to compare freshly +gathered markers with the cached ones, perhaps with a binary search after sorting. That still pays the full gather. + +The delta answer needs no gather. A scope is a set of resource ids, and a scope change is a set difference: + +1. Keep the current scope as a sorted `int[]` of resource ids (interned per resource path), built from + `MarkerResourceUtil.computeResources(selected, enabledFilters, andFilters)` once per change. +2. Diff old and new with a two-pointer merge, O(n + m): `entered` ids and `left` ids. Catalogue: sorted-array set + difference / merge-two-sorted-arrays. +3. Markers are already grouped by resource in lanes. For `left`, clear the scope bit of their markers. For `entered`, + read markers of those resources only (`IResource.findMarkers` per entered resource), then evaluate the remaining + filters for them only. +4. The visible result is `scopeMask & filterMask`. Report ENTERED/LEFT rows as `old ^ new` word by word, and turn + them into one `M3Patch` per category. Rows inside the shown window are inserted or removed. Outside the window, + only the category counts and the scroll extents change. + +An empty diff, with the same resources selected, makes no update at all. That is the `contentChanged() == false` +answer Bug 296695 wanted, obtained in O(n + m) on ids. + +## The four fallbacks, each as a delta + +| Fallback today | Delta path | +|---|---| +| Filters with a resource scope (selection, working set, project) | Scope set-diff above. Working-set content and remove events (`CachedMarkerBuilder` property listener, `group.refresh()`) feed the same diff. | +| Active search text | One filter bit lane over the description/resource/path text, as in sort-filter's `M3ColumnFilter`: compile the pattern on the UI thread, superseding generation, evaluate on a worker, `old ^ new` gives ENTERED/LEFT. Text is interned label ids, so the match cost is per distinct string. | +| Flat (ungrouped) presentation | The same patch with one implicit category. The sort permutation lane takes binary inserts for entered rows, and left rows are removed by rank. | +| More than `MAX_PENDING` (50,000) deltas | Keep the merge path and measure it against the clean rebuild at 10^4, 10^5 and 10^6. Keep the fallback only if the ledger shows the rebuild is faster, and record that in DELTA_GATE.tsv with the numbers. | + +## Debounce and keeping the UI interactive (TV_5.0, x86core jsonviewer) + +The sort-filter track already extracted the pattern from both donors (C:/m3-superset/swt-sortfilter docs/m3/sort-filter +DESIGN.md, section "Asynchronous filtering"; FOSS rows `filter-debounce-supersede`, `filter-on-model`, +`model-work-cancellable`). Apply it to every change source of the view: marker deltas, scope changes, filter edits and +search keystrokes. + +1. **One superseding generation**, an `int` per view. Every change records its input and increments it. A single + preallocated runnable is re-armed, and when it fires it returns unless its generation is still current. Nothing + is allocated per keystroke or per event. +2. **Model work off the UI thread.** One worker evaluates only what changed: the merged delta lanes, the scope diff, + or one filter lane. It checks the generation every 4096 rows and drops the work when a newer one exists. The UI + thread never walks the markers. +3. **One apply per result.** One `asyncExec` applies the `M3Patch` if its generation is still current. The tree is + patched in the window only. Counts come from lane counters (O(1); ui#4404/#4301/#4304/#4469). +4. The 150 ms `SHORT_DELAY` stays as the debounce default for marker deltas. Search keystrokes use the sort-filter + default, and the ledger records the input-to-pixel latency for both. + +## DOOP: the entries themselves + +`M3MarkerDeltas` still creates a `MarkerEntry` for each added or changed marker, and `Markers` keeps `markerToEntryMap` +(a HashMap, Markers.java:333). Target: +- marker id, resource id, severity, type, line and category as lanes; +- message and location as interned label ids; +- `MarkerEntry` created lazily only when an API asks for one (selection, Quick Fix, properties, copy), parent-owned + and released under pressure; +- the id-to-slot map as the open-addressing `int[]` table `M3MarkerDeltas` already uses, instead of `HashMap`. + +## Proof + +- Stock-vs-ours differential for each change source: marker deltas, selection-scope changes, working-set changes, + filter edits, search typing, grouping and presentation switches. Zero mismatches in visible rows, counts, + selection and expansion. +- Full-rebuild counter = 0 for every case except a fallback that is measured and justified. +- Re-run `C:/m3-superset/tools/delta_census.sh` and record the drop for org.eclipse.ui.ide. diff --git a/docs/m3/markers-view/HANDOVER.md b/docs/m3/markers-view/HANDOVER.md new file mode 100644 index 00000000000..57f0da71cf5 --- /dev/null +++ b/docs/m3/markers-view/HANDOVER.md @@ -0,0 +1,97 @@ +# Problems / Markers view: handover (resume here) + +Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + +User, 2026-10-20: "for markers view, document what you did, so Codex can resume if you run out of tokens, or you can +remember after a token reset". Read this file first, then the files in "Read next", in order. + +## Where + +- Repo: hsoliwal/eclipse.platform.ui (fork of eclipse-platform/eclipse.platform.ui). +- Branch: `m3/jface-viewport-20261019`. Local worktree: `S:/m3-scratch/worktrees/platform-ui`. Commits are pushed after + every leaf; a 20-minute sweep (K:/m3-work/logs/commit_sweep.sh) checkpoints everything. +- Package: `bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/`. +- Owner so far: the JFace agent of the lead's session (Claude). Codex or a later session continues from here. + +## What exists (code) + +| File | Role | +|---|---| +| `M3MarkerLanes.java` (new, ~800 lines) | the one lane model of the view: marker id, marker, severity, interned message/location/resource/path ids, category, counts per severity and category | +| `M3MarkerDeltas.java` | the delta path: IMarkerDelta/IResourceDelta merged per marker id into lanes, debounced job with a superseding generation, per-category merge, window patch; flat presentation and resource-scoped filters go through the lanes too | +| `M3MarkerKeys.java`, `M3MarkerCategory.java`, `M3SlotOrder.java` (new) | sort keys, categories and the slot permutation lane | +| `Markers.java`, `MarkerContentGenerator.java`, `MarkersChangeListener.java`, `MarkerViewerContentProvider.java`, `MarkersTreeViewer.java` | small hooks into stock classes (recipe-applied, see recipe/) | +| `ProblemsView.m3view` | the view template spec (rule 27) | +| `M3PartVisibility` (org.eclipse.ui.workbench) | IPartListener2 partHidden/partVisible, the stand-in until SWT.PartVisible lands (all-widgets track) | +| `M3ViewSpec` | the `.m3view` parser (view template) | + +Switch: `-Dorg.eclipse.ui.ide.markers.mode=viewport` turns the delta path on; without it the stock path runs unchanged. + +## What exists (docs, docs/m3/markers-view and docs/m3/jface-viewport) + +- `DESIGN.md`: stock behaviour, target, equality rules, measurements plan, differential, next. +- `docs/m3/jface-viewport/PROBLEMS_VIEW.md`: the lane model, the delta path, what is still a clean rebuild, proof. +- `FALLBACKS_TO_DELTAS.md`: how each clean-rebuild fallback becomes a delta, including Bug 296695 (scope set-diff). +- `REFERENCE_TREE_VIEW.md` + `TREE_VIEW_API_MATRIX.tsv`: the Problems view as the reference tree view; 305 viewer API + methods with lane/delta status (mechanical pass: 61 DELTA, 114 FACADE, ...); the adoption recipe for other views. +- `docs/m3/jface-viewport/DELTA_GATE.tsv`: every rebuild site with JUSTIFIED/FAIL. +- `docs/m3/jface-viewport/OPTIMIZATION_LEDGER.tsv`: before/after numbers. +- `INVENTORY.tsv`, `UPSTREAM_DEFECTS.tsv`, `recipe/` (OpenRewrite hooks), `bench-bundle/` (in-IDE bench). +- Integration branch (hsoliwal/eclipse.platform.swt, `m3/viewport-integration-20261016`): docs/m3/correction-sites + (marked rebuild sites across 12 forks), docs/m3/ui-thread-sites, docs/m3/view-template/VIEW_TEMPLATE.md, + docs/m3/behaviours/BEHAVIOURS.md, docs/m3/VIEWPORT_AGENT_BRIEF.md (rules 1-29), docs/m3/VIEWPORT_PROGRAMME_PLAN.md. + +## Tools (docs/m3/markers-view/tools) + +- `build_overlay.sh`: rebuilds the markers classes with the M3 hooks into an overlay of the official Eclipse 2026-09 bundles. +- `apply_recipe.sh`: applies the OpenRewrite hooks (the second pass must report UNCHANGED). +- `run_markers.sh ...`: one bench or differential run in an isolated Equinox configuration on + S:/m3-scratch/jface/eclipse (never the installed IDE). UI runs go through C:/m3-superset/tools/ui_lock.sh. +- `markers_round.sh`: a full round (stock and ours, sizes, seeds). +- `run_headless_tests.sh`: the headless unit tests. `COVER=1` adds JaCoCo over the M3 classes. +- `ledger_rows.sh`: bench results to OPTIMIZATION_LEDGER rows. `matrix_status.awk`: fills TREE_VIEW_API_MATRIX statuses. + +## State (2026-10-20 13:40) and what is open + +Done: lane model, delta path for marker deltas, resource-scoped filters through lanes, flat presentation, the Bug 296695 +scope diff against lanes (commit d13d2522a5), the view-template parser and spec, the PartVisible stand-in, bench and +differential harness, API matrix mechanical pass. + +Open, in order: +1. **Re-measure, not a regression (corrected 2026-10-20 14:20):** the JV-R3 `table.filter50` 10^5 timeout and the + `add1pct.sorted` 99 -> 130 ms rows were single runs with 3 desktop slots busy. The ledger's "JV-R3 note" row + (commit f52d18dcc8) shows viewport mode changes only `M3ViewerPaths.removeRows/selectRows` + (AbstractTableViewer.java:744, 895); setInput, refresh and filter run the same code in both modes. Re-run + `M3ViewerBench` as a median of 5 on quiet slots before calling it either way. +2. DELTA_GATE FAIL row: `CachedMarkerBuilder.java:597,611` (working-set listener: `group.refresh()` then a full + update). Make it the scope set-diff. +3. Deferred `MarkerEntry` facades: no entry object for rows outside the window; replace `Markers.markerToEntryMap` + (HashMap) with the open-addressing id table. +4. Differential at 10^4/10^5/10^6 with zero mismatches, and the full-refresh counter = 0. Record the run ids here. +5. TREE_VIEW_API_MATRIX: no TODO; every row has a differential status. +6. Switch the PartVisible stand-in to SWT.PartVisible/PartHidden once the all-widgets track lands it (rule 25). +7. Draft PR to hsoliwal/eclipse.platform.ui once the differential passes (the user merges). +8. Then the template: generate a PDE form section and the Java Outline from specs (rule 27), and the footer, + header-2, view bar and behaviours from docs/m3/behaviours. + +## Rules that apply (brief rules 1-29; the ones that bite here) + +Delta-only views, resize/layout and hidden viewports (24); own the implementation, PartVisible and Viewport listeners +(25); public model API (26); template-first views (27); threads (28); behaviours (29). Also: Java only, JUL logging, +recipe hooks, Synexia header on new files, no Co-Authored-By trailers, never merge PRs or force-push, scratch only under +S:/m3-scratch, never write to G:, D: or E:. + +## Resume checklist (Codex or a fresh session) + +1. `git -C S:/m3-scratch/worktrees/platform-ui fetch origin && git -C S:/m3-scratch/worktrees/platform-ui status` + (or clone hsoliwal/eclipse.platform.ui and check out `m3/jface-viewport-20261019`). +2. Read: this file, PROBLEMS_VIEW.md, DESIGN.md, FALLBACKS_TO_DELTAS.md, DELTA_GATE.tsv, OPTIMIZATION_LEDGER.tsv. +3. Run `tools/run_headless_tests.sh`; then one `run_markers.sh` round for stock and ours at 10^4 to confirm the setup. +4. Take "Open" item 1 and work down the list. Append each result to this file under "Log". + +## Log + +- 2026-10-20 13:40: handover written by the lead (Claude) from branch head af302a4438. +- 2026-10-20 14:05 (JFace agent): item 2 code done in d13d2522a5 (WorkingSetListener and requestMarkerUpdate offer scope changes to M3MarkerDeltas.scopeChanged: gather diff against the lanes, one delta); DELTA_GATE rows now PASS pending the differential scope sweep. Harness fixes since: m3Building readiness (fcdb7394b8: every earlier delta fell back), osgi.configuration.cascaded=false (2c12e1b555: every earlier m3 run had loaded the stock pool jars), in-process class histogram (3f4203ea90). Runs queued: round 1000 (stock+m3), stock 10^4 (done, 60-line log), stock 10^5. Item 1: same-build A/B with 5 interleaved repetitions under one slot (tools/run_ab.sh) queued; source check says viewport mode only changes remove/select paths (ledger note aab7823a2f). +- 2026-10-20 14:50 (lead, Fable): search text as a lane. M3MarkerLanes: textHits bit lane, applyText(filter), textHit/matching, windowSlots filters before the limit; Change.textHit/textGeneration set in write(); M3MarkerDeltas: ready() no longer treats a search text as a fallback, build() applies the text after finishBuild, prepareOne evaluates MarkerPatternFilter.matches per changed row, apply() re-evaluates rows prepared before a newer text, textChanged(view, filter) hook; MarkerPatternFilter.setPattern calls it; MarkerViewerContentProvider serves lane windows under a search; M3MarkerCategory.getShownChildrenCount = applyMarkerLimit(lanes.matching). Bench: filterText + search steps ('Added', 'problem 1', clear; 3 edits each) + diff-search-* rows. run_headless_tests.sh now uses JDK 25 (overlay ide classes are --release 25): 6/6 tests pass. Differential at n=1000 seed 7 (stock, then m3 with this build) queued on the UI lock; result to be logged here. diff --git a/docs/m3/markers-view/PROBLEMS_VIEW_MARKS.tsv b/docs/m3/markers-view/PROBLEMS_VIEW_MARKS.tsv new file mode 100644 index 00000000000..84eeac723ff --- /dev/null +++ b/docs/m3/markers-view/PROBLEMS_VIEW_MARKS.tsv @@ -0,0 +1,75 @@ +census category class enclosing_method file line stock_permalink snippet branch_status +correction full_refresh MODEL_LISTENER propertyChange CachedMarkerBuilder.java 593 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java#L593 group.refresh(); OPEN (site still present on branch) +correction full_refresh MODEL_LISTENER propertyChange CachedMarkerBuilder.java 607 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java#L607 group.refresh(); OPEN (site still present on branch) +correction full_refresh REVIEW addConfiguration FiltersConfigurationDialog.java 546 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/FiltersConfigurationDialog.java#L546 configsTable.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION performDefaults FiltersConfigurationDialog.java 687 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/FiltersConfigurationDialog.java#L687 configsTable.refresh(); OPEN (file untouched on branch) +correction full_refresh MAINTENANCE removeFilters FiltersConfigurationDialog.java 710 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/FiltersConfigurationDialog.java#L710 configsTable.refresh(); OPEN (file untouched on branch) +correction full_refresh REVIEW getResourcesForFilter MarkerResourceUtil.java 164 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L164 group.refresh(); OPEN (file untouched on branch) +correction full_refresh REVIEW getRelevance QuickFixPage.java 264 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixPage.java#L264 markersTable.refresh(); OPEN (file untouched on branch) +correction full_refresh INITIAL_OR_SETUP initializeFromGroup TypesConfigurationArea.java 463 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L463 typesViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh ASYNC_OR_REFRESH_METHOD runInUIThread UIUpdateJob.java 104 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/UIUpdateJob.java#L104 viewer.refresh(true); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleDownButton ViewerColumnsDialog.java 400 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L400 visibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleUpButton ViewerColumnsDialog.java 423 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L423 visibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleToVisibleButton ViewerColumnsDialog.java 445 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L445 visibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleToVisibleButton ViewerColumnsDialog.java 447 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L447 nonVisibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleToNonVisibleButton ViewerColumnsDialog.java 472 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L472 nonVisibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh USER_ACTION handleToNonVisibleButton ViewerColumnsDialog.java 474 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L474 visibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh ASYNC_OR_REFRESH_METHOD refreshViewers ViewerColumnsDialog.java 506 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L506 nonVisibleViewer.refresh(); OPEN (file untouched on branch) +correction full_refresh ASYNC_OR_REFRESH_METHOD refreshViewers ViewerColumnsDialog.java 509 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L509 visibleViewer.refresh(); OPEN (file untouched on branch) +correction set_input REVIEW startView ExtendedMarkersView.java 510 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java#L510 viewer.setInput(builder.getMarkers()); OPEN (site still present on branch) +correction set_input INITIAL_OR_SETUP initUI FiltersConfigurationDialog.java 177 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/FiltersConfigurationDialog.java#L177 configsTable.setInput(filterGroups); OPEN (file untouched on branch) +correction set_input REVIEW getImage QuickFixPage.java 224 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixPage.java#L224 resolutionsList.setInput(resolutions.keySet().toArray()); OPEN (file untouched on branch) +correction set_input MAINTENANCE removeListener QuickFixPage.java 370 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixPage.java#L370 markersTable.setInput(this); OPEN (file untouched on branch) +correction set_input INITIAL_OR_SETUP initializeFromGroup TypesConfigurationArea.java 462 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L462 typesViewer.setInput(group); OPEN (file untouched on branch) +correction set_input INITIAL_OR_SETUP createVisibleTable ViewerColumnsDialog.java 242 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L242 visibleViewer.setInput(getVisible()); OPEN (file untouched on branch) +correction set_input INITIAL_OR_SETUP createInvisibleTable ViewerColumnsDialog.java 280 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L280 nonVisibleViewer.setInput(getNonVisible()); OPEN (file untouched on branch) +correction per_element_object DOOP_OBJECTS prepare M3MarkerDeltas.java 313 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java#L313 MarkerEntry candidate = new MarkerEntry(marker); OPEN (site still present on branch) +correction per_element_object DOOP_OBJECTS build M3MarkerDeltas.java 496 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java#L496 made.add(new MarkerCategory(model, start, out - 1, name)); CHANGED_ON_BRANCH (site gone or rewritten) +correction per_element_object DOOP_OBJECTS internalGatherMarkers MarkerContentGenerator.java 940 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java#L940 entry = new MarkerEntry(markers[i]); OPEN (site still present on branch) +correction per_element_object DOOP_OBJECTS newMarkerItem MarkerSupportInternalUtilities.java 340 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerSupportInternalUtilities.java#L340 return new MarkerEntry(marker); OPEN (file untouched on branch) +correction per_element_object DOOP_OBJECTS clean MarkerUpdateJob.java 105 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerUpdateJob.java#L105 * the collection of new MarkerEntry(s) OPEN (file untouched on branch) +correction per_element_object DOOP_OBJECTS groupIntoCategories Markers.java 235 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java#L235 markerCategories[i++] = new MarkerCategory(this, start, end, OPEN (site still present on branch) +correction element_map FIELD_OR_STATIC - AllErrorsParameters.java 32 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/AllErrorsParameters.java#L32 errorsMap = new HashMap<>(); OPEN (file untouched on branch) +correction element_map FIELD_OR_STATIC - ErrorsWarningsParameters.java 33 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ErrorsWarningsParameters.java#L33 parametersMap = new HashMap<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getOpenableMarkers ExtendedMarkersView.java 618 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java#L618 HashSet result = new HashSet<>(); OPEN (site still present on branch) +correction element_map DOOP_STORE getCategoriesToExpand ExtendedMarkersView.java 726 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java#L726 categoriesToExpand = new HashSet<>(); OPEN (site still present on branch) +correction element_map UI_EVENT selectionChanged ExtendedMarkersView.java 1873 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java#L1873 Set selectedElements = new LinkedHashSet<>(); OPEN (site still present on branch) +correction element_map ASYNC_OR_REFRESH_METHOD execute MarkCompletedHandler.java 52 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkCompletedHandler.java#L52 Map attrs = new HashMap<>(); OPEN (file untouched on branch) +correction element_map FIELD_OR_STATIC - MarkerComparator.java 50 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerComparator.java#L50 HashSet descendingFields = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getHiddenFields MarkerContentGenerator.java 186 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java#L186 Collection hidden = new HashSet<>(); OPEN (site still present on branch) +correction element_map DOOP_STORE getEnabledFilters MarkerContentGenerator.java 309 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java#L309 Collection enabled = new HashSet<>(); OPEN (site still present on branch) +correction element_map FIELD_OR_STATIC - MarkerFieldFilterGroup.java 108 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerFieldFilterGroup.java#L108 private final Map EMPTY_MAP = new HashMap<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE loadSettings MarkerFieldFilterGroup.java 446 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerFieldFilterGroup.java#L446 Map filterMap = new HashMap<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE computeResources MarkerResourceUtil.java 65 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L65 HashSet set = new HashSet<>(1); OPEN (file untouched on branch) +correction element_map DOOP_STORE getResourcesFiltersOred MarkerResourceUtil.java 124 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L124 HashSet set = new HashSet<>(1); OPEN (file untouched on branch) +correction element_map DOOP_STORE getResourcesFiltersOred MarkerResourceUtil.java 128 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L128 Set resourceSet = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getResourcesFiltersOred MarkerResourceUtil.java 135 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L135 set = new HashSet<>(1); OPEN (file untouched on branch) +correction element_map DOOP_STORE getResourcesForFilter MarkerResourceUtil.java 148 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L148 HashSet resourceSet = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getProjectsAsCollection MarkerResourceUtil.java 195 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L195 HashSet projects = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getNestedChildProjects MarkerResourceUtil.java 220 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L220 Set nestedChildren = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getAllSubTypes MarkerResourceUtil.java 310 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L310 HashSet set = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getMutuallyExclusiveSupers MarkerResourceUtil.java 334 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L334 HashSet set = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getMutuallyExclusiveSupers MarkerResourceUtil.java 343 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L343 HashSet subsOnly = new HashSet<>(Arrays.asList(subs)); OPEN (file untouched on branch) +correction element_map DOOP_STORE toTypeStrings MarkerResourceUtil.java 355 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java#L355 HashSet ids = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE getAdapter MarkerShowInAdapter.java 44 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerShowInAdapter.java#L44 Collection resources = new HashSet<>(); OPEN (file untouched on branch) +correction element_map FIELD_OR_STATIC - MarkerTypeFieldFilter.java 43 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerTypeFieldFilter.java#L43 Collection selectedTypes = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE setContentGenerator MarkerTypeFieldFilter.java 167 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerTypeFieldFilter.java#L167 selectedTypes = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE populateWorkingCopy MarkerTypeFieldFilter.java 174 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerTypeFieldFilter.java#L174 ((MarkerTypeFieldFilter) copy).selectedTypes = new HashSet<>(selectedTypes); OPEN (file untouched on branch) +correction element_map DOOP_STORE getMarkerItem Markers.java 333 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java#L333 markerToEntryMap = new HashMap<>(); OPEN (site still present on branch) +correction element_map DOOP_STORE listenToTypes MarkersChangeListener.java 100 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersChangeListener.java#L100 listeningTypes = new HashSet<>(Arrays.asList(typeIds)); OPEN (site still present on branch) +correction element_map DOOP_STORE saveChanges MarkersPropertyPage.java 347 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersPropertyPage.java#L347 attrs = new HashMap<>(); OPEN (file untouched on branch) +correction element_map ASYNC_OR_REFRESH_METHOD execute QuickFixHandler.java 79 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixHandler.java#L79 final Map> resolutionsMap = new LinkedHashMap<>(); OPEN (file untouched on branch) +correction element_map ASYNC_OR_REFRESH_METHOD execute QuickFixHandler.java 97 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixHandler.java#L97 Collection markers1 = new LinkedHashSet<>(other.length + 1); OPEN (file untouched on branch) +correction element_map FIELD_OR_STATIC - SelectedWarningsParameters.java 33 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/SelectedWarningsParameters.java#L33 warningsMap = new HashMap<>(); OPEN (file untouched on branch) +correction element_map FIELD_OR_STATIC - TodoFiltersContributionParameters.java 30 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TodoFiltersContributionParameters.java#L30 todoMap = new HashMap<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE setParent TypesConfigurationArea.java 199 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L199 private static Collection EMPTY_COLLECTION = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE setParent TypesConfigurationArea.java 201 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L201 private final HashMap> models = new HashMap<>(0); OPEN (file untouched on branch) +correction element_map DOOP_STORE elementsForGroup TypesConfigurationArea.java 363 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L363 HashMap categories = new HashMap<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE initializeFromGroup TypesConfigurationArea.java 464 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L464 Collection checked = new HashSet<>(); OPEN (file untouched on branch) +correction element_map DOOP_STORE initializeFromGroup TypesConfigurationArea.java 465 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/TypesConfigurationArea.java#L465 Collection greyed = new HashSet<>(); OPEN (file untouched on branch) +ui-thread nested_event_loop UI_THREAD_WAIT ensureRepaint QuickFixWizard.java 144 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java#L144 dispatch = display.readAndDispatch(); OPEN (file untouched on branch) +ui-thread nested_event_loop UI_THREAD_WAIT main ViewerColumnsDialog.java 869 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java#L869 if (!display.readAndDispatch()) { OPEN (file untouched on branch) +ui-thread modal_no_fork UI_THREAD_WAIT performFinish QuickFixWizard.java 99 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/QuickFixWizard.java#L99 getContainer().run(false, true, finishRunnable); OPEN (file untouched on branch) +ui-thread busy_wait UI_THREAD_WAIT refreshContents CachedMarkerBuilder.java 258 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/CachedMarkerBuilder.java#L258 service.busyCursorWhile(monitor -> { OPEN (site still present on branch) +ui-thread workspace_io REVIEW internalGatherMarkers MarkerContentGenerator.java 927 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerContentGenerator.java#L927 markers = resource.findMarkers(typeId, includeSubTypes, IResource.DEPTH_INFINITE); OPEN (site still present on branch) +ui-thread display_default REVIEW prepare M3MarkerDeltas.java 328 https://github.com/hsoliwal/eclipse.platform.ui/blob/e71e89820b27e0e23b88e97cb4ef9e2e3f373641/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/M3MarkerDeltas.java#L328 Display display = Display.getDefault(); OPEN (site still present on branch) diff --git a/docs/m3/markers-view/REFERENCE_TREE_VIEW.md b/docs/m3/markers-view/REFERENCE_TREE_VIEW.md new file mode 100644 index 00000000000..0833bcc81ac --- /dev/null +++ b/docs/m3/markers-view/REFERENCE_TREE_VIEW.md @@ -0,0 +1,98 @@ +# The Problems view is the reference tree view + +Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + +User, 2026-10-20 (said four times): "problems view is the example of how a tree view should [work] with all its api". + +The Problems view is the template every other tree view follows: Project Explorer, Outline, Tasks, Bookmarks, Debug, +Search, Call/Type hierarchy, Synchronize. What it proves once, the others reuse: + +- one lane model (ids, parent/child topology, grouping keys, sort permutation, filter and scope bit lanes, interned + labels), with lazy parent-owned facades; +- deltas from every change source, including model deltas, scope and selection set-diffs, filter edits and search + keystrokes. See FALLBACKS_TO_DELTAS.md; +- the window patch: rows inside the window are patched, while outside it only counts, extents and the scrollbar + change; +- resize and layout as viewport deltas (brief rule 24); +- debounce with a superseding generation, model work off the UI thread, and one apply per result. + +## All of the API + +TREE_VIEW_API_MATRIX.tsv lists every public and protected method of Viewer, ContentViewer, StructuredViewer, +ColumnViewer, AbstractTreeViewer and TreeViewer: 305 methods, generated mechanically from the sources with grep and +awk. Each row has: + +- `used_by_markers_view`: call sites in org.eclipse.ui.internal.views.markers. +- `lane_delta_status`: how the method is answered on the lane model, as LANES, DELTA, FACADE (an object only on + demand), STOCK_OK (no model work) or TODO. +- `differential`: whether stock and ours give the same answers and events in the reference view's differential. The + value is PASS, FAIL or TODO. +- `delta_gate`: whether the method can trigger a full rebuild on a change path. The value is PASS (no) or + JUSTIFIED (with file:line). + +The reference is done when every row is filled in: no TODO, every differential PASS, and every delta_gate PASS or +JUSTIFIED. Methods the Problems view does not call itself are still exercised, through a generic tree-view test +that drives the same lane model. That is how "all its API" is covered, and that test becomes the template test for +every other tree view. + +Regenerate the method list after an upstream sync with the command in the commit that added this file, then merge +the status columns by `class` + `signature`. + +## Hidden viewports: one helper for every view + +User, 2026-10-20: "if the viewport becomes visible from hidden it should paint; while it is hidden the model may make +changes and the viewport is dirty and renders on becoming visible", and "IPartListener can base it on this". + +`org.eclipse.ui.internal.m3.M3PartVisibility` (org.eclipse.ui.workbench) is the one helper. A view calls +`M3PartVisibility.watch(part, onShown)` once. The workbench drives it: `IPartListener2.partHidden` hides the part +(behind another tab, in a minimized or inactive stack), and `partVisible` shows it. While the part is hidden, the view +applies its deltas to the lanes, keeps a coalesced dirty window (the touched categories and the changed ids), and calls +`markDirty()`. It does no tree work. On `partVisible`, `onShown` runs once, inside the event and before the first +paint, and applies ONE window patch against the current lanes. + +The Problems view uses it in `M3MarkerDeltas.apply` and `shown`. The bench's hidden sweep minimizes the view, changes +up to 10^4 markers in one operation and restores the view. It records paints and item changes while hidden (both must +be 0), the rows after the restore (in the differential log, compared with stock), and `shown-patches` (one per hidden +period with changes). + +### Source of truth: SWT (brief rule 25), M3PartVisibility is the interim bridge + +User, 2026-10-20: "you own the implementation, you are not a layer on it", "INTRODUCE A NEW LISTENER PART VISIBLE", +"the viewport becoming [visible] should come from SWT or Swing". + +- The source of truth is a new SWT event, `SWT.PartVisible` / `SWT.PartHidden`, with `Control.isPartVisible()`. The + all-widgets agent is adding it to SWT itself. The Problems view's tree hears it directly from SWT: the viewport + lives inside `Tree`. The view then needs no listener of its own. The tree defers its native work while part-hidden + and applies one window patch and one paint on `SWT.PartVisible`. +- Workbench `IPartListener2.partVisible` / `partHidden` and the e4 part visibility events are built on that SWT event + in the e4 SWT renderer, so there is one source. They are not computed separately. +- Until that event exists in the SWT this fork runs on, `M3PartVisibility` (org.eclipse.ui.workbench) stands in for + it, on `IPartListener2`. Once SWT delivers `SWT.PartVisible`, `M3PartVisibility.isHidden()` becomes + `!control.isPartVisible()` and its callback becomes an `SWT.PartVisible` listener on the view's tree. The + view-side contract stays the same: lanes take deltas while hidden, and one patch runs on show. This is the change + to make when the SWT event lands; it is tracked in TREE_VIEW_API_MATRIX.tsv. + +## Adoption recipe: from TreeViewer + refresh() to deltas (rule 27 template) + +A view moves in five mechanical steps. Each step is a recipe hook like the Problems view's +(docs/m3/markers-view/recipe), and the second recipe pass must report UNCHANGED. + +1. **Spec.** Write `.m3view` next to the view class (`M3ViewSpec`, org.eclipse.jface.viewers.m3). It + names the adapter, the lanes, grouping, sort, filters, counts and presentation. Example: ProblemsView.m3view. +2. **Change source.** Hook the view's model listener at the line where it schedules its rebuild: offer the event to + the adapter first, and keep the rebuild for what the adapter declines (`if (Adapter.offer(...)) return;`). + The Problems view does this at `MarkersChangeListener.resourceChanged` before `scheduleUpdate()`. +3. **Model.** Where the view builds its element list, build the lanes instead (`Markers.updateWithNewMarkers` -> + `M3MarkerDeltas.build`). The view's model accessors (elements, children, counts, item lookup, clone) answer from + the lanes, and facades are created only for shown rows. +4. **Content provider.** Children and elements return the parent's window from the lanes. hasChildren comes from a + count, never from materialized children. +5. **Patch.** The adapter's job applies the lanes change on the UI thread and patches the tree through one + `M3ViewerDelta` (`M3Viewers.apply`) inside `preservingSelection`. While the part is hidden it only marks dirty, + and on show it patches once (M3PartVisibility now, SWT.PartVisible next). Scope and filter changes diff the + selected ids against the lanes instead of rebuilding. + +The template runtime factors steps 3 to 5 out of M3MarkerLanes and M3MarkerDeltas into generic parts: lane schema, +adapter interface, scope/filter/search lanes, grouping and sort lanes, delta viewer and counts. After that, a view +conversion is its spec plus steps 1 and 2. diff --git a/docs/m3/markers-view/TREE_VIEW_API_MATRIX.tsv b/docs/m3/markers-view/TREE_VIEW_API_MATRIX.tsv new file mode 100644 index 00000000000..ecebd2066a0 --- /dev/null +++ b/docs/m3/markers-view/TREE_VIEW_API_MATRIX.tsv @@ -0,0 +1,306 @@ +class visibility method signature used_by_markers_view lane_delta_status differential delta_gate +Viewer protected Viewer protected Viewer() 0 STOCK_OK TODO PASS +Viewer public addHelpListener public void addHelpListener(HelpListener listener) 1 STOCK_OK TODO PASS +Viewer public addSelectionChangedListener public void addSelectionChangedListener(ISelectionChangedListener listener) 5 FACADE TODO PASS +Viewer protected fireHelpRequested protected void fireHelpRequested(HelpEvent event) 0 STOCK_OK TODO PASS +Viewer protected fireSelectionChanged protected void fireSelectionChanged(final SelectionChangedEvent event) 0 FACADE TODO PASS +Viewer public getControl public abstract Control getControl(); 16 STOCK_OK TODO PASS +Viewer public getData public Object getData(String key) 9 STOCK_OK TODO PASS +Viewer public getInput public abstract Object getInput(); 4 FACADE TODO PASS +Viewer public getSelection public abstract ISelection getSelection(); 24 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +Viewer protected handleHelpRequest protected void handleHelpRequest(HelpEvent event) 0 STOCK_OK TODO PASS +Viewer protected inputChanged protected void inputChanged(Object input, Object oldInput) 2 FACADE TODO PASS +Viewer public refresh public abstract void refresh(); 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +Viewer public removeHelpListener public void removeHelpListener(HelpListener listener) 0 STOCK_OK TODO PASS +Viewer public removeSelectionChangedListener public void removeSelectionChangedListener( 0 FACADE TODO PASS +Viewer public scrollDown public Item scrollDown(int x, int y) 0 STOCK_OK TODO PASS +Viewer public scrollUp public Item scrollUp(int x, int y) 0 STOCK_OK TODO PASS +Viewer public setData public void setData(String key, Object value) 2 STOCK_OK TODO PASS +Viewer public setInput public abstract void setInput(Object input); 7 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +Viewer public setSelection public void setSelection(ISelection selection) 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +Viewer public setSelection public abstract void setSelection(ISelection selection, boolean reveal); 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +ContentViewer protected ContentViewer protected ContentViewer() 0 STOCK_OK TODO PASS +ContentViewer public getContentProvider public IContentProvider getContentProvider() 3 STOCK_OK TODO PASS +ContentViewer public getInput public Object getInput() 4 FACADE TODO PASS +ContentViewer public getLabelProvider public IBaseLabelProvider getLabelProvider() 0 STOCK_OK TODO PASS +ContentViewer protected handleDispose protected void handleDispose(DisposeEvent event) 0 STOCK_OK TODO PASS +ContentViewer protected handleLabelProviderChanged protected void handleLabelProviderChanged(LabelProviderChangedEvent event) 0 STOCK_OK TODO PASS +ContentViewer protected hookControl protected void hookControl(Control control) 0 STOCK_OK TODO PASS +ContentViewer protected labelProviderChanged protected void labelProviderChanged() 0 STOCK_OK TODO PASS +ContentViewer public setContentProvider public void setContentProvider(IContentProvider contentProvider) 7 STOCK_OK TODO PASS +ContentViewer public setInput public void setInput(Object input) 7 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +ContentViewer public setLabelProvider public void setLabelProvider(IBaseLabelProvider labelProvider) 7 STOCK_OK TODO PASS +StructuredViewer protected StructuredViewer protected StructuredViewer() 0 STOCK_OK TODO PASS +StructuredViewer public addDoubleClickListener public void addDoubleClickListener(IDoubleClickListener listener) 1 STOCK_OK TODO PASS +StructuredViewer public addOpenListener public void addOpenListener(IOpenListener listener) 0 STOCK_OK TODO PASS +StructuredViewer public addPostSelectionChangedListener public void addPostSelectionChangedListener(ISelectionChangedListener listener) 0 FACADE TODO PASS +StructuredViewer public addDragSupport public void addDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener) 1 STOCK_OK TODO PASS +StructuredViewer public addDropSupport public void addDropSupport(int operations, Transfer[] transferTypes, 0 STOCK_OK TODO PASS +StructuredViewer public addFilter public void addFilter(ViewerFilter filter) 0 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected assertElementsNotNull protected void assertElementsNotNull(Object... elements) 0 STOCK_OK TODO PASS +StructuredViewer protected associate protected void associate(Object element, Item item) 0 DELTA TODO PASS +StructuredViewer protected disassociate protected void disassociate(Item item) 0 DELTA TODO PASS +StructuredViewer protected doFindInputItem protected abstract Widget doFindInputItem(Object element); 0 FACADE TODO PASS +StructuredViewer protected doFindItem protected abstract Widget doFindItem(Object element); 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected doUpdateItem protected abstract void doUpdateItem(Widget item, Object element, boolean fullMap); 1 DELTA TODO PASS +StructuredViewer protected equals protected boolean equals(Object elementA, Object elementB) 76 STOCK_OK TODO PASS +StructuredViewer protected filter protected Object[] filter(Object[] elements) 1 TODO TODO PASS +StructuredViewer protected findItem protected final Widget findItem(Object element) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected findItems protected final Widget[] findItems(Object element) 0 FACADE TODO PASS +StructuredViewer protected fireDoubleClick protected void fireDoubleClick(final DoubleClickEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected fireOpen protected void fireOpen(final OpenEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected firePostSelectionChanged protected void firePostSelectionChanged(final SelectionChangedEvent event) 0 FACADE TODO PASS +StructuredViewer public getComparer public IElementComparer getComparer() 0 STOCK_OK TODO PASS +StructuredViewer protected getFilteredChildren protected Object[] getFilteredChildren(Object parent) 0 FACADE TODO PASS +StructuredViewer public getFilters public ViewerFilter[] getFilters() 1 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected getItem protected Item getItem(int x, int y) 0 STOCK_OK TODO PASS +StructuredViewer protected getRawChildren protected Object[] getRawChildren(Object parent) 0 FACADE TODO PASS +StructuredViewer protected getRoot protected Object getRoot() 5 FACADE TODO PASS +StructuredViewer public getSelection public ISelection getSelection() 24 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public getStructuredSelection public IStructuredSelection getStructuredSelection() throws ClassCastException 15 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected getSelectionFromWidget protected abstract List getSelectionFromWidget(); 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected getSortedChildren protected Object[] getSortedChildren(Object parent) 0 FACADE TODO PASS +StructuredViewer public getSorter public ViewerSorter getSorter() 0 TODO TODO PASS +StructuredViewer public getComparator public ViewerComparator getComparator() 2 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected handleDoubleSelect protected void handleDoubleSelect(SelectionEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected handleOpen protected void handleOpen(SelectionEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected handleInvalidSelection protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) 0 FACADE TODO PASS +StructuredViewer protected handleLabelProviderChanged protected void handleLabelProviderChanged(LabelProviderChangedEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected handleSelect protected void handleSelect(SelectionEvent event) 0 STOCK_OK TODO PASS +StructuredViewer protected handlePostSelect protected void handlePostSelect(SelectionEvent e) 0 STOCK_OK TODO PASS +StructuredViewer protected hookControl protected void hookControl(Control control) 0 STOCK_OK TODO PASS +StructuredViewer protected hasFilters protected boolean hasFilters() 0 TODO TODO PASS +StructuredViewer protected internalRefresh protected abstract void internalRefresh(Object element); 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer protected internalRefresh protected void internalRefresh(Object element, boolean updateLabels) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer protected mapElement protected void mapElement(Object element, Widget item) 0 DELTA TODO PASS +StructuredViewer protected needsRefilter protected boolean needsRefilter(Object element, String property) 0 TODO TODO PASS +StructuredViewer protected preservingSelection protected void preservingSelection(Runnable updateCode) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public refresh public void refresh() 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer public refresh public void refresh(boolean updateLabels) 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer public refresh public void refresh(final Object element) 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer public refresh public void refresh(final Object element, final boolean updateLabels) 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer protected refreshItem protected final void refreshItem(Widget widget, Object element) 0 DELTA TODO PASS +StructuredViewer public removeOpenListener public void removeOpenListener(IOpenListener listener) 0 STOCK_OK TODO PASS +StructuredViewer public removePostSelectionChangedListener public void removePostSelectionChangedListener(ISelectionChangedListener listener) 0 FACADE TODO PASS +StructuredViewer public removeDoubleClickListener public void removeDoubleClickListener(IDoubleClickListener listener) 0 STOCK_OK TODO PASS +StructuredViewer public removeFilter public void removeFilter(ViewerFilter filter) 0 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public setFilters public void setFilters(ViewerFilter... filters) 0 TODO TODO PASS +StructuredViewer public resetFilters public void resetFilters() 0 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public reveal public abstract void reveal(Object element); 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public setContentProvider public void setContentProvider(IContentProvider provider) 7 STOCK_OK TODO PASS +StructuredViewer protected assertContentProviderType protected void assertContentProviderType(IContentProvider provider) 0 STOCK_OK TODO PASS +StructuredViewer public setInput public final void setInput(Object input) 7 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +StructuredViewer public setSelection public void setSelection(ISelection selection, boolean reveal) 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected setSelectionToWidget protected abstract void setSelectionToWidget(@SuppressWarnings("rawtypes") List l, boolean reveal); 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected setSelectionToWidget protected void setSelectionToWidget(ISelection selection, boolean reveal) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public setSorter public void setSorter(ViewerSorter sorter) 0 TODO TODO PASS +StructuredViewer public setComparator public void setComparator(ViewerComparator comparator) 2 TODO PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public setUseHashlookup public void setUseHashlookup(boolean enable) 1 STOCK_OK PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public setComparer public void setComparer(IElementComparer comparer) 0 STOCK_OK TODO PASS +StructuredViewer public testFindItem public Widget testFindItem(Object element) 1 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public testFindItems public Widget[] testFindItems(Object element) 0 FACADE TODO PASS +StructuredViewer protected unmapAllElements protected void unmapAllElements() 0 DELTA TODO PASS +StructuredViewer protected unmapElement protected void unmapElement(Object element) 0 DELTA TODO PASS +StructuredViewer protected unmapElement protected void unmapElement(Object element, Widget item) 0 DELTA TODO PASS +StructuredViewer public update public void update(Object[] elements, String[] properties) 8 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer public update public void update(Object element, String[] properties) 8 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected internalUpdate protected void internalUpdate(Widget widget, Object element, String[] properties) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +StructuredViewer protected updateItem protected final void updateItem(Widget widget, Object element) 0 DELTA TODO PASS +StructuredViewer protected updateSelection protected void updateSelection(ISelection selection) 0 FACADE TODO PASS +StructuredViewer protected usingElementMap protected boolean usingElementMap() 0 STOCK_OK TODO PASS +StructuredViewer public setLabelProvider public void setLabelProvider(IBaseLabelProvider labelProvider) 7 STOCK_OK TODO PASS +StructuredViewer protected buildLabel protected void buildLabel(ViewerLabel updateLabel, Object element) 0 STOCK_OK TODO PASS +StructuredViewer protected getColorAndFontCollector protected ColorAndFontCollector getColorAndFontCollector() 0 STOCK_OK TODO PASS +StructuredViewer protected handleDispose protected void handleDispose(DisposeEvent event) 0 STOCK_OK TODO PASS +ColumnViewer public ColumnViewer public ColumnViewer() 0 STOCK_OK TODO PASS +ColumnViewer protected hookControl protected void hookControl(Control control) 0 STOCK_OK TODO PASS +ColumnViewer protected hookEditingSupport protected void hookEditingSupport(Control control) 0 STOCK_OK TODO PASS +ColumnViewer protected createViewerEditor protected abstract ColumnViewerEditor createViewerEditor(); 0 STOCK_OK TODO PASS +ColumnViewer public getCell public ViewerCell getCell(Point point) 0 STOCK_OK TODO PASS +ColumnViewer protected getViewerRow protected ViewerRow getViewerRow(Point point) 0 STOCK_OK TODO PASS +ColumnViewer protected getViewerRowFromItem protected abstract ViewerRow getViewerRowFromItem(Widget item); 0 STOCK_OK TODO PASS +ColumnViewer protected getColumnViewerOwner protected abstract Widget getColumnViewerOwner(int columnIndex); 0 STOCK_OK TODO PASS +ColumnViewer protected getItemAt protected abstract Item getItemAt(Point point); 0 STOCK_OK TODO PASS +ColumnViewer protected getItem protected Item getItem(int x, int y) 0 STOCK_OK TODO PASS +ColumnViewer public setLabelProvider public void setLabelProvider(IBaseLabelProvider labelProvider) 7 STOCK_OK TODO PASS +ColumnViewer public cancelEditing public void cancelEditing() 0 STOCK_OK TODO PASS +ColumnViewer public applyEditorValue public void applyEditorValue() 0 STOCK_OK TODO PASS +ColumnViewer public editElement public void editElement(Object element, int column) 0 STOCK_OK TODO PASS +ColumnViewer public getCellEditors public CellEditor[] getCellEditors() 0 STOCK_OK TODO PASS +ColumnViewer public getCellModifier public ICellModifier getCellModifier() 0 STOCK_OK TODO PASS +ColumnViewer public getColumnProperties public Object[] getColumnProperties() 0 STOCK_OK TODO PASS +ColumnViewer public isCellEditorActive public boolean isCellEditorActive() 0 STOCK_OK TODO PASS +ColumnViewer public refresh public void refresh(Object element) 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +ColumnViewer public refresh public void refresh(Object element, boolean updateLabels) 19 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +ColumnViewer public update public void update(Object element, String[] properties) 8 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +ColumnViewer public setCellEditors public void setCellEditors(CellEditor[] editors) 0 STOCK_OK TODO PASS +ColumnViewer public setCellModifier public void setCellModifier(ICellModifier modifier) 0 STOCK_OK TODO PASS +ColumnViewer public setColumnProperties public void setColumnProperties(String[] columnProperties) 0 STOCK_OK TODO PASS +ColumnViewer protected doGetColumnCount protected abstract int doGetColumnCount(); 0 STOCK_OK TODO PASS +ColumnViewer public getLabelProvider public CellLabelProvider getLabelProvider(int columnIndex) 0 STOCK_OK TODO PASS +ColumnViewer protected handleDispose protected void handleDispose(DisposeEvent event) 0 STOCK_OK TODO PASS +ColumnViewer protected triggerEditorActivationEvent protected void triggerEditorActivationEvent( 0 STOCK_OK TODO PASS +ColumnViewer public setColumnViewerEditor public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) 0 STOCK_OK TODO PASS +ColumnViewer public getColumnViewerEditor public ColumnViewerEditor getColumnViewerEditor() 0 STOCK_OK TODO PASS +ColumnViewer protected getRawChildren protected Object[] getRawChildren(Object parent) 0 FACADE TODO PASS +ColumnViewer protected checkBusy protected boolean checkBusy() 0 STOCK_OK TODO PASS +ColumnViewer protected setBusy protected void setBusy(boolean busy) 0 STOCK_OK TODO PASS +ColumnViewer public isBusy public boolean isBusy() 0 STOCK_OK TODO PASS +ColumnViewer protected getSortedChildren protected Object[] getSortedChildren(Object parent) 0 FACADE TODO PASS +ColumnViewer public setDisplayIncrementally public void setDisplayIncrementally(int incrementSize) 0 STOCK_OK TODO PASS +ColumnViewer protected disassociate protected void disassociate(Item item) 0 DELTA TODO PASS +ColumnViewer protected handleDoubleSelect protected void handleDoubleSelect(SelectionEvent event) 0 STOCK_OK TODO PASS +ColumnViewer public isExpandableNode public final boolean isExpandableNode(Object element) 0 FACADE TODO PASS +ColumnViewer protected updateSelection protected void updateSelection(ISelection selection) 0 FACADE TODO PASS +ColumnViewer protected firePostSelectionChanged protected void firePostSelectionChanged(SelectionChangedEvent event) 0 FACADE TODO PASS +ColumnViewer protected unmapAllElements protected void unmapAllElements() 0 DELTA TODO PASS +AbstractTreeViewer protected AbstractTreeViewer protected AbstractTreeViewer() 0 STOCK_OK TODO PASS +AbstractTreeViewer public add public void add(Object parentElementOrTreePath, Object... childElements) 87 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected internalAdd protected void internalAdd(Widget widget, Object parentElementOrTreePath, 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected indexForElement protected int indexForElement(Widget parent, Object element) 0 FACADE TODO PASS +AbstractTreeViewer protected getSortedChildren protected Object[] getSortedChildren(Object parentElementOrTreePath) 0 FACADE TODO PASS +AbstractTreeViewer public add public void add(Object parentElementOrTreePath, Object childElement) 87 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected addSelectionListener protected void addSelectionListener(Control control, 21 FACADE TODO PASS +AbstractTreeViewer public addTreeListener public void addTreeListener(ITreeViewerListener listener) 1 STOCK_OK TODO PASS +AbstractTreeViewer protected addTreeListener protected abstract void addTreeListener(Control control, 1 STOCK_OK TODO PASS +AbstractTreeViewer protected associate protected void associate(Object element, Item item) 0 DELTA TODO PASS +AbstractTreeViewer public collapseAll public void collapseAll() 0 FACADE TODO PASS +AbstractTreeViewer public collapseSelection public void collapseSelection() 0 FACADE TODO PASS +AbstractTreeViewer public collapseSelectionToLevel public void collapseSelectionToLevel(int level) 0 FACADE TODO PASS +AbstractTreeViewer public collapseToLevel public void collapseToLevel(Object elementOrTreePath, int level) 0 FACADE TODO PASS +AbstractTreeViewer protected createChildren protected void createChildren(final Widget widget) 0 DELTA TODO PASS +AbstractTreeViewer protected createTreeItem protected void createTreeItem(Widget parent, Object element, int index) 0 DELTA TODO PASS +AbstractTreeViewer protected disassociate protected void disassociate(Item item) 0 DELTA TODO PASS +AbstractTreeViewer protected doFindInputItem protected Widget doFindInputItem(Object element) 0 FACADE TODO PASS +AbstractTreeViewer protected doFindItem protected Widget doFindItem(Object element) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected doUpdateItem protected void doUpdateItem(final Item item, Object element) 1 DELTA TODO PASS +AbstractTreeViewer protected isSameSelection protected boolean isSameSelection(List items, Item[] current) 0 FACADE TODO PASS +AbstractTreeViewer protected doUpdateItem protected void doUpdateItem(Widget widget, Object element, boolean fullMap) 1 DELTA TODO PASS +AbstractTreeViewer public expandAll public void expandAll() 0 FACADE TODO PASS +AbstractTreeViewer public expandSelection public void expandSelection() 0 FACADE TODO PASS +AbstractTreeViewer public expandSelectionToLevel public void expandSelectionToLevel(int level) 0 FACADE TODO PASS +AbstractTreeViewer public expandAll public void expandAll(boolean disableRedraw) 0 FACADE TODO PASS +AbstractTreeViewer public expandToLevel public void expandToLevel(int level) 1 FACADE TODO PASS +AbstractTreeViewer public expandToLevel public void expandToLevel(int level, boolean disableRedraw) 1 FACADE TODO PASS +AbstractTreeViewer public expandToLevel public void expandToLevel(Object elementOrTreePath, int level) 1 FACADE TODO PASS +AbstractTreeViewer public expandToLevel public void expandToLevel(Object elementOrTreePath, int level, boolean disableRedraw) 1 FACADE TODO PASS +AbstractTreeViewer protected fireTreeCollapsed protected void fireTreeCollapsed(final TreeExpansionEvent event) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected fireTreeExpanded protected void fireTreeExpanded(final TreeExpansionEvent event) 0 STOCK_OK TODO PASS +AbstractTreeViewer public getAutoExpandLevel public int getAutoExpandLevel() 0 FACADE TODO PASS +AbstractTreeViewer public getAutoExpandOnSingleChildLevels public int getAutoExpandOnSingleChildLevels() 0 FACADE TODO PASS +AbstractTreeViewer protected getChildren protected abstract Item[] getChildren(Widget widget); 21 FACADE TODO PASS +AbstractTreeViewer protected getChild protected Item getChild(Widget widget, int index) 3 FACADE TODO PASS +AbstractTreeViewer protected getExpanded protected abstract boolean getExpanded(Item item); 1 FACADE TODO PASS +AbstractTreeViewer public getExpandedElements public Object[] getExpandedElements() 0 FACADE TODO PASS +AbstractTreeViewer public getExpandedState public boolean getExpandedState(Object elementOrTreePath) 2 FACADE TODO PASS +AbstractTreeViewer protected getItemCount protected abstract int getItemCount(Control control); 0 FACADE TODO PASS +AbstractTreeViewer protected getItemCount protected abstract int getItemCount(Item item); 0 FACADE TODO PASS +AbstractTreeViewer protected getItems protected abstract Item[] getItems(Item item); 1 FACADE TODO PASS +AbstractTreeViewer protected getNextItem protected Item getNextItem(Item item, boolean includeChildren) 0 FACADE TODO PASS +AbstractTreeViewer protected getParentItem protected abstract Item getParentItem(Item item); 0 FACADE TODO PASS +AbstractTreeViewer protected getPreviousItem protected Item getPreviousItem(Item item) 0 FACADE TODO PASS +AbstractTreeViewer protected getRawChildren protected Object[] getRawChildren(Object parentElementOrTreePath) 0 FACADE TODO PASS +AbstractTreeViewer protected getSelection protected abstract Item[] getSelection(Control control); 24 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected getSelectionFromWidget protected List getSelectionFromWidget() 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected handleDoubleSelect protected void handleDoubleSelect(SelectionEvent event) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected handleTreeCollapse protected void handleTreeCollapse(TreeEvent event) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected handleTreeExpand protected void handleTreeExpand(TreeEvent event) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected hookControl protected void hookControl(Control control) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected inputChanged protected void inputChanged(Object input, Object oldInput) 2 FACADE TODO PASS +AbstractTreeViewer protected internalInitializeTree protected void internalInitializeTree(Control tree) 0 FACADE TODO PASS +AbstractTreeViewer protected internalCollapseToLevel protected void internalCollapseToLevel(Widget widget, int level) 0 FACADE TODO PASS +AbstractTreeViewer protected internalExpand protected Widget internalExpand(Object elementOrPath, boolean expand) 0 FACADE TODO PASS +AbstractTreeViewer protected getParentElement protected Object getParentElement(Object elementOrTreePath) 0 FACADE TODO PASS +AbstractTreeViewer protected internalGetWidgetToSelect protected Widget internalGetWidgetToSelect(Object elementOrTreePath) 0 FACADE TODO PASS +AbstractTreeViewer protected internalExpandToLevel protected void internalExpandToLevel(Widget widget, int level) 0 FACADE TODO PASS +AbstractTreeViewer protected internalRefresh protected void internalRefresh(Object element) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +AbstractTreeViewer protected internalRefresh protected void internalRefresh(Object element, boolean updateLabels) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +AbstractTreeViewer protected internalRefresh protected void internalRefresh(Widget widget, Object element, 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +AbstractTreeViewer protected internalRemove protected void internalRemove(Object[] elementsOrPaths) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected internalRemove protected void internalRemove(Object parent, Object[] elements) 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public isExpandable public boolean isExpandable(Object elementOrTreePath) 1 FACADE TODO PASS +AbstractTreeViewer protected labelProviderChanged protected void labelProviderChanged() 0 STOCK_OK TODO PASS +AbstractTreeViewer protected newItem protected abstract Item newItem(Widget parent, int style, int index); 0 DELTA TODO PASS +AbstractTreeViewer public remove public void remove(final Object... elementsOrTreePaths) 12 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public remove public void remove(final Object parent, final Object... elements) 12 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public remove public void remove(Object elementsOrTreePaths) 12 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected removeAll protected abstract void removeAll(Control control); 3 DELTA TODO JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +AbstractTreeViewer public removeTreeListener public void removeTreeListener(ITreeViewerListener listener) 0 STOCK_OK TODO PASS +AbstractTreeViewer public reveal public void reveal(Object elementOrTreePath) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public scrollDown public Item scrollDown(int x, int y) 0 STOCK_OK TODO PASS +AbstractTreeViewer public scrollUp public Item scrollUp(int x, int y) 0 STOCK_OK TODO PASS +AbstractTreeViewer public setAutoExpandLevel public void setAutoExpandLevel(int level) 0 FACADE TODO PASS +AbstractTreeViewer public setAutoExpandOnSingleChildLevels public void setAutoExpandOnSingleChildLevels(int level) 0 FACADE TODO PASS +AbstractTreeViewer public setContentProvider public void setContentProvider(IContentProvider provider) 7 STOCK_OK TODO PASS +AbstractTreeViewer protected assertContentProviderType protected void assertContentProviderType(IContentProvider provider) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected setExpanded protected abstract void setExpanded(Item item, boolean expand); 1 FACADE TODO PASS +AbstractTreeViewer public setExpandedElements public void setExpandedElements(Object... elements) 0 FACADE TODO PASS +AbstractTreeViewer public setExpandedTreePaths public void setExpandedTreePaths(TreePath... treePaths) 0 FACADE TODO PASS +AbstractTreeViewer public setExpandedState public void setExpandedState(Object elementOrTreePath, boolean expanded) 3 FACADE TODO PASS +AbstractTreeViewer public setExpandedStateWithAutoExpandOnSingleChild public void setExpandedStateWithAutoExpandOnSingleChild(Object elementOrTreePath, boolean expanded) 0 FACADE TODO PASS +AbstractTreeViewer protected setSelection protected abstract void setSelection(List items); 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected setSelectionToWidget protected void setSelectionToWidget(@SuppressWarnings("rawtypes") List v, boolean reveal) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected showItem protected abstract void showItem(Item item); 0 FACADE TODO PASS +AbstractTreeViewer protected updateChildren protected void updateChildren(Widget widget, Object parent, 0 DELTA TODO PASS +AbstractTreeViewer public getChildren public Item[] getChildren(Widget widget, Object[] elementChildren) 21 FACADE TODO PASS +AbstractTreeViewer protected updatePlus protected void updatePlus(Item item, Object element) 0 DELTA TODO PASS +AbstractTreeViewer public getVisibleExpandedElements public Object[] getVisibleExpandedElements() 0 FACADE TODO PASS +AbstractTreeViewer protected getTreePathFromItem protected TreePath getTreePathFromItem(Item item) 0 FACADE TODO PASS +AbstractTreeViewer public getSelection public ISelection getSelection() 24 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public getStructuredSelection public ITreeSelection getStructuredSelection() throws ClassCastException 15 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer protected setSelectionToWidget protected void setSelectionToWidget(ISelection selection, boolean reveal) 0 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +AbstractTreeViewer public getExpandedTreePaths public TreePath[] getExpandedTreePaths() 0 FACADE TODO PASS +AbstractTreeViewer public insert public void insert(Object parentElementOrTreePath, Object element, 2 DELTA TODO PASS +AbstractTreeViewer protected getColumnViewerOwner protected Widget getColumnViewerOwner(int columnIndex) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected getItemAt protected Item getItemAt(Point point) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected createViewerEditor protected ColumnViewerEditor createViewerEditor() 0 STOCK_OK TODO PASS +AbstractTreeViewer protected doGetColumnCount protected int doGetColumnCount() 0 STOCK_OK TODO PASS +AbstractTreeViewer protected buildLabel protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) 0 STOCK_OK TODO PASS +AbstractTreeViewer protected getViewerRowFromItem protected ViewerRow getViewerRowFromItem(Widget item) 0 STOCK_OK TODO PASS +AbstractTreeViewer public setExpandPreCheckFilters public void setExpandPreCheckFilters(boolean checkFilters) 0 FACADE TODO PASS +AbstractTreeViewer public contains public boolean contains(Object parent, Object element) 22 FACADE TODO PASS +TreeViewer public TreeViewer public TreeViewer(Composite parent) 0 STOCK_OK TODO PASS +TreeViewer public TreeViewer public TreeViewer(Composite parent, int style) 0 STOCK_OK TODO PASS +TreeViewer public TreeViewer public TreeViewer(Tree tree) 0 STOCK_OK TODO PASS +TreeViewer protected addTreeListener protected void addTreeListener(Control c, TreeListener listener) 1 STOCK_OK TODO PASS +TreeViewer protected getColumnViewerOwner protected Widget getColumnViewerOwner(int columnIndex) 0 STOCK_OK TODO PASS +TreeViewer protected getChildren protected Item[] getChildren(Widget o) 21 FACADE TODO PASS +TreeViewer public getControl public Control getControl() 16 STOCK_OK TODO PASS +TreeViewer protected getExpanded protected boolean getExpanded(Item item) 1 FACADE TODO PASS +TreeViewer protected getItemAt protected Item getItemAt(Point p) 0 STOCK_OK TODO PASS +TreeViewer protected getItemCount protected int getItemCount(Control widget) 0 FACADE TODO PASS +TreeViewer protected getItemCount protected int getItemCount(Item item) 0 FACADE TODO PASS +TreeViewer protected getItems protected Item[] getItems(Item item) 1 FACADE TODO PASS +TreeViewer public getLabelProvider public IBaseLabelProvider getLabelProvider() 0 STOCK_OK TODO PASS +TreeViewer protected getParentItem protected Item getParentItem(Item item) 0 FACADE TODO PASS +TreeViewer protected getSelection protected Item[] getSelection(Control widget) 24 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +TreeViewer public getTree public Tree getTree() 19 STOCK_OK TODO PASS +TreeViewer protected hookControl protected void hookControl(Control control) 0 STOCK_OK TODO PASS +TreeViewer protected createViewerEditor protected ColumnViewerEditor createViewerEditor() 0 STOCK_OK TODO PASS +TreeViewer protected newItem protected Item newItem(Widget parent, int flags, int ix) 0 DELTA TODO PASS +TreeViewer protected removeAll protected void removeAll(Control widget) 3 DELTA TODO JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +TreeViewer protected setExpanded protected void setExpanded(Item node, boolean expand) 1 FACADE TODO PASS +TreeViewer protected setSelection protected void setSelection(List items) 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +TreeViewer protected showItem protected void showItem(Item item) 0 FACADE TODO PASS +TreeViewer protected getChild protected Item getChild(Widget widget, int index) 3 FACADE TODO PASS +TreeViewer protected assertContentProviderType protected void assertContentProviderType(IContentProvider provider) 0 STOCK_OK TODO PASS +TreeViewer protected getRawChildren protected Object[] getRawChildren(Object parent) 0 FACADE TODO PASS +TreeViewer public setChildCount public void setChildCount(final Object elementOrTreePath, final int count) 0 DELTA TODO PASS +TreeViewer public replace public void replace(final Object parentElementOrTreePath, final int index, 0 DELTA TODO PASS +TreeViewer public isExpandable public boolean isExpandable(Object element) 1 FACADE TODO PASS +TreeViewer protected getParentElement protected Object getParentElement(Object element) 0 FACADE TODO PASS +TreeViewer protected internalAdd protected void internalAdd(Widget widget, Object parentElement, 0 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +TreeViewer protected internalRefreshStruct protected void internalRefreshStruct(Widget widget, Object element, 0 DELTA TODO JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510) +TreeViewer protected mapElement protected void mapElement(Object element, final Widget item) 0 DELTA TODO PASS +TreeViewer protected getViewerRowFromItem protected ViewerRow getViewerRowFromItem(Widget item) 0 STOCK_OK TODO PASS +TreeViewer protected internalInitializeTree protected void internalInitializeTree(Control widget) 0 FACADE TODO PASS +TreeViewer protected updatePlus protected void updatePlus(Item item, Object element) 0 DELTA TODO PASS +TreeViewer public remove public void remove(final Object parentOrTreePath, final int index) 12 DELTA PASS (JFace Layer A la4, 6f00b8d9ee) PASS +TreeViewer protected handleTreeExpand protected void handleTreeExpand(TreeEvent event) 0 STOCK_OK TODO PASS +TreeViewer protected handleTreeCollapse protected void handleTreeCollapse(TreeEvent event) 0 STOCK_OK TODO PASS +TreeViewer public setContentProvider public void setContentProvider(IContentProvider provider) 7 STOCK_OK TODO PASS +TreeViewer public setHasChildren public void setHasChildren(final Object elementOrTreePath, final boolean hasChildren) 0 DELTA TODO PASS +TreeViewer protected disassociate protected void disassociate(Item item) 0 DELTA TODO PASS +TreeViewer protected doGetColumnCount protected int doGetColumnCount() 0 STOCK_OK TODO PASS +TreeViewer public setSelection public void setSelection(ISelection selection, boolean reveal) 38 FACADE PASS (JFace Layer A la4, 6f00b8d9ee) PASS +TreeViewer public editElement public void editElement(Object element, int column) 0 STOCK_OK TODO PASS diff --git a/docs/m3/markers-view/bench-bundle/META-INF/MANIFEST.MF b/docs/m3/markers-view/bench-bundle/META-INF/MANIFEST.MF index 0c17c712bca..d6db087b598 100644 --- a/docs/m3/markers-view/bench-bundle/META-INF/MANIFEST.MF +++ b/docs/m3/markers-view/bench-bundle/META-INF/MANIFEST.MF @@ -4,6 +4,7 @@ Bundle-Name: M3 Markers view benchmark Bundle-SymbolicName: org.eclipse.ui.ide.m3bench;singleton:=true Bundle-Version: 1.0.0 Bundle-Vendor: Synexia +Import-Package: javax.management Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide, org.eclipse.core.resources, diff --git a/docs/m3/markers-view/bench-bundle/src/org/eclipse/ui/ide/m3bench/M3MarkersBench.java b/docs/m3/markers-view/bench-bundle/src/org/eclipse/ui/ide/m3bench/M3MarkersBench.java index 894a7f2064c..0f2afe2fe9b 100644 --- a/docs/m3/markers-view/bench-bundle/src/org/eclipse/ui/ide/m3bench/M3MarkersBench.java +++ b/docs/m3/markers-view/bench-bundle/src/org/eclipse/ui/ide/m3bench/M3MarkersBench.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import java.util.logging.Level; @@ -38,7 +39,9 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Tree; @@ -114,21 +117,64 @@ private void run() throws Exception { String desc = waitDescription(d -> d.contains(counted), 600_000); row("initial-build", n, millis(t0), -1, desc); settle(); - for (int rep = 0; rep < 5; rep++) { - measureChange(n, rep); + ui(() -> { + viewer().expandAll(); // the categories as a user works with them: windows of rows shown + return null; + }); + settle(); + Job.getJobManager().addJobChangeListener(jobCounter); + if (!Boolean.getBoolean("m3.markers.skipMeasure")) { //$NON-NLS-1$ + for (int k : new int[] { 1, 100, 10_000 }) { + if (k > n) { + continue; + } + for (int rep = 0; rep < (k >= 10_000 ? 3 : 5); rep++) { + measureBatch(n, k, rep); + } + } + heap(n); } - heap(n); String log = System.getProperty("m3.markers.log"); //$NON-NLS-1$ if (log != null) { - differential(Path.of(log), Long.getLong("m3.markers.seed", 1).longValue(), //$NON-NLS-1$ + differential(Path.of(log), n, Long.getLong("m3.markers.seed", 1).longValue(), //$NON-NLS-1$ Integer.getInteger("m3.markers.steps", 30).intValue(), project); //$NON-NLS-1$ } } - /** One severity change (error to warning), measured until the title shows it, then reverted. */ - private void measureChange(int n, int rep) throws Exception { - IMarker marker = markers.get(rep * 3); + /** Counts the markers view's UI updates (each one a full tree refresh) and clean rebuild jobs. */ + private final JobChangeAdapter jobCounter = new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + String name = event.getJob().getClass().getName(); + if (name.endsWith(".views.markers.UIUpdateJob")) { //$NON-NLS-1$ + refreshes.incrementAndGet(); + } else if (name.endsWith(".views.markers.MarkerUpdateJob")) { //$NON-NLS-1$ + rebuilds.incrementAndGet(); + } + } + }; + private final AtomicInteger refreshes = new AtomicInteger(); + private final AtomicInteger rebuilds = new AtomicInteger(); + + /** + * One delta of {@code k} markers (error to warning, in one workspace operation, so one resource change event + * carries {@code k} marker deltas), measured until the title shows it, then restored to the exact former + * severities (not measured). + */ + private void measureBatch(int n, int k, int rep) throws Exception { + List batch = new ArrayList<>(k); + int stride = k * 3 <= n ? 3 : 1; + for (int i = 0; i < k; i++) { + // i * 3 + 2 has severity error (i % 3) while the stride is 3 + batch.add(markers.get(stride == 3 ? i * 3 + 2 : i)); + } + int[] former = new int[k]; + for (int i = 0; i < k; i++) { + former[i] = batch.get(i).getAttribute(IMarker.SEVERITY, -1); + } String before = description(); + int refreshed = refreshes.get(); + int rebuilt = rebuilds.get(); com.sun.management.ThreadMXBean threads = (com.sun.management.ThreadMXBean) ManagementFactory .getThreadMXBean(); com.sun.management.OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean) ManagementFactory @@ -136,21 +182,63 @@ private void measureChange(int n, int rep) throws Exception { long bytes = threads.getTotalThreadAllocatedBytes(); long cpu = os.getProcessCpuTime(); long t0 = System.nanoTime(); - workspace().run((IWorkspaceRunnable) m -> marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING), - null); + workspace().run((IWorkspaceRunnable) m -> { + for (IMarker marker : batch) { + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); + } + }, null); String after = waitDescription(d -> !d.equals(before), 600_000); long t = millis(t0); long allocated = threads.getTotalThreadAllocatedBytes() - bytes; long cpuMillis = (os.getProcessCpuTime() - cpu) / 1_000_000; - row("one-change-ms", n, t, rep, after); - row("one-change-bytes", n, allocated, rep, ""); //$NON-NLS-1$ - row("one-change-cpu-ms", n, cpuMillis, rep, ""); //$NON-NLS-1$ - workspace().run((IWorkspaceRunnable) m -> marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR), - null); + settle(); + row("delta" + k + "-ms", n, t, rep, after); //$NON-NLS-1$ + row("delta" + k + "-bytes", n, allocated, rep, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("delta" + k + "-cpu-ms", n, cpuMillis, rep, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("delta" + k + "-full-refreshes", n, refreshes.get() - refreshed, rep, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("delta" + k + "-rebuilds", n, rebuilds.get() - rebuilt, rep, ""); //$NON-NLS-1$ //$NON-NLS-2$ + workspace().run((IWorkspaceRunnable) m -> { + for (int i = 0; i < k; i++) { + batch.get(i).setAttribute(IMarker.SEVERITY, former[i]); + } + }, null); waitDescription(d -> d.equals(before), 600_000); settle(); } + /** Types into the view's search box (the private {@code filteredTree} field of ExtendedMarkersView). */ + private void filterText(String text) throws ReflectiveOperationException { + for (Class c = view.getClass(); c != null; c = c.getSuperclass()) { + try { + java.lang.reflect.Field f = c.getDeclaredField("filteredTree"); //$NON-NLS-1$ + f.setAccessible(true); + Object tree = f.get(view); + ui(() -> { + ((org.eclipse.ui.dialogs.FilteredTree) tree).getFilterControl().setText(text); + return null; + }); + return; + } catch (NoSuchFieldException e) { + // try the superclass + } + } + throw new NoSuchFieldException("filteredTree"); //$NON-NLS-1$ + } + + /** The markers view's viewer, through its package-private {@code getViewer()} (reflection: internal class). */ + private TreeViewer viewer() throws ReflectiveOperationException { + for (Class c = view.getClass(); c != null; c = c.getSuperclass()) { + try { + Method m = c.getDeclaredMethod("getViewer"); //$NON-NLS-1$ + m.setAccessible(true); + return (TreeViewer) m.invoke(view); + } catch (NoSuchMethodException e) { + // try the superclass + } + } + throw new NoSuchMethodException("getViewer"); //$NON-NLS-1$ + } + private void heap(int n) throws Exception { for (int i = 0; i < 3; i++) { System.gc(); @@ -158,11 +246,11 @@ private void heap(int n) throws Exception { } long used = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); row("heap-used-bytes", n, used, -1, ""); //$NON-NLS-1$ - String jcmd = Path.of(System.getProperty("java.home"), "bin", "jcmd").toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Process p = new ProcessBuilder(jcmd, String.valueOf(ProcessHandle.current().pid()), "GC.class_histogram") //$NON-NLS-1$ - .redirectErrorStream(true).start(); - String histogram = new String(p.getInputStream().readAllBytes(), StandardCharsets.UTF_8); - p.waitFor(); + // GC.class_histogram in process (DiagnosticCommand MBean): jcmd cannot attach to a JVM on the hidden desktop + // and blocked the run forever + String histogram = String.valueOf(ManagementFactory.getPlatformMBeanServer().invoke( + new javax.management.ObjectName("com.sun.management:type=DiagnosticCommand"), "gcClassHistogram", //$NON-NLS-1$ //$NON-NLS-2$ + new Object[] { new String[0] }, new String[] { String[].class.getName() })); for (String line : histogram.split("\\R")) { //$NON-NLS-1$ if (line.matches( ".*\\s(\\S*\\.(MarkerEntry|MarkerCategory|MarkerInfo|MarkerAttributeMap|M3Marker\\w*)|org\\.eclipse\\.swt\\.widgets\\.TreeItem|java\\.text\\.\\w*CollationKey|java\\.util\\.concurrent\\.ConcurrentHashMap(\\$Node)?)\\s*(\\(.*)?$")) { //$NON-NLS-1$ @@ -174,17 +262,202 @@ private void heap(int n) throws Exception { } } - /** Seeded marker edits; after each, the view's answers are written to the log. */ - private void differential(Path log, long seed, int steps, IProject project) throws Exception { + /** + * Seeded marker edits; after each, the view's answers are written to the log. Then a resize sweep and a + * column-resize sweep (viewport deltas, brief rule 24) with their answers. The number of full tree refreshes + * (UI update jobs) and clean rebuilds during each phase go to the results, not to the log. + */ + private void differential(Path log, int n, long seed, int steps, IProject project) throws Exception { Random random = new Random(seed); List lines = new ArrayList<>(); + ui(() -> { + TreeViewer viewer = viewer(); + List rows = new ArrayList<>(); + for (TreeItem category : viewer.getTree().getItems()) { + for (TreeItem child : category.getItems()) { + if (rows.size() < 3 && child.getData() != null) { + rows.add(child.getData()); + } + } + } + viewer.setSelection(new org.eclipse.jface.viewers.StructuredSelection(rows)); + return null; + }); + settle(); lines.add("start | " + answers()); //$NON-NLS-1$ + int refreshed = refreshes.get(); + int rebuilt = rebuilds.get(); for (int step = 0; step < steps; step++) { String op = edit(random, project); settle(); lines.add(step + " " + op + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ } + row("diff-edits-full-refreshes", n, refreshes.get() - refreshed, steps, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-edits-rebuilds", n, rebuilds.get() - rebuilt, steps, ""); //$NON-NLS-1$ //$NON-NLS-2$ + refreshed = refreshes.get(); + int[] items = { ui(() -> Integer.valueOf(itemCount(viewer().getTree()))).intValue(), 0 }; + for (int step = 0; step < 6; step++) { + int s = step; + ui(() -> { + org.eclipse.swt.widgets.Shell shell = viewer().getTree().getShell(); + org.eclipse.swt.graphics.Point size = shell.getSize(); + shell.setSize(size.x + (s % 2 == 0 ? -120 : 120), size.y + (s % 2 == 0 ? -90 : 90)); + return null; + }); + settle(); + lines.add("resize " + step + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + } + for (int step = 0; step < 6; step++) { + int s = step; + ui(() -> { + Tree tree = viewer().getTree(); + org.eclipse.swt.widgets.TreeColumn column = tree.getColumn(s % tree.getColumnCount()); + column.setWidth(Math.max(20, column.getWidth() + (s % 2 == 0 ? 60 : -60))); + return null; + }); + settle(); + lines.add("column " + step + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + } + items[1] = ui(() -> Integer.valueOf(itemCount(viewer().getTree()))).intValue(); + row("diff-resize-full-refreshes", n, refreshes.get() - refreshed, 12, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-resize-items-delta", n, items[1] - items[0], 12, ""); //$NON-NLS-1$ //$NON-NLS-2$ + // the search box: typed text (stock: PatternFilter over every child, then the limit; M3: a hit lane), with + // marker edits while the text is active, then the text cleared + refreshed = refreshes.get(); + rebuilt = rebuilds.get(); + for (String text : new String[] { "Added", "problem 1", "" }) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + filterText(text); + Thread.sleep(600); // the FilteredTree refresh job runs after its own delay + settle(); + lines.add("search '" + text + "' | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + if (!text.isEmpty()) { + for (int step = 0; step < 3; step++) { + String op = edit(random, project); + settle(); + lines.add("search '" + text + "' " + step + " " + op + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } + } + row("diff-search-full-refreshes", n, refreshes.get() - refreshed, 9, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-search-rebuilds", n, rebuilds.get() - rebuilt, 9, ""); //$NON-NLS-1$ //$NON-NLS-2$ + hiddenSweep(lines, n); + scopeSweep(lines, n); Files.write(log, lines, StandardCharsets.UTF_8); + row("diff-counters", n, -1, -1, deltaCounters()); //$NON-NLS-1$ + } + + /** + * Hidden viewport (brief rule 24): the view is minimized, a build-like batch changes up to 10^4 markers in one + * operation, then the view is restored. While hidden the tree must do nothing (no paint, no item created or + * disposed); after the restore its rows must equal stock's, after one window patch. + */ + private void hiddenSweep(List lines, int n) throws Exception { + int k = Math.min(10_000, markers.size() / 2); + int[] paints = { 0 }; + org.eclipse.swt.widgets.Listener counter = e -> paints[0]++; + ui(() -> { + viewer().getTree().addListener(org.eclipse.swt.SWT.Paint, counter); + page().setPartState(page().getReference(view), IWorkbenchPage.STATE_MINIMIZED); + return null; + }); + settle(); + int itemsBefore = ui(() -> Integer.valueOf(itemCount(viewer().getTree()))).intValue(); + paints[0] = 0; + int refreshed = refreshes.get(); + workspace().run((IWorkspaceRunnable) m -> { + for (int i = 0; i < k; i++) { + IMarker marker = markers.get(i * (markers.size() / k)); + marker.setAttribute(IMarker.SEVERITY, (marker.getAttribute(IMarker.SEVERITY, 0) + 1) % 3); + } + }, null); + settle(); + int hiddenPaints = paints[0]; + int hiddenItems = ui(() -> Integer.valueOf(itemCount(viewer().getTree()))).intValue() - itemsBefore; + int hiddenRefreshes = refreshes.get() - refreshed; + paints[0] = 0; + refreshed = refreshes.get(); + ui(() -> { + page().setPartState(page().getReference(view), IWorkbenchPage.STATE_RESTORED); + page().activate(view); + return null; + }); + settle(); + lines.add("hidden " + k + " then shown | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-hidden-paints", n, hiddenPaints, k, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-hidden-items-delta", n, hiddenItems, k, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-hidden-ui-updates", n, hiddenRefreshes, k, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-shown-paints", n, paints[0], k, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-shown-ui-updates", n, refreshes.get() - refreshed, k, ""); //$NON-NLS-1$ //$NON-NLS-2$ + ui(() -> { + viewer().getTree().removeListener(org.eclipse.swt.SWT.Paint, counter); + return null; + }); + } + + /** + * Scope and filter changes (Bug 296695): up to four declared filter groups are enabled in turn, with the + * selection on one file and then on the project, and disabled again; each step logs the answers. Stock rebuilds + * on each; the M3 path diffs a gather against its lanes. Reached through the generator's package-private API. + */ + private void scopeSweep(List lines, int n) throws Exception { + Object generator = invoke(view, "getGenerator"); //$NON-NLS-1$ + List groups = new ArrayList<>((java.util.Collection) invoke(generator, "getAllFilters")); //$NON-NLS-1$ + int refreshed = refreshes.get(); + int rebuilt = rebuilds.get(); + int steps = Math.min(4, groups.size()); + for (int g = 0; g < steps; g++) { + Object group = groups.get(g); + String name = String.valueOf(invoke(group, "getName")); //$NON-NLS-1$ + ui(() -> invoke(generator, "toggleFilter", group)); //$NON-NLS-1$ + settle(); + lines.add("filter toggled " + name + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + for (Object[] selection : new Object[][] { { files.get(Math.min(1, files.size() - 1)) }, + { files.get(0).getProject() } }) { + ui(() -> invoke(generator, "updateSelectedResource", selection, Boolean.TRUE)); //$NON-NLS-1$ + settle(); + lines.add("select " + selection[0] + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + } + ui(() -> invoke(generator, "toggleFilter", group)); //$NON-NLS-1$ + settle(); + lines.add("filter toggled back " + name + " | " + answers()); //$NON-NLS-1$ //$NON-NLS-2$ + } + row("diff-scope-full-refreshes", n, refreshes.get() - refreshed, steps, ""); //$NON-NLS-1$ //$NON-NLS-2$ + row("diff-scope-rebuilds", n, rebuilds.get() - rebuilt, steps, ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* a declared method of the object's class or a superclass, made accessible (internal package-private API) */ + private static Object invoke(Object target, String name, Object... args) throws ReflectiveOperationException { + for (Class c = target.getClass(); c != null; c = c.getSuperclass()) { + for (Method m : c.getDeclaredMethods()) { + if (m.getName().equals(name) && m.getParameterCount() == args.length) { + m.setAccessible(true); + return m.invoke(target, args); + } + } + } + throw new NoSuchMethodException(target.getClass().getName() + '.' + name); + } + + private static int itemCount(Tree tree) { + int count = 0; + for (TreeItem category : tree.getItems()) { + count += 1 + category.getItemCount(); + } + return count; + } + + /** The M3 delta path's counters (applied, fallbacks, builds), when the M3 bundle is installed; else "-". */ + private String deltaCounters() { + try { + // the view class lives in org.eclipse.ui.ide: its loader sees the internal markers package + Class c = Class.forName("org.eclipse.ui.internal.views.markers.M3MarkerDeltas", true, //$NON-NLS-1$ + view.getClass().getClassLoader()); + Method m = c.getDeclaredMethod("counters"); //$NON-NLS-1$ + m.setAccessible(true); + return String.valueOf(m.invoke(null)); + } catch (ReflectiveOperationException | LinkageError e) { + return "-"; //$NON-NLS-1$ + } } private String edit(Random random, IProject project) throws CoreException { @@ -226,39 +499,32 @@ private String edit(Random random, IProject project) throws CoreException { return op.get(); } - /** The view's answers: title, then every category with its label, expansion and shown children. */ + /** + * The view's answers: title, then every category with its label, expansion and shown children, then the + * selection (widget and viewer). + */ private String answers() { return ui(() -> { StringBuilder b = new StringBuilder(((ViewPart) view).getContentDescription()); - Tree tree = viewTree(); - if (tree != null) { - for (TreeItem category : tree.getItems()) { - b.append(" || ").append(text(category)).append(category.getExpanded() ? " +" : " -"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (category.getExpanded()) { - for (TreeItem child : category.getItems()) { - b.append(" | ").append(text(child)); //$NON-NLS-1$ - } + TreeViewer viewer = viewer(); + Tree tree = viewer.getTree(); + for (TreeItem category : tree.getItems()) { + b.append(" || ").append(text(category)).append(category.getExpanded() ? " +" : " -"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (category.getExpanded()) { + for (TreeItem child : category.getItems()) { + b.append(" | ").append(text(child)); //$NON-NLS-1$ } } } + b.append(" || selection"); //$NON-NLS-1$ + for (TreeItem item : tree.getSelection()) { + b.append(" | ").append(text(item)); //$NON-NLS-1$ + } + b.append(" || viewer selection ").append(viewer.getStructuredSelection().size()); //$NON-NLS-1$ return b.toString(); }); } - /** The markers view's tree, through its package-private {@code getViewer()} (reflection: internal class). */ - private Tree viewTree() throws ReflectiveOperationException { - for (Class c = view.getClass(); c != null; c = c.getSuperclass()) { - try { - Method m = c.getDeclaredMethod("getViewer"); //$NON-NLS-1$ - m.setAccessible(true); - return ((TreeViewer) m.invoke(view)).getTree(); - } catch (NoSuchMethodException e) { - // try the superclass - } - } - return null; - } - private static String text(TreeItem item) { int columns = Math.max(1, item.getParent().getColumnCount()); StringBuilder b = new StringBuilder(); diff --git a/docs/m3/markers-view/recipe/META-INF/rewrite/m3-markers-view.yml b/docs/m3/markers-view/recipe/META-INF/rewrite/m3-markers-view.yml index f9afac46caa..a9401a5e103 100644 --- a/docs/m3/markers-view/recipe/META-INF/rewrite/m3-markers-view.yml +++ b/docs/m3/markers-view/recipe/META-INF/rewrite/m3-markers-view.yml @@ -3,11 +3,14 @@ --- type: specs.openrewrite.org/v1beta/recipe name: com.synexia.openrewrite.viewport.MarkersViewDeltaHooks -displayName: Markers view on marker deltas (M3) +displayName: Markers view on one lane model and marker deltas (M3) description: >- - Hooks of the markers views' delta path (docs/m3/markers-view/DESIGN.md): the change listener offers the - IMarkerDeltas to M3MarkerDeltas before scheduling a clean rebuild; a clean rebuild supersedes pending deltas; - categories sort completely so deltas insert by binary search; Markers gains one replace method for the patch. + Hooks of the markers views' lane model and delta path (docs/m3/markers-view/DESIGN.md, PROBLEMS_VIEW.md): the + change listener offers the IMarkerDeltas to M3MarkerDeltas before scheduling a clean rebuild; a clean rebuild + supersedes pending deltas and builds M3MarkerLanes instead of the entry array; Markers answers categories, counts, + marker items, clones and resorts from the lanes; the total count, the content provider's windows and hasChildren + come from the lanes; the tree viewer exposes preservingSelection for the window patch. Every hook is inert unless + -Dorg.eclipse.ui.ide.markers.mode=viewport. recipeList: - com.synexia.openrewrite.viewport.M3InsertStatements: declaringClasses: [org.eclipse.ui.internal.views.markers.MarkersChangeListener] @@ -22,12 +25,92 @@ recipeList: position: METHOD_START statements: "\t\tM3MarkerDeltas.supersede(this);" - com.synexia.openrewrite.viewport.M3InsertStatements: - declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] - methodName: getShowingLimit + declaringClasses: [org.eclipse.ui.internal.views.markers.CachedMarkerBuilder] + methodName: getTotalMarkerCount + parameterCount: 1 position: METHOD_START - statements: "\t\tif (M3MarkerDeltas.fullSort()) {\n\t\t\treturn available;\n\t\t}" + statements: "\t\tM3MarkerLanes lanes = markers.m3;\n\t\tif (lanes != null) {\n\t\t\treturn lanes.size();\n\t\t}" - com.synexia.openrewrite.viewport.M3AddMemberIfMissing: declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] - memberName: m3Replace - beforeMethod: getClone - memberSource: "\t/**\n\t * Replaces the model in one step with the result of a marker delta patch\n\t * (M3MarkerDeltas; docs/m3/markers-view/DESIGN.md).\n\t *\n\t * @param entries the entries, grouped by category\n\t * @param newCategories the categories over {@code entries}\n\t * @param counts the counts: errors, warnings, infos, others\n\t */\n\tsynchronized void m3Replace(MarkerEntry[] entries, MarkerCategory[] newCategories, Integer[] counts) {\n\t\tmarkerEntryArray = entries;\n\t\tcategories = newCategories;\n\t\tmarkerCounts = counts;\n\t\tmarkerToEntryMap = null;\n\t}\n" + memberName: m3 + beforeMethod: updateWithNewMarkers + memberSource: "\t/**\n\t * The lane model in M3 mode (M3MarkerLanes, docs/m3/markers-view/PROBLEMS_VIEW.md); {@code null} while\n\t * the entry array is the model.\n\t */\n\tvolatile M3MarkerLanes m3;\n" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: updateWithNewMarkers + anchor: "if (markerEntries.isEmpty())" + position: BEFORE + statements: "\t\t\tif (M3MarkerDeltas.ENABLED) {\n\t\t\t\tm3 = sortAndGroup ? M3MarkerDeltas.build(this, markerEntries, monitor) : null;\n\t\t\t\tif (m3 != null) {\n\t\t\t\t\tcategories = m3.categories();\n\t\t\t\t\tmarkerEntryArray = EMPTY_ENTRY_ARRAY;\n\t\t\t\t\tmarkerCounts = m3.counts();\n\t\t\t\t\treturn !monitor.isCanceled();\n\t\t\t\t}\n\t\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: sortMarkerEntries + position: METHOD_START + statements: "\t\tM3MarkerLanes lanes = m3;\n\t\tif (lanes != null) {\n\t\t\tif (lanes.resort(builder.getComparator())) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tm3 = null;\n\t\t\tbuilder.scheduleUpdate();\n\t\t\treturn false;\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: getMarkerCounts + parameterCount: 0 + position: METHOD_START + statements: "\t\tM3MarkerLanes lanes = m3;\n\t\tif (lanes != null) {\n\t\t\treturn lanes.counts();\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: getMarkerItem + position: METHOD_START + statements: "\t\tM3MarkerLanes lanes = m3;\n\t\tif (lanes != null) {\n\t\t\treturn lanes.item(marker);\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: getCategories + position: METHOD_START + statements: "\t\tM3MarkerLanes lanes = m3;\n\t\tif (lanes != null) {\n\t\t\treturn lanes.categories();\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: getElements + position: METHOD_START + statements: "\t\tM3MarkerLanes lanes = m3;\n\t\tif (lanes != null) {\n\t\t\treturn lanes.elements();\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.Markers] + methodName: getClone + anchor: "if (!inChange)" + position: BEFORE + statements: "\t\tmarkers.m3 = m3;\n\t\tif (markers.m3 != null) {\n\t\t\treturn markers;\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.MarkerViewerContentProvider] + methodName: getChildren + position: METHOD_START + statements: "\t\tif (parentElement instanceof M3MarkerCategory category && markersView.getSearchFilter() == null) {\n\t\t\treturn category.window(M3MarkerDeltas.limit(markersView));\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.MarkerViewerContentProvider] + methodName: hasChildren + position: METHOD_START + statements: "\t\tif (element instanceof M3MarkerCategory category) {\n\t\t\treturn category.getChildrenCount() > 0;\n\t\t}" + - com.synexia.openrewrite.viewport.M3AddMemberIfMissing: + declaringClasses: [org.eclipse.ui.internal.views.markers.MarkersTreeViewer] + memberName: m3PreservingSelection + beforeMethod: doUpdateItem + memberSource: "\t/**\n\t * Runs a window patch of the lane model (M3MarkerDeltas) the way refresh does: the selection is kept, and\n\t * selection listeners hear only of a selection that changed.\n\t *\n\t * @param patch the patch\n\t */\n\tvoid m3PreservingSelection(Runnable patch) {\n\t\tpreservingSelection(patch);\n\t}\n" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.MarkerViewerContentProvider] + methodName: getElements + position: METHOD_START + statements: "\t\tif (inputElement instanceof Markers markers && markers.m3 != null && markers.m3.isFlat()\n\t\t\t\t&& markersView.getSearchFilter() == null) {\n\t\t\treturn markers.m3.flatWindow(M3MarkerDeltas.limit(markersView));\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.ExtendedMarkersView] + methodName: getStatusMessage + position: METHOD_START + statements: "\t\tM3MarkerLanes m3Lanes = markers.m3;\n\t\tif (m3Lanes != null && m3Lanes.isFlat() && getSearchFilter() == null) {\n\t\t\t// flat lane model: the counts come from the lanes, no entry per marker (same messages as below)\n\t\t\tint m3Total = m3Lanes.size();\n\t\t\tint m3Shown = applyMarkerLimit(m3Total);\n\t\t\tif (counts[0].intValue() == 0 && counts[1].intValue() == 0) {\n\t\t\t\treturn m3Shown >= m3Total ? NLS.bind(MarkerMessages.filter_itemsMessage, m3Total)\n\t\t\t\t\t\t: NLS.bind(MarkerMessages.filter_matchedMessage, m3Shown, m3Total);\n\t\t\t}\n\t\t\tString m3Message = formatSummaryBreakdown(counts);\n\t\t\treturn m3Shown >= m3Total ? m3Message\n\t\t\t\t\t: NLS.bind(MarkerMessages.problem_filter_matchedMessage, m3Message, m3Shown, m3Total);\n\t\t}" + - com.synexia.openrewrite.viewport.M3AddMemberIfMissing: + declaringClasses: [org.eclipse.ui.internal.views.markers.CachedMarkerBuilder] + memberName: m3Building + beforeMethod: setBuilding + memberSource: "\t/**\n\t * Whether a clean rebuild is running, without the change listener's receiving flag that\n\t * {@link #isBuilding()} adds: the delta path asks from inside resourceChanged (M3MarkerDeltas).\n\t *\n\t * @return whether a clean rebuild is running\n\t */\n\tboolean m3Building() {\n\t\treturn building;\n\t}\n" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.MarkerContentGenerator] + methodName: requestMarkerUpdate + position: METHOD_START + statements: "\t\tif (builder != null && M3MarkerDeltas.scopeChanged(builder)) {\n\t\t\treturn;\n\t\t}" + - com.synexia.openrewrite.viewport.M3InsertStatements: + declaringClasses: [org.eclipse.ui.internal.views.markers.CachedMarkerBuilder$WorkingSetListener] + methodName: propertyChange + anchor: "scheduleUpdate();" + position: BEFORE + statements: "\t\t\t\tif (M3MarkerDeltas.scopeChanged(CachedMarkerBuilder.this)) {\n\t\t\t\t\treturn;\n\t\t\t\t}" diff --git a/docs/m3/markers-view/tools/apply_recipe.sh b/docs/m3/markers-view/tools/apply_recipe.sh index 3a95bfb8956..04b19583c97 100644 --- a/docs/m3/markers-view/tools/apply_recipe.sh +++ b/docs/m3/markers-view/tools/apply_recipe.sh @@ -9,7 +9,10 @@ JAVA_HOME="C:/Program Files/Java/jdk-21" C=K:/m3-work/syn-recipes/synexia-openrewrite-recipes/crates/m3-viewport-catalogue-recipes CPR="$(cygpath -w "$WT/docs/m3/markers-view/recipe");$C/target/classes;$(cat $C/target/cp.txt)" M="$SRC/org/eclipse/ui/internal/views/markers" -FILES=("$M/MarkersChangeListener.java" "$M/CachedMarkerBuilder.java" "$M/Markers.java") +FILES=("$M/MarkersChangeListener.java" "$M/CachedMarkerBuilder.java" "$M/Markers.java" "$M/MarkerViewerContentProvider.java" "$M/MarkersTreeViewer.java" "$M/ExtendedMarkersView.java" "$M/MarkerContentGenerator.java") +# The OpenRewrite Java 21 parser rejects unnamed variables (Java 22, e.g. "_ ->"): such a file parses as an error and +# stays UNCHANGED. Each isolated "_" token is swapped for a unique placeholder before the passes and back after. +sed -i "s/\b_\b/m3UnnamedVar0/g" "${FILES[@]}" for pass in 1 2; do echo "recipe pass $pass: $("$JAVA_HOME/bin/java" -Xmx1g -Djava.io.tmpdir="$(cygpath -w "$OUT/tmp")" -cp "$CPR" \ com.synexia.openrewrite.viewport.M3PerFileApply com.synexia.openrewrite.viewport.MarkersViewDeltaHooks \ @@ -17,3 +20,4 @@ for pass in 1 2; do # M3PerFileApply prints the changed statements with CRLF on Windows; the sources use LF sed -i 's/\r$//' "${FILES[@]}" done +sed -i "s/m3UnnamedVar0/_/g" "${FILES[@]}" diff --git a/docs/m3/markers-view/tools/build_overlay.sh b/docs/m3/markers-view/tools/build_overlay.sh index 1641ba9955c..c76cd477236 100644 --- a/docs/m3/markers-view/tools/build_overlay.sh +++ b/docs/m3/markers-view/tools/build_overlay.sh @@ -1,21 +1,50 @@ #!/usr/bin/env bash # Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. # SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 -# Build the measured "ours" org.eclipse.ui.ide: the official 3.23.200 jar from the p2 pool with the markers classes -# that this branch changes (hooked files + M3 classes) compiled from this worktree against the official bundles. -# The signature files are dropped (the content changed). Output: $OUT/eclipse/plugins/org.eclipse.ui.ide_m3.jar +# Build the measured "ours" bundles from the official 2026-09 jars in the p2 pool (signature files dropped, the +# content changed). Output in $OUT/eclipse/plugins: +# org.eclipse.jface_m3.jar - the official jar with this worktree's JFace classes (build_jface.sh output, +# $OUT/cand/classes: viewport mode, the M3ViewerDelta/M3Viewers delta API) and +# org.eclipse.jface.viewers.m3 exported; +# org.eclipse.ui.ide_m3.jar - the official jar with the markers classes this branch adds or hooks (every M3*.java +# of the package and the recipe-hooked files) compiled against the official bundles and +# the JFace above. set -e WT=${WT:-S:/m3-scratch/worktrees/platform-ui}; OUT=${OUT:-S:/m3-scratch/jface}; E=$OUT/eclipse; B=$OUT/markers-m3 POOL=$(cygpath -m ~/.p2/pool/plugins); JDK="C:/Program Files/Java/jdk-21" STOCK=$(ls "$POOL" | grep '^org.eclipse.ui.ide_3' | head -1) +BI=$(ls -d "$E"/config-stock*/org.eclipse.equinox.simpleconfigurator/bundles.info | head -1) +JFACE=$(grep -E '^org\.eclipse\.jface,' "$BI" | cut -d, -f3 | sed 's|^file:/||') mkdir -p "$B" "$E/plugins" -grep -v '^#' "$E/config-stock/org.eclipse.equinox.simpleconfigurator/bundles.info" | cut -d, -f3 | sed 's|^file:/||' | grep '\.jar$' | grep -v m3bench > "$B/cp.list" +# 1. JFace +J=$B/jface-jar; rm -rf "$J" && mkdir -p "$J" +(cd "$J" && "$JDK/bin/jar" xf "$JFACE" && rm -f META-INF/*.SF META-INF/*.RSA META-INF/*.DSA META-INF/*.EC) +cp -r "$OUT/cand/classes/." "$J/" +sed -i 's/^Export-Package: /Export-Package: org.eclipse.jface.viewers.m3,/' "$J/META-INF/MANIFEST.MF" +rm -f "$E/plugins/org.eclipse.jface_m3.jar" +(cd "$J" && "$JDK/bin/jar" cfm "$E/plugins/org.eclipse.jface_m3.jar" META-INF/MANIFEST.MF .) +# 2. org.eclipse.ui.workbench: the M3 helpers (org.eclipse.ui.internal.m3, e.g. M3PartVisibility) added and exported +WB=$(grep -E '^org\.eclipse\.ui\.workbench,' "$BI" | cut -d, -f3 | sed 's|^file:/||') +W=$B/workbench-jar; rm -rf "$W" "$B/wb-classes" && mkdir -p "$W" "$B/wb-classes" +grep -v '^#' "$BI" | cut -d, -f3 | sed 's|^file:/||' | grep '\.jar$' | grep -v m3bench > "$B/cp.list" +{ echo "-cp"; echo "$OUT/cand/classes;$(tr '\n' ';' < "$B/cp.list")"; } > "$B/javac.args" +"$JDK/bin/javac" --release 21 -nowarn -encoding UTF-8 -proc:none @"$B/javac.args" -d "$B/wb-classes" \ + "$WT"/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/m3/*.java +(cd "$W" && "$JDK/bin/jar" xf "$WB" && rm -f META-INF/*.SF META-INF/*.RSA META-INF/*.DSA META-INF/*.EC) +cp -r "$B/wb-classes/." "$W/" +sed -i 's/^Export-Package: /Export-Package: org.eclipse.ui.internal.m3;x-internal:=true,/' "$W/META-INF/MANIFEST.MF" +rm -f "$E/plugins/org.eclipse.ui.workbench_m3.jar" +(cd "$W" && "$JDK/bin/jar" cfm "$E/plugins/org.eclipse.ui.workbench_m3.jar" META-INF/MANIFEST.MF .) +# 3. org.eclipse.ui.ide M=$WT/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers +HOOKED=$(grep -o '\$M/[A-Za-z]*\.java' "$WT/docs/m3/markers-view/tools/apply_recipe.sh" | sed "s|\\\$M|$M|") rm -rf "$B/classes" "$B/jar" && mkdir -p "$B/classes" "$B/jar" -"$JDK/bin/javac" --release 21 -nowarn -encoding UTF-8 -proc:none -cp "$(tr '\n' ';' < "$B/cp.list")" -d "$B/classes" \ - "$M/M3MarkerDeltas.java" "$M/M3LongSet.java" "$M/MarkersChangeListener.java" "$M/CachedMarkerBuilder.java" "$M/Markers.java" +# the class path (425 jars) goes through an argument file: the command line is too long for Windows +{ echo "-cp"; echo "$OUT/cand/classes;$B/wb-classes;$(tr '\n' ';' < "$B/cp.list")"; } > "$B/javac.args" +# org.eclipse.ui.ide needs JavaSE-25 on master (unnamed variables in ExtendedMarkersView): compile it with JDK 25 +"F:/jdks/temurin25/jdk-25.0.4.1+1/bin/javac" --release 25 -nowarn -encoding UTF-8 -proc:none @"$B/javac.args" -d "$B/classes" "$M"/M3*.java $HOOKED (cd "$B/jar" && "$JDK/bin/jar" xf "$POOL/$STOCK" && rm -f META-INF/*.SF META-INF/*.RSA META-INF/*.DSA META-INF/*.EC) cp -r "$B/classes/." "$B/jar/" rm -f "$E/plugins/org.eclipse.ui.ide_m3.jar" (cd "$B/jar" && "$JDK/bin/jar" cfm "$E/plugins/org.eclipse.ui.ide_m3.jar" META-INF/MANIFEST.MF .) -echo "overlay: $E/plugins/org.eclipse.ui.ide_m3.jar from $STOCK + $(find "$B/classes" -name '*.class' | wc -l) classes" +echo "overlay: org.eclipse.jface_m3.jar ($(find "$OUT/cand/classes" -name '*.class' | wc -l) classes), org.eclipse.ui.workbench_m3.jar (+$(find "$B/wb-classes" -name '*.class' | wc -l)), org.eclipse.ui.ide_m3.jar ($(find "$B/classes" -name '*.class' | wc -l) classes from $STOCK)" diff --git a/docs/m3/markers-view/tools/ledger_rows.sh b/docs/m3/markers-view/tools/ledger_rows.sh new file mode 100644 index 00000000000..972a73b1d7b --- /dev/null +++ b/docs/m3/markers-view/tools/ledger_rows.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# Ledger rows (docs/m3/jface-viewport/OPTIMIZATION_LEDGER.tsv format) from the markers bench results: for each size +# and metric, the median over the repetitions of stock (before) and m3 (after). Usage: +# ledger_rows.sh [results.tsv] [before-side] [after-side] (prints rows; append them to the ledger) +LEAF=$1 COMMIT=$2 RES=${3:-S:/m3-scratch/jface/eclipse/markers-results.tsv} BEFORE=${4:-stock} AFTER=${5:-m3} +awk -F'\t' -v OFS='\t' -v leaf="$LEAF" -v commit="$COMMIT" -v before="$BEFORE" -v after="$AFTER" -v res="$RES" ' + function median(key, n, i, j, t, v) { + n = split(vals[key], v, " ") + for (i = 2; i <= n; i++) for (j = i; j > 1 && v[j-1] + 0 > v[j] + 0; j--) { t = v[j]; v[j] = v[j-1]; v[j-1] = t } + return n == 0 ? "" : (n % 2 ? v[(n + 1) / 2] : (v[n / 2] + v[n / 2 + 1]) / 2) + } + { + split($1, s, "-"); side = s[1]; metric = $2; n = $3 + if (metric ~ /^(ERROR|diff-counters)/ || metric ~ /^instances / && $4 + 0 == 0) next + key = side SUBSEP metric SUBSEP n + vals[key] = vals[key] " " $4; seen[metric SUBSEP n] = 1 + } + END { + for (k in seen) { + split(k, a, SUBSEP); metric = a[1]; n = a[2] + b = median(before SUBSEP metric SUBSEP n); c = median(after SUBSEP metric SUBSEP n) + if (b == "" || c == "") continue + unit = metric ~ /bytes/ ? "bytes" : metric ~ /-ms$|^initial-build$|^create-markers$/ ? "ms" : "count" + print leaf, metric, n, b, c, unit, "markers bench, median of the repetitions (5; 3 for 10^4-marker deltas), hidden desktop, JDK 25, same flags both sides", "order-statistic-list;interned-labels;open-addressing-id-index", commit, res + } + }' "$RES" | sort -t$'\t' -k3,3n -k2,2 diff --git a/docs/m3/markers-view/tools/markers_round.sh b/docs/m3/markers-view/tools/markers_round.sh index a6a34171bcd..c6578bbbabf 100644 --- a/docs/m3/markers-view/tools/markers_round.sh +++ b/docs/m3/markers-view/tools/markers_round.sh @@ -1,16 +1,26 @@ #!/usr/bin/env bash # Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. # SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 -# One measurement round: stock, fork-original (overlay, delta path off) and m3 (overlay, delta path on) per size, -# each with the seeded differential script. Usage: markers_round.sh ... +# One measurement round per size: stock (official bundles) and m3 (overlays from build_overlay.sh: JFace in viewport +# mode with the delta API, org.eclipse.ui.ide with the lane model and delta path on), each with the seeded +# differential script; then the two logs are compared. Usage: markers_round.sh ... +# SIDES="stock m3" by default; m3orig (overlays, both modes off) can be added. D=$(dirname "$0"); SEED=$1 STEPS=$2; shift 2 -export IDE_JAR=S:/m3-scratch/jface/eclipse/plugins/org.eclipse.ui.ide_m3.jar +E=S:/m3-scratch/jface/eclipse for n in "$@"; do - MARKERS_OPTS= bash "$D/run_markers.sh" stock "$n" "$SEED" "$STEPS" - MARKERS_OPTS= bash "$D/run_markers.sh" m3orig "$n" "$SEED" "$STEPS" - MARKERS_OPTS=-Dorg.eclipse.ui.ide.markers.mode=viewport bash "$D/run_markers.sh" m3 "$n" "$SEED" "$STEPS" - E=S:/m3-scratch/jface/eclipse - for side in m3orig m3; do - if diff -q "$E/diff-stock-$n-$SEED.log" "$E/diff-$side-$n-$SEED.log" > /dev/null 2>&1; then echo "n=$n $side vs stock: IDENTICAL"; else echo "n=$n $side vs stock: DIFFERENT (diff $E/diff-stock-$n-$SEED.log $E/diff-$side-$n-$SEED.log)"; fi + for side in ${SIDES:-stock m3}; do + case $side in + m3) opts="-Dorg.eclipse.ui.ide.markers.mode=viewport -Djface.viewer.mode=viewport" ;; + *) opts="" ;; + esac + MARKERS_OPTS="$opts ${EXTRA_OPTS:-}" bash "$D/run_markers.sh" "$side" "$n" "$SEED" "$STEPS" + done + for side in ${SIDES:-stock m3}; do + [ "$side" = stock ] && continue + if diff -q "$E/diff-stock-$n-$SEED.log" "$E/diff-$side-$n-$SEED.log" > /dev/null 2>&1; then + echo "n=$n $side vs stock: IDENTICAL ($(wc -l < "$E/diff-$side-$n-$SEED.log") steps)" + else + echo "n=$n $side vs stock: DIFFERENT (diff $E/diff-stock-$n-$SEED.log $E/diff-$side-$n-$SEED.log)" + fi done done diff --git a/docs/m3/markers-view/tools/matrix_status.awk b/docs/m3/markers-view/tools/matrix_status.awk new file mode 100644 index 00000000000..f5e64d283d3 --- /dev/null +++ b/docs/m3/markers-view/tools/matrix_status.awk @@ -0,0 +1,35 @@ +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# Mechanical pass over TREE_VIEW_API_MATRIX.tsv (REFERENCE_TREE_VIEW.md): fills lane_delta_status, differential and +# delta_gate by method-name rules. A cell that is not TODO is kept (a later manual verdict wins). Usage: +# awk -F'\t' -v OFS='\t' -v la= -f matrix_status.awk TREE_VIEW_API_MATRIX.tsv > out.tsv +# Rules (the lane model of the Problems view, M3MarkerLanes/M3MarkerDeltas, and the JFace delta API): +# DELTA element changes that the delta path issues or that serve it (add/insert/remove/update/replace, the +# item mapping, lazy children) +# FACADE answers about elements: the element is a facade created on demand (selection, find, reveal, +# expansion, children, input) +# STOCK_OK no model work: listeners, events, editing support, providers, data, busy, scrolling +# TODO viewer-side filters and comparators: the generic tree-view test on the lane model decides them +# (the Problems view filters and sorts in its model) +# differential: PASS where JFace Layer A (M3ViewerDifferential, 0 mismatches) drives the method, else TODO until the +# Problems view differential and the generic test cover it. delta_gate: JUSTIFIED for the full-rebuild entry points +# (initial input, user Refresh, the fallbacks of FALLBACKS_TO_DELTAS.md), PASS for every other method. +function cls(m) { + if (m ~ /^(add|insert|remove|replace|update|internalAdd|internalRemove|internalUpdate|updateItem|refreshItem|doUpdateItem|setChildCount|setHasChildren|updatePlus|associate|disassociate|mapElement|unmapElement|unmapAllElements|createTreeItem|newItem|createChildren|updateChildren|preservingSelection|removeAll)$/) return "DELTA" + if (m ~ /^(refresh|internalRefresh|internalRefreshStruct|setInput)$/) return "DELTA" + if (m ~ /^(filter|hasFilters|getFilters|setFilters|addFilter|removeFilter|resetFilters|needsRefilter|setComparator|getComparator|setSorter|getSorter)$/) return "TODO" + if (m ~ /Selection|^(reveal|showItem|findItem|findItems|doFindItem|doFindInputItem|testFindItem|testFindItems|getTreePathFromItem|getParentElement|getRawChildren|getFilteredChildren|getSortedChildren|getChildren|getRoot|getInput|inputChanged|contains|indexForElement|getItemCount|getItems|getChild|getNextItem|getPreviousItem|getParentItem|internalGetWidgetToSelect|internalInitializeTree|isExpandable|isExpandableNode)$/) return "FACADE" + if (m ~ /[Ee]xpand|[Cc]ollapse/ && m !~ /^fire|^handle|Listener$/) return "FACADE" + return "STOCK_OK" +} +function layerA(m) { + return m ~ /^(setSelection|getSelection|getStructuredSelection|refresh|remove|add|update|setComparator|addFilter|removeFilter|resetFilters|setInput|reveal|setUseHashlookup|getComparator|getFilters|internalRefresh|internalRemove|internalAdd|internalUpdate|preservingSelection|setSelectionToWidget|getSelectionFromWidget|findItem|doFindItem|testFindItem)$/ +} +NR == 1 { print; next } +{ + m = $3 + if ($6 == "TODO" || $6 == "") $6 = cls(m) + if ($7 == "TODO" || $7 == "") $7 = layerA(m) ? "PASS (" la ")" : "TODO" + if ($8 == "TODO" || $8 == "") $8 = (m ~ /^(refresh|setInput|internalRefresh|internalRefreshStruct|removeAll)$/) ? "JUSTIFIED (initial input, user Refresh, fallbacks; DELTA_GATE.tsv UIUpdateJob.java:104, ExtendedMarkersView.java:510)" : "PASS" + print +} diff --git a/docs/m3/markers-view/tools/run_headless_tests.sh b/docs/m3/markers-view/tools/run_headless_tests.sh new file mode 100644 index 00000000000..3525998d204 --- /dev/null +++ b/docs/m3/markers-view/tools/run_headless_tests.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. +# SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 +# Headless JUnit 5 tests of the markers lane model (no Display, no workspace) with JaCoCo, after build_overlay.sh. +# Usage: run_headless_tests.sh ... (classes of org.eclipse.ui.tests.markers) +WT=${WT:-S:/m3-scratch/worktrees/platform-ui}; OUT=${OUT:-S:/m3-scratch/jface}; B=$OUT/markers-m3 +. "$WT/docs/m3/jface-viewport/tools/jface_env.sh" +EXEC=$1; shift +T="$WT/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers" +C=$B/test-classes; rm -rf "$C"; mkdir -p "$C" "$OUT/coverage" +SRC=(); SEL=() +for c in "$@"; do SRC+=("$T/$c.java"); SEL+=(--select-class "org.eclipse.ui.tests.markers.$c"); done +JDK25=${JDK25:-F:/jdks/temurin25/jdk-25.0.4.1+1} # the overlay compiles the ide classes with --release 25 (build_overlay.sh) +"$JDK25/bin/javac" --release 25 -nowarn -encoding UTF-8 -proc:none \ + -cp "$(cygpath -w "$B/classes");$(cygpath -w "$JUNIT")" -d "$C" "${SRC[@]}" || exit 1 +DEST=$(cygpath -w "$OUT/coverage/$EXEC.exec"); rm -f "$OUT/coverage/$EXEC.exec" +"$JDK25/bin/java" -Xmx1g -Djava.io.tmpdir=$(cygpath -w "$OUT/tmp") \ + "-javaagent:$(cygpath -w "$JACOCO_AGENT")=destfile=$DEST,includes=org.eclipse.ui.internal.views.markers.M3*" \ + -jar "$(cygpath -w "$JUNIT")" execute --disable-banner --details=tree --details-theme=ascii \ + -cp "$(cygpath -w "$C");$(cygpath -w "$B/classes")" "${SEL[@]}" 2>&1 \ + | sed 's/\x1b\[[0-9;]*m//g' | grep -E "tests (successful|failed)|\[X\]|=>|Exception|expected" | head -${TAILN:-30} diff --git a/docs/m3/markers-view/tools/run_markers.sh b/docs/m3/markers-view/tools/run_markers.sh index 0d771de32f9..cfdbf65e7fb 100644 --- a/docs/m3/markers-view/tools/run_markers.sh +++ b/docs/m3/markers-view/tools/run_markers.sh @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 # Markers view benchmark/differential inside the official Eclipse 2026-09 bundles (read from the p2 pool, never # written), on the hidden desktop, with configuration, workspace, user area and temp on S:. -# Usage: run_markers.sh [seed steps] (IDE_JAR= for m3) +# Usage: run_markers.sh [seed steps] (non-stock sides: IDE_JAR and JFACE_JAR overlays from +# build_overlay.sh; MARKERS_OPTS=-Dorg.eclipse.ui.ide.markers.mode=viewport -Djface.viewer.mode=viewport for m3) set -e WT=${WT:-S:/m3-scratch/worktrees/platform-ui} OUT=${OUT:-S:/m3-scratch/jface}; E=$OUT/eclipse; mkdir -p "$E/plugins" "$OUT/tmp" @@ -12,22 +13,30 @@ SIDE=$1 N=$2 SEED=${3:-} STEPS=${4:-30} if [ "$5" != --inner ]; then INSTALL=$(cygpath -m ~/eclipse/jee-2026-09/eclipse); POOL=$(cygpath -m ~/.p2/pool/plugins) JDK25=F:/jdks/temurin25/jdk-25.0.4.1+1 + # one configuration per side and size: runs of one side in two desktop slots never share a configuration area; + # the bench jar and the overlay jars are copied into it, so a rebuild never touches a queued or running run + CFG=$E/config-$SIDE-$N; rm -rf "$CFG"; mkdir -p "$CFG/org.eclipse.equinox.simpleconfigurator" "$CFG/jars" # 1. bench bundle - B=$WT/docs/m3/markers-view/bench-bundle; C=$OUT/markers-bench; rm -rf "$C" && mkdir -p "$C/classes" + B=$WT/docs/m3/markers-view/bench-bundle; C=$OUT/markers-bench-$SIDE-$N; rm -rf "$C" && mkdir -p "$C/classes" CP=$(ls "$POOL" | grep -E '^org\.eclipse\.(ui\.workbench|ui\.ide|core\.resources|core\.runtime|equinox\.common|core\.jobs|jface|swt\.win32\.win32\.x86_64|osgi|equinox\.registry|core\.commands|ui\.views)_[0-9]' | grep '\.jar$' | sed "s|^|$POOL/|" | tr '\n' ';') "C:/Program Files/Java/jdk-21/bin/javac" --release 21 -nowarn -encoding UTF-8 -proc:none -cp "$CP" -d "$C/classes" $(find "$B/src" -name '*.java') cp -r "$B/META-INF" "$B/plugin.xml" "$C/classes/" - (cd "$C/classes" && "C:/Program Files/Java/jdk-21/bin/jar" cfm "$E/plugins/org.eclipse.ui.ide.m3bench_1.0.0.jar" META-INF/MANIFEST.MF .) + (cd "$C/classes" && "C:/Program Files/Java/jdk-21/bin/jar" cfm "$CFG/jars/org.eclipse.ui.ide.m3bench_1.0.0.jar" META-INF/MANIFEST.MF .) # 2. configuration: platform bundles only (no EPP, Oomph, p2, intro), plus the bench bundle - CFG=$E/config-$SIDE; rm -rf "$CFG"; mkdir -p "$CFG/org.eclipse.equinox.simpleconfigurator" BI=$INSTALL/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info { grep '^#' "$BI" - grep -v '^#' "$BI" | grep -E '^(org\.eclipse\.(osgi|equinox|core|e4|emf|ui|jface|swt|help|text|urischeme|platform|ant\.core|update|compare\.core)|org\.apache\.(felix|aries|commons|batik|xmlgraphics|lucene)|org\.osgi|javax|jakarta|org\.w3c|com\.ibm\.icu|com\.sun\.jna|org\.objectweb|org\.sat4j|org\.tukaani|org\.bouncycastle|org\.apache\.httpcomponents)' \ - | grep -vE '^[^,]*(intro|equinox\.p2|oomph|cheatsheets|ui\.views\.log|ui\.trace|e4\.tools|ui\.monitoring)[^,]*,' - echo "org.eclipse.ui.ide.m3bench,1.0.0,file:/$E/plugins/org.eclipse.ui.ide.m3bench_1.0.0.jar,4,false" + grep -v '^#' "$BI" | grep -E '^(org\.eclipse\.(osgi|equinox|core|e4|emf|ui|jface|swt|help|text|urischeme|platform|ant\.core|update|compare|debug|search|ltk|team|ecf)|org\.slf4j|ch\.qos|org\.apache\.(felix|aries|commons|batik|xmlgraphics|lucene|ant)|org\.osgi|javax|jakarta|org\.w3c|com\.ibm\.icu|com\.sun\.jna|org\.objectweb|org\.sat4j|org\.tukaani|org\.bouncycastle|bc[a-z]+,|org\.apache\.httpcomponents|com\.github\.weisj)' \ + | grep -vE '^[^,]*(equinox\.p2\.ui|p2\.updatechecker|oomph|epp|cheatsheets|ui\.views\.log|ui\.trace|e4\.tools|ui\.monitoring|team\.svn)[^,]*,' + echo "org.eclipse.ui.ide.m3bench,1.0.0,file:/$CFG/jars/org.eclipse.ui.ide.m3bench_1.0.0.jar,4,false" } > "$CFG/org.eclipse.equinox.simpleconfigurator/bundles.info" if [ "$SIDE" != stock ]; then - sed -i "s|^org\.eclipse\.ui\.ide,\([^,]*\),[^,]*,|org.eclipse.ui.ide,\1,file:/${IDE_JAR},|" "$CFG/org.eclipse.equinox.simpleconfigurator/bundles.info" + # snapshot of the overlays (build_overlay.sh) at queue time + cp "${IDE_JAR:-$E/plugins/org.eclipse.ui.ide_m3.jar}" "$CFG/jars/org.eclipse.ui.ide_m3.jar" + cp "${JFACE_JAR:-$E/plugins/org.eclipse.jface_m3.jar}" "$CFG/jars/org.eclipse.jface_m3.jar" + cp "${WORKBENCH_JAR:-$E/plugins/org.eclipse.ui.workbench_m3.jar}" "$CFG/jars/org.eclipse.ui.workbench_m3.jar" + for b in ui.ide jface ui.workbench; do + sed -i "s|^org\.eclipse\.${b//./\\.},\([^,]*\),[^,]*,|org.eclipse.$b,\1,file:/$CFG/jars/org.eclipse.${b}_m3.jar,|" "$CFG/org.eclipse.equinox.simpleconfigurator/bundles.info" + done fi SC=$(ls "$POOL" | grep '^org.eclipse.equinox.simpleconfigurator_' | head -1) FW=$(ls "$POOL" | grep '^org.eclipse.osgi_3' | head -1); CS=$(ls "$POOL" | grep '^org.eclipse.osgi.compatibility.state_' | head -1) @@ -40,16 +49,40 @@ org.eclipse.equinox.simpleconfigurator.configUrl=file\:${CFG/:/\:}/org.eclipse.e eclipse.application=org.eclipse.ui.ide.workbench eclipse.product=org.eclipse.platform.ide osgi.splashPath=platform\:/base/plugins/org.eclipse.platform +eclipse.pluginCustomization=${CFG/:/\:}/plugin_customization.ini +osgi.configuration.cascaded=false CFGEOF + # no welcome page, no workspace prompt, no update check: nothing but the workbench and the bench + printf '%s\n' org.eclipse.ui/showIntro=false org.eclipse.ui.ide/SHOW_WORKSPACE_SELECTION_DIALOG=false \ + org.eclipse.equinox.p2.ui.sdk.scheduler/enabled=false > "$CFG/plugin_customization.ini" echo "bundles: $(grep -vc '^#' "$CFG/org.eclipse.equinox.simpleconfigurator/bundles.info")" + # 3. first start outside the lock, headless (no application): Equinox installs the framework extensions and asks + # for a restart (exit 23, which only the native launcher handles), the second start resolves; the measured run + # then starts without -clean + LAUNCHER=$(ls "$POOL" | grep "^org.eclipse.equinox.launcher_" | head -1) + for clean in -clean ""; do + "$JDK25/bin/java.exe" -Xmx1g -XX:ErrorFile="$(cygpath -w "$OUT/tmp")\hs_err_%p.log" -Djava.io.tmpdir="$(cygpath -w "$OUT/tmp")" -jar "$POOL/$LAUNCHER" -install "$INSTALL" -configuration "$(cygpath -w "$CFG")" \ + -data "$(cygpath -w "$E/ws-warm-$SIDE-$N")" -nosplash -consoleLog $clean -application m3.none.app > "$E/warm-$SIDE-$N.log" 2>&1 \ + && rc=0 || rc=$? + echo "warm start ${clean:-plain}: exit $rc" + done + echo "unresolved platform UI bundles: $(grep -cE "Could not resolve module: org\.eclipse\.(jface|swt|ui\.ide|ui\.workbench|ui\.views|e4\.ui)" "$E/warm-$SIDE-$N.log" || true)" + [ -n "${WARM_ONLY:-}" ] && exit 0 exec bash C:/m3-superset/tools/ui_lock.sh jface-viewport bash "$0" "$SIDE" "$N" "$SEED" "$STEPS" --inner "$INSTALL" "$POOL" "$JDK25" fi INSTALL=$6 POOL=$7 JDK25=$8 -CFG=$E/config-$SIDE; WS=$E/ws-$SIDE-$N; rm -rf "$WS" "$E/user-$SIDE"; mkdir -p "$WS" +CFG=$E/config-$SIDE-$N; [ -d "$CFG" ] || CFG=$E/config-$SIDE +WS=$E/ws-$SIDE-$N; rm -rf "$WS" "$E/user-$SIDE-$N"; mkdir -p "$WS" LAUNCHER=$(ls "$POOL" | grep '^org.eclipse.equinox.launcher_' | head -1) RES=$E/markers-results.tsv; LABEL=$SIDE-$N +COV="" +if [ -n "${COVER:-}" ] && [ "$SIDE" != stock ]; then + # JaCoCo over the M3 classes the run exercises (markers lanes and delta path, the viewer delta API, the part visibility bridge) + AG=$(cygpath -m "$HOME/.m2/repository")/org/jacoco/org.jacoco.agent/0.8.15/org.jacoco.agent-0.8.15-runtime.jar; mkdir -p "$OUT/coverage" + COV="-javaagent:$(cygpath -w "$AG")=destfile=$(cygpath -w "$OUT/coverage/markers-$SIDE-$N.exec"),includes=org.eclipse.ui.internal.views.markers.M3*:org.eclipse.jface.viewers.m3.*:org.eclipse.ui.internal.m3.*" +fi DIFF=""; [ -n "$SEED" ] && DIFF="-Dm3.markers.log=$(cygpath -w "$E/diff-$SIDE-$N-$SEED.log") -Dm3.markers.seed=$SEED -Dm3.markers.steps=$STEPS" w() { cygpath -w "$1"; } -CMD="\"$(w "$JDK25/bin/java.exe")\" -Xmx${XMX:-3g} -XX:+UseG1GC --add-modules=ALL-SYSTEM -Djava.io.tmpdir=$(w "$OUT/tmp") -Dosgi.requiredJavaVersion=21 -Dosgi.user.area=$(w "$E/user-$SIDE") -Dm3.markers.out=$(w "$RES") -Dm3.markers.label=$LABEL -Dm3.markers.n=$N $DIFF ${MARKERS_OPTS:-} -jar $(w "$POOL/$LAUNCHER") -install $(w "$INSTALL") -configuration $(w "$CFG") -data $(w "$WS") -nosplash -consoleLog -clean" -powershell -NoProfile -ExecutionPolicy Bypass -File "$(cygpath -w C:/m3-superset/tools/run_hidden_desktop.ps1)" -TimeoutSec ${MARKERS_TIMEOUT:-1800} -Log "$(w "$E/run-$LABEL.log")" -CommandLine "$CMD" -Desktop "${M3_UI_DESKTOP:-m3-ui-tests}" +CMD="\"$(w "$JDK25/bin/java.exe")\" -Xmx${XMX:-4g} -XX:+UseG1GC -XX:ErrorFile=$(w "$OUT/tmp")\hs_err_%p.log --add-modules=ALL-SYSTEM -Djava.io.tmpdir=$(w "$OUT/tmp") -Dosgi.requiredJavaVersion=21 -Dosgi.user.area=$(w "$E/user-$SIDE-$N") -Dm3.markers.out=$(w "$RES") -Dm3.markers.label=$LABEL -Dm3.markers.n=$N $DIFF $COV ${MARKERS_OPTS:-} -jar $(w "$POOL/$LAUNCHER") -install $(w "$INSTALL") -configuration $(w "$CFG") -data $(w "$WS") -nosplash -consoleLog ${MARKERS_ARGS:-}" +powershell -NoProfile -ExecutionPolicy Bypass -File "$(cygpath -w C:/m3-superset/tools/run_hidden_desktop.ps1)" -TimeoutSec ${MARKERS_TIMEOUT:-1800} -Log "$(w "$E/run-$LABEL.log")" -CommandLine "$CMD" -Desktop "${M3_UI_DESKTOP:-m3-ui-tests}" || echo "hidden desktop run: exit $?" grep -P "^$LABEL\t" "$RES" || { echo "no rows for $LABEL; log tail:"; tail -30 "$E/run-$LABEL.log"; } diff --git a/docs/m3/views/PROGRAMME.md b/docs/m3/views/PROGRAMME.md new file mode 100644 index 00000000000..c4b1df9af86 --- /dev/null +++ b/docs/m3/views/PROGRAMME.md @@ -0,0 +1,49 @@ +# Platform UI views on the event stream (programme) + +User, 2026-10-19: "look at the UI views; you will receive a stream of events; all Eclipse, same problem." +Rule: memory `feedback-one-model-delta-processing.md`. + +## The pattern (every view) + +``` +event stream (IResourceDelta, IMarkerDelta, MatchEvent, job events, UIEvents, log events, selection) + -> view delta: insert / remove / update / move runs over int ids in ONE lane model (no per-view copies) + -> M3Patch applied through the viewer: + inside the visible window: rows (native updates, O(changed)) + outside it: extents and the scroll bar only + -> deltas coalesced by the superseding-generation debounce (jface-viewport DESIGN.md section 5.1) +``` + +A view keeps no element store of its own: no entry objects per element, no per-entry hash maps, no cloned arrays. +Facades (entries, items) are deferred: created when an API asks, parent-owned, released under pressure. + +## Order and leaves + +`VIEW_INVENTORY.tsv` lists every view with its event source, what it does today on an event (rebuild or delta), +the stores it keeps per element, the stock cost at 10^5 elements where measured, and the upstream issues it answers +(from the GitHub harvest, com.synexia `docs/M3-SCALE/runs/20261017-ui-donor-atomize/GITHUB_PR_HARVEST.tsv`, +theme one-model-deltas). + +| leaf | view | branch / PR | +|---|---|---| +| 1 | Markers (Problems, Tasks, Bookmarks, All Markers) | `m3/jface-viewport-20261019` (this branch), `docs/m3/markers-view/` | +| 2 | Project Explorer (CNF) | own branch, one PR | +| 3 | Outline (host; JDT pages are external) | pattern only | +| 4 | Properties | own branch | +| 5 | Progress | own branch | +| 6 | Error Log | own branch | +| 7 | Search results | own branch | +| 8 | e4 part stacks (editor and view stacks) | own branch; 10^4 editors, LRU residency | +| 9 | FilteredItemsSelectionDialog, Quick Search | own branch | + +One PR per view. Each leaf carries: inventory rows with file:line, a stock measurement at 10^4/10^5/10^6, the +differential of the view's answers and events against stock, JUL logging, docs and examples. + +## Method per leaf + +1. Stock evidence: the listener, the rebuild call chain and the stores, with file:line (grep). +2. Design doc under `docs/m3//DESIGN.md`: lanes, facades, the delta mapping, the fallback to the stock path. +3. Opt-in property (`-D..mode=viewport`), hooks by recipe, new M3 classes. +4. Harness on the official 2026-09 bundles on the hidden desktop (`docs/m3/markers-view/tools/run_markers.sh` is the + template): stock, fork-original, m3; differential logs; measurements TSV. +5. Flip the default only on an identical differential and the user's go. diff --git a/docs/m3/views/VIEW_INVENTORY.tsv b/docs/m3/views/VIEW_INVENTORY.tsv new file mode 100644 index 00000000000..3895b5bd1eb --- /dev/null +++ b/docs/m3/views/VIEW_INVENTORY.tsv @@ -0,0 +1,13 @@ +priority view bundle viewer_type event_source today_on_event rebuild_evidence own_stores_per_element stock_cost_1e5 upstream_issues_addressed leaf_status +1 Problems / Tasks / Bookmarks / All Markers (ExtendedMarkersView) org.eclipse.ui.ide MarkersTreeViewer (TreeViewer, no SWT.VIRTUAL) in MarkersFilteredTree IResourceChangeEvent -> IMarkerDelta[] (MarkersChangeListener:153); selection (scope); IPropertyChange (filters) REBUILDS: deltas only type-checked, then a clean MarkerUpdateJob: new MarkerEntry per marker, regroup, sort, viewer.refresh(true) MarkersChangeListener.java:126-130; MarkerUpdateJob.java:63-65; MarkerContentGenerator.java:940; UIUpdateJob.java:95-104 MarkerEntry per marker with a ConcurrentHashMap attribute cache (MarkerEntry.java:72) + static CollationKey maps (:76-77); Markers.markerToEntryMap HashMap (:333); category child array copies (MarkerCategory.java:94); UI clone array (Markers.java:377) see docs/m3/markers-view/MEASUREMENTS.tsv (stock one-change at 1e4/1e5/1e6) #4404, #4301, #4304, #4469 (getMarkerCounts walks all markers); #1093/#1095/#1010/#1626 (viewer limit family); prior art #4247, #3527 leaf 1 implemented (M3MarkerDeltas); measurement pending +2 Project Explorer (CNF: CommonNavigator/CommonViewer + ResourceExtensionContentProvider) org.eclipse.ui.navigator; org.eclipse.ui.navigator.resources; org.eclipse.ui.ide (WorkbenchContentProvider) CommonViewer (TreeViewer) IResourceChangeEvent POST_CHANGE -> IResourceDelta (ResourceExtensionContentProvider:89; WorkbenchContentProvider:101) PARTIAL DELTAS: delta -> add/remove runnables per parent, but any CONTENT/TYPE/OPEN change becomes viewer.refresh(resource) (subtree relabel); pipeline modifications allocate HashSets per add/remove ResourceExtensionContentProvider.java:104-134, :156 (full refresh of the parent when children change type), :278, :289; CommonViewer.java:337-375 (PipelinedShapeModification per call) CommonViewer element map (CustomHashtable, hash lookup on) + NavigatorContentService caches (6 cache fields) + pipeline HashSets per modification not measured yet #649 (lazy TreeViewer reveal quadratic); prior art #1331 (faster expand), #4247 (expansion restore hashing) next (leaf 2) +3 Outline (ContentOutline hosting IContentOutlinePage) org.eclipse.ui.views (host); pages external (JDT/PDE/text editors) TreeViewer per page (ContentOutlinePage) per page: editor model listeners (external); host: selection HOST PASSES THROUGH; pages (JDT) refresh() the tree on reconcile: external ContentOutline.java (242 lines: page book only) none in the host n/a (host) none in platform.ui pattern only; JDT external +4 Properties (PropertySheet / PropertySheetPage / PropertySheetViewer) org.eclipse.ui.views PropertySheetViewer (own Tree, not a StructuredViewer) ISelectionListener (workbench selection); IPropertySourceProvider REBUILDS: every selection change -> setInput -> updateChildrenOf(root): entries recomputed (computeMergedPropertyDescriptors), TreeItems disposed and recreated below the changed node PropertySheetViewer.java:955-970, :1197-1234; PropertySheetEntry.java:163-257 entryToItemMap HashMap (PropertySheetViewer.java:88); per entry: sources HashMap (PropertySheetEntry.java:69), childEntries array, descriptor merge HashMap (:229), categoryCache (:1087) not measured yet (bounded by descriptor count, not element count) none found later (leaf 5) +5 Progress view (ProgressView / DetailedProgressViewer) org.eclipse.ui.workbench DetailedProgressViewer (a Composite of ProgressInfoItem controls per job, not a Table) ProgressManager job change events -> ProgressViewerContentProvider.refresh/add/remove; FinishedJobs REBUILDS: refresh() -> refreshAll() disposes and recreates every ProgressInfoItem control; refreshNeeded forces a full refresh on input change DetailedProgressViewer.java:436-523 (refreshAll, dispose children), :220 (new ProgressInfoItem per element); ProgressViewerContentProvider.java:61-69 LinkedHashSets per getElements (ProgressViewerContentProvider.java:93, :117); one Composite plus labels per job not measured yet (control per row: O(jobs) native widgets) none found later (leaf 6) +6 Error Log (LogView) org.eclipse.ui.views.log TreeViewer (fTreeViewer) ILogListener (platform log) + log file reads REBUILDS: readLogFile() re-parses the whole file, then asyncRefresh() -> fTreeViewer.refresh() LogView.java:901-930 (readLogFile), :1114-1138 (batchEntries), :1253-1262 (asyncRefresh) elements CopyOnWriteArrayList, groups ConcurrentHashMap (:189-191); copies per refresh (:1028) not measured yet none found later (leaf 7) +7 Search results (SearchView + AbstractTextSearchViewPage, FileSearchPage) org.eclipse.search TreeViewer or TableViewer (fViewer), page-owned SearchResultEvent (MatchEvent ADDED/REMOVED) from AbstractTextSearchResult BATCHED DELTAS: handleSearchResultChanged -> fBatchedUpdates deque -> UpdateUIJob -> elementsChanged(Object[]) (page refreshes those elements); clear() on removeAll AbstractTextSearchViewPage.java:1249-1319 AbstractTextSearchResult: ConcurrentHashMap> + ConcurrentHashMap collisionOrder (one map node per match); page HashSets per batch (:1276, :1398) not measured yet prior art #3733 (remove/sort performance, merged) later (leaf 8): matches as lanes (element id, offset, length); batch -> M3Patch +8 e4 part stacks (StackRenderer: editor and view stacks, MPartStack) org.eclipse.e4.ui.workbench.renderers.swt CTabFolder with one CTabItem per MPart (not a viewer) IEventBroker UIEvents (children, label, dirty, closeable, visible, toBeRendered, activate, selectedElement) EVENT-DRIVEN per tab (updateTab), but every part keeps its CTabItem and rendered widgets; a children change disposes and re-creates the tab (:446-448); MRU only hides tabs StackRenderer.java:330-700 (subscribeTopic*), :1077 (createTab), :735 (loop over all tabs) tab list = CTabFolder items array (O(parts) native items); part widgets materialized for every open editor not measured yet (10^4 editors: 10^4 CTabItems plus composites) #4403 (UI freezes with many stack frames: Debug view, the same widget-per-row pattern) later (leaf 9): virtual tab lane; LRU residency of part widgets (object-residency law) +9 Open Resource / Open Type style dialogs (FilteredItemsSelectionDialog) org.eclipse.ui.workbench TableViewer (list) with ItemsListContentProvider keystrokes (pattern); history REBUILDS per pattern: FilterJob refills the content provider from scratch unless the new filter is a sub-filter (then re-scans lastCompletedResult); RefreshJob -> list.refresh FilteredItemsSelectionDialog.java:1924-2022, :1332 (RefreshJob), :1421 (RefreshCacheJob) lastCompletedResult ArrayList; history LinkedHashSet (:2065); ItemsListSeparator per group; duplicates HashSet not measured yet none found later (leaf 10): pattern filter as a bitmask over an interned name lane +10 Quick Search (QuickSearchDialog) org.eclipse.text.quicksearch TableViewer SWT.VIRTUAL (list.setItemCount) search job results (incremental) INCREMENTAL: virtual table; refreshJob (UIJob) updates the item count; sortList re-sorts the full list (:979-980) QuickSearchDialog.java:828-875, :979-980 content provider list of LineItem; MAX_RESULTS cap not measured yet none found later (pattern already close; sort as a permutation) +11 Console (ConsoleView, TextConsoleViewer, IOConsolePartitioner) eclipse.platform repo (bundles/org.eclipse.ui.console): external to platform.ui TextConsoleViewer (SourceViewer over an IDocument) IOConsoleOutputStream writes -> partitioner queue -> document append; trim at the high water mark APPEND AND TRIM (already a delta); an IOConsolePartition object per write not in this repo partition objects per write not measured none later; external repo +12 Package Explorer, Debug/Variables views, Synchronize view JDT / Debug / Team: external - - - - - - #4403 (Debug view freeze with many stack frames); #649 (lazy reveal) pattern only; the same method once the platform.ui leaves land diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3IndexTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3IndexTest.java new file mode 100644 index 00000000000..52ff317de45 --- /dev/null +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3IndexTest.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.tests.viewers.m3; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import org.eclipse.jface.internal.m3.M3FirstIndex; +import org.eclipse.jface.internal.m3.M3IdentityIndex; +import org.eclipse.jface.internal.m3.M3ViewerMode; +import org.eclipse.jface.viewers.IElementComparer; +import org.junit.jupiter.api.Test; + +/** + * Headless tests of the JFace viewport index lanes: every answer is checked + * against the linear scan the viewers use in the original code. + */ +public class M3IndexTest { + + /** Equality by id, as in models with value equality. */ + record Key(int id, int copy) { + @Override + public boolean equals(Object o) { + return o instanceof Key k && k.id == id; + } + + @Override + public int hashCode() { + return id; + } + } + + /** A comparer that compares and hashes on the copy instead of the id. */ + static final IElementComparer BY_COPY = new IElementComparer() { + @Override + public boolean equals(Object a, Object b) { + return ((Key) a).copy == ((Key) b).copy; + } + + @Override + public int hashCode(Object element) { + return ((Key) element).copy; + } + }; + + static int scan(Object[] rows, Object key, IElementComparer comparer) { + for (int i = 0; i < rows.length; i++) { + if (rows[i] != null && (comparer == null ? key.equals(rows[i]) : comparer.equals(key, rows[i]))) { + return i; + } + } + return -1; + } + + @Test + public void firstIndexAnswersLikeTheScan() { + Random random = new Random(7); + for (int round = 0; round < 50; round++) { + int n = random.nextInt(300); + Object[] rows = new Object[n]; + for (int i = 0; i < n; i++) { + rows[i] = random.nextInt(10) == 0 ? null : new Key(random.nextInt(60), random.nextInt(5)); + } + for (IElementComparer comparer : new IElementComparer[] { null, BY_COPY }) { + M3FirstIndex index = new M3FirstIndex(n, comparer); + for (int i = 0; i < n; i++) { + index.add(rows[i], i); + } + for (int q = 0; q < 100; q++) { + Key key = new Key(random.nextInt(70), random.nextInt(6)); + assertEquals(scan(rows, key, comparer), index.first(key), "round " + round + " key " + key); + } + } + } + } + + @Test + public void firstIndexKeepsTheFirstOfEqualElements() { + M3FirstIndex index = new M3FirstIndex(4, null); + Key a0 = new Key(1, 0); + Key a1 = new Key(1, 1); + index.add(a0, 3); + index.add(a1, 5); + assertEquals(3, index.first(a1)); + assertEquals(-1, index.first(new Key(2, 0))); + } + + @Test + public void firstIndexAcceptsZeroAndOneElement() { + M3FirstIndex empty = new M3FirstIndex(0, null); + assertEquals(-1, empty.first("x")); + M3FirstIndex one = new M3FirstIndex(1, null); + one.add("x", 0); + assertEquals(0, one.first("x")); + assertEquals(-1, one.first("y")); + } + + @Test + public void identityIndexAnswersPositionsByIdentity() { + Random random = new Random(11); + for (int round = 0; round < 30; round++) { + int n = random.nextInt(200); + Object[] items = new Object[n]; + List pool = new ArrayList<>(); + for (int i = 0; i < n; i++) { + if (random.nextInt(8) == 0) { + items[i] = null; + } else if (!pool.isEmpty() && random.nextInt(4) == 0) { + items[i] = pool.get(random.nextInt(pool.size())); + } else { + items[i] = new Key(i, 0); + pool.add(items[i]); + } + } + M3IdentityIndex index = new M3IdentityIndex(items); + Map first = new HashMap<>(); + for (int i = 0; i < n; i++) { + if (items[i] != null) { + first.putIfAbsent(new IdentityKey(items[i]), Integer.valueOf(i)); + } + } + for (Object item : pool) { + assertEquals(first.get(new IdentityKey(item)).intValue(), index.positionOf(item)); + } + assertEquals(-1, index.positionOf(new Key(0, 0))); + assertEquals(-1, index.positionOf(null)); + } + assertEquals(-1, new M3IdentityIndex(new Object[0]).positionOf("x")); + } + + record IdentityKey(Object o) { + @Override + public boolean equals(Object other) { + return other instanceof IdentityKey k && k.o == o; + } + + @Override + public int hashCode() { + return System.identityHashCode(o); + } + } + + @Test + public void modeReadsTheProperties() { + assertEquals("original", M3ViewerMode.ORIGINAL); + assertEquals("viewport", M3ViewerMode.VIEWPORT); + String expected = System.getProperty(M3ViewerMode.PROPERTY, M3ViewerMode.ORIGINAL).trim(); + assertEquals(M3ViewerMode.VIEWPORT.equals(expected), M3ViewerMode.ENABLED); + assertTrue(!M3ViewerMode.ENABLED || M3ViewerMode.ANY); + System.setProperty(M3ViewerMode.PROPERTY + ".M3IndexTestViewer", M3ViewerMode.VIEWPORT); + try { + assertTrue(M3ViewerMode.enabled("M3IndexTestViewer")); + assertEquals(M3ViewerMode.ENABLED, M3ViewerMode.enabled("NoSuchViewer")); + } finally { + System.clearProperty(M3ViewerMode.PROPERTY + ".M3IndexTestViewer"); + } + System.setProperty(M3ViewerMode.PROPERTY + ".M3IndexTestViewer", " "); + try { + assertEquals(M3ViewerMode.ENABLED, M3ViewerMode.enabled("M3IndexTestViewer")); + } finally { + System.clearProperty(M3ViewerMode.PROPERTY + ".M3IndexTestViewer"); + } + assertFalse(M3ViewerMode.enabled("M3IndexTestViewer") && !M3ViewerMode.ENABLED); + } +} diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewSpecTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewSpecTest.java new file mode 100644 index 00000000000..0e72d5d361f --- /dev/null +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewSpecTest.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.tests.viewers.m3; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +import org.eclipse.jface.viewers.m3.M3ViewSpec; +import org.eclipse.jface.viewers.m3.M3ViewSpec.LaneType; +import org.junit.jupiter.api.Test; + +/** Headless tests of the view template's spec parser (brief rule 27). */ +public class M3ViewSpecTest { + + private static final String PROBLEMS = """ + # a comment line + view.id=org.eclipse.ui.views.ProblemView + element=IMarker + source=markers # adapter id + lanes=id:long, severity:byte, message:label, resource:label, line:int, type:label, flags:bits, icon:image + group=severity|type|none + sort=severity desc, message, resource asc, line + filters=scope, severity, type, text + counts=severity + presentation=tree|flat + label=MarkerColumnLabelProvider + """; + + @Test + public void parsesTheProblemsViewSpec() { + M3ViewSpec spec = M3ViewSpec.parse(PROBLEMS); + assertEquals("org.eclipse.ui.views.ProblemView", spec.viewId()); + assertEquals("IMarker", spec.element()); + assertEquals("markers", spec.source()); + assertEquals(8, spec.lanes().size()); + assertEquals(LaneType.BYTE, spec.lane("severity").type()); + assertEquals(LaneType.LABEL, spec.lane("message").type()); + assertEquals(LaneType.BITS, spec.lane("flags").type()); + assertEquals(LaneType.IMAGE, spec.lane("icon").type()); + assertNull(spec.lane("nope")); + assertEquals(List.of("severity", "type", "none"), spec.groups()); + assertTrue(spec.sort().get(0).descending()); + assertFalse(spec.sort().get(2).descending()); + assertEquals("line", spec.sort().get(3).lane()); + assertEquals(List.of("scope", "severity", "type", "text"), spec.filters()); + assertEquals(List.of("severity"), spec.counts()); + assertEquals(List.of("tree", "flat"), spec.presentations()); + assertEquals("MarkerColumnLabelProvider", spec.label()); + assertTrue(spec.toString().contains("source=markers")); + } + + @Test + public void defaultsForOptionalKeys() { + M3ViewSpec spec = M3ViewSpec.parse("view.id=v\nelement=E\nsource=observables\nlanes=id:long\n"); + assertEquals(List.of("none"), spec.groups()); + assertEquals(List.of("tree"), spec.presentations()); + assertTrue(spec.sort().isEmpty()); + assertTrue(spec.filters().isEmpty()); + assertNull(spec.label()); + } + + @Test + public void theCommittedProblemsViewSpecIsValid() throws IOException { + Path file = Path.of(System.getProperty("m3.wt", "S:/m3-scratch/worktrees/platform-ui"), + "bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ProblemsView.m3view"); + if (Files.exists(file)) { + M3ViewSpec spec = M3ViewSpec.parse(Files.readString(file)); + assertEquals("markers", spec.source()); + assertEquals(LaneType.LONG, spec.lane("id").type()); + } + } + + @Test + public void loadFindsTheSpecNextToTheClass() { + assertThrows(IOException.class, () -> M3ViewSpec.load(M3ViewSpecTest.class)); + } + + @Test + public void errorsNameTheProblem() { + String base = "view.id=v\nelement=E\nsource=markers\nlanes=id:long, sev:byte\n"; + assertMessage("line 5: unknown key: colour", base + "colour=red"); + assertMessage("line 1: expected key=value: nonsense", "nonsense"); + assertMessage("line 5: duplicate key: source", base + "source=markers"); + assertMessage("missing key: lanes", "view.id=v\nelement=E\nsource=markers\n"); + assertMessage("unknown source adapter: telepathy", "view.id=v\nelement=E\nsource=telepathy\nlanes=id:long\n"); + assertMessage("lane without a type: id", "view.id=v\nelement=E\nsource=markers\nlanes=id\n"); + assertMessage("unknown lane type: id:float", "view.id=v\nelement=E\nsource=markers\nlanes=id:float\n"); + assertMessage("unknown presentation: carousel", base + "presentation=carousel"); + assertMessage("group names an undeclared lane: kind", base + "group=kind|none"); + assertMessage("sort names an undeclared lane: x", base + "sort=x"); + assertMessage("sort key must be ' [asc|desc]': sev up", base + "sort=sev up"); + assertMessage("filters names an undeclared lane: f", base + "filters=scope, f"); + assertMessage("counts names an undeclared lane: c", base + "counts=c"); + assertMessage("duplicate lane: id", "view.id=v\nelement=E\nsource=markers\nlanes=id:long, id:int\n"); + } + + private static void assertMessage(String expected, String spec) { + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> M3ViewSpec.parse(spec)); + assertTrue(e.getMessage().startsWith(expected), e.getMessage()); + } +} diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDeltaTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDeltaTest.java new file mode 100644 index 00000000000..33a48349355 --- /dev/null +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDeltaTest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.tests.viewers.m3; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.eclipse.jface.viewers.m3.M3ViewerDelta; +import org.junit.jupiter.api.Test; + +/** Headless tests of the {@link M3ViewerDelta} lanes. */ +public class M3ViewerDeltaTest { + + @Test + public void operationsKeepTheirOrderAndFields() { + String[] props = { "label" }; + M3ViewerDelta d = new M3ViewerDelta().add("root", "a", 2).add("root", "b", -1).remove("c").update("d", props) + .refresh(null).refresh("e"); + assertEquals(6, d.size()); + assertFalse(d.isEmpty()); + assertEquals(M3ViewerDelta.ADD, d.kind(0)); + assertEquals("root", d.parent(0)); + assertEquals("a", d.element(0)); + assertEquals(2, d.index(0)); + assertEquals(-1, d.index(1)); + assertEquals(M3ViewerDelta.REMOVE, d.kind(2)); + assertNull(d.parent(2)); + assertEquals(M3ViewerDelta.UPDATE, d.kind(3)); + assertArrayEquals(props, d.properties(3)); + assertEquals(M3ViewerDelta.REFRESH, d.kind(4)); + assertNull(d.element(4)); + assertEquals("e", d.element(5)); + assertEquals("M3ViewerDelta[add a, add b, remove c, update d, refresh null, refresh e]", d.toString()); + } + + @Test + public void lanesGrowAndAppendMerges() { + M3ViewerDelta a = new M3ViewerDelta(); + for (int i = 0; i < 100; i++) { + a.remove(Integer.valueOf(i)); + } + M3ViewerDelta b = new M3ViewerDelta().update("x", null); + a.append(b); + assertEquals(101, a.size()); + assertEquals(Integer.valueOf(99), a.element(99)); + assertEquals("x", a.element(100)); + assertTrue(new M3ViewerDelta().isEmpty()); + } + + @Test + public void rejectsNullElementsAndBadIndexes() { + M3ViewerDelta d = new M3ViewerDelta(); + assertThrows(IllegalArgumentException.class, () -> d.add("p", null, 0)); + assertThrows(IllegalArgumentException.class, () -> d.remove(null)); + assertThrows(IllegalArgumentException.class, () -> d.update(null, null)); + assertThrows(IndexOutOfBoundsException.class, () -> d.kind(0)); + assertThrows(IndexOutOfBoundsException.class, () -> d.element(-1)); + } +} diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDifferential.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDifferential.java index 27e6095254d..146bbf7012c 100644 --- a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDifferential.java +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewerDifferential.java @@ -318,7 +318,14 @@ java.util.List run(Display display, int steps) { v.setInput(input()); record(display, v, "setInput"); for (int step = 0; step < steps; step++) { - String op = operate(v); + String op; + try { + op = operate(v); + } catch (RuntimeException e) { + // a defect of the viewer under test is part of its behaviour: record it and stop this script + log.add(step + " exception " + e.getClass().getName() + " " + e.getMessage()); + break; + } record(display, v, step + " " + op); } } finally { diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewersTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewersTest.java new file mode 100644 index 00000000000..45269824977 --- /dev/null +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/viewers/m3/M3ViewersTest.java @@ -0,0 +1,270 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.jface.tests.viewers.m3; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.BooleanSupplier; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ListViewer; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.m3.M3ViewerDelta; +import org.eclipse.jface.viewers.m3.M3Viewers; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.Widget; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * {@link M3Viewers} against tree, table and list viewers: every delta leaves the + * widget in the state a model-driven refresh would produce. Runs on a display + * (hidden desktop). + */ +public class M3ViewersTest { + + private Display display; + private Shell shell; + private final List roots = new ArrayList<>(); + + @BeforeEach + public void setUp() { + display = Display.getDefault(); + shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setSize(300, 300); + shell.open(); + for (int i = 0; i < 5; i++) { + roots.add("r" + i); + } + } + + @AfterEach + public void tearDown() { + shell.dispose(); + drain(); + } + + private void drain() { + while (display.readAndDispatch()) { + // pending events + } + } + + private void waitUntil(BooleanSupplier done) { + long end = System.currentTimeMillis() + 10_000; + while (!done.getAsBoolean() && System.currentTimeMillis() < end) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + assertTrue(done.getAsBoolean(), "timed out"); + } + + private TreeViewer tree() { + TreeViewer v = new TreeViewer(shell, SWT.MULTI); + v.setLabelProvider(new LabelProvider()); + v.setContentProvider(new ITreeContentProvider() { + @Override + public Object[] getElements(Object input) { + return roots.toArray(); + } + + @Override + public Object[] getChildren(Object parent) { + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + return false; + } + }); + v.setInput(roots); + return v; + } + + private TableViewer table() { + TableViewer v = new TableViewer(shell, SWT.MULTI); + v.setLabelProvider(new LabelProvider()); + v.setContentProvider(ArrayContentProvider.getInstance()); + v.setInput(roots); + return v; + } + + private ListViewer list() { + ListViewer v = new ListViewer(shell, SWT.MULTI); + v.setLabelProvider(new LabelProvider()); + v.setContentProvider(ArrayContentProvider.getInstance()); + v.setInput(roots); + return v; + } + + private static String texts(StructuredViewer v) { + Control c = v.getControl(); + StringBuilder b = new StringBuilder(); + Item[] items = c instanceof Tree t ? t.getItems() : c instanceof Table t ? t.getItems() : null; + if (items != null) { + for (Item item : items) { + b.append(item.getText()).append(' '); + } + } else { + for (String s : ((org.eclipse.swt.widgets.List) c).getItems()) { + b.append(s).append(' '); + } + } + return b.toString().trim(); + } + + /** Applies the same model change to the model and, as a delta, to the viewer. */ + private void exercise(StructuredViewer v) { + roots.add(2, "x"); + roots.add("y"); + roots.add("z"); + roots.remove("r0"); + roots.remove("r4"); + M3ViewerDelta d = new M3ViewerDelta().add(roots, "x", 2).add(roots, "y", -1).add(roots, "z", -1).remove("r0") + .remove("r4").update("r1", null).update("r2", null).update("x", new String[] { "p" }); + M3Viewers.apply(v, d); + assertEquals(String.join(" ", roots), texts(v)); + M3Viewers.apply(v, new M3ViewerDelta().refresh("r1").refresh(null)); + assertEquals(String.join(" ", roots), texts(v)); + } + + @Test + public void appliesToTreeTableAndList() { + exercise(tree()); + roots.clear(); + setUpRoots(); + exercise(table()); + roots.clear(); + setUpRoots(); + exercise(list()); + } + + private void setUpRoots() { + for (int i = 0; i < 5; i++) { + roots.add("r" + i); + } + } + + @Test + public void largeDeltasRunWithRedrawOff() { + TableViewer v = table(); + M3ViewerDelta d = new M3ViewerDelta(); + for (int i = 0; i < 100; i++) { + roots.add("n" + i); + d.add(roots, "n" + i, -1); + } + M3Viewers.apply(v, d); + assertEquals(105, v.getTable().getItemCount()); + } + + @Test + public void postMergesABurstAndAppliesOnce() throws Exception { + TableViewer v = table(); + Thread poster = new Thread(() -> { + for (int i = 0; i < 3; i++) { + String e = "p" + i; + synchronized (roots) { + roots.add(e); + } + M3Viewers.post(v, new M3ViewerDelta().add(roots, e, -1), 50); + } + }); + poster.start(); + poster.join(); + waitUntil(() -> v.getTable().getItemCount() == 8); + assertEquals("r0 r1 r2 r3 r4 p0 p1 p2", texts(v)); + } + + @Test + public void refreshFlushesQueuedDeltasFirst() { + TableViewer v = table(); + roots.add("q"); + M3Viewers.post(v, new M3ViewerDelta().add(roots, "q", -1), 60_000); + drain(); + v.refresh(); + assertEquals("r0 r1 r2 r3 r4 q", texts(v)); + M3Viewers.flush(v); + } + + @Test + public void refreshLaterRefreshesOnce() { + TableViewer v = table(); + roots.add("later"); + M3Viewers.refreshLater(v, 10); + M3Viewers.refreshLater(v, 10); + waitUntil(() -> v.getTable().getItemCount() == 6); + assertEquals("r0 r1 r2 r3 r4 later", texts(v)); + } + + @Test + public void aFailingDeltaFallsBackToRefresh() { + ListViewer v = list(); + M3Viewers.post(v, new M3ViewerDelta().add(roots, "bad", 99), 0); + waitUntil(() -> v.getList().getItemCount() == 5); + drain(); + assertEquals("r0 r1 r2 r3 r4", texts(v)); + } + + @Test + public void disposedAndEmptyAreIgnored() { + TableViewer v = table(); + M3Viewers.apply(v, new M3ViewerDelta()); + M3Viewers.post(v, new M3ViewerDelta(), 0); + Widget control = v.getControl(); + control.dispose(); + M3Viewers.apply(v, new M3ViewerDelta().remove("r0")); + M3Viewers.post(v, new M3ViewerDelta().remove("r0"), 0); + M3Viewers.flush(v); + drain(); + assertTrue(control.isDisposed()); + } + + @Test + public void flushOffTheUiThreadDoesNothing() throws Exception { + TableViewer v = table(); + roots.add("t"); + M3Viewers.post(v, new M3ViewerDelta().add(roots, "t", -1), 60_000); + drain(); + Thread t = new Thread(() -> M3Viewers.flush(v)); + t.start(); + t.join(); + assertEquals(5, v.getTable().getItemCount()); + M3Viewers.flush(v); + assertEquals(6, v.getTable().getItemCount()); + } +} diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/M3MarkerLanesAlgorithmsTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/M3MarkerLanesAlgorithmsTest.java new file mode 100644 index 00000000000..a036e3d154f --- /dev/null +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/M3MarkerLanesAlgorithmsTest.java @@ -0,0 +1,230 @@ +/******************************************************************************* + * Copyright (c) 2026 Synexia, Hitesh Soliwal (hsoliwal@gmail.com) and others. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, or (at your option) the Eclipse + * Public License 2.0, which are available at + * https://www.apache.org/licenses/LICENSE-2.0 and + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: Apache-2.0 OR EPL-2.0 + * + * Contributors: + * Hitesh Soliwal (Synexia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.tests.markers; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.text.Collator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import org.eclipse.ui.internal.views.markers.M3LabelTable; +import org.eclipse.ui.internal.views.markers.M3SlotOrder; +import org.junit.jupiter.api.Test; + +/** + * Headless tests of the two algorithms under the markers lane model: the + * blocked order-statistic list of slots ({@link M3SlotOrder}) and the interned + * label table ({@link M3LabelTable}), each checked against a plain reference + * (a sorted list, a hash map) over random operation sequences. + */ +public class M3MarkerLanesAlgorithmsTest { + + /* slots ordered by a key lane, ties by slot: a total order like the lane model's */ + private static int[] keys(int n, Random random) { + int[] key = new int[n]; + for (int i = 0; i < n; i++) { + key[i] = random.nextInt(n / 4 + 1); + } + return key; + } + + private static M3SlotOrder.SlotComparator order(int[] key) { + return (a, b) -> { + int c = Integer.compare(key[a], key[b]); + return c != 0 ? c : Integer.compare(a, b); + }; + } + + private static void sortedInsert(List ref, int slot, M3SlotOrder.SlotComparator order) { + int lo = 0; + int hi = ref.size(); + while (lo < hi) { + int mid = (lo + hi) >>> 1; + if (order.compare(ref.get(mid), slot) < 0) { + lo = mid + 1; + } else { + hi = mid; + } + } + ref.add(lo, slot); + } + + private static void check(M3SlotOrder list, List ref) { + assertEquals(ref.size(), list.size()); + int[] head = new int[ref.size()]; + assertEquals(ref.size(), list.head(Integer.MAX_VALUE, head)); + for (int i = 0; i < ref.size(); i++) { + assertEquals(ref.get(i).intValue(), head[i]); + } + for (int i = 0; i < ref.size(); i += 97) { + assertEquals(ref.get(i).intValue(), list.get(i)); + assertEquals(i, list.indexOf(ref.get(i))); + } + } + + @Test + public void randomInsertsAndRemovesMatchASortedList() { + Random random = new Random(7); + int n = 6000; + int[] key = keys(n, random); + M3SlotOrder.SlotComparator order = order(key); + M3SlotOrder list = new M3SlotOrder(order); + List ref = new ArrayList<>(); + boolean[] in = new boolean[n]; + for (int step = 0; step < 30_000; step++) { + int slot = random.nextInt(n); + if (in[slot]) { + int at = ref.indexOf(slot); + assertEquals(at, list.remove(slot)); + ref.remove(at); + } else { + int at = list.insert(slot); + sortedInsert(ref, slot, order); + assertEquals(ref.indexOf(slot), at); + } + in[slot] = !in[slot]; + if (step % 5000 == 0) { + check(list, ref); + } + } + check(list, ref); + // drain completely: blocks are dropped + for (int slot = 0; slot < n; slot++) { + if (in[slot]) { + list.remove(slot); + } + } + assertEquals(0, list.size()); + list.insert(3); + assertEquals(0, list.indexOf(3)); + } + + @Test + public void ascendingAndDescendingRunsSplitBlocks() { + int n = 5000; + int[] key = new int[n]; + for (int i = 0; i < n; i++) { + key[i] = i; + } + M3SlotOrder up = new M3SlotOrder(order(key)); + M3SlotOrder down = new M3SlotOrder(order(key)); + for (int i = 0; i < n; i++) { + up.insert(i); + down.insert(n - 1 - i); + } + for (int i = 0; i < n; i += 499) { + assertEquals(i, up.get(i)); + assertEquals(i, down.get(i)); + assertEquals(i, down.indexOf(i)); + } + int[] five = new int[5]; + assertEquals(5, up.head(5, five)); + assertEquals(4, five[4]); + } + + @Test + public void fillAndSortMatchASort() { + Random random = new Random(11); + int n = 4000; + int[] key = keys(n, random); + M3SlotOrder.SlotComparator order = order(key); + int[] slots = new int[n]; + List ref = new ArrayList<>(); + for (int i = 0; i < n; i++) { + slots[i] = n - 1 - i; + sortedInsert(ref, i, order); + } + M3SlotOrder list = new M3SlotOrder(order); + list.sortAndFill(slots, n); + check(list, ref); + // still a valid list after the bulk fill: inserts and removes keep working + assertEquals(ref.indexOf(17), list.remove(17)); + ref.remove(Integer.valueOf(17)); + check(list, ref); + M3SlotOrder empty = new M3SlotOrder(order); + empty.sortAndFill(new int[1], 0); + assertEquals(0, empty.size()); + assertEquals(-1, empty.indexOf(0)); + assertEquals(-1, empty.remove(0)); + } + + @Test + public void misuseIsReported() { + M3SlotOrder list = new M3SlotOrder(order(new int[] { 1, 2, 3 })); + list.insert(1); + assertThrows(IllegalArgumentException.class, () -> list.insert(1)); + assertThrows(IndexOutOfBoundsException.class, () -> list.get(1)); + assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1)); + assertEquals(-1, list.indexOf(2)); + assertEquals(-1, list.remove(0)); + assertEquals(-1, list.remove(2)); + } + + @Test + public void labelsInternCountAndFree() { + M3LabelTable labels = new M3LabelTable(Collator.getInstance()); + Random random = new Random(5); + Map refs = new HashMap<>(); + Map ids = new HashMap<>(); + for (int step = 0; step < 20_000; step++) { + String s = "m" + random.nextInt(500); + int count = refs.getOrDefault(s, 0); + if (count > 0 && random.nextBoolean()) { + labels.release(ids.get(s)); + refs.put(s, count - 1); + if (count == 1) { + ids.remove(s); + } + } else { + int id = labels.acquire(s); + Integer before = ids.putIfAbsent(s, id); + if (before != null) { + assertEquals(before.intValue(), id); + } + refs.put(s, count + 1); + assertEquals(count + 1, labels.references(id)); + assertEquals(s, labels.text(id)); + } + } + assertEquals(ids.size(), labels.size()); + for (Map.Entry e : ids.entrySet()) { + assertEquals(e.getKey(), labels.text(e.getValue())); + } + } + + @Test + public void labelsCompareLikeTheStockFields() { + Collator collator = Collator.getInstance(); + M3LabelTable labels = new M3LabelTable(collator); + int a = labels.acquire("apple"); + int b = labels.acquire("Banana"); + int e = labels.acquire(""); + assertEquals(Integer.signum(collator.getCollationKey("apple").compareTo(collator.getCollationKey("Banana"))), + Integer.signum(labels.collate(a, b))); + assertEquals(Integer.signum("apple".compareTo("Banana")), Integer.signum(labels.compare(a, b))); + assertEquals(0, labels.collate(a, a)); + assertEquals(0, labels.compare(b, b)); + assertNotEquals(0, labels.collate(e, a)); + // a freed id is reused + labels.release(b); + assertEquals(b, labels.acquire("cherry")); + } +}