/** this performs the refactoring */ protected void transform() { File newFile = createInterfaceFile(); // Add declarations of the common methods to the interface Vector methodSummaries = getMethodSummaries(); for (int i = 0; i < methodSummaries.size(); i++) { MethodSummary ms = (MethodSummary) methodSummaries.elementAt(i); m_complexTransform.add(new AddConcreteMethod(ms)); } // Add necessary import statements to support parameter and return types Iterator importTypes = getImportTypes(methodSummaries); while ((importTypes != null) && (importTypes.hasNext())) { TypeDeclSummary decl = (TypeDeclSummary) importTypes.next(); TypeSummary type = GetTypeSummary.query(decl); // If the type is not found, don't attempt to add an import statement if (type != null) { m_complexTransform.add(new AddImportTransform(type)); } } m_complexTransform.apply(newFile, newFile); /* * Delete the backup file for the intermediate new interface file to * ensure that an 'undo' does not recover it. */ newFile = new File(newFile.getAbsolutePath() + ".0"); newFile.delete(); addInterfaceToClasses(); }
/** * Adds a class that will implement the new interface * * @param packageName The feature to be added to the ImplementingClass attribute * @param className The feature to be added to the ImplementingClass attribute */ public void addImplementingClass(String packageName, String className) { TypeSummary summary = GetTypeSummary.query(PackageSummary.getPackageSummary(packageName), className); addImplementingClass(summary); }