/* * The Rename Type refactoring */ aspect RenameType { public void TypeDecl.rename(String new_name) { if(name().equals(new_name)) return; checkRenamingPreconds(new_name); String old_name = name(); Collection endangered = new ArrayList(2); endangered.add(old_name); endangered.add(new_name); programRoot().lockNames(endangered); setID(new_name); if(isTopLevelType() && isPublic()) compilationUnit().setID(new_name); programRoot().eliminate(LOCKED_NAMES); } protected void TypeDecl.checkRenamingPreconds(String new_name) { if(!isValidName(new_name)) throw new RefactoringException("not a valid name: "+new_name); if(containsNativeMethod()) throw new RefactoringException("contains a native method"); if(hasNestedType(new_name)) throw new RefactoringException("nested type of the same name exists"); if(isNestedType()) { TypeDecl enc = enclosingType(); if(!enc.memberTypes(new_name).isEmpty()) throw new RefactoringException("type of the same name exists in enclosing type"); if(hasEnclosingType(new_name)) throw new RefactoringException("enclosing type of the same name exists"); } else if(isTopLevelType()) { String pkg = hostPackage(); if(lookupType(pkg, new_name) != null) throw new RefactoringException("type of the same name exists in enclosing package"); if(programRoot().hasPackage(pkg+"."+new_name)) throw new RefactoringException("sub-package of the same name exists in enclosing package"); } } protected void TypeVariable.checkRenamingPreconds(String new_name) { super.checkRenamingPreconds(new_name); GenericElement owner = owner(); for(int i=0;i