本文整理汇总了Java中com.android.tools.lint.client.api.JavaParser.ResolvedAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java JavaParser.ResolvedAnnotation方法的具体用法?Java JavaParser.ResolvedAnnotation怎么用?Java JavaParser.ResolvedAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.client.api.JavaParser
的用法示例。
在下文中一共展示了JavaParser.ResolvedAnnotation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isThisMethodHasLayoutAnnotation_ForActivity
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* As there are more than one methods overload "setContentView",
* we have to identify the one we want to check, whose param has an Annotation of "@LayoutRes".
* In fact, {public void setContentView(@LayoutRes int layoutResID)} is the one we are looking for.
*/
private boolean isThisMethodHasLayoutAnnotation_ForActivity(@NonNull JavaContext context, @NonNull MethodInvocation node) {
JavaParser.ResolvedNode resolved = context.resolve(node);
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
if (node.astArguments().size() != 1) {
return false;
}
Iterable<JavaParser.ResolvedAnnotation> annotations = method.getParameterAnnotations(0);
for (JavaParser.ResolvedAnnotation annotation : annotations) {
if ("android.support.annotation.LayoutRes".equals(annotation.getName())) {
return true;
}
}
return false;
}
示例2: getParamWithLayoutAnnotation_ForFragment
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* There are more than one methods overloading in the name of "inflate()" in android.view.LayoutInflater.<br>
* We only care about those having an param with `@LayoutRes` annotation,
* for example {public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)}.<br>
* This method will find out the resource param with an `@LayoutRes` annotation in String format, for example `R.layout.fragment_blank` .<br>
* If no such param exists, <B>null</B> will be returned.
*/
private String getParamWithLayoutAnnotation_ForFragment(@NonNull JavaContext context, @NonNull MethodInvocation node) {
Iterator<Expression> arguments = node.astArguments().iterator();
Expression argument = arguments.next();
JavaParser.ResolvedNode resolved = context.resolve(node);
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedAnnotation layoutParamAnnotation = method.getParameterAnnotation("android.support.annotation.LayoutRes", 0);
if (layoutParamAnnotation != null) {
return argument.toString();
} else {
return null;
}
}
示例3: getParamWithLayoutAnnotation
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* There are more than one methods overloading in the name of "inflate()" in android.view.LayoutInflater.<br>
* We only care about those having an param with `@LayoutRes` annotation,
* for example {public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)}.<br>
* This method will find out the resource param with an `@LayoutRes` annotation in String format, for example `R.layout.fragment_blank` .<br>
* If no such param exists, <B>null</B> will be returned.
*/
private String getParamWithLayoutAnnotation(@NonNull JavaContext context, @NonNull MethodInvocation node) {
Iterator<Expression> arguments = node.astArguments().iterator();
Expression argument = arguments.next();
JavaParser.ResolvedNode resolved = context.resolve(node);
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolved;
JavaParser.ResolvedAnnotation layoutParamAnnotation = method.getParameterAnnotation("android.support.annotation.LayoutRes", 0);
if (layoutParamAnnotation != null) {
return argument.toString();
} else {
return null;
}
}
示例4: getRequiredSuperMethod
import com.android.tools.lint.client.api.JavaParser; //导入方法依赖的package包/类
/**
* Checks whether the given method overrides a method which requires the super method
* to be invoked, and if so, returns it (otherwise returns null)
*/
@Nullable
private static ResolvedMethod getRequiredSuperMethod(
@NonNull ResolvedMethod method) {
String name = method.getName();
if (ON_DETACHED_FROM_WINDOW.equals(name)) {
// No longer annotated on the framework method since it's
// now handled via onDetachedFromWindowInternal, but overriding
// is still dangerous if supporting older versions so flag
// this for now (should make annotation carry metadata like
// compileSdkVersion >= N).
if (!method.getContainingClass().isSubclassOf(CLASS_VIEW, false)) {
return null;
}
return method.getSuperMethod();
} else if (ON_VISIBILITY_CHANGED.equals(name)) {
// From Android Wear API; doesn't yet have an annotation
// but we want to enforce this right away until the AAR
// is updated to supply it once @CallSuper is available in
// the support library
if (!method.getContainingClass().isSubclassOf(
"android.support.wearable.watchface.WatchFaceService.Engine", false)) {
return null;
}
return method.getSuperMethod();
}
// Look up annotations metadata
ResolvedMethod directSuper = method.getSuperMethod();
ResolvedMethod superMethod = directSuper;
while (superMethod != null) {
Iterable<JavaParser.ResolvedAnnotation> annotations = superMethod.getAnnotations();
for (JavaParser.ResolvedAnnotation annotation : annotations) {
annotation = SupportAnnotationDetector.getRelevantAnnotation(annotation);
if (annotation != null) {
String signature = annotation.getSignature();
if (CALL_SUPER_ANNOTATION.equals(signature)) {
return directSuper;
} else if (signature.endsWith(".OverrideMustInvoke")) {
// Handle findbugs annotation on the fly too
return directSuper;
}
}
}
superMethod = superMethod.getSuperMethod();
}
return null;
}