Add intentions Add/Remove/Redo parcelable implementation

#KT-17465 Fixed
#KT-12049 Fixed
This commit is contained in:
Vyacheslav Gerasimov
2017-04-18 18:53:51 +03:00
parent 37c3d8f204
commit 5b58a6f9e8
71 changed files with 2583 additions and 2 deletions
+1
View File
@@ -19,5 +19,6 @@
<orderEntry type="module" module-name="idea-analysis" />
<orderEntry type="module" module-name="idea-core" />
<orderEntry type="module" module-name="idea" />
<orderEntry type="module" module-name="idea-android" />
</component>
</module>
@@ -255,7 +255,11 @@ public class AndroidLintInspectionToolProvider {
public AndroidKLintParcelCreatorInspection() {
super(AndroidBundle.message("android.lint.inspections.parcel.creator"), ParcelDetector.ISSUE);
}
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull String message) {
return new AndroidLintQuickFix[]{ new ParcelableQuickFix() };
}
}
public static class AndroidKLintPluralsCandidateInspection extends AndroidLintInspectionBase {
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.android.inspections.klint
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.android.util.AndroidBundle
import org.jetbrains.kotlin.android.canAddParcelable
import org.jetbrains.kotlin.android.implementParcelable
import org.jetbrains.kotlin.psi.KtClass
class ParcelableQuickFix : AndroidLintQuickFix {
override fun apply(startElement: PsiElement, endElement: PsiElement, context: AndroidQuickfixContexts.Context) {
startElement.getTargetClass()?.implementParcelable()
}
override fun isApplicable(startElement: PsiElement, endElement: PsiElement, contextType: AndroidQuickfixContexts.ContextType): Boolean =
startElement.getTargetClass()?.canAddParcelable() ?: false
override fun getName(): String = AndroidBundle.message("implement.parcelable.intention.text")
private fun PsiElement.getTargetClass(): KtClass? = PsiTreeUtil.getParentOfType(this, KtClass::class.java, false)
}