Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Nosakhare Belvi KingsMentor

🎯
Focusing
Block or report user

Report or block KingsMentor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AbstractDetectorTest.java
public abstract class AbstractDetectorTest extends LintDetectorTest {
protected static final String PATH_TEST_RESOURCES = "/lint/src/test/resources/";
protected static final String NO_WARNINGS = "No warnings.";
protected abstract String getTestResourceDirectory();
@Override
protected InputStream getTestResource(String relativePath, boolean expectExists) {
String path = (PATH_TEST_RESOURCES + getTestResourceDirectory() + File.separatorChar + relativePath).replace('/', File.separatorChar);
View lint_gradle_snippet.gradle
jar {
baseName 'ai.helfie.lintrules'
version '1.0'
manifest {
attributes 'Manifest-Version': 1.0
attributes('Lint-Registry': 'ai.helfie.lintrules.CustomIssueRegistry')
}
}
View lintRegistery.java
import com.android.tools.lint.client.api.IssueRegistry;
import com.android.tools.lint.detector.api.Issue;
import java.util.Arrays;
import java.util.List;
import static ai.helfie.lintrules.Issues.ISSUE;
public class CustomIssueRegistry extends IssueRegistry {
View AsyncTaskDetector.java
package ai.helfie.lintrules;
import android.support.annotation.NonNull;
import com.android.resources.ResourceFolderType;
import com.android.tools.lint.detector.api.*;
import lombok.ast.*;
import java.io.File;
import java.util.Arrays;
import java.util.EnumSet;
View lintscope.java
/** All scopes: running lint on a project will check these scopes */
public static final EnumSet<Scope> ALL = EnumSet.allOf(Scope.class);
/** Scope-set used for detectors which are affected by a single resource file */
public static final EnumSet<Scope> RESOURCE_FILE_SCOPE = EnumSet.of(RESOURCE_FILE);
/** Scope-set used for detectors which are affected by a single resource folder */
public static final EnumSet<Scope> RESOURCE_FOLDER_SCOPE = EnumSet.of(RESOURCE_FOLDER);
/** Scope-set used for detectors which scan all resources */
public static final EnumSet<Scope> ALL_RESOURCES_SCOPE = EnumSet.of(ALL_RESOURCE_FILES);
/** Scope-set used for detectors which are affected by a single Java source file */
public static final EnumSet<Scope> JAVA_FILE_SCOPE = EnumSet.of(JAVA_FILE);
View annotations.csv
Annotion Type Example Usage
Nullness @Nullable and @NonNull,check for nullness of a given variable parametar or return value.
Thread @MainThread,@UiThread,@WorkerThread,@BinderThread,@AnyThread Thread annotations check if a method is called from a specific type of thread.
Value constraint @IntRange, @FloatRange, and @Size to validate the values of passed parameters
Permission @to validate the permissions of the caller of a method to validate the permissions of the caller of a method
Return value @CheckResult to validate that a method's result or return value is actually used
CallSuper @CallSuper to validate that an overriding method calls the super implementation of the method
Typedef @IntDef and @StringDef ensure that a particular parameter, return value, or field references a specific set of constants
Keep @Keep ensures that an annotated class or method is not removed when the code is minified at build time
Code visibility @VisibleForTesting indicates that an annotated method is more visible th
View activity_main.xml
<LinearLayout 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"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.android.sunshine.app.MainActivity">
<!--
You can’t perform that action at this time.