/**
* Perform a simple (ie, non-renaming) factoring
* @param info
*/
private void command_refactor(String info) {
Refactorer refactorer = null;
boolean noGrouping = false;
String[] args = info.split(" ");
if(args[0].equals("import") || args[0].equals("imports")) {
ModuleName moduleName = targetModule;
if(args.length >= 3) {
moduleName = ModuleName.maybeMake(args[1]);
if(moduleName == null) {
iceLogger.log(Level.INFO, "Invalid module name '" + args[1] + "'");
return;
}
if(args[2].equals("nogroup")) {
noGrouping = true;
} else {
iceLogger.log(Level.INFO, "Unrecognized option '" + args[2]);
return;
}
} else if(args.length >= 2) {
moduleName = ModuleName.maybeMake(args[1]);
if (moduleName == null) {
if(args[1].equals("nogroup")){
moduleName = targetModule;
noGrouping = true;
} else {
iceLogger.log(Level.INFO, "Unrecognized option '" + args[1]);
return;
}
}
}
moduleName = resolveModuleNameInWorkspace(moduleName.toSourceText(), true);
if (moduleName == null) {
return;
}
refactorer = new Refactorer.CleanImports(getWorkspaceManager().getWorkspace().asModuleContainer(), moduleName, noGrouping);
iceLogger.log(Level.INFO, "Cleaning imports in module " + moduleName + "...");
} else if(args[0].equals("typeDecls")) {
final ModuleName moduleName;
if(args.length > 1) {
moduleName = resolveModuleNameInWorkspace(args[1], true);
if (moduleName == null) {
return;
}
} else {
moduleName = targetModule;
}
refactorer = new Refactorer.InsertTypeDeclarations(getWorkspaceManager().getWorkspace().asModuleContainer(), moduleName, -1, -1, -1, -1);
iceLogger.log(Level.INFO, "Adding type declarations to module " + moduleName + "...");
} else {
iceLogger.log(Level.INFO, "unrecognized refactoring type '" + args[0] + "'");
return;
}
CompilerMessageLogger messageLogger = new MessageLogger();
refactorer.calculateModifications(messageLogger);
if (messageLogger.getNErrors() == 0) {
// apply the changes, unless we encountered errors while calculating them
refactorer.apply(messageLogger);
}
if (messageLogger.getNErrors() > 0) {
dumpCompilerMessages(messageLogger);
return;