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