use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class LanguageTextField method createEditor.
@Override
protected EditorEx createEditor() {
final EditorEx ex = super.createEditor();
if (myLanguage != null) {
final FileType fileType = myLanguage.getAssociatedFileType();
ex.setHighlighter(HighlighterFactory.createHighlighter(myProject, fileType));
}
ex.setEmbeddedIntoDialogWrapper(true);
return ex;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class TodoIndex method getVersion.
@Override
public int getVersion() {
int version = 9;
FileType[] types = myFileTypeManager.getRegisteredFileTypes();
Arrays.sort(types, (o1, o2) -> Comparing.compare(o1.getName(), o2.getName()));
for (FileType fileType : types) {
DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = TodoIndexers.INSTANCE.forFileType(fileType);
if (indexer == null)
continue;
int versionFromIndexer = indexer instanceof VersionedTodoIndexer ? (((VersionedTodoIndexer) indexer).getVersion()) : 0xFF;
version = version * 31 + (versionFromIndexer ^ indexer.getClass().getName().hashCode());
}
return version;
}
use of com.intellij.openapi.fileTypes.FileType in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method doAnnotate.
@Override
public State doAnnotate(final State state) {
final IntellijLintClient client = IntellijLintClient.forEditor(state);
try {
final LintDriver lint = new LintDriver(new IntellijLintIssueRegistry(), client);
EnumSet<Scope> scope;
VirtualFile mainFile = state.getMainFile();
final FileType fileType = mainFile.getFileType();
String name = mainFile.getName();
if (fileType == StdFileTypes.XML) {
if (name.equals(ANDROID_MANIFEST_XML)) {
scope = Scope.MANIFEST_SCOPE;
} else {
scope = Scope.RESOURCE_FILE_SCOPE;
}
} else if (fileType == KotlinFileType.INSTANCE) {
scope = Scope.JAVA_FILE_SCOPE;
} else if (name.equals(OLD_PROGUARD_FILE) || name.equals(FN_PROJECT_PROGUARD_FILE)) {
scope = EnumSet.of(Scope.PROGUARD_FILE);
} else if (fileType == StdFileTypes.PROPERTIES) {
scope = Scope.PROPERTY_SCOPE;
} else {
// #collectionInformation above should have prevented this
assert false;
return state;
}
Project project = state.getModule().getProject();
if (project.isDisposed()) {
return state;
}
List<VirtualFile> files = Collections.singletonList(mainFile);
final LintRequest request = new IntellijLintRequest(client, project, files, Collections.singletonList(state.getModule()), true);
request.setScope(scope);
ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(new Runnable() {
@Override
public void run() {
lint.analyze(request);
}
});
} finally {
Disposer.dispose(client);
}
return state;
}
use of com.intellij.openapi.fileTypes.FileType in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method collectInformation.
@Override
public State collectInformation(@NotNull PsiFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null && !IntellijLintProject.hasAndroidModule(module.getProject())) {
return null;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return null;
}
final FileType fileType = file.getFileType();
if (fileType == FileTypes.PLAIN_TEXT) {
if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
return null;
}
} else if (fileType != KotlinFileType.INSTANCE && fileType != StdFileTypes.PROPERTIES) {
return null;
}
final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
if (issues.size() == 0) {
return null;
}
return new State(module, vFile, file.getText(), issues);
}
use of com.intellij.openapi.fileTypes.FileType in project kotlin by JetBrains.
the class AbstractQuickFixMultiFileTest method createVirtualFileFromTestFile.
/**
* @param sourceRootDir Base path of test file(Test source directory)
* @param testFile source of VFile content
* @return created VirtualFile
*/
protected static VirtualFile createVirtualFileFromTestFile(File sourceRootDir, final TestFile testFile) {
try {
assertFalse("Please don't use absolute path for multifile test 'FILE' directive: " + testFile.path, FileUtil.isAbsolutePlatformIndependent(testFile.path));
FileType fileType = guessFileType(testFile);
String extension = fileType.getDefaultExtension();
final File fileInSourceRoot = new File(testFile.path);
File container = FileUtil.getParentFile(fileInSourceRoot);
if (container == null) {
container = sourceRootDir;
} else {
container = new File(sourceRootDir, container.getPath());
}
if (!container.exists()) {
assertTrue(container.mkdirs());
}
final File tempFile = FileUtil.createTempFile(container, FileUtil.getNameWithoutExtension(testFile.path), "." + extension, true);
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
assert vFile != null;
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
vFile.setCharset(CharsetToolkit.UTF8_CHARSET);
VfsUtil.saveText(vFile, testFile.content);
}
}.execute();
return vFile;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations