@NonNull @Override protected String readText(@NonNull File file) { if (context != null) { return context.getClient().readFile(file).toString(); } try { return Files.toString(file, UTF_8); } catch (IOException e) { return ""; // Lint API } }
@Override public void beforeCheckProject(@NonNull Context context) { mApiDatabase = ApiLookup.get(context.getClient()); }
@Override public void beforeCheckProject(@NonNull Context context) { mApiDatabase = ApiLookup.get(context.getClient()); }
@Override public void beforeCheckFile(@NonNull Context context) { initLocale(context.file.getParentFile().getName()); if (mLanguage == null) { // Check to see if the user has specified the language for this folder // using a tools:locale attribute if (context instanceof XmlContext) { Element root = ((XmlContext) context).document.getDocumentElement(); if (root != null) { String locale = root.getAttributeNS(TOOLS_URI, ATTR_LOCALE); if (locale != null && !locale.isEmpty()) { initLocale(FD_RES_VALUES + '-' + locale); } } } if (mLanguage == null) { mLanguage = "en"; } } if (!equal(mLastLanguage, mLanguage) || !equal(mLastRegion, mRegion)) { mLookup = TypoLookup.get(context.getClient(), mLanguage, mRegion); mLastLanguage = mLanguage; mLastRegion = mRegion; } }
@Override public void beforeCheckFile(@NonNull Context context) { initLocale(context.file.getParentFile().getName()); if (mLanguage == null) { // Check to see if the user has specified the language for this folder // using a tools:locale attribute if (context instanceof XmlContext) { Element root = ((XmlContext) context).document.getDocumentElement(); if (root != null) { String locale = root.getAttributeNS(TOOLS_URI, ATTR_LOCALE); if (locale != null && !locale.isEmpty()) { initLocale(FD_RES_VALUES + '-' + locale); } } } if (mLanguage == null) { mLanguage = "en"; //$NON-NLS-1$ } } if (!equal(mLastLanguage, mLanguage) || !equal(mLastRegion, mRegion)) { mLookup = TypoLookup.get(context.getClient(), mLanguage, mRegion); mLastLanguage = mLanguage; mLastRegion = mRegion; } }
@Nullable private Multimap<String, String> getIdToTagsIn(@NonNull Context context, @NonNull File file) { if (!file.getPath().endsWith(DOT_XML)) { return null; } if (mFileIdMap == null) { mFileIdMap = Maps.newHashMap(); } Multimap<String, String> map = mFileIdMap.get(file); if (map == null) { map = ArrayListMultimap.create(); mFileIdMap.put(file, map); String xml = context.getClient().readFile(file); // TODO: Use pull parser instead for better performance! Document document = XmlUtils.parseDocumentSilently(xml, true); if (document != null && document.getDocumentElement() != null) { addViewTags(map, document.getDocumentElement()); } } return map; }
@Nullable private Multimap<String, String> getIdToTagsIn(@NonNull Context context, @NonNull File file) { if (!file.getPath().endsWith(DOT_XML)) { return null; } if (mFileIdMap == null) { mFileIdMap = Maps.newHashMap(); } Multimap<String, String> map = mFileIdMap.get(file); if (map == null) { map = ArrayListMultimap.create(); mFileIdMap.put(file, map); CharSequence xml = context.getClient().readFile(file); // TODO: Use pull parser instead for better performance! // See LayoutInflationDetector#hasLayoutParams for an example Document document = CharSequences.parseDocumentSilently(xml, true); if (document != null && document.getDocumentElement() != null) { addViewTags(map, document.getDocumentElement()); } } return map; }
LintClient client = context.getClient(); try { URL url = new URL(query);
@Override public void beforeCheckProject(@NonNull Context context) { mApiDatabase = ApiLookup.get(context.getClient()); // We can't look up the minimum API required by the project here: // The manifest file hasn't been processed yet in the -before- project hook. // For now it's initialized lazily in getMinSdk(Context), but the // lint infrastructure should be fixed to parse manifest file up front. if (mApiDatabase == null && !mWarnedMissingDb) { mWarnedMissingDb = true; context.report(IssueRegistry.LINT_ERROR, Location.create(context.file), "Can't find API database; API check not performed"); } }
return; String properties = context.getClient().readFile(propertyFile); int i = properties.indexOf(PROGUARD_CONFIG); if (i == -1) {
private boolean idDefined(@NonNull Context context, @NonNull String id, @Nullable File notIn) { AbstractResourceRepository resources = context.getClient().getResourceRepository(context.getProject(), true, true); if (resources != null) { List<ResourceItem> items = resources.getResourceItem(ResourceType.ID,
private boolean idDefined(@NonNull Context context, @NonNull String id, @Nullable File notIn) { AbstractResourceRepository resources = context.getClient().getProjectResources(context.getProject(), true); if (resources != null) { List<ResourceItem> items = resources.getResourceItem(ResourceType.ID,
private static Location refineLocation(Context context, Location location, String formatString, int substringStart, int substringEnd) { Position startLocation = location.getStart(); Position endLocation = location.getEnd(); if (startLocation != null && endLocation != null) { int startOffset = startLocation.getOffset(); int endOffset = endLocation.getOffset(); if (startOffset >= 0) { String contents = context.getClient().readFile(location.getFile()); if (endOffset <= contents.length() && startOffset < endOffset) { int formatOffset = contents.indexOf(formatString, startOffset); if (formatOffset != -1 && formatOffset <= endOffset) { return Location.create(location.getFile(), contents, formatOffset + substringStart, formatOffset + substringEnd); } } } } return location; }
private void checkPlayServices(Context context, GradleCoordinate dependency, Object cookie) { String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); assert groupId != null && artifactId != null; File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.GOOGLE.getRepositoryLocation(sdkHome, true); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on Play Services, but the SDK installation does not " + "have the \"Extras > Google Repository\" installed. " + "Open the SDK manager and install it."); } else { checkLocalMavenVersions(context, dependency, cookie, groupId, artifactId, repository); } }
return; CharSequence properties = context.getClient().readFile(propertyFile); int i = indexOf(properties, PROGUARD_CONFIG); if (i == -1) {
private static Location refineLocation(Context context, Location location, String formatString, int substringStart, int substringEnd) { Position startLocation = location.getStart(); Position endLocation = location.getEnd(); if (startLocation != null && endLocation != null) { int startOffset = startLocation.getOffset(); int endOffset = endLocation.getOffset(); if (startOffset >= 0) { CharSequence contents = context.getClient().readFile(location.getFile()); if (endOffset <= contents.length() && startOffset < endOffset) { int formatOffset = indexOf(contents, formatString, startOffset); if (formatOffset != -1 && formatOffset <= endOffset) { return Location.create(location.getFile(), contents, formatOffset + substringStart, formatOffset + substringEnd); } } } } return location; }
assert groupId != null && artifactId != null; File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.GOOGLE.getRepositoryLocation(sdkHome, true, FileOpUtils.create());
return NONE; JavaParser javaParser = context.getClient().getJavaParser(null); if (javaParser == null) { return NONE;
private void checkSupportLibraries(Context context, GradleCoordinate dependency, Object cookie) { String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); assert groupId != null && artifactId != null; // See if the support library version is lower than the targetSdkVersion if (mTargetSdkVersion > 0 && dependency.getMajorVersion() < mTargetSdkVersion && dependency.getMajorVersion() != GradleCoordinate.PLUS_REV_VALUE && // The multidex library doesn't follow normal supportlib numbering scheme !dependency.getArtifactId().startsWith("multidex") && context.isEnabled(COMPATIBILITY)) { String message = "This support library should not use a lower version (" + dependency.getMajorVersion() + ") than the `targetSdkVersion` (" + mTargetSdkVersion + ")"; report(context, cookie, COMPATIBILITY, message); } // Check to make sure you have the Android support repository installed File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.ANDROID.getRepositoryLocation(sdkHome, true); if (repository == null) { report(context, cookie, DEPENDENCY, "Dependency on a support library, but the SDK installation does not " + "have the \"Extras > Android Support Repository\" installed. " + "Open the SDK manager and install it."); } else { checkLocalMavenVersions(context, dependency, cookie, groupId, artifactId, repository); } }
File sdkHome = context.getClient().getSdkHome(); File repository = SdkMavenRepository.ANDROID.getRepositoryLocation(sdkHome, true, FileOpUtils.create());