Search in sources :

Example 1 with SourceProviderContainer

use of com.android.builder.model.SourceProviderContainer in project kotlin by JetBrains.

the class RegistrationDetector method reportMissing.

private static void reportMissing(@NonNull JavaContext context, @NonNull PsiClass node, @NonNull String className, @NonNull String tag) {
    if (tag.equals(TAG_RECEIVER)) {
        // Receivers can be registered in code; don't flag these.
        return;
    }
    // Don't flag activities registered in test source sets
    if (context.getProject().isGradleProject()) {
        AndroidProject model = context.getProject().getGradleProjectModel();
        if (model != null) {
            String javaSource = context.file.getPath();
            for (SourceProviderContainer extra : model.getDefaultConfig().getExtraSourceProviders()) {
                String artifactName = extra.getArtifactName();
                if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
                    for (File file : extra.getSourceProvider().getJavaDirectories()) {
                        if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
                            return;
                        }
                    }
                }
            }
            for (ProductFlavorContainer container : model.getProductFlavors()) {
                for (SourceProviderContainer extra : container.getExtraSourceProviders()) {
                    String artifactName = extra.getArtifactName();
                    if (AndroidProject.ARTIFACT_ANDROID_TEST.equals(artifactName)) {
                        for (File file : extra.getSourceProvider().getJavaDirectories()) {
                            if (SdkUtils.startsWithIgnoreCase(javaSource, file.getPath())) {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    Location location = context.getNameLocation(node);
    String message = String.format("The `<%1$s> %2$s` is not registered in the manifest", tag, className);
    context.report(ISSUE, node, location, message);
}
Also used : ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) AndroidProject(com.android.builder.model.AndroidProject) SourceProviderContainer(com.android.builder.model.SourceProviderContainer) File(java.io.File) Location(com.android.tools.klint.detector.api.Location)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)1 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)1 SourceProviderContainer (com.android.builder.model.SourceProviderContainer)1 Location (com.android.tools.klint.detector.api.Location)1 File (java.io.File)1