2323import com .sun .source .tree .Tree ;
2424import com .sun .source .util .SourcePositions ;
2525import com .sun .source .util .TreePath ;
26- import java .awt .Point ;
27- import java .awt .event .ActionEvent ;
28- import java .awt .event .ActionListener ;
29- import java .beans .PropertyChangeEvent ;
30- import java .beans .PropertyChangeListener ;
3126import java .io .IOException ;
32- import java .util .Arrays ;
33- import java .util .Collections ;
3427import java .util .HashSet ;
3528import java .util .List ;
3629import java .util .Set ;
3932import javax .lang .model .element .TypeElement ;
4033import javax .lang .model .type .TypeMirror ;
4134import javax .lang .model .util .Types ;
42- import javax .swing .BorderFactory ;
4335import javax .swing .JEditorPane ;
4436import javax .swing .SwingUtilities ;
4537import javax .swing .text .BadLocationException ;
4638import javax .swing .text .Element ;
4739import javax .swing .text .StyledDocument ;
4840import org .netbeans .api .debugger .DebuggerEngine ;
4941import org .netbeans .api .debugger .DebuggerManager ;
50- import org .netbeans .api .debugger .Watch ;
5142import org .netbeans .api .debugger .jpda .CallStackFrame ;
5243import org .netbeans .api .debugger .jpda .Field ;
5344import org .netbeans .api .debugger .jpda .InvalidExpressionException ;
6556import org .netbeans .api .java .source .JavaSource .Phase ;
6657import org .netbeans .api .java .source .TreeUtilities ;
6758import org .netbeans .editor .EditorUI ;
68- import org .netbeans .editor .PopupManager ;
6959import org .netbeans .editor .Utilities ;
7060import org .netbeans .editor .ext .ToolTipSupport ;
7161import org .netbeans .modules .parsing .api .ParserManager ;
7666import org .netbeans .modules .parsing .spi .Parser .Result ;
7767import org .netbeans .spi .debugger .jpda .EditorContext .Operation ;
7868import org .netbeans .spi .debugger .ui .EditorContextDispatcher ;
79- import org .netbeans .spi .debugger .ui .EditorPin ;
80- import org .netbeans .spi .debugger .ui .PinWatchUISupport ;
8169import org .netbeans .spi .debugger .ui .ToolTipUI ;
8270import org .netbeans .spi .debugger .ui .ViewFactory ;
8371import org .openide .cookies .EditorCookie ;
8472import org .openide .filesystems .FileObject ;
8573import org .openide .loaders .DataObject ;
86- import org .openide .loaders .DataObjectNotFoundException ;
8774import org .openide .text .Annotation ;
8875import org .openide .text .DataEditorSupport ;
8976import org .openide .text .Line ;
9077import org .openide .text .Line .Part ;
9178import org .openide .text .NbDocument ;
92- import org .openide .util .Exceptions ;
9379import org .openide .util .RequestProcessor ;
94- import org .openide .util .WeakListeners ;
95-
9680
9781public class ToolTipAnnotation extends Annotation implements Runnable {
9882
99- private static final Set <String > JAVA_KEYWORDS = new HashSet < String >( Arrays . asList ( new String [] {
83+ private static final Set <String > JAVA_KEYWORDS = Set . of (
10084 "abstract" , "continue" , "for" , "new" , "switch" ,
10185 "assert" , "default" , "goto" , "package" , "synchronized" ,
10286 "boolean" , "do" , "if" , "private" , /*"this",*/
@@ -106,37 +90,10 @@ public class ToolTipAnnotation extends Annotation implements Runnable {
10690 "catch" , "extends" , "int" , "short" , "try" ,
10791 "char" , "final" , "interface" , "static" , "void" ,
10892 /*"class",*/ "finally" , "long" , "strictfp" , "volatile" ,
109- "const" , "float" , "native" , "super" , "while" ,
110- }));
111-
112- private static final int MAX_STRING_LENGTH ;
93+ "const" , "float" , "native" , "super" , "while"
94+ );
11395
114- static {
115- int maxStringLength = 100000 ;
116- String javaV = System .getProperty ("java.version" );
117- if (javaV .startsWith ("1.8.0" )) {
118- String update = "" ;
119- for (int i = "1.8.0_" .length (); i < javaV .length (); i ++) {
120- char c = javaV .charAt (i );
121- if (Character .isDigit (c )) {
122- update += c ;
123- } else {
124- break ;
125- }
126- }
127- int updateNo = 0 ;
128- if (!update .isEmpty ()) {
129- try {
130- updateNo = Integer .parseInt (update );
131- } catch (NumberFormatException nfex ) {}
132- }
133- if (updateNo < 60 ) {
134- // Memory problem on JDK 8, fixed in update 60 (https://bugs.openjdk.java.net/browse/JDK-8072775):
135- maxStringLength = 1000 ;
136- }
137- }
138- MAX_STRING_LENGTH = maxStringLength ;
139- }
96+ private static final int MAX_STRING_LENGTH = 100000 ;
14097
14198 private Part lp ;
14299 private EditorCookie ec ;
@@ -266,36 +223,36 @@ public void run () {
266223 return ; // Something went wrong...
267224 }
268225 String type = v .getType ();
269- if (v instanceof ObjectVariable ) {
270- tooltipVariable = ( ObjectVariable ) v ;
226+ if (v instanceof ObjectVariable objectVariable ) {
227+ tooltipVariable = objectVariable ;
271228 try {
272229 Object jdiValue = v .getClass ().getMethod ("getJDIValue" ).invoke (v );
273230 if (jdiValue == null ) {
274231 tooltipVariable = null ;
275232 }
276233 } catch (Exception ex ) {}
277234 if (tooltipVariable != null ) {
278- v = getFormattedValue (d , ( ObjectVariable ) v );
235+ v = getFormattedValue (d , objectVariable );
279236 }
280237 }
281- if (v instanceof ObjectVariable ) {
238+ if (v instanceof ObjectVariable objectVariable ) {
282239 try {
283- String toString = (( ObjectVariable ) v ) .getToStringValue ();
240+ String toString = objectVariable .getToStringValue ();
284241 toolTipText = expression + " = " +
285- (type .length () == 0 ?
242+ (type .isEmpty () ?
286243 "" :
287244 "(" + type + ") " ) +
288245 toString ;
289246 } catch (InvalidExpressionException ex ) {
290247 toolTipText = expression + " = " +
291- (type .length () == 0 ?
248+ (type .isEmpty () ?
292249 "" :
293250 "(" + type + ") " ) +
294251 v .getValue ();
295252 }
296253 } else {
297254 toolTipText = expression + " = " +
298- (type .length () == 0 ?
255+ (type .isEmpty () ?
299256 "" :
300257 "(" + type + ") " ) +
301258 v .getValue ();
@@ -462,7 +419,7 @@ private static boolean isValidTooltipLocation(JPDADebugger debugger,
462419 final String [] className = new String []{"" };
463420 Future <Void > parsingTask ;
464421 try {
465- parsingTask = ParserManager .parseWhenScanFinished (Collections . singleton (Source .create (doc )), new UserTask () {
422+ parsingTask = ParserManager .parseWhenScanFinished (List . of (Source .create (doc )), new UserTask () {
466423 @ Override
467424 public void run (ResultIterator resultIterator ) throws Exception {
468425 Result res = resultIterator .getParserResult (offset );
@@ -530,7 +487,7 @@ public void run(ResultIterator resultIterator) throws Exception {
530487 isValid [0 ] = false ;
531488 return ;
532489 }
533- if (TreeUtilities .CLASS_TREE_KINDS .contains (kind ) && className [0 ].length () == 0 ) {
490+ if (TreeUtilities .CLASS_TREE_KINDS .contains (kind ) && className [0 ].isEmpty () ) {
534491 TypeElement typeElement = (TypeElement )controller .getTrees ().getElement (path );
535492 className [0 ] = ElementUtilities .getBinaryName (typeElement );
536493 }
@@ -547,8 +504,8 @@ public void run(ResultIterator resultIterator) throws Exception {
547504 if (ElementKind.CLASS.equals(tk) ||
548505 ElementKind.ENUM.equals(tk) ||
549506 ElementKind.INTERFACE.equals(tk)) {*/
550- if (typeElement instanceof TypeElement ) {
551- String binaryClassName = ElementUtilities .getBinaryName (( TypeElement ) typeElement );
507+ if (typeElement instanceof TypeElement typeElement1 ) {
508+ String binaryClassName = ElementUtilities .getBinaryName (typeElement1 );
552509 fieldOfPtr [0 ] = binaryClassName ;
553510 /*
554511 String currentClassName = currentFrame.getClassName();
@@ -582,7 +539,7 @@ public void run(ResultIterator resultIterator) throws Exception {
582539 return false ;
583540 }
584541 if (className [0 ].length () > 0 ) {
585- Set <String > superTypeNames = new HashSet <String >();
542+ Set <String > superTypeNames = new HashSet <>();
586543 This thisVar = currentFrame .getThisVariable ();
587544 if (thisVar != null ) {
588545 String fqn = thisVar .getType ();
@@ -676,7 +633,7 @@ private String resolveTypeName (final int offset, Source source) {
676633 final String [] result = new String [1 ];
677634 result [0 ] = null ;
678635 try {
679- ParserManager .parse (Collections . singleton (source ), new UserTask () {
636+ ParserManager .parse (List . of (source ), new UserTask () {
680637 @ Override
681638 public void run (ResultIterator resultIterator ) throws Exception {
682639 Result res = resultIterator .getParserResult (offset );
0 commit comments