/* * @see ASTVisitor#visit(SingleVariableDeclaration) */ public boolean visit(SingleVariableDeclaration node) { if (node.getAST().apiLevel() == AST.JLS2) { printModifiers(node.getModifiers()); } if (node.getAST().apiLevel() >= AST.JLS3) { printModifiers(node.modifiers()); } // node.getType().accept(this); if (node.getAST().apiLevel() >= AST.JLS3) { if (node.isVarargs()) { this.fBuffer.append("..."); // $NON-NLS-1$ } } this.fBuffer.append(" "); // $NON-NLS-1$ node.getName().accept(this); for (int i = 0; i < node.getExtraDimensions(); i++) { this.fBuffer.append("[]"); // $NON-NLS-1$ } if (node.getInitializer() != null) { this.fBuffer.append("="); // $NON-NLS-1$ node.getInitializer().accept(this); } return false; }
/** @deprecated using deprecated code */ public void testMethodParamsRenameReorder() throws Exception { if (true) return; IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append(" function m( y, a) {\n"); buf.append(" m(y, a);\n"); buf.append(" }\n"); IJavaScriptUnit cu = pack1.createCompilationUnit("E.js", buf.toString(), false, null); JavaScriptUnit astRoot = createAST(cu); ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST()); AST ast = astRoot.getAST(); assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0); // TypeDeclaration type= findTypeDeclaration(astRoot, "E"); FunctionDeclaration methodDecl = findMethodDeclaration(astRoot, "m"); Block block = methodDecl.getBody(); List statements = block.statements(); assertTrue("Number of statements not 1", statements.size() == 1); { // params List params = methodDecl.parameters(); SingleVariableDeclaration firstParam = (SingleVariableDeclaration) params.get(0); SingleVariableDeclaration secondParam = (SingleVariableDeclaration) params.get(1); // args ExpressionStatement stmt = (ExpressionStatement) statements.get(0); FunctionInvocation invocation = (FunctionInvocation) stmt.getExpression(); List arguments = invocation.arguments(); SimpleName first = (SimpleName) arguments.get(0); SimpleName second = (SimpleName) arguments.get(1); // rename args SimpleName newFirstArg = methodDecl.getAST().newSimpleName("yyy"); SimpleName newSecondArg = methodDecl.getAST().newSimpleName("bb"); rewrite.replace(first, newFirstArg, null); rewrite.replace(second, newSecondArg, null); // rename params SimpleName newFirstName = methodDecl.getAST().newSimpleName("yyy"); SimpleName newSecondName = methodDecl.getAST().newSimpleName("bb"); rewrite.replace(firstParam.getName(), newFirstName, null); rewrite.replace(secondParam.getName(), newSecondName, null); // reoder params ASTNode paramplaceholder1 = rewrite.createCopyTarget(firstParam); ASTNode paramplaceholder2 = rewrite.createCopyTarget(secondParam); rewrite.replace(firstParam, paramplaceholder2, null); rewrite.replace(secondParam, paramplaceholder1, null); // reorder args ASTNode placeholder1 = rewrite.createCopyTarget(first); ASTNode placeholder2 = rewrite.createCopyTarget(second); rewrite.replace(first, placeholder2, null); rewrite.replace(second, placeholder1, null); } String preview = evaluateRewrite(cu, rewrite); buf = new StringBuffer(); buf.append(" function m(bb, yyy) {\n"); buf.append(" m(bb, yyy);\n"); buf.append(" }\n"); assertEqualString(preview, buf.toString()); }