IDEA-129070 Macro: multiple $Prompt$ in External Tools

(External Tools case)
This commit is contained in:
Vassiliy.Kudryashov
2018-11-15 21:02:48 +03:00
parent 6c276a28c7
commit 9c8ee2fbfa
2 changed files with 23 additions and 12 deletions
@@ -185,17 +185,22 @@ public final class MacroManager {
String name = "$" + macro.getName() + "$";
String macroNameWithParamStart = "$" + macro.getName() + "(";
if (str.contains(name)) {
String expanded = macro.expand(dataContext);
//if (dataContext instanceof DataManagerImpl.MyDataContext) {
// // hack: macro.expand() can cause UI events such as showing dialogs ('Prompt' macro) which may 'invalidate' the datacontext
// // since we know exactly that context is valid, we need to update its event count
// ((DataManagerImpl.MyDataContext)dataContext).setEventCount(IdeEventQueue.getInstance().getEventCount());
//}
expanded = expanded == null ? defaultExpandValue : expanded;
if (expanded == null) {
return null;
for (int index = str.indexOf(name);
index != -1 && index <= str.length() - name.length();
index = str.indexOf(name, index)) {
String expanded = macro.expand(dataContext);
//if (dataContext instanceof DataManagerImpl.MyDataContext) {
// // hack: macro.expand() can cause UI events such as showing dialogs ('Prompt' macro) which may 'invalidate' the datacontext
// // since we know exactly that context is valid, we need to update its event count
// ((DataManagerImpl.MyDataContext)dataContext).setEventCount(IdeEventQueue.getInstance().getEventCount());
//}
expanded = expanded == null ? defaultExpandValue : expanded;
if (expanded == null) {
return null;
}
str = str.substring(0, index) + expanded + str.substring(index + name.length());
index += expanded.length();
}
str = StringUtil.replace(str, name, expanded);
}
else if(str.contains(macroNameWithParamStart)) {
String macroNameWithParamEnd = ")$";
@@ -79,7 +79,13 @@ public class MacroManagerTest extends CodeInsightFixtureTestCase {
}
public void testContentRootMacro() throws Exception {
doTest("foo/bar/baz.txt", "$ContentRoot$",
FileUtil.toSystemDependentName(ModuleRootManager.getInstance(myModule).getContentRoots()[0].getPath()));
String root = FileUtil.toSystemDependentName(ModuleRootManager.getInstance(myModule).getContentRoots()[0].getPath());
doTest("foo/bar/baz.txt", "$ContentRoot$", root);
doTest("foo/bar/baz2.txt", "$ContentRoot$$ContentRoot$", root+root);
doTest("foo/bar/baz3.txt", "$ContentRoot$$ContentRoot$$ContentRoot$", root+root+root);
doTest("foo/bar/baz4.txt", "$ContentRoot$test", root+"test");
doTest("foo/bar/baz5.txt", "test$ContentRoot$$ContentRoot$", "test"+root+root);
doTest("foo/bar/baz6.txt", "test$ContentRoot$test$ContentRoot$", "test"+root+"test"+root);
doTest("foo/bar/baz7.txt", "$ContentRoot$$ContentRoot$$ContentRoot$test", root+root+root+"test");
}
}