}
}
private static void toggleGrammarKitSrc(Module module, String testDataPath) throws Exception {
String absolutePath = new File("").getAbsolutePath();
JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
boolean add = facade.findPackage("org.intellij.grammar.psi") == null;
if (add) {
VfsRootAccess.allowRootAccess(absolutePath);
}
else {
VfsRootAccess.disallowRootAccess(absolutePath);
}
AccessToken accessToken = ApplicationManager.getApplication().acquireWriteActionLock(null);
try {
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
String supportUrl = getUrl(testDataPath + "/../../support");
String genUrl = getUrl(testDataPath + "/../../gen");
if (add) {
model.addContentEntry(supportUrl).addSourceFolder(supportUrl, false);
model.addContentEntry(genUrl).addSourceFolder(genUrl, false);
}
else {
for (ContentEntry entry : model.getContentEntries()) {
if (supportUrl.equals(entry.getUrl()) || genUrl.equals(entry.getUrl())) {
model.removeContentEntry(entry);
}
}
}
model.commit();
}
finally {
accessToken.finish();
}
assertTrue("GrammarKit src problem", add == (null != facade.findPackage("org.intellij.grammar.psi")));
}