title: Eclipse AST not changing class files when changing TypeDeclaration
body: <p><strong>I am trying to edit several Java classes with the Java AST. But my changes wont show in the Java class files.</strong> </p>
  
  <p>What specifically do I want to do? I want to take an <code>IPackageFragment</code> and visit all the <code>ICompilationUnit</code>s. For every declared class I want to set the super class to a specific class (using the qualified name of the super class, <a href="https://stackoverflow.com/questions/42189523/programmatically-setting-a-xtend-class-as-super-class-of-a-java-class">because it is an Xtend class</a>). I also tried applying the edits via the <code>Document</code> class.</p>
  
  <p><strong>For example:</strong> A class <code>main.model.someClass</code> should inherit from <code>wrappers.main.model.someClassWrapper</code></p>
  
  <p>I am relatively new to the JDT API, so I cannot find the reason why the class files are not changed. I already checked <a href="https://stackoverflow.com/questions/22317911/eclipse-ast-not-changing-files-which-are-not-opened-in-eclipse">this post</a>, but it did not help me. I tried to stay as close as possible to the examples from <a href="http://www.eclipsecon.org/2012/sites/eclipsecon.org.2012/files/How%20To%20Train%20the%20JDT%20Dragon%20combined.pdf" rel="nofollow noreferrer">How To Train the JDT Dragon</a> other tips/examples I got from Stackoverflow. But it will not work.</p>
  
  <p><strong>This is how I do it:</strong></p>
  
  <pre><code>private void editTypesIn(IPackageFragment myPackage) throws JavaModelException {
      for (ICompilationUnit unit : myPackage.getCompilationUnits()) {
          TypeVisitor visitor = new TypeVisitor(myPackage.getElementName(), unit);
          unit.becomeWorkingCopy(new NullProgressMonitor());
          CompilationUnit parse = parse(unit);
          parse.recordModifications();
          parse.accept(visitor);
      }
  }
  
  private static CompilationUnit parse(ICompilationUnit unit) {
      ASTParser parser = ASTParser.newParser(AST.JLS8);
      parser.setKind(ASTParser.K_COMPILATION_UNIT);
      parser.setSource(unit);
      parser.setResolveBindings(true);
      return (CompilationUnit) parser.createAST(null); // parse
  }
  </code></pre>
  
  <p><strong>And this is the visitor class:</strong></p>
  
  <pre><code>public class TypeVisitor extends ASTVisitor {
      private final String currentPackage;
      private final ICompilationUnit compilationUnit;
  
      public TypeVisitor(String currentPackage, ICompilationUnit compilationUnit) {
          this.currentPackage = currentPackage;
          this.compilationUnit = compilationUnit;
      }
  
      @Override
      public boolean visit(TypeDeclaration node) {
          if (!node.isInterface()) { // is class
              setSuperClass(node, "wrappers." + currentPackage + "." + node.getName().toString() + "Wrapper");
          }
          return super.visit(node);
      }
  
      public void setSuperClass(TypeDeclaration declaration, String qualifiedName) {
          try {
              // create ast and rewrite:
              AST ast = declaration.getAST();
              ASTRewrite astRewrite = ASTRewrite.create(ast);
              // set super:
              Name name = ast.newName(qualifiedName);
              Type type = ast.newSimpleType(name);
              declaration.setSuperclassType(type);
              // apply changes
              TextEdit edits = astRewrite.rewriteAST();
              compilationUnit.applyTextEdit(edits, new NullProgressMonitor());
              compilationUnit.commitWorkingCopy(true, new NullProgressMonitor());
          } catch (JavaModelException exception) {
              exception.printStackTrace();
          } catch (IllegalArgumentException exception) {
              exception.printStackTrace();
          } catch (MalformedTreeException exception) {
              exception.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance for any help!</p>