Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ide/editor.lib/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

javac.compilerargs=-Xlint:unchecked
javac.source=1.8
javac.release=17
spec.version.base=4.38.0
is.autoload=true

Expand Down
24 changes: 16 additions & 8 deletions ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.netbeans.editor.ext;

import org.netbeans.api.editor.StickyWindowSupport;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
Expand All @@ -35,6 +34,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
Expand Down Expand Up @@ -156,7 +156,11 @@ public class ToolTipSupport {
private static final String HTML_PREFIX_UPPERCASE = "<HTML"; //NOI18N

private static final String LAST_TOOLTIP_POSITION = "ToolTipSupport.lastToolTipPosition"; //NOI18N

/// Key for ignored area rectangle stored as client property.
/// Allowes the mouse pointer to safely enter the tooltip without the risk of it disapearing.
private static final String MOUSE_MOVE_IGNORED_AREA = "ToolTipSupport.mouseMoveIgnoredArea"; //NOI18N

private static final String MOUSE_LISTENER = "ToolTipSupport.noOpMouseListener"; //NOI18N

private static final Action NO_ACTION = new TextAction("tooltip-no-action") { //NOI18N
Expand Down Expand Up @@ -667,8 +671,7 @@ private void setStatus(int status) {
if (this.status != status) {
int oldStatus = this.status;
this.status = status;
firePropertyChange(PROP_STATUS,
Integer.valueOf(oldStatus), Integer.valueOf(this.status));
firePropertyChange(PROP_STATUS, oldStatus, this.status);
}
}

Expand Down Expand Up @@ -799,9 +802,15 @@ private void ensureVisibility(Point toolTipPosition) {
try {
int[] offsets = Utilities.getSelectionOrIdentifierBlock(component, pos);
if (offsets != null) {
Rectangle r1 = component.modelToView(offsets[0]);
Rectangle r2 = component.modelToView(offsets[1]);
blockBounds = new Rectangle(r1.x, r1.y, r2.x - r1.x, r1.height);
Rectangle2D r1 = component.modelToView2D(offsets[0]);
Rectangle2D r2 = component.modelToView2D(offsets[1]);
int margin = 6; // additional x-margin for the ignore area, shouldn't be much wider than 1-2 characters
blockBounds = new Rectangle(
(int) (r1.getX() - margin),
(int) (r1.getY()),
(int) (r2.getX() - r1.getX() + margin * 2),
(int) (r1.getHeight())
);
}
} catch (BadLocationException ble) {}
toolTip.putClientProperty(MOUSE_MOVE_IGNORED_AREA, computeMouseMoveIgnoredArea(
Expand Down Expand Up @@ -975,8 +984,7 @@ private Point getLastMouseEventPoint() {
if (parent instanceof JLayeredPane) {
parent = parent.getParent();
}
if (parent instanceof JViewport) {
JViewport vp = (JViewport)parent;
if (parent instanceof JViewport vp) {
p = new Point(vp.getViewPosition().x, p.y);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static class ExpandableTooltip extends JPanel {

private JButton expButton;
private JButton pinButton;
private JComponent textToolTip;
private final JComponent textToolTip;
private boolean widthCheck = true;
private boolean sizeSet = false;

Expand Down Expand Up @@ -245,6 +245,23 @@ private static JTextArea createMultiLineToolTip(String toolTipText, boolean wrap
return ta;
}

/**
* Adjusts the tooltip location to position the pin button above the cursor.
*
* Helps to keep the mouse pointer within the mouse motion ignore area of ext.ToolTipSupport
* with the purpose of preventing the tooltip from disappearing while the mouse is moving towards it.
*/
public int getXOffset() {
double offset = 0;
if (pinButton != null) {
offset += pinButton.getPreferredSize().getWidth();
}
if (expButton != null) {
offset += expButton.getPreferredSize().getWidth();
}
return - (int) (offset / 2 + 2);
}

private static class TextToolTip extends JTextArea {

private static final String ELIPSIS = "..."; //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public final class ToolTipUI {
public ToolTipSupport show(JEditorPane editorPane) {
EditorUI eui = Utilities.getEditorUI(editorPane);
if (eui != null) {
eui.getToolTipSupport().setToolTip(et);
eui.getToolTipSupport().setToolTip(
et,
PopupManager.ViewPortBounds,
PopupManager.AbovePreferred,
et.getXOffset(),
0
);
this.editorPane = editorPane;
return eui.getToolTipSupport();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@
import com.sun.source.tree.Tree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -39,15 +32,13 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Types;
import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.StyledDocument;
import org.netbeans.api.debugger.DebuggerEngine;
import org.netbeans.api.debugger.DebuggerManager;
import org.netbeans.api.debugger.Watch;
import org.netbeans.api.debugger.jpda.CallStackFrame;
import org.netbeans.api.debugger.jpda.Field;
import org.netbeans.api.debugger.jpda.InvalidExpressionException;
Expand All @@ -65,7 +56,6 @@
import org.netbeans.api.java.source.JavaSource.Phase;
import org.netbeans.api.java.source.TreeUtilities;
import org.netbeans.editor.EditorUI;
import org.netbeans.editor.PopupManager;
import org.netbeans.editor.Utilities;
import org.netbeans.editor.ext.ToolTipSupport;
import org.netbeans.modules.parsing.api.ParserManager;
Expand All @@ -76,27 +66,21 @@
import org.netbeans.modules.parsing.spi.Parser.Result;
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
import org.netbeans.spi.debugger.ui.EditorContextDispatcher;
import org.netbeans.spi.debugger.ui.EditorPin;
import org.netbeans.spi.debugger.ui.PinWatchUISupport;
import org.netbeans.spi.debugger.ui.ToolTipUI;
import org.netbeans.spi.debugger.ui.ViewFactory;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.text.Annotation;
import org.openide.text.DataEditorSupport;
import org.openide.text.Line;
import org.openide.text.Line.Part;
import org.openide.text.NbDocument;
import org.openide.util.Exceptions;
import org.openide.util.RequestProcessor;
import org.openide.util.WeakListeners;


public class ToolTipAnnotation extends Annotation implements Runnable {

private static final Set<String> JAVA_KEYWORDS = new HashSet<String>(Arrays.asList(new String[] {
private static final Set<String> JAVA_KEYWORDS = Set.of(
"abstract", "continue", "for", "new", "switch",
"assert", "default", "goto", "package", "synchronized",
"boolean", "do", "if", "private", /*"this",*/
Expand All @@ -106,37 +90,10 @@ public class ToolTipAnnotation extends Annotation implements Runnable {
"catch", "extends", "int", "short", "try",
"char", "final", "interface", "static", "void",
/*"class",*/ "finally", "long", "strictfp", "volatile",
"const", "float", "native", "super", "while",
}));

private static final int MAX_STRING_LENGTH;
"const", "float", "native", "super", "while"
);

static {
int maxStringLength = 100000;
String javaV = System.getProperty("java.version");
if (javaV.startsWith("1.8.0")) {
String update = "";
for (int i = "1.8.0_".length(); i < javaV.length(); i++) {
char c = javaV.charAt(i);
if (Character.isDigit(c)) {
update += c;
} else {
break;
}
}
int updateNo = 0;
if (!update.isEmpty()) {
try {
updateNo = Integer.parseInt(update);
} catch (NumberFormatException nfex) {}
}
if (updateNo < 60) {
// Memory problem on JDK 8, fixed in update 60 (https://bugs.openjdk.java.net/browse/JDK-8072775):
maxStringLength = 1000;
}
}
MAX_STRING_LENGTH = maxStringLength;
}
private static final int MAX_STRING_LENGTH = 100000;

private Part lp;
private EditorCookie ec;
Expand Down Expand Up @@ -266,36 +223,36 @@ public void run () {
return ; // Something went wrong...
}
String type = v.getType ();
if (v instanceof ObjectVariable) {
tooltipVariable = (ObjectVariable) v;
if (v instanceof ObjectVariable objectVariable) {
tooltipVariable = objectVariable;
try {
Object jdiValue = v.getClass().getMethod("getJDIValue").invoke(v);
if (jdiValue == null) {
tooltipVariable = null;
}
} catch (Exception ex) {}
if (tooltipVariable != null) {
v = getFormattedValue(d, (ObjectVariable) v);
v = getFormattedValue(d, objectVariable);
}
}
if (v instanceof ObjectVariable) {
if (v instanceof ObjectVariable objectVariable) {
try {
String toString = ((ObjectVariable) v).getToStringValue();
String toString = objectVariable.getToStringValue();
toolTipText = expression + " = " +
(type.length () == 0 ?
(type.isEmpty() ?
"" :
"(" + type + ") ") +
toString;
} catch (InvalidExpressionException ex) {
toolTipText = expression + " = " +
(type.length () == 0 ?
(type.isEmpty() ?
"" :
"(" + type + ") ") +
v.getValue ();
}
} else {
toolTipText = expression + " = " +
(type.length () == 0 ?
(type.isEmpty() ?
"" :
"(" + type + ") ") +
v.getValue ();
Expand Down Expand Up @@ -462,7 +419,7 @@ private static boolean isValidTooltipLocation(JPDADebugger debugger,
final String[] className = new String[]{""};
Future<Void> parsingTask;
try {
parsingTask = ParserManager.parseWhenScanFinished(Collections.singleton(Source.create(doc)), new UserTask() {
parsingTask = ParserManager.parseWhenScanFinished(List.of(Source.create(doc)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Result res = resultIterator.getParserResult(offset);
Expand Down Expand Up @@ -530,7 +487,7 @@ public void run(ResultIterator resultIterator) throws Exception {
isValid[0] = false;
return;
}
if (TreeUtilities.CLASS_TREE_KINDS.contains(kind) && className[0].length() == 0) {
if (TreeUtilities.CLASS_TREE_KINDS.contains(kind) && className[0].isEmpty()) {
TypeElement typeElement = (TypeElement)controller.getTrees().getElement(path);
className[0] = ElementUtilities.getBinaryName(typeElement);
}
Expand All @@ -547,8 +504,8 @@ public void run(ResultIterator resultIterator) throws Exception {
if (ElementKind.CLASS.equals(tk) ||
ElementKind.ENUM.equals(tk) ||
ElementKind.INTERFACE.equals(tk)) {*/
if (typeElement instanceof TypeElement) {
String binaryClassName = ElementUtilities.getBinaryName((TypeElement) typeElement);
if (typeElement instanceof TypeElement typeElement1) {
String binaryClassName = ElementUtilities.getBinaryName(typeElement1);
fieldOfPtr[0] = binaryClassName;
/*
String currentClassName = currentFrame.getClassName();
Expand Down Expand Up @@ -582,7 +539,7 @@ public void run(ResultIterator resultIterator) throws Exception {
return false;
}
if (className[0].length() > 0) {
Set<String> superTypeNames = new HashSet<String>();
Set<String> superTypeNames = new HashSet<>();
This thisVar = currentFrame.getThisVariable();
if (thisVar != null) {
String fqn = thisVar.getType();
Expand Down Expand Up @@ -676,7 +633,7 @@ private String resolveTypeName (final int offset, Source source) {
final String[] result = new String[1];
result[0] = null;
try {
ParserManager.parse(Collections.singleton(source), new UserTask() {
ParserManager.parse(List.of(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Result res = resultIterator.getParserResult(offset);
Expand Down
Loading