MCPcopy Index your code
hub / github.com/beanshell/beanshell / doCommandCompletion

Method doCommandCompletion

src/bsh/util/JConsole.java:301–354  ·  view source on GitHub ↗
( String part )

Source from the content-addressed store, hash-verified

299 }
300
301 private void doCommandCompletion( String part ) {
302 if ( nameCompletion == null )
303 return;
304
305 int i=part.length()-1;
306
307 // Character.isJavaIdentifierPart() How convenient for us!!
308 while (
309 i >= 0 &&
310 ( Character.isJavaIdentifierPart(part.charAt(i))
311 || part.charAt(i) == '.' )
312 )
313 i--;
314
315 part = part.substring(i+1);
316
317 if ( part.length() < 2 ) // reasonable completion length
318 return;
319
320 //System.out.println("completing part: "+part);
321
322 // no completion
323 String [] complete = nameCompletion.completeName(part);
324 if ( complete.length == 0 ) {
325 java.awt.Toolkit.getDefaultToolkit().beep();
326 return;
327 }
328
329 // Found one completion (possibly what we already have)
330 if ( complete.length == 1 && !complete.equals(part) ) {
331 String append = complete[0].substring(part.length());
332 append( append );
333 return;
334 }
335
336 // Found ambiguous, show (some of) them
337
338 String line = text.getText();
339 String command = line.substring( cmdStart );
340 // Find prompt
341 for(i=cmdStart; line.charAt(i) != '\n' && i > 0; i--);
342 String prompt = line.substring( i+1, cmdStart );
343
344 // Show ambiguous
345 StringBuilder sb = new StringBuilder("\n");
346 for( i=0; i<complete.length && i<SHOW_AMBIG_MAX; i++)
347 sb.append( complete[i] +"\n" );
348 if ( i == SHOW_AMBIG_MAX )
349 sb.append("...\n");
350
351 print( sb, Color.gray );
352 print( prompt ); // print resets command start
353 append( command ); // append does not reset command start
354 }
355
356 private void resetCommandStart() {
357 cmdStart = textLength();

Callers 1

typeMethod · 0.95

Calls 5

appendMethod · 0.95
printMethod · 0.95
getTextMethod · 0.80
completeNameMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected