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


Java AstVisitor类代码示例

本文整理汇总了Java中lombok.ast.AstVisitor的典型用法代码示例。如果您正苦于以下问题:Java AstVisitor类的具体用法?Java AstVisitor怎么用?Java AstVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AstVisitor类属于lombok.ast包,在下文中一共展示了AstVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
    if (!isNode(context, node, MethodDefinitions.ALL_OF)) {
        return;
    }
    // is parent onView or withView?
    Node parentNode = node.getParent();
    if (isInvalidParent(context, parentNode)) {
        return;
    }

    MethodInvocation matcher = extractMatcher(context, node);
    // has withXXX()
    if (!isWithNode(context, matcher)) {
        return;
    }
    String message = argumentsAsString(matcher, MESSAGE_FORMAT);
    context.report(ISSUE, node, context.getLocation(parentNode), message);
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:20,代码来源:AllOfIsDisplayedDetector.java

示例2: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor,
                        @NonNull MethodInvocation node) {
    VariableReference ref = (VariableReference) node.astOperand();
    if (!"QMUILog".equals(ref.astIdentifier().astValue())) {
        return;
    }

    StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
    if (args.isEmpty()) {
        return;
    }

    for (Expression expression : args) {
        String input = expression.toString();
        if (input != null && input.contains("fuck")) {
            context.report(
                    ISSUE_F_WORD, expression,
                    context.getLocation(expression), "\uD83D\uDD95");
        }
    }
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:23,代码来源:QMUIFWordDetector.java

示例3: createJavaVisitor

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public AstVisitor createJavaVisitor(final @NonNull JavaContext context) {
    return new ForwardingAstVisitor() {

        @Override
        public boolean visitConstructorInvocation(ConstructorInvocation node) {
            TypeReference reference = node.astTypeReference();
            String typeName = reference.astParts().last().astIdentifier().astValue();
            // TODO: Should we handle factory method constructions of HashMaps as well,
            // e.g. via Guava? This is a bit trickier since we need to infer the type
            // arguments from the calling context.
            if (typeName.equals(HASH_MAP)) {
                checkHashMap(context, node, reference);
            }
            return super.visitConstructorInvocation(node);
        }
    };
}
 
开发者ID:GavinCT,项目名称:MeituanLintDemo,代码行数:19,代码来源:HashMapForJDK7Detector.java

示例4: createJavaVisitor

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public AstVisitor createJavaVisitor(final JavaContext context) {
    return new ForwardingAstVisitor() {
        @Override
        public boolean visitMethodInvocation(MethodInvocation node) {
            JavaParser.ResolvedNode resolve = context.resolve(node);
            if (resolve instanceof JavaParser.ResolvedMethod) {
                JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolve;
                // 方法所在的类校验
                JavaParser.ResolvedClass containingClass = method.getContainingClass();
                if (containingClass.matches("android.util.Log")) {
                    context.report(ISSUE, node, context.getLocation(node),
                                   "请使用Ln,避免使用Log");
                    return true;
                }
                if (node.toString().startsWith("System.out.println")) {
                    context.report(ISSUE, node, context.getLocation(node),
                                   "请使用Ln,避免使用System.out.println");
                    return true;
                }
            }
            return super.visitMethodInvocation(node);
        }
    };
}
 
开发者ID:GavinCT,项目名称:MeituanLintDemo,代码行数:26,代码来源:LogDetector.java

示例5: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
    //String methodName = node.astName().astValue();

    StrictListAccessor<Expression, MethodInvocation> arguments = node.astArguments();
    Iterator<Expression> argIterator = arguments.iterator();
    while (argIterator.hasNext()){
        Expression mArg = argIterator.next();
        if (mArg instanceof BinaryExpression){
            context.report(ISSUE,
                    node,
                    context.getLocation(node),
                    "You should pass in a value or variable as a parameter, rather than passing in operands and operator as parameters.");
        }
    }

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

示例6: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {
    JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass)context.resolve(JavaContext.findSurroundingClass(node));
    JavaParser.ResolvedMethod sorroundingMethod = (JavaParser.ResolvedMethod)context.resolve(JavaContext.findSurroundingMethod(node));

    if (sorroundingMethod.getName().equals("onCreateViewHolder")
            && sorroundingClass.isSubclassOf("android.support.v7.widget.RecyclerView.Adapter", false)){


        String layoutString = getParamWithLayoutAnnotation(context, node);
        if (layoutString == null){
            return;
        }

        if (!isFileStringStartWithPrefix(layoutString, "item_")) {
            context.report(ISSUE,
                    node,
                    context.getLocation(node),
                    "Layout resource file in ViewHolder must be named with prefix `item_`.");
        }

    }


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

示例7: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {
    ResolvedNode resolved = context.resolve(node);

    if (!(resolved instanceof ResolvedMethod) ||
            !((ResolvedMethod) resolved).getContainingClass()
                    .isSubclassOf(PACKAGE_MANAGER_CLASS, false)) {
        return;
    }
    StrictListAccessor<Expression, MethodInvocation> argumentList = node.astArguments();

    // Ignore if the method doesn't fit our description.
    if (argumentList != null && argumentList.size() == 2) {
        TypeDescriptor firstParameterType = context.getType(argumentList.first());
        if (firstParameterType != null
            && firstParameterType.matchesSignature(JavaParser.TYPE_STRING)) {
            maybeReportIssue(calculateValue(context, argumentList.last()), context, node);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GetSignaturesDetector.java

示例8: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(
        @NonNull JavaContext context,
        @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {
    StrictListAccessor<Expression, MethodInvocation> argumentList = node.astArguments();
    if (argumentList != null && argumentList.size() == 1) {
        Expression argument = argumentList.first();
        if (argument instanceof Select) {
            String expression = argument.toString();
            if (expression.startsWith(R_LAYOUT_RESOURCE_PREFIX)) {
                whiteListLayout(expression.substring(R_LAYOUT_RESOURCE_PREFIX.length()));
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MergeRootFrameLayoutDetector.java

示例9: visitResourceReference

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitResourceReference(
        @NonNull JavaContext context,
        @Nullable AstVisitor visitor,
        @NonNull Node node,
        @NonNull String type,
        @NonNull String name,
        boolean isFramework) {
    if (context.getProject().isGradleProject() && !isFramework) {
        Project project = context.getProject();
        if (project.getGradleProjectModel() != null && project.getCurrentVariant() != null) {
            ResourceType resourceType = ResourceType.getEnum(type);
            if (resourceType != null && isPrivate(context, resourceType, name)) {
                String message = createUsageErrorMessage(context, resourceType, name);
                context.report(ISSUE, node, context.getLocation(node), message);
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PrivateResourceDetector.java

示例10: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {

    // Call is only allowed if it is both only called on the super class (invoke special)
    // as well as within the same overriding method (e.g. you can't call super.onLayout
    // from the onMeasure method)
    Expression operand = node.astOperand();
    if (!(operand instanceof Super)) {
        report(context, node);
        return;
    }

    Node method = StringFormatDetector.getParentMethod(node);
    if (!(method instanceof MethodDeclaration) ||
            !((MethodDeclaration)method).astMethodName().astValue().equals(
                    node.astName().astValue())) {
        report(context, node);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:WrongCallDetector.java

示例11: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {
    if (mDependsOnAppCompat && isAppBarActivityCall(context, node)) {
        String name = node.astName().astValue();
        String replace = null;
        if (GET_ACTION_BAR.equals(name)) {
            replace = "getSupportActionBar";
        } else if (START_ACTION_MODE.equals(name)) {
            replace = "startSupportActionMode";
        } else if (SET_PROGRESS_BAR_VIS.equals(name)) {
            replace = "setSupportProgressBarVisibility";
        } else if (SET_PROGRESS_BAR_IN_VIS.equals(name)) {
            replace = "setSupportProgressBarIndeterminateVisibility";
        } else if (SET_PROGRESS_BAR_INDETERMINATE.equals(name)) {
            replace = "setSupportProgressBarIndeterminate";
        } else if (REQUEST_WINDOW_FEATURE.equals(name)) {
            replace = "supportRequestWindowFeature";
        }

        if (replace != null) {
            String message = String.format(ERROR_MESSAGE_FORMAT, replace, name);
            context.report(ISSUE, node, context.getLocation(node), message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:AppCompatCallDetector.java

示例12: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {
    assert node.astName().astValue().equals("sendTextMessage") ||  //$NON-NLS-1$
        node.astName().astValue().equals("sendMultipartTextMessage");  //$NON-NLS-1$
    if (node.astOperand() == null) {
        // "sendTextMessage"/"sendMultipartTextMessage" in the code with no operand
        return;
    }

    StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
    if (args.size() == 5) {
        Expression destinationAddress = args.first();
        if (destinationAddress instanceof StringLiteral) {
            String number = ((StringLiteral) destinationAddress).astValue();

            if (!number.startsWith("+")) {  //$NON-NLS-1$
               context.report(ISSUE, node, context.getLocation(destinationAddress),
                   "To make sure the SMS can be sent by all users, please start the SMS number " +
                   "with a + and a country code or restrict the code invocation to people in the country " +
                   "you are targeting.");
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:NonInternationalizedSmsDetector.java

示例13: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
    if (isNode(context, node, METHOD_CALL)) {
        MethodInvocation first = getFirstArgument(node);
        if (isWithNode(context, first)) {
            String message = argumentsAsString(first, MESSAGE_FORMAT);
            context.report(ISSUE, node, context.getLocation(node), message);
        }
    }
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:11,代码来源:OnViewDetector.java

示例14: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
    if (isNode(context, node, METHOD_CALL)) {
        String message = argumentsAsString(node, MESSAGE_FORMAT);
        context.report(ISSUE, node, context.getLocation(node), message);
    }
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:8,代码来源:WithTextDetector.java

示例15: visitMethod

import lombok.ast.AstVisitor; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, AstVisitor visitor, @NonNull MethodInvocation node) {

    StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
    if (args.isEmpty()) {
        return;
    }

    Project project = context.getProject();
    List<File> resourceFolder = project.getResourceFolders();
    if (resourceFolder.isEmpty()) {
        return;
    }

    String resourcePath = resourceFolder.get(0).getAbsolutePath();
    for (Expression expression : args) {
        String input = expression.toString();
        if (input != null && input.contains("R.drawable")) {
            // 找出 drawable 相关的参数

            // 获取 drawable 名字
            String drawableName = input.replace("R.drawable.", "");
            try {
                // 若 drawable 为 Vector Drawable,则文件后缀为 xml,根据 resource 路径,drawable 名字,文件后缀拼接出完整路径
                FileInputStream fileInputStream = new FileInputStream(resourcePath + "/drawable/" + drawableName + ".xml");
                BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
                String line = reader.readLine();
                if (line.contains("vector")) {
                    // 若文件存在,并且包含首行包含 vector,则为 Vector Drawable,抛出警告
                    context.report(ISSUE_JAVA_VECTOR_DRAWABLE, node, context.getLocation(node), expression.toString() + " 为 Vector Drawable,请使用 getVectorDrawable 方法获取,避免 4.0 及以下版本的系统产生 Crash");
                }
                fileInputStream.close();
            } catch (Exception ignored) {
            }
        }
    }
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:38,代码来源:QMUIJavaVectorDrawableDetector.java


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