Set<Tree> syntheticTrees = new HashSet<Tree>(); if (getFileObject() != null) { result.addAll(processCurrentCompilationUnit(new DiffContext(this, syntheticTrees), tag2Span));
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; }
@Override public void run(CompilationController cc) throws Exception { final WorkingCopy copy = new WorkingCopy(cc.impl, overlay); copy.setJavaSource(JavaSource.this); if (sources.isEmpty()) { //runUserActionTask for source-less JavaSources does not require toPhase //so automatically initializing also for runModificationTask: copy.toPhase(Phase.PARSED); } task.run(copy); final JavacTaskImpl jt = copy.impl.getJavacTask(); Log.instance(jt.getContext()).nerrors = 0; final List<ModificationResult.Difference> diffs = copy.getChanges(result.tag2Span); if (diffs != null && diffs.size() > 0) { final FileObject file = copy.getFileObject(); result.diffs.put(file != null ? file : FileUtil.createMemoryFileSystem().getRoot().createData("temp", "java"), diffs); } } };
public void run(WorkingCopy compiler) throws IOException { compiler.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cu = compiler.getCompilationUnit(); if (cu == null) { ErrorManager.getDefault().log(ErrorManager.ERROR, "compiler.getCompilationUnit() is null " + compiler); return; } StringLiteralTransformer stringLiteralTransformer = new StringLiteralTransformer(compiler, oldString, newString, matchKind); stringLiteralTransformer.scan(compiler.getCompilationUnit(), null); for (TreePath tree : stringLiteralTransformer.getUsages()) { ElementGripFactory.getDefault().put(compiler.getFileObject(), tree, compiler); } fireProgressListenerStep(); } }
public void run(WorkingCopy compiler) throws IOException { compiler.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cu = compiler.getCompilationUnit(); if (cu == null) { ErrorManager.getDefault().log(ErrorManager.ERROR, "compiler.getCompilationUnit() is null " + compiler); return; } StringLiteralTransformer stringLiteralTransformer = new StringLiteralTransformer(compiler, oldString, newString, matchKind); stringLiteralTransformer.scan(compiler.getCompilationUnit(), null); for (TreePath tree : stringLiteralTransformer.getUsages()) { ElementGripFactory.getDefault().put(compiler.getFileObject(), tree, compiler); } fireProgressListenerStep(); } }
getFileObject() != null ? getSnapshot().getSource() : null); } catch (IOException ex) { if (!diffContext.file.isValid()) {