1 19 20 package org.netbeans.modules.java.source.builder; 21 22 import org.netbeans.modules.java.source.engine.EngineEnvironment; 23 import org.netbeans.modules.java.source.engine.EngineEnvironment; 24 import org.netbeans.modules.java.source.engine.ASTModel; 25 import org.netbeans.modules.java.source.engine.RootTree; 26 import org.netbeans.api.java.source.query.QueryEnvironment; 27 import org.netbeans.modules.java.source.engine.QueryProgress; 28 import org.netbeans.modules.java.source.engine.ReattributionException; 29 import org.netbeans.api.java.source.query.Query; 30 import org.netbeans.api.java.source.query.ResultTableModel; 31 import org.netbeans.api.java.source.transform.Transformer; 32 import org.netbeans.modules.java.source.engine.RootTree; 33 34 import java.util.ArrayList ; 35 import java.util.List ; 36 37 40 public final class MultiTransformer extends Transformer<Object , Object > { 41 ASTModel model; 42 Query[] commands; 43 List <ResultTableModel> resultsList; 44 QueryProgress progressBar; 45 int done; 46 47 public MultiTransformer(String name, Query[] queries, QueryProgress progress) throws Exception { 48 super(); 49 setQueryDescription(name); 50 commands = queries; 51 resultsList = new ArrayList <ResultTableModel>(); 52 progressBar = progress; 53 progressBar.setTotalQueries(queries.length); 54 } 55 56 @Override 57 public void init() { 58 super.init(); 59 for (Query q : commands) 60 q.init(); 61 } 62 63 @Override 64 public void attach(QueryEnvironment env) { 65 super.attach(env); 66 model = ((EngineEnvironment)env).getModel(); 67 for (Query q : commands) 68 q.attach(env); 69 } 70 71 @Override 72 public void release() { 73 super.release(); 74 model = null; 75 for (Query q : commands) 76 q.release(); 77 } 78 79 @Override 80 public void destroy() { 81 super.destroy(); 82 resultsList = null; 83 progressBar = null; 84 for (Query q : commands) 85 q.destroy(); 86 } 87 88 @Override 89 public void apply() { 90 try { 91 for (Query q : commands) { 92 String name = q.getQueryDescription(); 93 progressBar.queryStarted(name); 94 q.apply(); 95 if (q instanceof Transformer) { 96 changes.add(((Transformer)q).getChanges()); 97 } 98 resultsList.add(q.getResult()); 99 progressBar.queryFinished(); 100 } 101 RootTree newRoot = commit((RootTree)model.getRoot()); 102 if (!translationSuccessful()) { 103 result = null; env.setErrorMessage(getFailureMessage(), queryDescription); 105 } else if (changes.hasChanges()) { 106 model.setRoot(newRoot); 107 } 108 show(resultsList.toArray(new ResultTableModel[0]), getQueryDescription()); 109 } catch (ReattributionException e) { 110 error(e); 111 } 112 } 113 } 114 | Popular Tags |