use of com.intellij.psi.PsiDocumentManager in project buck by facebook.
the class BuckModule method projectOpened.
@Override
public void projectOpened() {
projectClosed = new AtomicBoolean(false);
BuckFileUtil.setBuckFileType();
// connect to the Buck client
BuckClientManager.getOrCreateClient(mProject, mEventHandler).connect();
if (!UISettings.getInstance().SHOW_MAIN_TOOLBAR) {
BuckPluginNotifications.notifyActionToolbar(mProject);
}
mBuckEventsConsumer = new BuckEventsConsumer(mProject);
PsiDocumentManager manager = PsiDocumentManager.getInstance(mProject);
manager.addListener(new BuckAutoDepsContributor(mProject));
}
use of com.intellij.psi.PsiDocumentManager in project android by JetBrains.
the class GradleFileEditor method refresh.
public void refresh() {
if (myDocument != null) {
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
psiDocumentManager.commitDocument(myDocument);
}
disposeGroups();
myGroups = new GradleEditorModelParserFacade().parse(myVirtualFile, myProject);
myComponent.setData(myGroups);
}
use of com.intellij.psi.PsiDocumentManager in project android by JetBrains.
the class AndroidModuleInfoTest method testManifestPlaceholderCompletion.
public void testManifestPlaceholderCompletion() throws Exception {
loadProject(MODULE_INFO_MERGE);
assertNotNull(myAndroidFacet);
VirtualFile file = getProject().getBaseDir().findFileByRelativePath("src/main/AndroidManifest.xml");
assertNotNull(file);
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
assertNotNull(psiFile);
myFixture.configureFromExistingVirtualFile(file);
List<HighlightInfo> highlights = myFixture.doHighlighting(HighlightSeverity.ERROR);
assertTrue(highlights.isEmpty());
myFixture.testHighlighting(false, false, false, file);
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
final Document document = manager.getDocument(psiFile);
assertNotNull(document);
final String defaultPlaceholder = "${defaultTheme}";
// Check placeholder completion
new WriteCommandAction.Simple(getProject(), psiFile) {
@Override
protected void run() throws Throwable {
int offset = document.getText().indexOf(defaultPlaceholder);
document.replaceString(offset, offset + defaultPlaceholder.length(), "${<caret>");
manager.commitAllDocuments();
}
}.execute();
FileDocumentManager.getInstance().saveAllDocuments();
myFixture.configureFromExistingVirtualFile(file);
myFixture.complete(CompletionType.BASIC);
assertThat(myFixture.getLookupElementStrings()).containsExactly("defaultTheme");
// Check that there are no errors
myFixture.testHighlighting();
}
use of com.intellij.psi.PsiDocumentManager in project android by JetBrains.
the class LombokPsiConverterTest method check.
private static void check(PsiFile psiFile, @Language("JAVA") String source) {
assertTrue(psiFile.getClass().getName(), psiFile instanceof PsiJavaFile);
PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
CompilationUnit node = LombokPsiConverter.convert(psiJavaFile);
assertNotNull(node);
String actualStructure;
if (CHECK_POSITIONS) {
StructureFormatter structureFormatter = StructureFormatter.formatterWithPositions();
node.accept(new SourcePrinter(structureFormatter));
actualStructure = structureFormatter.finish();
}
TextFormatter formatter = new TextFormatter();
node.accept(new SourcePrinter(formatter));
String actual = formatter.finish();
Node expectedNode = parse(source);
assertNotNull(expectedNode);
if (CHECK_POSITIONS) {
StructureFormatter structureFormatter = StructureFormatter.formatterWithPositions();
expectedNode.accept(new SourcePrinter(structureFormatter));
String masterStructure = structureFormatter.finish();
assertEquals(masterStructure, actualStructure);
}
formatter = new TextFormatter();
expectedNode.accept(new SourcePrinter(formatter));
String master = formatter.finish();
assertEquals(master, actual);
// Check for resilience to error nodes being present in the AST
Project project = psiFile.getProject();
final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
final Document document = manager.getDocument(psiFile);
assertNotNull(document);
// fixed seed for test reproducibility
final Random random = new Random(0L);
for (int i = 0; i < 500; i++) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
int pos = random.nextInt(document.getTextLength() - 1);
char ch = (char) (random.nextInt(64) + 32);
double operation = random.nextDouble();
if (operation < 0.33) {
document.insertString(pos, Character.toString(ch));
} else if (operation < 0.67) {
document.replaceString(pos, pos + 1, Character.toString(ch));
} else {
document.deleteString(pos, pos + 1);
}
manager.commitDocument(document);
}
});
node = LombokPsiConverter.convert(psiJavaFile);
assertNotNull(psiJavaFile.getText(), node);
}
}
use of com.intellij.psi.PsiDocumentManager in project android by JetBrains.
the class ResourceFolderRepositoryTest method testRemoveStringArrayItemElements.
public void testRemoveStringArrayItemElements() throws Exception {
resetScanCounter();
VirtualFile file1 = myFixture.copyFileToProject(VALUES1, "res/values/myvalues.xml");
PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
assertNotNull(psiFile1);
ResourceFolderRepository resources = createRepository();
assertNotNull(resources);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
final Document document = documentManager.getDocument(psiFile1);
assertNotNull(document);
assertTrue(resources.hasResourceItem(ResourceType.ARRAY, "security_questions"));
ResourceItem array = getOnlyItem(resources, ResourceType.ARRAY, "security_questions");
ResourceValue resourceValue = array.getResourceValue(false);
assertNotNull(resourceValue);
assertEquals("Question 4", resourceValue.getValue());
assertTrue(resourceValue instanceof ArrayResourceValue);
ArrayResourceValue arv = (ArrayResourceValue) resourceValue;
assertEquals(5, arv.getElementCount());
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
String elementString = "<item>Question 3</item>";
final int offset = document.getText().indexOf(elementString);
document.deleteString(offset, offset + elementString.length());
document.insertString(offset, "<item>Question X</item>");
documentManager.commitDocument(document);
}
});
// First edit won't be incremental (file -> Psi).
assertTrue(resources.isScanPending(psiFile1));
UIUtil.dispatchAllInvocationEvents();
assertTrue(resources.hasResourceItem(ResourceType.ARRAY, "security_questions"));
array = getOnlyItem(resources, ResourceType.ARRAY, "security_questions");
resourceValue = array.getResourceValue(false);
assertNotNull(resourceValue);
assertEquals("Question 4", resourceValue.getValue());
assertTrue(resourceValue instanceof ArrayResourceValue);
arv = (ArrayResourceValue) resourceValue;
assertEquals(5, arv.getElementCount());
resetScanCounter();
// Now try another edit that is also a delete item, where things should be incremental now.
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
String elementString = "<item>Question X</item>";
final int offset = document.getText().indexOf(elementString);
document.deleteString(offset, offset + elementString.length());
documentManager.commitDocument(document);
}
});
assertTrue(resources.hasResourceItem(ResourceType.ARRAY, "security_questions"));
array = getOnlyItem(resources, ResourceType.ARRAY, "security_questions");
resourceValue = array.getResourceValue(false);
assertNotNull(resourceValue);
assertEquals("Question 5", resourceValue.getValue());
assertTrue(resourceValue instanceof ArrayResourceValue);
arv = (ArrayResourceValue) resourceValue;
assertEquals(4, arv.getElementCount());
// Shouldn't have done any full file rescans during the above edits
ensureIncremental();
}
Aggregations