Tree newTree = null; if(!map.containsKey(tree)) { Tree importComments = GeneratorUtilities.get(WorkingCopy.this).importComments(tree, getCompilationUnit()); newTree = importComments.accept(duplicator, null); map.put(tree, newTree);
private List<Difference> processExternalCUs(Map<?, int[]> tag2Span, Set<Tree> syntheticTrees) { if (externalChanges == null) { return Collections.<Difference>emptyList(); } List<Difference> result = new LinkedList<Difference>(); for (CompilationUnitTree t : externalChanges.values()) { try { FileObject targetFile = doCreateFromTemplate(t); CompilationUnitTree templateCUT = impl.getJavacTask().parse(FileObjects.sourceFileObject(targetFile, targetFile.getParent())).iterator().next(); CompilationUnitTree importComments = GeneratorUtilities.get(this).importComments(templateCUT, templateCUT); rewrite(importComments, getTreeMaker().asRemoved(t)); //changes.put(importComments, t); StringWriter target = new StringWriter(); ModificationResult.commit(targetFile, processCurrentCompilationUnit(new DiffContext(this, templateCUT, codeForCompilationUnit(templateCUT), new PositionConverter(), targetFile, syntheticTrees, getFileObject() != null ? getCompilationUnit() : null, getFileObject() != null ? getText() : null), tag2Span), target); result.add(new CreateChange(t.getSourceFile(), target.toString())); target.close(); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } return result; }
N result = asReplacementOf(setLabelImpl(node, aLabel), node, true); GeneratorUtilities gu = GeneratorUtilities.get(copy);
if (info instanceof WorkingCopy) { CompilationUnitTree nue = (CompilationUnitTree) ((WorkingCopy)info).resolveRewriteTarget(cut); ((WorkingCopy)info).rewrite(info.getCompilationUnit(), GeneratorUtilities.get((WorkingCopy)info).addImports(nue, elementsToImport)); } else { final ElementHandle handle = ElementHandle.create(toImport);
/** * Create a new CompilationUnitTree from a template. * * @param sourceRoot a source root under which the new file is created * @param path a relative path to file separated by '/' * @param kind the kind of Element to use for the template, can be null or * CLASS, INTERFACE, ANNOTATION_TYPE, ENUM, PACKAGE * @return new CompilationUnitTree created from a template * @throws IOException when an exception occurs while creating the template * @since 0.101 */ public CompilationUnitTree createFromTemplate(FileObject sourceRoot, String path, ElementKind kind) throws IOException { String[] nameComponent = FileObjects.getFolderAndBaseName(path, '/'); JavaFileObject sourceFile = FileObjects.templateFileObject(sourceRoot, nameComponent[0], nameComponent[1]); FileObject template = FileUtil.getConfigFile(copy.template(kind)); FileObject targetFile = copy.doCreateFromTemplate(template, sourceFile); CompilationUnitTree templateCUT = copy.impl.getJavacTask().parse(FileObjects.sourceFileObject(targetFile, targetFile.getParent())).iterator().next(); CompilationUnitTree importComments = GeneratorUtilities.get(copy).importComments(templateCUT, templateCUT); CompilationUnitTree result = copy.getTreeMaker().CompilationUnit(importComments.getPackageAnnotations(), sourceRoot, path, importComments.getImports(), importComments.getTypeDecls()); return result; }
protected final CompilationUnitTree rewriteChildren(CompilationUnitTree tree) { ExpressionTree pid = (ExpressionTree)translate(tree.getPackageName()); importAnalysis.setCompilationUnit(tree); importAnalysis.setPackage(tree.getPackageName()); List<? extends ImportTree> imps = translate(tree.getImports()); importAnalysis.setImports(imps); List<? extends AnnotationTree> annotations = translate(tree.getPackageAnnotations()); List<? extends Tree> types = translate(tree.getTypeDecls()); Set<? extends Element> newImports = importAnalysis.getImports(); if (copy != null && newImports != null && !newImports.isEmpty()) { imps = GeneratorUtilities.get(copy).addImports(tree, newImports).getImports(); } if (!annotations.equals(tree.getPackageAnnotations()) || pid!=tree.getPackageName() || !imps.equals(tree.getImports()) || !types.equals(tree.getTypeDecls())) { CompilationUnitTree n = make.CompilationUnit(annotations, pid, imps, types, tree.getSourceFile()); model.setElement(n, model.getElement(tree)); copyCommentTo(tree,n); model.setPos(n, model.getPos(tree)); tree = n; } return tree; }
CompilationUnitTree ncut = GeneratorUtilities.get(this).addImports(diffContext.origUnit, nueImports); additionalDiffs.addAll(CasualDiff.diff(getContext(), diffContext, getTreeUtilities(), diffContext.origUnit.getImports(), ncut.getImports(), userInfo, tree2Tag, tree2Doc, tag2Span, oldTrees));
return GeneratorUtilities.get(copy).insertClassMembers(clazz, members);
case BLOCK: tree = tm.Block(((BlockTree)from).getStatements(), ((BlockTree)from).isStatic()); GeneratorUtilities gu = GeneratorUtilities.get(wc); gu.copyComments(from, tree, true); gu.copyComments(from, tree, false);