本文整理汇总了Java中com.android.tools.lint.detector.api.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于com.android.tools.lint.detector.api包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterCheckProject
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Override
public void afterCheckProject(@NonNull Context context) {
// if it's not a library, it's an application
if (context.getProject() == context.getMainProject() && !context.getMainProject().isLibrary() && mApplicationTagLocation != null) {
if (!mHasActivity) {
context.report(ISSUE_MISSING_LAUNCHER, mApplicationTagLocation,
"Expecting " + ANDROID_MANIFEST_XML + " to have an <" + TAG_ACTIVITY + "> tag.");
} else if (!mHasLauncherActivity) {
context.report(ISSUE_MISSING_LAUNCHER, mApplicationTagLocation,
"Expecting " + ANDROID_MANIFEST_XML + " to have an activity with a launcher intent.");
}
}
}
示例2: reportMap
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
private void reportMap(Context context, Issue issue, Map<String, Location> map) {
if (map != null) {
for (Map.Entry<String, Location> entry : map.entrySet()) {
Location location = entry.getValue();
String name = entry.getKey();
String message = mDescriptions.get(name);
if (location == null) {
location = Location.create(context.getProject().getDir());
}
// We were prepending locations, but we want to prefer the base folders
location = Location.reverse(location);
context.report(issue, location, message);
}
}
}
示例3: checkBuildScripts
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
private void checkBuildScripts(Project project, Project main) {
List<Detector> detectors = mScopeDetectors.get(Scope.GRADLE_FILE);
if (detectors != null) {
List<File> files = project.getSubset();
if (files == null) {
files = project.getGradleBuildScripts();
}
for (File file : files) {
Context context = new Context(this, project, main, file);
fireEvent(EventType.SCANNING_FILE, context);
for (Detector detector : detectors) {
if (detector.appliesTo(context, file)) {
detector.beforeCheckFile(context);
detector.visitBuildScript(context, Maps.<String, Object>newHashMap());
detector.afterCheckFile(context);
}
}
}
}
}
示例4: refineLocation
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
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;
}
示例5: rtlApplies
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
private boolean rtlApplies(@NonNull Context context) {
Project project = context.getMainProject();
if (project.getTargetSdk() < RTL_API) {
return false;
}
int buildTarget = project.getBuildSdk();
if (buildTarget != -1 && buildTarget < RTL_API) {
return false;
}
//noinspection RedundantIfStatement
if (mEnabledRtlSupport != null && !mEnabledRtlSupport) {
return false;
}
return true;
}
示例6: run
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Override
public void run(@NonNull Context context) {
if (!context.getProject().getReportIssues()) {
// If this is a library project not being analyzed, ignore it
return;
}
File file = context.file;
if (isPrivateKeyFile(file)) {
String fileName = file.getParentFile().getName() + File.separator
+ file.getName();
String message = String.format(
"The `%1$s` file seems to be a private key file. " +
"Please make sure not to embed this in your APK file.", fileName);
context.report(ISSUE, Location.create(file), message);
}
}
示例7: beforeCheckFile
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
if (endsWith(context.file.getName(), DOT_XML)) {
// Drawable XML files should not be considered for overdraw, except for <bitmap>'s.
// The bitmap elements are handled in the scanBitmap() method; it will clear
// out anything added by this method.
File parent = context.file.getParentFile();
ResourceFolderType type = ResourceFolderType.getFolderType(parent.getName());
if (type == ResourceFolderType.DRAWABLE) {
if (mValidDrawables == null) {
mValidDrawables = new ArrayList<String>();
}
String resource = getDrawableResource(context.file);
mValidDrawables.add(resource);
}
}
}
示例8: scanActivity
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
private void scanActivity(Context context, Element element) {
String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
if (name.indexOf('$') != -1) {
name = name.replace('$', '.');
}
if (name.startsWith(".")) { //$NON-NLS-1$
String pkg = context.getProject().getPackage();
if (pkg != null && !pkg.isEmpty()) {
name = pkg + name;
}
}
if (mActivities == null) {
mActivities = new HashSet<String>();
}
mActivities.add(name);
String theme = element.getAttributeNS(ANDROID_URI, ATTR_THEME);
if (theme != null && !theme.isEmpty()) {
if (mActivityToTheme == null) {
mActivityToTheme = new HashMap<String, String>();
}
mActivityToTheme.put(name, getResourceFieldName(theme));
}
}
示例9: afterCheckFile
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Override
public void afterCheckFile(@NonNull Context context) {
if (context.getPhase() == 1) {
// Store this layout's set of ids for full project analysis in afterCheckProject
if (context.getProject().getReportIssues() && mNames != null && !mNames.isEmpty()) {
mFileToNames.put(context.file, mNames);
Element root = ((XmlContext) context).document.getDocumentElement();
if (root != null) {
String locale = root.getAttributeNS(TOOLS_URI, ATTR_LOCALE);
if (locale != null && !locale.isEmpty()) {
if (mFileToLocale == null) {
mFileToLocale = Maps.newHashMap();
}
mFileToLocale.put(context.file, locale);
}
// Add in English here if not specified? Worry about false positives listing "en" explicitly
}
}
mNames = null;
}
}
示例10: getIdToTagsIn
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@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;
}
示例11: resolveCoordinate
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Nullable
private static GradleCoordinate resolveCoordinate(@NonNull Context context,
@NonNull GradleCoordinate gc) {
assert gc.getFullRevision().contains("$") : gc.getFullRevision();
Variant variant = context.getProject().getCurrentVariant();
if (variant != null) {
Dependencies dependencies = variant.getMainArtifact().getDependencies();
for (AndroidLibrary library : dependencies.getLibraries()) {
MavenCoordinates mc = library.getResolvedCoordinates();
if (mc != null
&& mc.getGroupId().equals(gc.getGroupId())
&& mc.getArtifactId().equals(gc.getArtifactId())) {
List<RevisionComponent> revisions =
GradleCoordinate.parseRevisionNumber(mc.getVersion());
if (!revisions.isEmpty()) {
return new GradleCoordinate(mc.getGroupId(), mc.getArtifactId(),
revisions, null);
}
break;
}
}
}
return null;
}
示例12: checkMethodCall
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
protected void checkMethodCall(
@NonNull Context context,
@NonNull String statement,
@Nullable String parent,
@NonNull Map<String, String> namedArguments,
@SuppressWarnings("UnusedParameters")
@NonNull List<String> unnamedArguments,
@NonNull Object cookie) {
String plugin = namedArguments.get("plugin");
if (statement.equals("apply") && parent == null) {
boolean isOldAppPlugin = OLD_APP_PLUGIN_ID.equals(plugin);
if (isOldAppPlugin || OLD_LIB_PLUGIN_ID.equals(plugin)) {
String replaceWith = isOldAppPlugin ? APP_PLUGIN_ID : LIB_PLUGIN_ID;
String message = String.format("'%1$s' is deprecated; use '%2$s' instead", plugin,
replaceWith);
report(context, cookie, DEPRECATED, message);
}
}
}
示例13: getLibraryName
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
/** Pick a suitable name to describe the library defining the private resource */
@Nullable
private static String getLibraryName(@NonNull Context context, @NonNull ResourceType type,
@NonNull String name) {
ResourceVisibilityLookup lookup = context.getProject().getResourceVisibility();
AndroidLibrary library = lookup.getPrivateIn(type, name);
if (library != null) {
String libraryName = library.getProject();
if (libraryName != null) {
return libraryName;
}
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates != null) {
return coordinates.getGroupId() + ':' + coordinates.getArtifactId();
}
}
return "the library";
}
示例14: beforeCheckFile
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
if (mPrefix != null && context instanceof XmlContext) {
XmlContext xmlContext = (XmlContext) context;
ResourceFolderType folderType = xmlContext.getResourceFolderType();
if (folderType != null && folderType != ResourceFolderType.VALUES) {
String name = LintUtils.getBaseName(context.file.getName());
if (!name.startsWith(mPrefix)) {
// Attempt to report the error on the root tag of the associated
// document to make suppressing the error with a tools:suppress
// attribute etc possible
if (xmlContext.document != null) {
Element root = xmlContext.document.getDocumentElement();
if (root != null) {
xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
getErrorMessage(name));
return;
}
}
context.report(ISSUE, Location.create(context.file),
getErrorMessage(name));
}
}
}
}
示例15: reportErrors
import com.android.tools.lint.detector.api.Context; //导入依赖的package包/类
private void reportErrors(Context context) {
List<String> layouts = new ArrayList<String>(mLocations.keySet());
Collections.sort(layouts);
for (String layout : layouts) {
Map<String, List<Location>> locationMap = mLocations.get(layout);
Map<String, String> messageMap = mErrorMessages.get(layout);
assert locationMap != null;
assert messageMap != null;
List<String> ids = new ArrayList<String>(locationMap.keySet());
Collections.sort(ids);
for (String id : ids) {
String message = messageMap.get(id);
List<Location> locations = locationMap.get(id);
if (locations != null) {
Location location = chainLocations(locations);
context.report(INCONSISTENT_IDS, location, message);
}
}
}
}