try { ShellUtils.getShellManager().registerShell(this); } catch (NameNotFoundException ex) { }  dirty = false; String result = null; try { CommandLine cl = new CommandLine(partial); String cmd = ""; if (cl.hasNext()) { cmd = cl.next(); if (!cmd.trim().equals("") && cl.hasNext()) try {  Class cmdClass = getCommandClass(cmd); Help.Info info = Help.getInfo(cmdClass);   result = cmd + " " + info.complete(cl);  } catch (ClassNotFoundException ex) { throw new CompletionException("Command class not found"); } } if (result == null) result = defaultArg.complete(cmd);  if (!partial.equals(result) && !dirty) { dirty = true; for (int i = 0; i < partial.length() + currentPrompt.length(); i++) System.out.print("\b"); } } catch (CompletionException ex) { System.out.println(); System.err.println(ex.getMessage());   result = partial; dirty = true; }  if (dirty) { dirty = false; System.out.print(currentPrompt + result);  } return result; }
try { ShellUtils.getShellManager().registerShell(this); } catch (NameNotFoundException ex) { }  dirty = false; String result = null; try { CommandLine cl = new CommandLine(partial); String cmd = ""; if (cl.hasNext()) { cmd = cl.next(); if (!cmd.trim().equals("") && cl.hasNext()) try {  Class cmdClass = getCommandClass(cmd); Help.Info info = Help.getInfo(cmdClass);   result = cmd + " " + info.complete(cl);     } catch (ClassNotFoundException ex) { throw new CompletionException( "Command class not found"); } catch (HelpException ex) { ex.printStackTrace(); throw new CompletionException( "Command class not found"); } } if (result == null) result = defaultArg.complete(cmd);  if (!partial.equals(result) && !dirty) {   dirty = true; for (int i = 0; i < partial.length() + currentPrompt.length(); i++) System.out.print("\b"); } } catch (CompletionException ex) { System.out.println(); System.err.println(ex.getMessage());   result = partial; dirty = true; }  if (dirty) { dirty = false; System.out.print(currentPrompt + result);   } return result; }
	private String complete(String partial) {		// workaround to set the currentShell to this shell		try {			ShellUtils.getShellManager().registerShell(this);		} catch (NameNotFoundException ex) {		}				dirty = false;		String result = null;		try {			CommandLine cl = new CommandLine(partial);			String cmd = "";			if (cl.hasNext()) {				cmd = cl.next();				if (!cmd.trim().equals("") && cl.hasNext())					try {						// get command's help info						Class cmdClass = getCommandClass(cmd);						Help.Info info = Help.getInfo(cmdClass);												// perform completion						result = cmd + " " + info.complete(cl); // prepend command name and space						// again					} catch (ClassNotFoundException ex) {					throw new CompletionException("Command class not found");				}			}			if (result == null) // assume this is the alias to be called				result = defaultArg.complete(cmd);						if (!partial.equals(result) && !dirty) { // performed direct completion without listing				dirty = true; // indicate we want to have a new prompt				for (int i = 0; i < partial.length() + currentPrompt.length(); i++)					System.out.print("\b"); // clear line (cheap approach)			}		} catch (CompletionException ex) {			System.out.println(); // next line			System.err.println(ex.getMessage()); // print the error (optional)			// this debug output is to trace where the Exception came from			//ex.printStackTrace(System.err);			result = partial; // restore old value			dirty = true; // we need a new prompt		}				if (dirty) {			dirty = false;			System.out.print(currentPrompt + result); // print the prompt and go on with normal			// operation		}		return result;	}