use of com.intellij.psi.impl.source.PsiFileImpl in project idea-handlebars by dmarcotte.
the class HbFileViewProvider method createFile.
@Override
protected PsiFile createFile(@NotNull Language lang) {
ParserDefinition parserDefinition = getDefinition(lang);
if (parserDefinition == null) {
return null;
}
if (lang.is(getTemplateDataLanguage())) {
PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
return file;
} else if (lang.isKindOf(getBaseLanguage())) {
return parserDefinition.createFile(this);
} else {
return null;
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class XmlEventsTest method testDocumentChange.
public void testDocumentChange() throws Exception {
final String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_height=\"fill_parent\">\n" + " <include layout=\"@layout/colorstrip\" />\n" + "\n" + "\n" + " <LinearLayout\n" + " android:id=\"@+id/noteArea\"\n" + " android:layout_width=\"fill_parent\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_weight=\"1\"\n" + " android:layout_margin=\"5dip\">\n" + " </LinearLayout>\n" + "\n" + "</LinearLayout>\n";
PsiFile file = createFile("file.xml", xml);
assertTrue(file instanceof XmlFile);
XmlDocument xmlDocument = ((XmlFile) file).getDocument();
assertNotNull(xmlDocument);
final XmlTag tagFromText = xmlDocument.getRootTag();
assertNotNull(tagFromText);
final PsiFileImpl containingFile = (PsiFileImpl) tagFromText.getContainingFile();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
final Document document = documentManager.getDocument(containingFile);
assertNotNull(document);
final TestListener listener = new TestListener();
PsiManager.getInstance(getProject()).addPsiTreeChangeListener(listener);
CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
int positionToInsert = xml.indexOf(" <LinearLayout\n" + " android:id=\"@+id/noteArea\"\n");
assertFalse(positionToInsert == -1);
String stringToInsert = "<Button android:id=\"@+id/newid\" />\n";
document.insertString(positionToInsert, stringToInsert);
documentManager.commitDocument(document);
}), "", null);
PsiManager.getInstance(getProject()).removePsiTreeChangeListener(listener);
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class XmlEventsTest method checkEventsByDocumentChange.
private void checkEventsByDocumentChange(final String rootTagText, final int positionToInsert, final String stringToInsert, String events) throws Exception {
final Listener listener = addPomListener();
final XmlTag tagFromText = ((XmlFile) createFile("file.xml", rootTagText)).getDocument().getRootTag();
final PsiFileImpl containingFile = (PsiFileImpl) tagFromText.getContainingFile();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
final Document document = documentManager.getDocument(containingFile);
WriteCommandAction.runWriteCommandAction(null, () -> {
document.insertString(positionToInsert, stringToInsert);
documentManager.commitDocument(document);
});
assertEquals(events, listener.getEventString());
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PyMultiFileResolveTest method testKeywordArgument.
public void testKeywordArgument() {
final PsiFile file = prepareFile();
final PsiManager psiManager = myFixture.getPsiManager();
final VirtualFile dir = myFixture.findFileInTempDir("a.py");
final PsiFile psiFile = psiManager.findFile(dir);
//noinspection ConstantConditions we need to unstub a.py here
((PsiFileImpl) psiFile).calcTreeElement();
final PsiElement element;
try {
element = doResolve(file);
} catch (Exception e) {
throw new RuntimeException(e);
}
assertResolveResult(element, PyClass.class, "A");
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class RestFileViewProvider method createFile.
@Override
protected PsiFile createFile(@NotNull final Language lang) {
ParserDefinition def = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
if (def == null)
return null;
if (lang == getTemplateDataLanguage()) {
PsiFileImpl file = (PsiFileImpl) def.createFile(this);
file.setContentElementType(RestPythonElementTypes.PYTHON_BLOCK_DATA);
return file;
} else if (lang.getID().equals("DjangoTemplate")) {
PsiFileImpl file = (PsiFileImpl) def.createFile(this);
file.setContentElementType(RestPythonElementTypes.DJANGO_BLOCK_DATA);
return file;
} else if (lang == RestLanguage.INSTANCE) {
return def.createFile(this);
}
return null;
}
Aggregations