本文整理汇总了Java中com.android.tools.lint.detector.api.Location类的典型用法代码示例。如果您正苦于以下问题:Java Location类的具体用法?Java Location怎么用?Java Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Location类属于com.android.tools.lint.detector.api包,在下文中一共展示了Location类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAttribute
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void visitAttribute(XmlContext context, Attr attribute) {
super.visitAttribute(context, attribute);
String value = attribute.getValue();
if (Utils.stringIsEmpty(value)) return;
//onClick 属性被赋值
Element element = attribute.getOwnerElement();
boolean has = element.hasAttributeNS(SdkConstants.ANDROID_URI, SdkConstants.ATTR_ID);
if (!has) {
Location location = context.getLocation(attribute);
context.report(ISSUE_MISSING_ID, location, "the view with onClick attribute set should has id attribute");
}
}
示例2: reportSeparateByIsolatedGroup
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportSeparateByIsolatedGroup(@NonNull WriteFieldGroupMethod method, @NonNull List<WriteFieldGroupMethod> groupMethods) {
// ISSUE レポート
String contents = mContext.getJavaFile().getText();
int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
String groups = getSharedMethodNames(groupMethods);
String fieldNames = getWriteFieldNames(method);
String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全共有かつクラス唯一です。\n"
+ "これはメソッドの責務(役割)が共有されている、責務合体したクラスであることを示すので、\n"
+ "他のメソッド " + groups + " と共に、"
+ "メソッドの利用先が適切であるかを確認して、変更するフイールド変数(状態)の分割をおすすめします。\n"
+ fieldNames;
Location location = createLocation(mContext.file, contents, startOffset, endOffset);
mContext.report(SEPARATE_BY_ISOLATED_GROUP_ISSUE, location, message);
Debug.report("SeparateByIsolateGroup", method);
}
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:18,代码来源:SharingGroupClassificationDetector.java
示例3: reportSeparateByGroup
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportSeparateByGroup(@NonNull WriteFieldGroupMethod method, @NonNull List<WriteFieldGroupMethod> groupMethods) {
// ISSUE レポート
String contents = mContext.getJavaFile().getText();
int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
String groups = getSharedMethodNames(groupMethods);
String fieldNames = getWriteFieldNames(method);
String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全共有ですがクラス唯一でありません。\n"
+ "これはメソッドの責務(役割)が共有されていますが、責務混在したクラスであることを示すので、\n"
+ "他のメソッド " + groups + " と、"
+ "メソッドが変更するフィールド変数(状態)ごと新クラスへの分離をおすすめします。\n"
+ fieldNames;
Location location = createLocation(mContext.file, contents, startOffset, endOffset);
mContext.report(SEPARATE_BY_GROUP_ISSUE, location, message);
Debug.report("SeparateByGroup", method);
}
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:18,代码来源:SharingGroupClassificationDetector.java
示例4: reportTrySeparateByRole
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportTrySeparateByRole(@NonNull WriteFieldGroupMethod method) {
// ISSUE レポート
String contents = mContext.getJavaFile().getText();
int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
String fieldNames = getWriteFieldNames(method);
String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全独立でも完全共有でもありません。\n"
+ "このメソッドが変更するフィールド変数(状態)は、他のメソッドとの間で共有の一部に過不足があります。\n"
+ "これはメソッドの責務(役割)が明確に区別されておらず、責務(役割)が混在していることを示すので、\n"
+ "先ずはメソッドや変更フィールド変数(状態)の分割や統合をおすすめします。\n"
+ fieldNames;
Location location = createLocation(mContext.file, contents, startOffset, endOffset);
mContext.report(TRY_SEPARATE_BY_ROLE_ISSUE, location, message);
Debug.report("TrySeparateByRole", method);
}
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:17,代码来源:SharingGroupClassificationDetector.java
示例5: visitAnnotation
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public boolean visitAnnotation(Annotation node) {
String type = node.astAnnotationTypeReference().getTypeName();
if (DAGGER_MODULE.equals(type)) {
Node parent = node.getParent();
if (parent instanceof Modifiers) {
parent = parent.getParent();
if (parent instanceof ClassDeclaration) {
int flags = ((ClassDeclaration) parent).astModifiers().getEffectiveModifierFlags();
if ((flags & Modifier.ABSTRACT) == 0) {
context.report(ISSUE, Location.create(context.file), ISSUE.getBriefDescription(TextFormat.TEXT));
}
}
}
}
return super.visitAnnotation(node);
}
示例6: checkExtendsClass
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void checkExtendsClass(ClassContext context, ClassNode classNode, int classMinSdk,
String signature) {
int api = mApiDatabase.getClassVersion(signature);
if (api > classMinSdk) {
String fqcn = ClassContext.getFqcn(signature);
String message = String.format(
"Class requires API level %1$d (current min is %2$d): `%3$s`",
api, classMinSdk, fqcn);
String name = signature.substring(signature.lastIndexOf('/') + 1);
name = name.substring(name.lastIndexOf('$') + 1);
SearchHints hints = SearchHints.create(BACKWARD).matchJavaSymbol();
int lineNumber = ClassContext.findLineNumber(classNode);
Location location = context.getLocationForLine(lineNumber, name, null,
hints);
context.report(UNSUPPORTED, location, message);
}
}
示例7: resolve
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@NonNull
@Override
public Location resolve() {
if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
return ApplicationManager.getApplication().runReadAction(new Computable<Location>() {
@Override
public Location compute() {
return resolve();
}
});
}
TextRange textRange = DomPsiConverter.getTextRange(myNode);
Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
return Location.create(myFile, start, end);
}
示例8: visitSelect
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public boolean visitSelect(Select node) {
String description = node.astIdentifier().astValue();
boolean isIfRoom = description.equals("SHOW_AS_ACTION_IF_ROOM"); //$NON-NLS-1$
boolean isAlways = description.equals("SHOW_AS_ACTION_ALWAYS"); //$NON-NLS-1$
if ((isIfRoom || isAlways)
&& node.astOperand().toString().equals("MenuItem")) { //$NON-NLS-1$
if (isAlways) {
if (mContext.getDriver().isSuppressed(mContext, ISSUE, node)) {
return super.visitSelect(node);
}
if (mAlwaysFields == null) {
mAlwaysFields = new ArrayList<Location>();
}
mAlwaysFields.add(mContext.getLocation(node));
} else {
mHasIfRoomRefs = true;
}
}
return super.visitSelect(node);
}
示例9: beforeCheckFile
import com.android.tools.lint.detector.api.Location; //导入依赖的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));
}
}
}
}
示例10: visitDocument
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void visitDocument(@NonNull XmlContext context, @NonNull Document document) {
Element root = document.getDocumentElement();
if (root != null) {
if (context.getPhase() == 1) {
// Map from ids to types
Map<String,String> fileMap = Maps.newHashMapWithExpectedSize(10);
addIds(root, fileMap);
getFileMapList(context).add(Pair.of(context.file, fileMap));
} else {
String name = LintUtils.getLayoutName(context.file);
Map<String, List<Location>> map = mLocations.get(name);
if (map != null) {
lookupLocations(context, root, map);
}
}
}
}
示例11: checkLauncherShape
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
/**
* Check that launcher icons do not fill every pixel in the image
*/
private void checkLauncherShape(Context context, File file) {
try {
BufferedImage image = getImage(file);
if (image != null) {
// TODO: see if the shape is rectangular but inset from outer rectangle; if so
// that's probably not right either!
for (int y = 0, height = image.getHeight(); y < height; y++) {
for (int x = 0, width = image.getWidth(); x < width; x++) {
int rgb = image.getRGB(x, y);
if ((rgb & 0xFF000000) == 0) {
return;
}
}
}
String message = "Launcher icons should not fill every pixel of their square " +
"region; see the design guide for details";
context.report(ICON_LAUNCHER_SHAPE, Location.create(file),
message);
}
} catch (IOException e) {
// Pass: ignore files we can't read
}
}
示例12: checkInnerClass
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private static void checkInnerClass(XmlContext context, Element element, String pkg,
Node classNameNode, String className) {
if (pkg != null && className.indexOf('$') == -1 && className.indexOf('.', 1) > 0) {
boolean haveUpperCase = false;
for (int i = 0, n = pkg.length(); i < n; i++) {
if (Character.isUpperCase(pkg.charAt(i))) {
haveUpperCase = true;
break;
}
}
if (!haveUpperCase) {
String fixed = className.charAt(0) + className.substring(1).replace('.','$');
String message = "Use '$' instead of '.' for inner classes " +
"(or use only lowercase letters in package names); replace \"" +
className + "\" with \"" + fixed + "\"";
Location location = context.getLocation(classNameNode);
context.report(INNERCLASS, element, location, message);
}
}
}
示例13: visitElement
import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
Node parentNode = element.getParentNode();
if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parent = (Element)parentNode;
Attr width = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_WIDTH);
Attr height = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_HEIGHT);
Attr attr = null;
if (width != null && VALUE_WRAP_CONTENT.equals(width.getValue())) {
attr = width;
}
if (height != null && VALUE_WRAP_CONTENT.equals(height.getValue())) {
attr = height;
}
if (attr != null) {
String message = String.format("Placing a `<WebView>` in a parent element that "
+ "uses a `wrap_content %1$s` can lead to subtle bugs; use `match_parent` "
+ "instead", attr.getLocalName());
Location location = context.getLocation(element);
Location secondary = context.getLocation(attr);
secondary.setMessage("`wrap_content` here may not work well with WebView below");
location.setSecondary(secondary);
context.report(ISSUE, element, location, message);
}
}
}
示例14: reportMap
import com.android.tools.lint.detector.api.Location; //导入依赖的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);
}
}
}
示例15: run
import com.android.tools.lint.detector.api.Location; //导入依赖的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);
}
}