use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyEditingTest method doTestTyping.
private String doTestTyping(final String text, final int offset, final char character) {
final PsiFile file = myFixture.configureByText(PythonFileType.INSTANCE, text);
myFixture.getEditor().getCaretModel().moveToOffset(offset);
myFixture.type(character);
return myFixture.getDocument(file).getText();
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyFormatterTest method doTest.
private void doTest(final boolean reformatText) {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
WriteCommandAction.runWriteCommandAction(null, () -> {
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myFixture.getProject());
PsiFile file = myFixture.getFile();
if (reformatText) {
codeStyleManager.reformatText(file, 0, file.getTextLength());
} else {
codeStyleManager.reformat(file);
}
});
myFixture.checkResultByFile("formatter/" + getTestName(true) + "_after.py");
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyRegexpTest method getElementAtCaret.
@NotNull
private PsiElement getElementAtCaret() {
final Editor editor = myFixture.getEditor();
final Document document = editor.getDocument();
final PsiFile file = PsiDocumentManager.getInstance(myFixture.getProject()).getPsiFile(document);
assertNotNull(file);
final PsiElement element = file.findElementAt(myFixture.getCaretOffset());
assertNotNull(element);
return element;
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class DomServiceImpl method getFileElements.
@Override
public <T extends DomElement> List<DomFileElement<T>> getFileElements(final Class<T> clazz, final Project project, @Nullable final GlobalSearchScope scope) {
final Collection<VirtualFile> list = getDomFileCandidates(clazz, project, scope != null ? scope : GlobalSearchScope.allScope(project));
final ArrayList<DomFileElement<T>> result = new ArrayList<>(list.size());
for (VirtualFile file : list) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile instanceof XmlFile) {
final DomFileElement<T> element = DomManager.getDomManager(project).getFileElement((XmlFile) psiFile, clazz);
if (element != null) {
result.add(element);
}
}
}
return result;
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class XmlNamespaceIndex method guessDtd.
@Nullable
public static XmlFile guessDtd(String dtdUri, @NotNull PsiFile baseFile) {
if (!dtdUri.endsWith(".dtd") || DumbService.isDumb(baseFile.getProject()) || XmlUtil.isStubBuilding())
return null;
String dtdFileName = new File(dtdUri).getName();
List<IndexedRelevantResource<String, XsdNamespaceBuilder>> list = getResourcesByNamespace(dtdFileName, baseFile.getProject(), ModuleUtilCore.findModuleForPsiElement(baseFile));
if (list.isEmpty()) {
return null;
}
IndexedRelevantResource<String, XsdNamespaceBuilder> resource;
if (list.size() > 1) {
final String[] split = dtdUri.split("/");
resource = Collections.max(list, new Comparator<IndexedRelevantResource<String, XsdNamespaceBuilder>>() {
@Override
public int compare(IndexedRelevantResource<String, XsdNamespaceBuilder> o1, IndexedRelevantResource<String, XsdNamespaceBuilder> o2) {
return weight(o1) - weight(o2);
}
int weight(IndexedRelevantResource<String, XsdNamespaceBuilder> o1) {
VirtualFile file = o1.getFile();
for (int i = split.length - 1; i >= 0 && file != null; i--) {
String s = split[i];
if (!s.equals(file.getName())) {
return split.length - i;
}
file = file.getParent();
}
return 0;
}
});
} else {
resource = list.get(0);
}
return findSchemaFile(resource.getFile(), baseFile);
}
Aggregations