private static void setPackageDefinition(GroovyFile file, GroovyFile newFile, String newPackageName) {
    String modifiersText = null;

    final GrPackageDefinition packageDefinition = file.getPackageDefinition();
    if (packageDefinition != null) {
      final PsiModifierList modifierList = packageDefinition.getModifierList();
      if (modifierList != null) {
        modifiersText = modifierList.getText().trim();
      }
    }

    if (modifiersText != null && !modifiersText.isEmpty()) {
      final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(file.getProject());
      final GrPackageDefinition newPackageDefinition = (GrPackageDefinition)factory.createTopElementFromText(modifiersText + " package " + newPackageName);
      newFile.setPackage(newPackageDefinition);
    }
    else {
      newFile.setPackageName(newPackageName);
    }
  }
private static void setPackageDefinition(GroovyFile file, GroovyFile newFile, String newPackageName)