@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("sleep") && operand.toString().equals("Thread") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, node, context.getLocation(node), "Don't call sleep. Use MockTimer instead."); } return super.visitMethodInvocation(node); } };
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && operand.toString().equals("System") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " on system. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } };
@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"); } } } }
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); String methodName = node.astName().toString(); if (BAD_METHODS.contains(methodName) && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't call " + methodName + " directly. Use" + " Timer instead."); } return super.visitMethodInvocation(node); } };
@Override public boolean visitMethodInvocation(MethodInvocation node) { Expression operand = node.astOperand(); if (node.astName().toString().equals("wait") && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, context.getLocation(node), "Don't wait on object. Use Timer's wait instead."); } return super.visitMethodInvocation(node); } };
@Override public boolean visitMethodInvocation(MethodInvocation node) { if (node == mTarget) { mSeenTarget = true; } else if ((mSeenTarget || node.astOperand() == mTarget) && "show".equals(node.astName().astValue())) { //$NON-NLS-1$ // TODO: Do more flow analysis to see whether we're really calling show // on the right type of object? mFound = true; } return true; }
@Override public void visitMessageSend(MessageSend node) { lombok.ast.MethodInvocation inv = new lombok.ast.MethodInvocation(); fillList(node.arguments, inv.rawArguments()); fillList(node.typeArguments, inv.rawMethodTypeArguments()); inv.astOperand(((lombok.ast.Expression) toTree(node.receiver))); inv.astName(toIdentifier(node.selector, node.nameSourcePosition)); setPosition(node, inv); set(node, inv); }
@Override public void visitMessageSend(MessageSend node) { lombok.ast.MethodInvocation inv = new lombok.ast.MethodInvocation(); fillList(node.arguments, inv.rawArguments()); fillList(node.typeArguments, inv.rawMethodTypeArguments()); inv.astOperand(((lombok.ast.Expression) toTree(node.receiver))); inv.astName(toIdentifier(node.selector, node.nameSourcePosition)); setPosition(node, inv); set(node, inv); }
@Override public void visitMessageSend(MessageSend node) { lombok.ast.MethodInvocation inv = new lombok.ast.MethodInvocation(); fillList(node.arguments, inv.rawArguments()); fillList(node.typeArguments, inv.rawMethodTypeArguments()); inv.astOperand(((lombok.ast.Expression) toTree(node.receiver))); inv.astName(toIdentifier(node.selector, node.nameSourcePosition)); setPosition(node, inv); set(node, inv); }
private void updateRestrictionFlags(lombok.ast.Node node, NameReference ref) { ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.VARIABLE; if (node.getParent() instanceof lombok.ast.MethodInvocation) { if (((lombok.ast.MethodInvocation)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } if (node.getParent() instanceof lombok.ast.Select) { if (((lombok.ast.Select)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } }
private void updateRestrictionFlags(lombok.ast.Node node, NameReference ref) { ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.VARIABLE; if (node.getParent() instanceof lombok.ast.MethodInvocation) { if (((lombok.ast.MethodInvocation)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } if (node.getParent() instanceof lombok.ast.Select) { if (((lombok.ast.Select)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } }
private void updateRestrictionFlags(lombok.ast.Node node, NameReference ref) { ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.VARIABLE; if (node.getParent() instanceof lombok.ast.MethodInvocation) { if (((lombok.ast.MethodInvocation)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } if (node.getParent() instanceof lombok.ast.Select) { if (((lombok.ast.Select)node.getParent()).astOperand() == node) { ref.bits |= Binding.TYPE; } } }
@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."); } } } } }
@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); } }
@Override public boolean visitMethodInvocation(MethodInvocation node) { JCExpression methodId; if (node.astOperand() == null) { methodId = (JCExpression) toTree(node.astName()); } else { int start = hasSourceStructures() ? posOfStructure(node, ".", true) : node.astName().getPosition().getStart(); int end = node.astName().getPosition().getEnd(); methodId = setPos(start, end, treeMaker.Select( toExpression(node.astOperand()), toName(node.astName()))); } int start = posOfStructure(node, "(", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Apply( toList(JCExpression.class, node.astMethodTypeArguments()), methodId, toList(JCExpression.class, node.astArguments()) ))); }
@Override public boolean visitMethodInvocation(MethodInvocation node) { JCExpression methodId; if (node.astOperand() == null) { methodId = (JCExpression) toTree(node.astName()); } else { int start = hasSourceStructures() ? posOfStructure(node, ".", true) : node.astName().getPosition().getStart(); int end = node.astName().getPosition().getEnd(); methodId = setPos(start, end, treeMaker.Select( toExpression(node.astOperand()), toName(node.astName()))); } int start = posOfStructure(node, "(", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Apply( toList(JCExpression.class, node.astMethodTypeArguments()), methodId, toList(JCExpression.class, node.astArguments()) ))); }
@Override public boolean visitMethodInvocation(MethodInvocation node) { JCExpression methodId; if (node.astOperand() == null) { methodId = (JCExpression) toTree(node.astName()); } else { int start = hasSourceStructures() ? posOfStructure(node, ".", true) : node.astName().getPosition().getStart(); int end = node.astName().getPosition().getEnd(); methodId = setPos(start, end, treeMaker.Select( toExpression(node.astOperand()), toName(node.astName()))); } int start = posOfStructure(node, "(", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Apply( toList(JCExpression.class, node.astMethodTypeArguments()), methodId, toList(JCExpression.class, node.astArguments()) ))); }
@Override public boolean visitMethodInvocation(lombok.ast.MethodInvocation node) { MessageSend inv = new MessageSend(); inv.sourceStart = start(node); inv.sourceEnd = end(node); inv.nameSourcePosition = pos(node.astName()); inv.arguments = toArray(Expression.class, node.astArguments()); inv.receiver = toExpression(node.astOperand()); if (inv.receiver instanceof NameReference) { inv.receiver.bits |= Binding.TYPE; } //TODO do we have an implicit this style call somewhere in our test sources? if (inv.receiver == null) { inv.receiver = new ThisReference(0, 0); inv.receiver.bits |= ASTNode.IsImplicitThis; } if (!node.astMethodTypeArguments().isEmpty()) inv.typeArguments = toArray(TypeReference.class, node.astMethodTypeArguments()); inv.selector = toName(node.astName()); return set(node, inv); }
@Override public boolean visitMethodInvocation(lombok.ast.MethodInvocation node) { MessageSend inv = new MessageSend(); inv.sourceStart = start(node); inv.sourceEnd = end(node); inv.nameSourcePosition = pos(node.astName()); inv.arguments = toArray(Expression.class, node.astArguments()); inv.receiver = toExpression(node.astOperand()); if (inv.receiver instanceof NameReference) { inv.receiver.bits |= Binding.TYPE; } //TODO do we have an implicit this style call somewhere in our test sources? if (inv.receiver == null) { inv.receiver = new ThisReference(0, 0); inv.receiver.bits |= ASTNode.IsImplicitThis; } if (!node.astMethodTypeArguments().isEmpty()) inv.typeArguments = toArray(TypeReference.class, node.astMethodTypeArguments()); inv.selector = toName(node.astName()); return set(node, inv); }
@Override public boolean visitMethodInvocation(lombok.ast.MethodInvocation node) { MessageSend inv = new MessageSend(); inv.sourceStart = start(node); inv.sourceEnd = end(node); inv.nameSourcePosition = pos(node.astName()); inv.arguments = toArray(Expression.class, node.astArguments()); inv.receiver = toExpression(node.astOperand()); if (inv.receiver instanceof NameReference) { inv.receiver.bits |= Binding.TYPE; } //TODO do we have an implicit this style call somewhere in our test sources? if (inv.receiver == null) { inv.receiver = new ThisReference(0, 0); inv.receiver.bits |= ASTNode.IsImplicitThis; } if (!node.astMethodTypeArguments().isEmpty()) inv.typeArguments = toArray(TypeReference.class, node.astMethodTypeArguments()); inv.selector = toName(node.astName()); return set(node, inv); }