/** * @deprecated Do not use. Use {@link GeneratorUtilities#importComments(com.sun.source.tree.Tree, com.sun.source.tree.CompilationUnitTree) } instead. */ @Deprecated public void collect(WorkingCopy copy) throws IOException { GeneratorUtilities.importComments(copy, copy.getCompilationUnit(), copy.getCompilationUnit()); }
/** * 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) { new Refactor.ElementsRenamer(wc, elementAndNames).scan(wc.getCompilationUnit(), null); //To take care of VB expressions, Ex:- getValue(#{SessionBean1.personRowSet}) renamePropertyBindingExpression(wc, name, newName); return null; } }, fObjs);
public Object run(WorkingCopy wc) { ElementsUsageFinder usageFinder = new ElementsUsageFinder(wc, elementAndNames); usageFinder.scan(wc.getCompilationUnit(), null); UsageStatus result = usageFinder.getUseStatus(); return result; } }, fObjs);
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);
public void run(WorkingCopy parameter) throws Exception { parameter.toPhase(JavaSource.Phase.PARSED); String typeFqn = getComponent().getType().getString(); if (!fullyNamesList.contains(typeFqn)) { fullyNamesList.add(typeFqn); } DesignComponent connector = MidpDatabindingSupport.getConnector(getComponent(), bindedProperty); for (String fqn : fullyNamesList) { if (bindedProperty == null) { SourceUtils.resolveImport(parameter, new TreePath(parameter.getCompilationUnit()), fqn); } else if (connector != null) { SourceUtils.resolveImport(parameter, new TreePath(parameter.getCompilationUnit()), fqn); } } } }).commit();
private void renamePropertyBindingExpression(WorkingCopy wc, String name, String newName) { String oldLiteral = "#{" + getShortName() + "." + name + "}"; //NOI18N String newLiteral = "#{" + getShortName() + "." + newName + "}"; //NOI18N new Refactor.LiteralRenamer(wc, oldLiteral, newLiteral).scan(wc.getCompilationUnit(), null); }
public void run(WorkingCopy workingCopy) throws Exception { workingCopy.toPhase(Phase.RESOLVED); CompilationUnitTree cut = workingCopy.getCompilationUnit(); gu = GenerationUtils.newInstance(workingCopy); for (Tree typeDecl : cut.getTypeDecls()) { if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) { Element e = workingCopy.getTrees().getElement(new TreePath(new TreePath(workingCopy.getCompilationUnit()), typeDecl)); if (e != null && e.getKind().isClass()) { TypeElement te = (TypeElement) e; ClassTree ct = (ClassTree) typeDecl; workingCopy.rewrite(ct, generateInterfaces(workingCopy, te, ct, gu)); } } } } };
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(); } }
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; }
List<? extends ImportTree> imports = wc.getCompilationUnit().getImports(); ImportTree newImportTree = make.Import(make.QualIdent(replacingClass), false); for (ImportTree importTree : imports) {
public static <T extends Tree> T importFQNs(WorkingCopy copy, T tree) { if (tree == null) return null; TranslateIdentifier ti = new TranslateIdentifier(copy); //XXX: the TreePath constructed below below depends on javac internals (that elements are attributes of a tree, not a tree path): ti.scan(tree.getKind() == Kind.COMPILATION_UNIT ? new TreePath((CompilationUnitTree) tree) : new TreePath(new TreePath(copy.getCompilationUnit()), tree), null); return (T) copy.getTreeUtilities().translate(tree, ti.translateMap); }
@Override public void run(WorkingCopy copy) throws IOException { copy.toPhase(JavaSource.Phase.RESOLVED); TreeMaker maker = copy.getTreeMaker(); ClassTree tree = getTopLevelClassTree(copy); if ( tree ==null ){ return; } Element element = copy.getTrees().getElement( copy.getTrees().getPath(copy.getCompilationUnit(), tree) ); ModifiersTree modifiers = tree.getModifiers(); modifiers = addAnnotation(INTERCEPTOR, maker, modifiers); TypeElement annotation = handle.resolve( copy ); if ( annotation != null ){ modifiers = addAnnotation(annotation.getQualifiedName().toString(), maker, modifiers); } copy.rewrite(tree.getModifiers(), modifiers); ElementOpen.open(copy.getClasspathInfo(), element); }
@Override public void run(WorkingCopy wc) throws Exception { wc.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cu = wc.getCompilationUnit(); ClassTree clazz = null; for (Tree typeDecl : cu.getTypeDecls()) {
@Override public void run(WorkingCopy wc) throws Exception { wc.toPhase(JavaSource.Phase.RESOLVED); CompilationUnitTree cu = wc.getCompilationUnit(); ClassTree clazz = null; for (Tree typeDecl : cu.getTypeDecls()) {
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param method figures out the scope for attribution. * @param bodyText text which will be used for method body creation. * @return a new tree for <tt>bodyText</tt>. */ public BlockTree createMethodBody(MethodTree method, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), method)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param lambda figures out the scope for attribution. * @param bodyText text which will be used for lambda body creation. * @return a new tree for <tt>bodyText</tt>. * @since 2.19 */ public BlockTree createLambdaBody(LambdaExpressionTree lambda, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), lambda)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
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); } } } } });
break; boolean before = (int)wc.getTrees().getSourcePositions().getStartPosition(wc.getCompilationUnit(), from) >= offset; if (fromIdx >=0 && toIdx >= 0 && toIdx - fromIdx > 0) { for (int i = toIdx - 1; i >= fromIdx; i--) {