fileIndex.isInSourceContent(existingFile) ? fileIndex.getSourceRootForFile(existingFile) : fileIndex.isInContent(existingFile) ? fileIndex.getContentRootForFile(existingFile) : null; VirtualFile[] contentRoots = rootManager.getContentRoots(); final VirtualFile virtualRoot = existingFileRoot != null ? existingFileRoot : preferSourceRoot && fileIndex.isInSource(sourceFile) ? fileIndex.getSourceRootForFile(sourceFile) : fileIndex.isInContent(sourceFile) ? fileIndex.getContentRootForFile(sourceFile) : getFirstElement(preferSourceRoot && sourceRoots.length > 0? sourceRoots : contentRoots);
private Result checkFileInSourceFolders(VirtualFile file, Module module) { ProjectFileIndex fileIndex = projectRootManager.getFileIndex(); if (fileIndex.isExcluded(file)) { return Result.excluded("file is excluded or ignored in IntelliJ's project structure"); } SourceFolder sourceFolder = SonarLintUtils.getSourceFolder(fileIndex.getSourceRootForFile(file), module); if (sourceFolder != null) { if (SonarLintUtils.isGeneratedSource(sourceFolder)) { return Result.excluded("file is classified as generated in IntelliJ's project structure"); } if (SonarLintUtils.isJavaResource(sourceFolder)) { return Result.excluded("file is classified as resource in IntelliJ's project structure"); } } // the fact that the file doesn't explicitly belong to sources doesn't mean it's not sources. // In WebStorm, for example, everything is considered to be sources unless it is explicitly marked otherwise. return Result.notExcluded(); }