use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertBefore.
@Test
public void testInsertBefore() {
String before = "var someRandomCode = {};";
String after = "/** some comment */\ngoog.foo();";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
Node newNode = IR.exprResult(IR.call(IR.getprop(IR.name("goog2"), "get"), IR.string("service")));
SuggestedFix fix = new SuggestedFix.Builder().insertBefore(root.getLastChild().getFirstChild(), newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, "goog2.get('service');\n");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertBeforeWithNonJSDocBlockComment.
@Test
public void testInsertBeforeWithNonJSDocBlockComment() {
String before = "var someRandomCode = {};";
String after = "/* some comment */\ngoog.foo();";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
Node newNode = IR.exprResult(IR.call(IR.getprop(IR.name("goog2"), "get"), IR.string("service")));
SuggestedFix fix = new SuggestedFix.Builder().insertBefore(root.getLastChild(), newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, "goog2.get('service');\n");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testReplaceText.
@Test
public void testReplaceText() {
String input = "var foo = new Bar();";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().replaceText(root.getFirstFirstChild(), 3, "quux").build();
CodeReplacement replacement = CodeReplacement.create(4, 3, "quux");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameProperty_entireName.
@Test
public void testRenameProperty_entireName() {
String input = "obj.test.property";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().rename(root.getFirstFirstChild(), "renamedProperty", true).build();
CodeReplacement replacement = CodeReplacement.create(0, input.length(), "renamedProperty");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDelete_multipleConstDeclaration.
@Test
public void testDelete_multipleConstDeclaration() {
String input = "const foo = 3, bar = 4, baz = 5;";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
// Delete the 1st variable on the line. Make sure the deletion includes the assignment and the
// trailing comma.
SuggestedFix fix = new SuggestedFix.Builder().delete(root.getFirstFirstChild()).build();
CodeReplacement replacement = CodeReplacement.create(6, "foo = 3, ".length(), "");
assertReplacement(fix, replacement);
// Delete the 2nd variable.
fix = new SuggestedFix.Builder().delete(root.getFirstChild().getSecondChild()).build();
replacement = CodeReplacement.create(input.indexOf("bar = 4, "), "bar = 4, ".length(), "");
assertReplacement(fix, replacement);
// Delete the last variable. Make sure it removes the leading comma.
fix = new SuggestedFix.Builder().delete(root.getFirstChild().getLastChild()).build();
replacement = CodeReplacement.create(input.indexOf(", baz = 5"), ", baz = 5".length(), "");
assertReplacement(fix, replacement);
}
Aggregations