Giter Club home page Giter Club logo

mikes_idea_extensions's Introduction

Mike's IDEA extensions

IntelliJ IDEA Plugin IntelliJ IDEA Plugin

Code quality goodifier, RAM saver, performance watcher, mood upgrader, vector drawable optimizer, color previewer.

UAST (Java + Kotlin) inspections

  • Atomic can be replaced with volatile
  • Allocation should be cached (new Gson(), new OkHttpClient())
  • BigDecimal|BigInteger instantiation can be replaced with constant by stokito
  • (BigDecimal|BigInteger).compareTo(ZERO) can be replaced with signum() by stokito

Kotlin inspections

  • Heavyweight property delegation
  • Declaration name is Java keyword
  • Inline function leaks anonymous declaration which will be inlined to the call-site if called from another module
  • Anonymous function won't be inlined; function cannot be inlined if it is a receiver of an extension function
  • Nullable argument to string concatenation should be re-implemented in more reliable way
  • Boxed primitive array allocation

Android inspections

  • <include layout="?themeAttribute"> requires Marshmallow
  • <drawable android:tint> requires Lollipop
  • <layer-list><item android:gravity> requires Marshmallow
  • @TargetApi should be replaced with @RequiresApi
  • Use of reflective ObjectAnimator/PropertyValuesHolder
  • Use of attributes like android.R.attr.enabled in context where state attributes expected, like android.R.attr.state_enabled
  • Color.parseColor(<constant expression>) should be replaced with an integer literal
  • Useless resource element
    • Drawables: single-item layer-lists, single stateless item selectors, insetless insets, empty shapes
    • Vector drawables: empty paths and clip-paths, invisible paths, useless clip-paths and groups, attributes with no effect
    • Animations and animators: empty and single-element sets
    • Layouts: overridden attributes in (layout_margin|padding)(Left|Top|Right|Bottom|Start|End|Horizontal|Vertical|*)
  • Android utility methods should be replaced with Kotlin extensions
  • setOnClickListener doesn't work on RecyclerView, on VideoView before API 26
  • Kotlin Android Extensions are deprecated
  • Drawable subclass should override getConstantState()
  • Activity#onCreate(, PersistableBundle) will highly likely not be called
  • <AnyScrollableView> should have an ID to save its scroll position

Editor tweaks

  • Inlay hints when upcasting to interface, e. g.
    putExtra(listas Serializable)
  • Inlay hints when overriding an interface method, e. g.
    @Override from Runnable,
    override fun Runnable.run()
  • ARGB Color swatches in gutter, folding int literals to #[AA]RRGGBB, color picker for Android, pasting CSS colors as int literals
  • Backing property folding for Kotlin
  • Live templates for SVG and Android Vector Drawable pathData
  • Live templates for implementing Property for ObjectAnimator

Plugin page on JetBrains marketplace

mikes_idea_extensions's People

Contributors

jb-dmitry avatar miha-x64 avatar stokito avatar vadiole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mikes_idea_extensions's Issues

Request: add inspection of using "entries" for enum classes

We have an inspection for caching the "values", but it seems there might be a better inspection, to use "entries".

It's currently in experimental phase, but maybe you could have an inspection for it now, and mark it too as experimental and turned off by default.

Video about it:
https://youtu.be/R1JpkpPzyBU?t=340

Not sure if it's available for Android projects.
If you try it out, please let me know and have a sample to show that it works. I hope it's possible for Android projects too.

Request: add Android inspection to make preferences callbacks a bit shorter

Examples:

instead of:

somePreference.onPreferenceChangeListener =
            Preference.OnPreferenceChangeListener { preference: Preference?, newValue: Any? ->
...

use:

somePreference.setOnPreferenceChangeListener { preference, newValue ->
...

Same goes for setOnPreferenceClickListener.

Not sure if it's available on Java, but could be nice to have it there too

Request: read colours in json files

Flutter has a great theme builder that outputs json like this

{
  "appBarTheme": {
    "backgroundColor": "#fffdfbff",
    "foregroundColor": "#ff3f51b5",
    "shadowColor": "#ff000000",
    ```
    It would be awesome if your extension was able to add those colours to the gutter too.

ref: https://appainter.dev/#/

Request: add warning when a padding/margin seem to be used to override, but actually doesn't do anything

If I have in a layout XML a value for "padding", and also for "paddingBottom", sadly the "paddingBottom" doesn't do anything.

I sometimes make this mistake, because I think to myself : "I've created a general rule, and also an exception to the rule".

In this case, the proper way to fix it is to split the "padding" to "paddingHorizontal" and "paddingTop", so that "paddingBottom" would do what it's supposed to do.

I don't remember how it works for margins.

Please offer a warning about such a case and similar cases.

Request: in Kotlin, offer inspection to replace negative hex values of colors to positive ones

When Android Studio converts from Java to Kotlin, it often converts numbers that were supposed to be of colors.

So, it creates something like:

var someColor = -0x555556

The safe way to find what color this is, is to use Integer.toHexString(), which would result in 0xffaaaaaa for this case.

After I do this, the IDE has a tiny preview of the color on the side, so it helps me read it in both ARGB format and visually:

image

This is a bit tricky for an inspection, so maybe offer it by default only to places that have the @ColorInt annotation, and an option to expand it even for places that the value doesn't have it.

Please offer such an inspection, and auto-add "0x" and ".toInt()" if needed (IDE says it's an Int already), and if ".toInt()" isn't needed, add the type of the field instead. Or maybe always add the type.
This will make sure that if we change the value with some mistake, it won't change the type so easily to Long type instead.

Bug: false positive of "Nullable argument to string concatenation" inspection

Just this simple code would trigger this, even though I don't use a null value to concatenate to a string, at all...

@JvmStatic
fun getString(id: Long): String {
    var value: String = "AttrId:0x" + java.lang.Long.toHexString(id)
    return value
}

wLPaRfzrhb

My Application.zip

Android Studio Electric Eel | 2022.1.1 Canary 6
Build #AI-221.4501.155.2211.8738788, built on June 17, 2022
Runtime version: 11.0.13+0-b1751.21-8125866 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 4000M
Cores: 12
Registry:
external.system.auto.import.disabled=true
debugger.watches.in.variables=false
ide.text.editor.with.preview.show.floating.toolbar=false

Non-Bundled Plugins:
com.intellij.marketplace (221.4501.163)
com.github.beansoft.jadx.gui.idea (2021.2.1)
com.dubreuia (2.3.0)
String Manipulation (9.5.0)
Show As ... (1.0.3)
com.google.mad-scorecard (1.2)
net.aquadc.mike.plugin (0.24)

Bug: "Invisible path" inspection always (or most of the times) incorrect

v0.23.

For many cases of VectorDrawable, I see this inspection falsely claim that it should be removed, but when I try, it changes the VectorDrawable.

For example this one:

cat_parking.zip

It claims that the first path should be removed, so here's before and after:

image

image

Please fix this.

Android Studio Dolphin | 2021.3.1 Beta 3
Build #AI-213.7172.25.2113.8684940, built on June 6, 2022
Runtime version: 11.0.13+0-b1751.21-8125866 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 8048M
Cores: 12
Registry:
external.system.auto.import.disabled=true
debugger.watches.in.variables=false
ide.text.editor.with.preview.show.floating.toolbar=false
ide.images.show.chessboard=true

Non-Bundled Plugins:
com.intellij.marketplace (213.7172.48)
com.dubreuia (2.3.0)
String Manipulation (9.5.0)
Show As ... (1.0.3)
GenerateSerializationHelpers (1.0.6)
GenerateSerialVersionUID (3.0.3)
com.google.mad-scorecard (1.2)
net.aquadc.mike.plugin (0.23)
izhangzhihao.rainbow.brackets (6.25)
com.ppismerov.ksvu (0.0.1)

Request: just like we have "Kotlin Interoperability" inspection to help with null-ness annotations, offer one to tell us when it seems ready

Currently we have "Kotlin Interoperability" inspection to show which Java files need to have @Nullable/@nonnull annotations.
It shows under :

Unknown nullness, Android->Interoperability->Kotlin Interoperability->Unknown nullness

The message is:

explicitly declare as '@nullable' or '@nonnull' to improve Kotlin interoperability; see https://android.github.io/kotlin-guides/interop.html#nullability-annotations

This can help when converting to Kotlin, as it's the major obstacle to convert properly (and one of the major reasons of issues after conversion is NPE).

My request:
Have an inspection that's based on this one, that shows which Java files can be converted as they have enough of these annotations (meaning there is no result from the "Kotlin Interoperability" on these files).

I hope it's possible.

Add the ability to disable a specific hint

After enabling this plugin I started seeing a hint on lambda arguments

Screenshot 2022-11-17 at 17 09 29

Screenshot 2022-11-17 at 17 16 53

I find it quite noisy, especially in Compose, since it is added after every block of view content, and I would like to be able to disable it - ideally using the same mechanism I use with built-in tooltips - โŒฅ โŽ and "Disable Hint".

False positive "Useless resource element" ignoring fillAlpha

False positive "Useless resource element" ignoring fillAlpha

Sample code to reproduce:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="56dp"
    android:height="56dp"
    android:viewportWidth="56"
    android:viewportHeight="56">
    <path
        android:pathData="h56v56h-56v-56"
        android:fillColor="#ffffff"
        android:fillAlpha="0.16"/>
    <path
        android:pathData="h56v56h-56v-56"
        android:fillColor="#ffffff"
        android:fillAlpha="0.16"/>
</vector>

Second path is marked as "invisible" and suggested to be removed. But it's visible because of first path fillAlpha parameter, which seems to be ignored during this inspection.

Screenshot 2022-12-06 at 10 27 25

Request: add more inspections in layout XML for removing layout configurations that aren't needed

Examples:

layout_centerHorizontal="true", layout_centerInParent="true" - one of them isn't needed

layout_width="match_parent", layout_centerHorizontal="true" - no need to center if it's all size. This is a bit problematic because in code the size might change, so maybe have this disabled by default, or a weak warning, or something.

And of course any layout configuration that doesn't belong to the parent. such as layout_centerHorizontal for a child of LinearLayout and many more. These happen when copy-pasting and when converting from one layout to another without noticing them.

Bug: when ObjectAnimator is created outside of current code block, there are false-positive warnings of not starting it

V0.26
Example:


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val view = findViewById<View>(android.R.id.content)!!
        ObjectAnimatorEx.ofFloat(view, View.ALPHA, 1f).setDuration(500).start()
    }

    object ObjectAnimatorEx {
        @JvmStatic
        fun <T> ofFloat(target: T, property: Property<T, Float>, vararg values: Float): ObjectAnimator {
            return ObjectAnimator.ofFloat(target, property, *values)
        }
    }
}

image

My Application.zip

Android Studio Flamingo | 2022.2.1 Canary 4
Build #AI-222.4167.29.2221.9153536, built on October 8, 2022
Runtime version: 17.0.4.1+0-b2043.56-9127311 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 9048M
Cores: 12
Registry:
external.system.auto.import.disabled=true
debugger.watches.in.variables=false
ide.text.editor.with.preview.show.floating.toolbar=false
ide.images.show.chessboard=true

Non-Bundled Plugins:
idea.plugin.protoeditor (222.4167.21)
com.intellij.marketplace (222.4167.37)
com.dubreuia (2.3.0)
com.dethlex.numberconverter (1.5.0)
String Manipulation (9.5.1)
Show As ... (1.0.3)
GenerateSerializationHelpers (1.0.6)
GenerateSerialVersionUID (3.0.3)
com.google.mad-scorecard (1.2)
net.aquadc.mike.plugin (0.26)
izhangzhihao.rainbow.brackets (6.26)
com.ppismerov.ksvu (0.0.1)

Request: add inspection of strings, to warn about possible duplicates

For example if we have :

    <string name="choose_a_card">Choose a Card</string>
    <string name="choose_card">Choose a Card</string>

This also includes checking with modules, meaning that if in one module that the app uses there is the same string that is defined in the app's module (or on another module that the app is using).

This can help with translation services, to reduce the need to re-translate already translated strings.

It can also help with cases that in one module there is translation of some language to this string, and on another there isn't (or worse: it's different or a bad one, such as bad/missing placeholder).

Request: add inspection for replacing nullable/non-nullable parameter of functions, when it seems it's used as such

For example:

fun foo(someInt:Int?){
  val temp=someInt!!.toString()
  ...
}

This means that the parameter is actually supposed to be non-null, because it would cause a crash otherwise.
This also helps the IDE to detect bad usages from outside the function.

As for the opposite, not sure if it's needed (non-null parameter, which is treated as if it's nullable), but maybe for Java it's useful.

If this is too hard, I've also requested on IntelliJ:
https://youtrack.jetbrains.com/issue/IDEA-309644/Request-add-inspection-for-replacing-nullable-non-nullable-parameter-of-functions-when-it-seems-its-used-as-such

Bug: causes the IDE to always stay on "Analyzing" for many/all classes

After updating to this version of the IDE:

Android Studio Chipmunk | 2021.2.1
Build #AI-212.5712.43.2112.8512546, built on April 28, 2022

It seems that in a large project I work on, it keeps showing "Analyzing" for various classes, and never finishes.

I thought it's an issue on the IDE, so reported here:
https://issuetracker.google.com/issues/232107687

After trying to disable the current addon, it seems that the issue is gone, so this means it's something related to the addon.

I wish I could somehow filter the inspections of the addon (write "mike" for example), to see which one might be causing it, but sadly there is no such a thing.

Possible bug about `Replace '!!' with '?: return'` : incorrect and turned on forever

I don't know if this inspection is by this addon, but I got it recently.
If it's not, please close this and I will write it on the Android issue tracker or IntelliJ .

image

There are 2 bugs for this inspection:

  1. It's always used, even when it's turned off (and it's turned off by default).
  2. It doesn't make sense, and can ruin the flow of the code.

Example is right in the inspection:

val number: Int? = 42
fun foo() {
    val a = number!! // Replace '!!' with '?: return'
    println(1 + a)
}

If we have "!!", it means that at this point, we expect it to be non-null.
If we are wrong, we will have a crash that we should know about, and fix it.

Request: offer inspection for Kotlin, to avoid comment-block that ends with code in the same line

Many times, when I convert some Java code that has a comment-block and then some code beneath it (on a new line), I get them both in the same line.

For example, from this:

/* comment*/
foo();

I get this in Kotlin:

/* comment*/ foo()

Can you please add an inspection to fix this?
I'd prefer to use // instead BTW.
If this could be even another inspection (unless it's JavaDocs of course), could be nice.

Bug: false positive warning of "Appending nullable value to StringBuilder " being shown on something that has no null value

v0.28

For some reason, I can reproduce this only on a large project, but not on POC.

The code has something like that:

...
        val select =
            StringBuilder("${ActionLogColumns.COLUMN_NAME_IGNORE}=? AND ${ActionLogColumns.COLUMN_NAME_IS_PRIVATE_NUMBER}=?")
        select.append(" AND ${ActionLogColumns.COLUMN_NAME_CONTACTABLE_ROW_ID} IS NULL AND ${ActionLogColumns.COLUMN_NAME_PHONE_NUMBER} =?")
...


    object ActionLogColumns : BaseColumns {
        const val COLUMN_NAME_IGNORE = "ignore"
        const val COLUMN_NAME_IS_PRIVATE_NUMBER = "is_private_number"
        const val COLUMN_NAME_CONTACTABLE_ROW_ID = "contactable_row_id"
        const val COLUMN_NAME_PHONE_NUMBER = "phone_number"
    }
}

On the line that has "append", I get a warning even though nothing here is null (right in the editor, no need to perform code-analysis).
And, when I tried to create a new sample with these, I couldn't reproduce this.
It appears even after an OS restart.

image

Request: for Kotlin, offer to replace View.setVisibility to View.isVisible and similar cases

Meaning:

view.setVisibility = View.VISIBLE -> view.isVisible = true
view.setVisibility = View.GONE -> view.isVisible = false
view.setVisibility = View.INVISIBLE -> view.isInvisible = true

And also the getter:

if(view.visibility==View.VISIBLE) -> if(view.isVisible)
if(view.visibility==View.GONE) -> if(view.isGone)
if(view.visibility==View.INVISIBLE) -> if(view.isInvisible )

And the negated forms.

This is only to make code shorter and cleaner, of course. If you check its code, it does about the same...

Bug: false positive of "Use of reflective ObjectAnimator/PropertyValuesHolder" for GradientDrawable and customized classes too

V0.27

Examples:

final GradientDrawable gradientDrawable = ...;
final ObjectAnimator test = ObjectAnimator.ofInt(gradientDrawable, "color", fromColor, toColor);
final ObjectAnimator test2 =
                ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", fromCornerRadius, toCornerRadius);

It can also occur for a customized class:

public class StrokeGradientDrawable {

    public int getStrokeColor() {...}

    @Keep
    public void setStrokeColor(final int strokeColor) {...} 
}

Usage:

final ObjectAnimator strokeColorAnimation =
                ObjectAnimator.ofInt(drawable, "strokeColor", fromStrokeColor, toStrokeColor);

Request: for Kotlin, offer remove un-needed `?` and `!!` when you see `?)!!`

Often when I convert from Java to Kotlin, I see something like this:

foo((value as Boolean?)!!)

Instead, it should be like this:

foo(value as Boolean)

If foo is defined only as foo(Boolean) , it could even be replaced in this case to just:

foo(value)

Can you please add this ? I don't know of similar cases, but maybe there are some...

java.lang.NoSuchMethodError: 'java.util.List org.jetbrains.uast.UDeclaration.getAnnotations()'

IntelliJ IDEA 2021.2
Build #IU-212.4746.92, built on July 27, 2021

java.lang.NoSuchMethodError: 'java.util.List org.jetbrains.uast.UDeclaration.getAnnotations()'
	at net.aquadc.mike.plugin.android.TargetApiInspection$uVisitor$1.visitDeclaration(TargetApiInspection.kt:26)
	at org.jetbrains.uast.visitor.UastVisitor$DefaultImpls.visitVariable(UastVisitor.kt:15)
	at org.jetbrains.uast.visitor.AbstractUastNonRecursiveVisitor.visitVariable(UastVisitor.kt:128)
	at org.jetbrains.uast.visitor.UastVisitor$DefaultImpls.visitParameter(UastVisitor.kt:16)
	at org.jetbrains.uast.visitor.AbstractUastNonRecursiveVisitor.visitParameter(UastVisitor.kt:128)
	at org.jetbrains.uast.UParameter$DefaultImpls.accept(UVariable.kt:80)
	at org.jetbrains.uast.UParameterEx$DefaultImpls.accept(UVariable.kt)
	at org.jetbrains.uast.kotlin.KotlinUParameter.accept(KotlinUVariable.kt:177)
	at com.intellij.uast.UastVisitorAdapter.visitElement(UastVisitorAdapter.java:32)
	at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:63)
	at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:64)
	at com.intellij.codeInspection.InspectionEngine.createVisitorAndAcceptElements(InspectionEngine.java:55)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.runToolOnElements(LocalInspectionsPass.java:326)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$4(LocalInspectionsPass.java:285)
	at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:159)
	at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:151)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$5(LocalInspectionsPass.java:283)
	at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:130)
	at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:119)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitPriorityElementsAndInit$6(LocalInspectionsPass.java:283)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:136)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1078)
	at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:92)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
	at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:104)
	at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:83)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:174)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:183)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:83)
	at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

ktNoinlineFunc appears on valid (?) code

plugin version: 0.10
IDEA version: IntelliJ IDEA 2020.1 Beta (Build #IU-201.6668.13)
Kotlin version: 1.3.70

import org.gradle.api.Project
import org.gradle.api.artifacts.component.ModuleComponentIdentifier

internal fun getDependencies(project: Project): List<ModuleComponentIdentifier> {
	return project.configurations.asSequence().filter {
		it.isCanBeResolved && !it.name.endsWith("Metadata")
	}.map {
		it.resolvedConfiguration.resolvedArtifacts
	}.flatten().distinct().map {
		it.id.componentIdentifier
	}.filterIsInstance(ModuleComponentIdentifier::class.java).toList()
}

image

Request: add inspection of suggesting to add annotations of WorkerThread/UiThread/AnyThread based on usage

If in all calls of a function "foo", we call it from the UI-thread, it could suggest us to add the UiThread annotation.
Same for WorkerThread.
If it's mixed, suggest to add "AnyThread" annotation.

You can also add a setting of how far to suggest, because if a function is private, it's safer to use the quick-fix than when it's public.
That's especially important for the case of library-modules.

Bug: inspection to remove/merge margins/padding doesn't seem to work

v0.24

I'm talking about this inspection:
#16

Example for this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_marginLeft="12dp" android:layout_marginRight="12dp"
        android:text="Hello World!" />

</FrameLayout>

image

My Application.zip

How to improve the code to avoid "heavyweight property delegation" hint.

image

The following is the function definition:

inline fun <reified R : Any> arg(
    needLock: Boolean = false,
    noinline converter: (Any) -> R = getDefaultConverter()
) =
    PropertyDelegateProvider<ArgumentProvider, ReadOnlyProperty<ArgumentProvider, R?>> { _, _ ->
        ReadOnlyProperty { thisRef, property ->
            thisRef.getArgument(property.name, needLock, converter)
        }
    }

Request: offer intention of removing useless annotations of JvmStatic, JvmField, JvmOverloads...

If all the functions/classes in the entire project that use a function/field that's annotated with one of these are in Kotlin, such annotations can be removed.

There should also be a similar intention to be run on Android-library modules, because for these maybe the developer wishes to have them stay

Also requested here:
https://youtrack.jetbrains.com/issue/IDEA-297947/Request-offer-intention-of-removing-useless-annotations-of-JvmStatic-JvmField-JvmOverloads

Question: How do you use the "Reflective property animation " inspection?

v0.19

I've noticed an inspection of code similar to this (made it simple and shorter here) :

ObjectAnimator.ofInt(horizontalScrollView, "scrollX",123) 

And after using the inspection quick-fix, I got this weird code that can't be built:

ObjectAnimator.ofInt(horizontalScrollView, View.null, 123)

What is this "View.null" ? What is it supposed to be? How is it better?

Request: add inspections for things that look useless in VectorDrawable (stroke, fill)

Could be weak-level inspections by default, but probably useless in most cases to have these, for example:

  1. strokeWidth without strokeColor or with strokeColor that is completely transparent
  2. strokeColor that is completely transparent or without strokeWidth
  3. fillAlpha without fillColor
  4. fillColor that is completely transparent

Maybe other cases I didn't think of, because I'm not an expert at all about VectorDrawable.

The reason it might be weak-level inspection is that maybe in some cases it's intentional, when you want to animate/change things at runtime.
Sadly there isn't an official way to do it that I've found (found a request here: https://issuetracker.google.com/issues/172425450 ), but there are some old libraries that promise to do it:
https://github.com/devendroid/VectorChildFinder
https://github.com/harjot-oberai/VectorMaster

The reason I see these is conversion from SVG. Sometimes bad conversion, too.

Please let me know if I'm wrong here.

Request: offer to merge margins/padding when possible, into horizontal/vertical/all

Meaning in layout XML file, if there is android:layout_marginLeft="20dp" android:layout_marginRight="20dp" , offer android:layout_marginHorizontal="20dp".

Same goes for android:layout_marginStart="20dp" android:layout_marginEnd="20dp" to offer android:layout_marginHorizontal="20dp".

And of course for vertical ones, from android:layout_marginTop="20dp" android:layout_marginBottom="20dp" into android:layout_marginVertical="20dp" .

And the very rare case of all sides that are the same, from android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="20dp" android:layout_marginBottom="20dp" into just android:layout_margin="20dp" . And the same if used with start&end.

Of course, if there is a mix that contradicts the merging, don't offer it. For example android:layout_marginLeft="20dp" android:layout_marginStart="15dp" . However, if there is a mix that is identical (start&end&left&right with the same value, for example), offer to merge.

Same goes for padding.

If the mix is weird, I suggest to warn about it, as a different inspection.

Fix `Heavyweight property delegation` warning

i always add this snippet code to use datastore
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = BuildConfig.SETTINGS_PREF)
but this warning always appear

Heavyweight property delegation

how to fix it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.