use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class PyMultiFileResolveTestCase method doResolve.
protected PsiElement doResolve(PsiFile psiFile) {
final PsiReference ref = PyResolveTestCase.findReferenceByMarker(psiFile);
final PsiManagerEx psiManager = (PsiManagerEx) myFixture.getPsiManager();
psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() {
@Override
public boolean accept(VirtualFile file) {
FileType fileType = file.getFileType();
return fileType == PythonFileType.INSTANCE;
}
}, myFixture.getTestRootDisposable());
final PsiElement result;
if (ref instanceof PsiPolyVariantReference) {
final ResolveResult[] resolveResults = ((PsiPolyVariantReference) ref).multiResolve(false);
result = resolveResults.length == 0 || !resolveResults[0].isValidResult() ? null : resolveResults[0].getElement();
} else {
result = ref.resolve();
}
psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myFixture.getTestRootDisposable());
return result;
}
use of com.intellij.openapi.fileTypes.FileType in project Main by SpartanRefactoring.
the class NanoPatternTipper method createUtilsFile.
@SuppressWarnings({ "OptionalGetWithoutIsPresent", "ResultOfMethodCallIgnored" })
private PsiFile createUtilsFile(PsiElement e, PsiDirectory d) throws IOException {
URL is = getClass().getResource("/spartanizer/SpartanizerUtils.java");
File file = new File(is.getPath());
FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(file.getName());
file.setReadable(true, false);
String s = IOUtils.toString(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/spartanizer/SpartanizerUtils.java"))));
PsiFile pf = PsiFileFactory.getInstance(e.getProject()).createFileFromText("SpartanizerUtils.java", type, s);
d.add(pf);
Arrays.stream(d.getFiles()).filter(f -> "SpartanizerUtils.java".equals(f.getName())).findFirst().get().getVirtualFile().setWritable(false);
Toolbox.getInstance().excludeFile(pf);
return pf;
}
use of com.intellij.openapi.fileTypes.FileType in project kotlin by JetBrains.
the class KotlinTypedHandler method indentBrace.
/**
* Copied from
* @see com.intellij.codeInsight.editorActions.TypedHandler#indentBrace(Project, Editor, char)
*/
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, char braceChar) {
final int offset = editor.getCaretModel().getOffset() - 1;
Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();
if (offset < 0 || chars.charAt(offset) != braceChar)
return;
int spaceStart = CharArrayUtil.shiftBackward(chars, offset - 1, " \t");
if (spaceStart < 0 || chars.charAt(spaceStart) == '\n' || chars.charAt(spaceStart) == '\r') {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null || !file.isWritable())
return;
PsiElement element = file.findElementAt(offset);
if (element == null)
return;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset);
FileType fileType = file.getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || braceMatcher.isRBraceToken(iterator, chars, fileType);
if (element.getNode() != null && isBrace) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
int newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
editor.getCaretModel().moveToOffset(newOffset + 1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
}
});
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaFxFileTypeFactory method createFileTypes.
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
final FileType fileType = consumer.getStandardFileTypeByName("XML");
assert fileType != null;
consumer.consume(fileType, FXML_EXTENSION);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaFxLocationReferenceProvider method collectRefs.
private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
final int atSignIndex = value.indexOf('@');
if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
value = value.substring(atSignIndex + 1);
startInElement += atSignIndex + 1;
}
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = item.getVirtualFile();
if (virtualFile == null)
return false;
final FileType fileType = virtualFile.getFileType();
return myAcceptedFileTypes.contains(fileType);
};
}
};
if (value.startsWith("/")) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return set.getAllReferences();
}
Aggregations