本文整理汇总了Java中com.android.tools.lint.detector.api.JavaContext.findSurroundingClass方法的典型用法代码示例。如果您正苦于以下问题:Java JavaContext.findSurroundingClass方法的具体用法?Java JavaContext.findSurroundingClass怎么用?Java JavaContext.findSurroundingClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.detector.api.JavaContext
的用法示例。
在下文中一共展示了JavaContext.findSurroundingClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAppBarActivityCall
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
private static boolean isAppBarActivityCall(@NonNull JavaContext context,
@NonNull MethodInvocation node) {
ResolvedNode resolved = context.resolve(node);
if (resolved instanceof ResolvedMethod) {
ResolvedMethod method = (ResolvedMethod) resolved;
ResolvedClass containingClass = method.getContainingClass();
if (containingClass.isSubclassOf(CLASS_ACTIVITY, false)) {
// Make sure that the calling context is a subclass of ActionBarActivity;
// we don't want to flag these calls if they are in non-appcompat activities
// such as PreferenceActivity (see b.android.com/58512)
ClassDeclaration surroundingClass = JavaContext.findSurroundingClass(node);
if (surroundingClass != null) {
ResolvedNode clz = context.resolve(surroundingClass);
return clz instanceof ResolvedClass &&
((ResolvedClass)clz).isSubclassOf(
"android.support.v7.app.ActionBarActivity",
false);
}
}
}
return false;
}
示例2: parseContainingClass
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
public static JavaParser.ResolvedClass parseContainingClass(
@NonNull JavaContext context, @NonNull Node node) {
if (null == context || null == node) {
return null;
}
JavaParser.ResolvedNode resolvedNode = null;
try {
resolvedNode = context.resolve(node);
} catch (Exception e) {
// TODO
}
if (resolvedNode instanceof JavaParser.ResolvedMethod) {
return ((JavaParser.ResolvedMethod)resolvedNode).getContainingClass();
} else if (resolvedNode instanceof JavaParser.ResolvedField) {
return ((JavaParser.ResolvedField)resolvedNode).getContainingClass();
} else if (resolvedNode instanceof JavaParser.ResolvedClass) {
return ((JavaParser.ResolvedClass)resolvedNode).getContainingClass();
} else {
ClassDeclaration classDeclaration = JavaContext.findSurroundingClass(node);
if (null == classDeclaration) {
return null;
}
resolvedNode = context.resolve(classDeclaration);
return (resolvedNode instanceof JavaParser.ResolvedClass) ?
(JavaParser.ResolvedClass)resolvedNode : null;
}
}
示例3: getTargetApi
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
private static int getTargetApi(ClassDeclaration node) {
while (node != null) {
int targetApi = ApiDetector.getTargetApi(node.astModifiers());
if (targetApi != -1) {
return targetApi;
}
node = JavaContext.findSurroundingClass(node.getParent());
}
return -1;
}