Apply "library call could be simplified" to idea + other style fixes
This commit is contained in:
+1
-1
@@ -66,7 +66,7 @@ class ImplementAsConstructorParameter : ImplementMembersHandler() {
|
||||
|
||||
override fun collectMembersToGenerate(descriptor: ClassDescriptor, project: Project): Collection<OverrideMemberChooserObject> {
|
||||
return OverrideResolver.getMissingImplementations(descriptor)
|
||||
.filter { it is PropertyDescriptor }
|
||||
.filterIsInstance<PropertyDescriptor>()
|
||||
.map { OverrideMemberChooserObject.create(project, it, it, OverrideMemberChooserObject.BodyType.FROM_TEMPLATE, true) }
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,8 @@ class KotlinCoverageExtension : JavaCoverageEngineExtension() {
|
||||
if (srcFile is KtFile) {
|
||||
val fileIndex = ProjectRootManager.getInstance(srcFile.getProject()).fileIndex
|
||||
if (fileIndex.isInLibraryClasses(srcFile.getVirtualFile()) ||
|
||||
fileIndex.isInLibrarySource(srcFile.getVirtualFile())) {
|
||||
fileIndex.isInLibrarySource(srcFile.getVirtualFile())
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -136,22 +137,20 @@ class KotlinCoverageExtension : JavaCoverageEngineExtension() {
|
||||
|
||||
private fun getClassesGeneratedFromFile(outputRoot: VirtualFile?, file: KtFile): List<VirtualFile> {
|
||||
val relativePath = file.packageFqName.asString().replace('.', '/')
|
||||
val packageOutputDir = outputRoot?.findFileByRelativePath(relativePath)
|
||||
if (packageOutputDir == null) return listOf()
|
||||
val packageOutputDir = outputRoot?.findFileByRelativePath(relativePath) ?: return listOf()
|
||||
|
||||
val prefixes = collectClassFilePrefixes(file)
|
||||
LOG.debug("ClassFile prefixes: [${prefixes.joinToString(", ")}]")
|
||||
return packageOutputDir.children.filter { packageFile ->
|
||||
prefixes.any {
|
||||
(packageFile.name.startsWith(it + "$") && FileUtilRt.getExtension(packageFile.name) == "class") ||
|
||||
packageFile.name == it + ".class"
|
||||
(packageFile.name.startsWith("$it$") && FileUtilRt.getExtension(packageFile.name) == "class") ||
|
||||
packageFile.name == "$it.class"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findOutputRoot(file: KtFile): VirtualFile? {
|
||||
val module = ModuleUtilCore.findModuleForPsiElement(file)
|
||||
if (module == null) return null
|
||||
val module = ModuleUtilCore.findModuleForPsiElement(file) ?: return null
|
||||
val fileIndex = ProjectRootManager.getInstance(file.project).fileIndex
|
||||
val inTests = fileIndex.isInTestSourceContentKotlinAware(file.virtualFile)
|
||||
val compilerOutputExtension = CompilerModuleExtension.getInstance(module)
|
||||
@@ -162,7 +161,7 @@ class KotlinCoverageExtension : JavaCoverageEngineExtension() {
|
||||
}
|
||||
|
||||
private fun collectClassFilePrefixes(file: KtFile): Collection<String> {
|
||||
val result = file.children.filter { it is KtClassOrObject }.mapNotNull { (it as KtClassOrObject).name }
|
||||
val result = file.children.filterIsInstance<KtClassOrObject>().mapNotNull { it.name }
|
||||
val packagePartFqName = JvmFileClassUtil.getFileClassInfoNoResolve(file).fileClassFqName
|
||||
return result.union(arrayListOf(packagePartFqName.shortName().asString()))
|
||||
}
|
||||
|
||||
+2
-3
@@ -15,8 +15,7 @@ import java.io.File
|
||||
|
||||
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
||||
class LiveTemplatesContextTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
override fun getTestDataPath(): String =
|
||||
File(TEST_DATA_BASE_PATH, "/context").path + File.separator
|
||||
override fun getTestDataPath(): String = File(TEST_DATA_BASE_PATH, "/context").path + File.separator
|
||||
|
||||
fun testInDocComment() {
|
||||
assertInContexts(Generic::class.java, Comment::class.java)
|
||||
@@ -84,7 +83,7 @@ class LiveTemplatesContextTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
private fun assertInContexts(vararg expectedContexts: java.lang.Class<out KotlinTemplateContextType>) {
|
||||
myFixture.configureByFile(getTestName(false) + ".kt")
|
||||
val allContexts = TemplateContextType.EP_NAME.extensions.filter { it is KotlinTemplateContextType }
|
||||
val allContexts = TemplateContextType.EP_NAME.extensions.filterIsInstance<KotlinTemplateContextType>()
|
||||
val enabledContexts = allContexts.filter { it.isInContext(myFixture.file, myFixture.caretOffset) }.map { it::class.java }
|
||||
UsefulTestCase.assertSameElements(enabledContexts, *expectedContexts)
|
||||
}
|
||||
|
||||
+4
-4
@@ -430,7 +430,7 @@ class MoveConflictChecker(
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.targetAwareContainingClass(): ClassDescriptor? {
|
||||
return targetAwareContainers().firstIsInstanceOrNull<ClassDescriptor>()
|
||||
return targetAwareContainers().firstIsInstanceOrNull()
|
||||
}
|
||||
|
||||
fun DeclarationDescriptorWithVisibility.isProtectedVisible(referrerDescriptor: DeclarationDescriptor): Boolean {
|
||||
@@ -578,7 +578,7 @@ class MoveConflictChecker(
|
||||
true // => 100% clash
|
||||
aSupertypes.size == 1 && bSupertypes.size == 1 -> // a = T: T1, b = T: T2
|
||||
equivalent(aSupertypes.first(), bSupertypes.first()) // equivalent(T1, T2) => clash
|
||||
a.arguments.size != 0 && b.arguments.size != 0 ->
|
||||
a.arguments.isNotEmpty() && b.arguments.isNotEmpty() ->
|
||||
equivalent( // a = Something<....>, b = SomethingElse<....>
|
||||
a.constructor.declarationDescriptor?.name, // equivalent(Something, SomethingElse) => clash
|
||||
b.constructor.declarationDescriptor?.name
|
||||
@@ -625,10 +625,10 @@ class MoveConflictChecker(
|
||||
}
|
||||
|
||||
(elementsToMove - doNotGoIn)
|
||||
.filter {it is PsiNamedElement}
|
||||
.filterIsInstance<PsiNamedElement>()
|
||||
.forEach { declaration ->
|
||||
val declarationDescriptor =
|
||||
declaration.analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
(declaration as KtElement).analyze().get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
if (declarationDescriptor is DeclarationDescriptor) {
|
||||
val baseDescriptor = moveTarget.getContainerDescriptor()
|
||||
if (baseDescriptor != null) {
|
||||
|
||||
+19
-15
@@ -82,17 +82,17 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
val allReferences = super.findReferences(element)
|
||||
return when {
|
||||
getJvmName(element) == null -> allReferences
|
||||
element is KtElement -> allReferences.filter { it is KtReference }
|
||||
element is KtElement -> allReferences.filterIsInstance<KtReference>()
|
||||
element is KtLightElement<*, *> -> allReferences.filterNot { it is KtReference }
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun findCollisions(
|
||||
element: PsiElement,
|
||||
newName: String,
|
||||
allRenames: Map<out PsiElement, String>,
|
||||
result: MutableList<UsageInfo>
|
||||
element: PsiElement,
|
||||
newName: String,
|
||||
allRenames: Map<out PsiElement, String>,
|
||||
result: MutableList<UsageInfo>
|
||||
) {
|
||||
val declaration = element.unwrapped as? KtNamedFunction ?: return
|
||||
checkConflictsAndReplaceUsageInfos(element, allRenames, result)
|
||||
@@ -104,8 +104,8 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
}
|
||||
|
||||
class FunctionWithSupersWrapper(
|
||||
val originalDeclaration: KtNamedFunction,
|
||||
val supers: List<PsiElement>
|
||||
val originalDeclaration: KtNamedFunction,
|
||||
val supers: List<PsiElement>
|
||||
) : KtLightElement<KtNamedFunction, KtNamedFunction>, PsiNamedElement by originalDeclaration {
|
||||
override val kotlinOrigin: KtNamedFunction?
|
||||
get() = originalDeclaration
|
||||
@@ -143,8 +143,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
fun preprocessAndPass(substitutedJavaElement: PsiElement) {
|
||||
val elementToProcess = if (substitutedJavaElement is KtLightMethod && element is KtDeclaration) {
|
||||
substitutedJavaElement.kotlinOrigin as? KtNamedFunction
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
substitutedJavaElement
|
||||
}
|
||||
renameCallback.pass(elementToProcess)
|
||||
@@ -172,10 +171,16 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun createRenameDialog(project: Project, element: PsiElement, nameSuggestionContext: PsiElement?, editor: Editor?): RenameDialog {
|
||||
override fun createRenameDialog(
|
||||
project: Project,
|
||||
element: PsiElement,
|
||||
nameSuggestionContext: PsiElement?,
|
||||
editor: Editor?
|
||||
): RenameDialog {
|
||||
val elementForDialog = (element as? FunctionWithSupersWrapper)?.originalDeclaration ?: element
|
||||
return object : RenameDialog(project, elementForDialog, nameSuggestionContext, editor) {
|
||||
override fun createRenameProcessor(newName: String) = RenameProcessor(getProject(), element, newName, isSearchInComments, isSearchInNonJavaFiles)
|
||||
override fun createRenameProcessor(newName: String) =
|
||||
RenameProcessor(getProject(), element, newName, isSearchInComments, isSearchInNonJavaFiles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +202,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
mangleInternalName(newName, getModuleNameSuffix(baseName)!!)
|
||||
} else newName
|
||||
if (psiMethod.containingClass != null) {
|
||||
psiMethod.forEachOverridingMethod(scope) { it ->
|
||||
psiMethod.forEachOverridingMethod(scope) {
|
||||
val overrider = (it as? PsiMirrorElement)?.prototype as? PsiMethod ?: it
|
||||
|
||||
if (overrider is SyntheticElement) return@forEachOverridingMethod true
|
||||
@@ -206,7 +211,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
val newOverriderName = RefactoringUtil.suggestNewOverriderName(overriderName, baseName, newBaseName)
|
||||
if (newOverriderName != null) {
|
||||
RenameProcessor.assertNonCompileElement(overrider)
|
||||
allRenames.put(overrider, newOverriderName)
|
||||
allRenames[overrider] = newOverriderName
|
||||
}
|
||||
return@forEachOverridingMethod true
|
||||
}
|
||||
@@ -225,8 +230,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
|
||||
if (usage.isAmbiguousImportUsage()) {
|
||||
ambiguousImportUsages += usage
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!renameMangledUsageIfPossible(usage, element, newName)) {
|
||||
simpleUsages += usage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user