Refine search
private BlockTree addStatement(WorkingCopy wc, BlockTree blockTree, StatementTree stmtTree) { BlockTree newBlockTree = wc.getTreeMaker().addBlockStatement(blockTree, stmtTree); wc.rewrite(blockTree, newBlockTree); return newBlockTree; }
public void run (WorkingCopy workingCopy) throws Exception { workingCopy.toPhase (JavaSource.Phase.ELEMENTS_RESOLVED); CompilationUnitTree compilationUnit = workingCopy.getCompilationUnit (); TreeMaker treeMaker = workingCopy.getTreeMaker (); Trees trees = workingCopy.getTrees (); ContainsMethodTreeVisitor visitor = new ContainsMethodTreeVisitor (trees, methodName, parameters); visitor.scan (compilationUnit, null); TreePath classTreePath = visitor.getClassTreePath (); if (classTreePath != null) { ExpressionTree expressionTree = findImplementIdentifier (trees, classTreePath, className); if (visitor.isMethodExists ()) { if (expressionTree == null) { TypeElement typeElement = workingCopy.getElements ().getTypeElement (className); ExpressionTree implementsClause = typeElement != null ? treeMaker.QualIdent (typeElement) : treeMaker.Identifier (className); ClassTree oldClassTree = (ClassTree) classTreePath.getLeaf (); ClassTree newClassTree = treeMaker.addClassImplementsClause (oldClassTree, implementsClause); workingCopy.rewrite (oldClassTree, newClassTree); } } else { if (expressionTree != null) { ClassTree oldClassTree = (ClassTree) classTreePath.getLeaf (); ClassTree newClassTree = treeMaker.removeClassImplementsClause (oldClassTree, expressionTree); workingCopy.rewrite (oldClassTree, newClassTree); } } } } });
public Object run(WorkingCopy wc) { TreeMaker make = wc.getTreeMaker(); ExpressionTree arg = getArgument(wc); SourcePositions[] positions = new SourcePositions[1]; ExpressionTree newArg = wc.getTreeUtilities().parseExpression(valueSource, positions); wc.rewrite(arg, newArg); return null; } }, method.getJavaClass().getFileObject());
public Object run(WorkingCopy wc) { MethodInvocationTree methInvk = getDelegate(wc); if(methInvk != null) { IdentifierTree oldTree = (IdentifierTree)methInvk.getMethodSelect(); IdentifierTree newTree = wc.getTreeMaker().Identifier(name); wc.rewrite(oldTree, newTree); } return null; } }, javaClass.getFileObject());
private void renameIfMatch(LiteralTree tree) { if(tree.getKind() == Tree.Kind.STRING_LITERAL && oldName.equals(tree.getValue())) { Tree nju = workingCopy.getTreeMaker().Literal(newName); workingCopy.rewrite(tree, nju); } } }
private void renameIfMatch(ReturnTree tree) { ExpressionTree expr = tree.getExpression(); if(expr.getKind() == Tree.Kind.STRING_LITERAL) { LiteralTree literal = (LiteralTree)expr; if(oldName.equals(literal.getValue())) { Tree newLiteral = workingCopy.getTreeMaker().Literal(newName); workingCopy.rewrite(literal, newLiteral); } } } }
/** * Add a new import * */ private void addImport(WorkingCopy wc, String fqn) { ImportTree imprt = TreeMakerUtils.createImport(wc, fqn); CompilationUnitTree cunit = wc.getTreeMaker().addCompUnitImport(wc.getCompilationUnit(), imprt); wc.rewrite(wc.getCompilationUnit(), cunit); }
public Object run(WorkingCopy wc) { ExecutableElement execElement = execElementHandle.resolve(wc); MethodTree oldTree = wc.getTrees().getTree(execElement); Tree newTree = wc.getTreeMaker().setLabel(oldTree, name); wc.rewrite(oldTree, newTree); return null; } }, javaClass.getFileObject());
private void renameIfMatch(TreePath path, Tree tree, Element elemToRename) { if (workingCopy.getTreeUtilities().isSynthetic(path)) return; Element el = workingCopy.getTrees().getElement(path); if (el != null && el.equals(elemToRename)) { Tree nju = workingCopy.getTreeMaker().setLabel(tree, newName); workingCopy.rewrite(tree, nju); } } }
boolean removeStatement(WorkingCopy wc, StatementTree stmtTree) { ExecutableElement execElement = execElementHandle.resolve(wc); if(execElement != null) { BlockTree blockTree = wc.getTrees().getTree(execElement).getBody(); BlockTree newBlockTree = wc.getTreeMaker().removeBlockStatement(blockTree, stmtTree); wc.rewrite(blockTree, newBlockTree); return true; } return false; }
public Object run(WorkingCopy wc) { ExecutableElement execElement = execElementHandle.resolve(wc); BlockTree block = wc.getTrees().getTree(execElement).getBody(); List<? extends StatementTree> stmts = block.getStatements(); if(stmts.size() > 0) { StatementTree stmt = stmts.get(stmts.size() - 1); if(stmt.getKind() == Tree.Kind.RETURN) { ReturnTree ret = (ReturnTree)stmt; ExpressionTree expr = ret.getExpression(); if(expr.getKind() == Tree.Kind.NULL_LITERAL) { Tree newExpr = wc.getTreeMaker().Literal(newStr); wc.rewrite(expr, newExpr); } } } return null; } }, javaClass.getFileObject());
public void run(WorkingCopy workingCopy) throws Exception { workingCopy.toPhase(Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); GenerationUtils gu = GenerationUtils.newInstance(workingCopy); TypeElement typeElement = SourceUtils.getPublicTopLevelElement(workingCopy); ClassTree oldClassTree = workingCopy.getTrees().getTree(typeElement); ClassTree classTree = addFields(gu, make, typeElement, oldClassTree); if (isBodyTag) { classTree = make.addClassMember(classTree, addBodyEvaluatorCheck(evaluateBody, make)); } classTree = addSetters(gu, make, typeElement, classTree); workingCopy.rewrite(oldClassTree, classTree); } };
public Object run(WorkingCopy wc) { ExecutableElement execElement = methodElementHandle.resolve(wc); TypeElement typeElement = typeElementHandle.resolve(wc); ClassTree ctree = wc.getTrees().getTree(typeElement); ClassTree newctree = ctree; newctree = wc.getTreeMaker().removeClassMember(ctree, wc.getTrees().getTree(execElement)); wc.rewrite(ctree, newctree); return null; } }, fObj);
TreeMaker maker = workingCopy.getTreeMaker(); ClassTree modified = classTree; workingCopy.rewrite(classTree, modified);
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; }
public Object run(WorkingCopy wc) { Method m = getMethod(wc, cm.getName(), cm.getParameterTypes(), kind); if(m == null) { TreeMaker make = wc.getTreeMaker(); TypeElement typeElement = typeElementHandle.resolve(wc); ClassTree ctree = wc.getTrees().getTree(typeElement); ClassTree newctree = ctree; MethodTree mtree = TreeMakerUtils.createMethod(wc, cm, retType); newctree = make.addClassMember(ctree, mtree); wc.rewrite(ctree, newctree); } return m; } }, fObj);
public Object run(WorkingCopy wc) { TreeMaker make = wc.getTreeMaker(); ExecutableElement execElement = execElementHandle.resolve(wc); MethodTree methodTree = wc.getTrees().getTree(execElement); MethodTree newMethodTree = wc.getTreeMaker().Method(methodTree.getModifiers(), methodTree.getName(), methodTree.getReturnType(), methodTree.getTypeParameters(), methodTree.getParameters(), methodTree.getThrows(), "{" + bodyText + "}", (ExpressionTree)methodTree.getDefaultValue()); wc.rewrite(methodTree, newMethodTree); return null; } }, javaClass.getFileObject());
TreeMaker make = workingCopy.getTreeMaker(); AnnotationTree annotation = createAnnotation(action, make, workingCopy); modifiedClassTree = make.insertClassMember(classTree, insertIndex, newMethod); workingCopy.rewrite(classTree, modifiedClassTree);
WorkingCopy wc = ctx.getWorkingCopy(); wc.toPhase(JavaSource.Phase.RESOLVED); TreeMaker make = wc.getTreeMaker(); AnnotationTree newTree = GenerationUtils.newInstance(wc).createAnnotation(replacingClass, arguments); newModifiersTree = make.addModifiersAnnotation(newModifiersTree, newTree); wc.rewrite(modifiers, newModifiersTree); for (ImportTree importTree : imports) { if (deprecatedClass.equals(importTree.getQualifiedIdentifier().toString())) { wc.rewrite(importTree, newImportTree);
TreeMaker make = wc.getTreeMaker(); ClassTree modifiedClass = clazz; MethodInvocationTree notification = make.MethodInvocation(Collections.EMPTY_LIST, fireMethod, fireArgs); newBlock = make.addBlockStatement(newBlock, make.ExpressionStatement(notification)); wc.rewrite(block, newBlock); wc.rewrite(clazz, modifiedClass);