private static void detectR2(JavaContext context, UElement node) { UFile sourceFile = context.getUastFile(); List<UClass> classes = sourceFile.getClasses(); if (!classes.isEmpty() && classes.get(0).getName() != null) { String qualifiedName = classes.get(0).getName(); if (qualifiedName.contains("_ViewBinder") || qualifiedName.contains("_ViewBinding") || qualifiedName.equals(R2)) { // skip generated files and R2 return; } } boolean isR2 = isR2Expression(node); if (isR2 && !context.isSuppressedWithComment(node, ISSUE)) { context.report(ISSUE, node, context.getLocation(node), LINT_ERROR_BODY); } }
@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 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); } };
/** * @deprecated Use {@link #isSuppressedWithComment(PsiElement, Issue)} instead */ @Deprecated public boolean isSuppressedWithComment(@NonNull Node scope, @NonNull Issue issue) { // Check whether there is a comment marker CharSequence contents = getContents(); assert contents != null; // otherwise we wouldn't be here Position position = scope.getPosition(); if (position == null) { return false; } int start = position.getStart(); return isSuppressedWithComment(start, issue); }
public boolean isSuppressedWithComment(@NonNull PsiElement scope, @NonNull Issue issue) { // Check whether there is a comment marker CharSequence contents = getContents(); assert contents != null; // otherwise we wouldn't be here TextRange textRange = scope.getTextRange(); if (textRange == null) { return false; } int start = textRange.getStartOffset(); return isSuppressedWithComment(start, issue); }
public boolean isSuppressed(@Nullable JavaContext context, @NonNull Issue issue, @Nullable PsiElement scope) { boolean checkComments = client.checkForSuppressComments() && context != null && context.containsCommentSuppress(); while (scope != null) { if (scope instanceof PsiModifierListOwner) { PsiModifierListOwner owner = (PsiModifierListOwner) scope; if (isSuppressed(issue, owner.getModifierList())) { return true; } } if (checkComments && context.isSuppressedWithComment(scope, issue)) { return true; } scope = scope.getParent(); if (scope instanceof PsiFile) { return false; } } return false; }
if (checkComments && context.isSuppressedWithComment(scope, issue)) { return true;