当前位置: 首页>>代码示例>>Java>>正文


Java JavaParser.ResolvedAnnotation方法代码示例

本文整理汇总了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;

}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:24,代码来源:ActivityFragmentLayoutNameDetector.java

示例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;
    }

}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:23,代码来源:ActivityFragmentLayoutNameDetector.java

示例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;
    }

}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:23,代码来源:ViewHolderItemNameDetector.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:54,代码来源:CallSuperDetector.java


注:本文中的com.android.tools.lint.client.api.JavaParser.ResolvedAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。