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


Java MethodInvocation.getParent方法代码示例

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


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

示例1: visitMethod

import lombok.ast.MethodInvocation; //导入方法依赖的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: isThisInstanceOfActivity_ForActivity

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
 * If setContentView is called by 'this' instance,
 * this method will check if 'this' is an instance of a Class inherit from android.app.Activity, for eaxmple AppCompatActivity or FragmentActivity, and so on.
 */
private boolean isThisInstanceOfActivity_ForActivity(@NonNull JavaContext context, @NonNull MethodInvocation node) {
    Node currentNode = node.getParent();

    JavaParser.ResolvedNode resolved = context.resolve(JavaContext.findSurroundingClass(node));
    JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass) resolved;
    while (sorroundingClass != null) {
        //System.out.println("sorroundingClass = " + sorroundingClass);
        if ("android.app.Activity".equals(sorroundingClass.getName())) {
            return true;
        } else {
            sorroundingClass = sorroundingClass.getSuperClass();
        }
    }


    return false;


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

示例3: getLhs

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Nullable
private static String getLhs(@NonNull MethodInvocation call) {
    Node parent = call.getParent();
    if (parent instanceof Cast) {
        parent = parent.getParent();
    }

    if (parent instanceof VariableDefinitionEntry) {
        VariableDefinitionEntry vde = (VariableDefinitionEntry) parent;
        return vde.astName().astValue();
    } else if (parent instanceof BinaryExpression) {
        BinaryExpression be = (BinaryExpression) parent;
        Expression left = be.astLeft();
        if (left instanceof VariableReference || left instanceof Select) {
            return be.astLeft().toString();
        } else if (left instanceof ArrayAccess) {
            ArrayAccess aa = (ArrayAccess) left;
            return aa.astOperand().toString();
        }
    }

    return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CutPasteDetector.java

示例4: isCommittedInChainedCalls

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
private static boolean isCommittedInChainedCalls(@NonNull JavaContext context,
        @NonNull MethodInvocation node) {
    // Look for chained calls since the FragmentManager methods all return "this"
    // to allow constructor chaining, e.g.
    //    getFragmentManager().beginTransaction().addToBackStack("test")
    //            .disallowAddToBackStack().hide(mFragment2).setBreadCrumbShortTitle("test")
    //            .show(mFragment2).setCustomAnimations(0, 0).commit();
    Node parent = node.getParent();
    while (parent instanceof MethodInvocation) {
        MethodInvocation methodInvocation = (MethodInvocation) parent;
        if (isTransactionCommitMethodCall(context, methodInvocation)
                || isShowFragmentMethodCall(context, methodInvocation)) {
            return true;
        }

        parent = parent.getParent();
    }

    return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CleanupDetector.java

示例5: isInsideDialogFragment

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
private boolean isInsideDialogFragment(JavaContext context, MethodInvocation node) {
    Node parent = node.getParent();
    while (parent != null) {
        Object resolvedNode = context.resolve(parent);
        if (resolvedNode instanceof JavaParser.ResolvedMethod) {
            JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolvedNode;
            if (isDialogFragment(method.getContainingClass())) {
                return true;
            }
        }
        parent = parent.getParent();
    }
    return false;
}
 
开发者ID:Piasy,项目名称:SafelyAndroid,代码行数:15,代码来源:UnsafeAndroidDetector.java

示例6: visitMethodInvocation

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
     JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
     if (null == resolvedMethod) {
          return  super.visitMethodInvocation(node);
     }
     //判断是不是zipEntry.getName()函数
     if ("java.util.zip.ZipEntry".equals(resolvedMethod.getContainingClass().getName()) && "public java.lang.String getName() ".equals(resolvedMethod.getSignature())) {
          //找到当前调用所在的方法定义边界
          boolean isSafe = false;
          Node surroundingNode = JavaContext.findSurroundingMethod(node);
          Node parent = node.getParent();
          while (surroundingNode != parent) {
               //判断有没有做保护
               String judgeState = ".contains(\"../\")";
               if (parent.toString().contains(judgeState)) {
                    isSafe = true;
                    break;
               }
               parent = parent.getParent();
          }
          if (!isSafe) {
               mContext.report(
                         ZipEntryDetector.ISSUE,
                         mContext.getLocation(node),
                         "请检查zipEntry.getName()的返回值中是否含有字符串../,如果有,则是有危险的Zip包(可抛异常等操作"
               );
          }
     }
     return super.visitMethodInvocation(node);
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:32,代码来源:ZipEntryAstVisitor.java

示例7: checkSingleThreadIterating

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
private boolean checkSingleThreadIterating(MethodInvocation node) {
    boolean ret = false;

    if (!modCountChangeable(node)) {
        return ret;
    }

    // 获取Method的operand,此处应为一个Collection实例
    String operand = node.astOperand().toString();

    // 获取当前调用所在的方法定义,作为检查的边界
    Node surroundingMethod = JavaContext.findSurroundingMethod(node);
    Node parent = node.getParent();
    // 试图寻找,可能改变operand modCount的方法,是否运行在operand的iterating中
    while (surroundingMethod != parent) {
        if (parent instanceof ForEach &&
                operand.equals(((ForEach)parent).astIterable().toString())) {
            ret = true;
            mContext.report(
                    ConcurrentModificationDetector.ISSUE,
                    mContext.getLocation(node),
                    "Please DO NOT modify elements DIRECTLY when iterating \"" + operand + "\".");
            break;
        }
        parent = parent.getParent();
    }

    return ret;
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:30,代码来源:ConcurrentModificationAstVisitor.java

示例8: visitMethodInvocation

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
    if (node.astOperand() != null) {
        String methodName = node.astName().astValue();
        if (methodName.equals(INFLATE) && node.astArguments().size() >= 1) {
            // See if we're inside a conditional
            boolean insideIf = false;
            Node p = node.getParent();
            while (p != null) {
                if (p instanceof If || p instanceof InlineIfExpression
                        || p instanceof Switch) {
                    insideIf = true;
                    mHaveConditional = true;
                    break;
                } else if (p == node) {
                    break;
                }
                p = p.getParent();
            }
            if (!insideIf) {
                // Rather than reporting immediately, we only report if we didn't
                // find any conditionally executed inflate statements in the method.
                // This is because there are cases where getView method is complicated
                // and inflates not just the top level layout but also children
                // of the view, and we don't want to flag these. (To be more accurate
                // should perform flow analysis and only report unconditional inflation
                // of layouts that wind up flowing to the return value; that requires
                // more work, and this simple heuristic is good enough for nearly all test
                // cases I've come across.
                if (mNodes == null) {
                    mNodes = Lists.newArrayList();
                }
                mNodes.add(node);
            }
        }
    }

    return super.visitMethodInvocation(node);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ViewHolderDetector.java

示例9: checkResult

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
private static void checkResult(@NonNull JavaContext context, @NonNull MethodInvocation node,
        @NonNull ResolvedAnnotation annotation) {
    if (node.getParent() instanceof ExpressionStatement) {
        String methodName = node.astName().astValue();
        Object suggested = annotation.getValue(ATTR_SUGGEST);

        // Failing to check permissions is a potential security issue (and had an existing
        // dedicated issue id before which people may already have configured with a
        // custom severity in their LintOptions etc) so continue to use that issue
        // (which also has category Security rather than Correctness) for these:
        Issue issue = CHECK_RESULT;
        if (methodName.startsWith("check") && methodName.contains("Permission")) {
            issue = CHECK_PERMISSION;
        }

        String message = String.format("The result of `%1$s` is not used",
                methodName);
        if (suggested != null) {
            // TODO: Resolve suggest attribute (e.g. prefix annotation class if it starts
            // with "#" etc?
            message = String.format(
                    "The result of `%1$s` is not used; did you mean to call `%2$s`?",
                    methodName, suggested.toString());
        }
        context.report(issue, node, context.getLocation(node), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:SupportAnnotationDetector.java

示例10: visitMethod

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {
    if (node.getParent() instanceof Cast) {
        Cast cast = (Cast) node.getParent();
        StrictListAccessor<Expression, MethodInvocation> args = node.astArguments();
        if (args.size() == 1) {
            String name = stripPackage(args.first().toString());
            String expectedClass = getExpectedType(name);
            if (expectedClass != null) {
                String castType = cast.astTypeReference().getTypeName();
                if (castType.indexOf('.') == -1) {
                    expectedClass = stripPackage(expectedClass);
                }
                if (!castType.equals(expectedClass)) {
                    // It's okay to mix and match
                    // android.content.ClipboardManager and android.text.ClipboardManager
                    if (isClipboard(castType) && isClipboard(expectedClass)) {
                        return;
                    }

                    String message = String.format(
                            "Suspicious cast to `%1$s` for a `%2$s`: expected `%3$s`",
                            stripPackage(castType), name, stripPackage(expectedClass));
                    context.report(ISSUE, node, context.getLocation(cast), message);
                }
            }

        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:ServiceCastDetector.java

示例11: isCommittedInChainedCalls

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
/**
 * @return true if exists a commit or a getIntent
 */
private static boolean isCommittedInChainedCalls(@NonNull JavaContext context, @NonNull MethodInvocation node) {
    JavaParser.ResolvedVariable boundVariable = getVariable(context, node);
    if (boundVariable == null) {
        Node parent = node.getParent();
        while (parent instanceof MethodInvocation) {
            MethodInvocation methodInvocation = (MethodInvocation) parent;
            if (isTransactionCommitMethodCall(methodInvocation)) {
                return true;
            }

            parent = parent.getParent();
        }
    }

    if (boundVariable != null) {
        Node method = JavaContext.findSurroundingMethod(node);
        if (method == null) {
            return true;
        }

        FinishVisitor commitVisitor = new FinishVisitor(context, boundVariable) {
            @Override
            protected boolean isCleanupCall(@NonNull MethodInvocation call) {
                if (isTransactionCommitMethodCall(call)) {
                    Expression operand = call.astOperand();
                    if (operand != null) {
                        JavaParser.ResolvedNode resolved = mContext.resolve(operand);
                        //noinspection SuspiciousMethodCalls
                        if (resolved != null && mVariables.contains(resolved)) {
                            return true;
                        } else if (resolved instanceof JavaParser.ResolvedMethod
                                && operand instanceof MethodInvocation
                                && isCommittedInChainedCalls(mContext, (MethodInvocation) operand)) {
                            // Check that the target of the committed chains is the
                            // right variable!
                            while (operand instanceof MethodInvocation) {
                                operand = ((MethodInvocation) operand).astOperand();
                            }
                            if (operand instanceof VariableReference) {
                                resolved = mContext.resolve(operand);
                                //noinspection SuspiciousMethodCalls
                                if (resolved != null && mVariables.contains(resolved)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
                return false;
            }
        };

        method.accept(commitVisitor);
        if (commitVisitor.isCleanedUp()) {
            return true;
        }
    }

    return false;
}
 
开发者ID:massivedisaster,项目名称:ActivityFragmentManager,代码行数:64,代码来源:CommitTransaction.java

示例12: visitMethodInvocation

import lombok.ast.MethodInvocation; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
    if (node == mTarget) {
        mSeenTarget = true;
    } else if (mAllowCommitBeforeTarget || mSeenTarget || node.astOperand() == mTarget) {
        String name = node.astName().astValue();
        boolean isCommit = "commit".equals(name);
        if (isCommit || "apply".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$
            // TODO: Do more flow analysis to see whether we're really calling commit/apply
            // on the right type of object?
            mFound = true;

            ResolvedNode resolved = mContext.resolve(node);
            if (resolved instanceof JavaParser.ResolvedMethod) {
                ResolvedMethod method = (ResolvedMethod) resolved;
                JavaParser.ResolvedClass clz = method.getContainingClass();
                if (clz.isSubclassOf("android.content.SharedPreferences.Editor", false)
                        && mContext.getProject().getMinSdkVersion().getApiLevel() >= 9) {
                    // See if the return value is read: can only replace commit with
                    // apply if the return value is not considered
                    Node parent = node.getParent();
                    boolean returnValueIgnored = false;
                    if (parent instanceof MethodDeclaration ||
                            parent instanceof ConstructorDeclaration ||
                            parent instanceof ClassDeclaration ||
                            parent instanceof Block ||
                            parent instanceof ExpressionStatement) {
                        returnValueIgnored = true;
                    } else if (parent instanceof Statement) {
                        if (parent instanceof If) {
                            returnValueIgnored = ((If) parent).astCondition() != node;
                        } else if (parent instanceof Return) {
                            returnValueIgnored = false;
                        } else if (parent instanceof VariableDeclaration) {
                            returnValueIgnored = false;
                        } else if (parent instanceof For) {
                            returnValueIgnored = ((For) parent).astCondition() != node;
                        } else if (parent instanceof While) {
                            returnValueIgnored = ((While) parent).astCondition() != node;
                        } else if (parent instanceof DoWhile) {
                            returnValueIgnored = ((DoWhile) parent).astCondition() != node;
                        } else if (parent instanceof Case) {
                            returnValueIgnored = ((Case) parent).astCondition() != node;
                        } else if (parent instanceof Assert) {
                            returnValueIgnored = ((Assert) parent).astAssertion() != node;
                        } else {
                            returnValueIgnored = true;
                        }
                    }
                    if (returnValueIgnored && isCommit) {
                        String message = "Consider using `apply()` instead; `commit` writes "
                                + "its data to persistent storage immediately, whereas "
                                + "`apply` will handle it in the background";
                        mContext.report(ISSUE, node, mContext.getLocation(node), message);
                    }
                }
            }
        }
    }

    return super.visitMethodInvocation(node);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:63,代码来源:SharedPrefsDetector.java


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