@Override public void visitMethod(@NonNull JavaContext context, @Nullable JavaElementVisitor visitor, @NonNull PsiMethodCallExpression node, @NonNull PsiMethod method) { boolean isLayoutInflaterCall = isLayoutInflaterCall(context, node, method); boolean isViewInflateCall = isInViewCall(context, node, method); String name = method.getName(); boolean fromMethod = LAYOUTINFLATER_FROM.equals(name); boolean viewInflateMethod = VIEW_INFLATE.equals(name); if (isLayoutInflaterCall && fromMethod) { context.report(ISSUE_LAYOUTINFLATER, node, context.getLocation(node), "error use system LayoutInflater,should use LayoutInflaterWrapper."); return; } if (viewInflateMethod && isViewInflateCall) { context.report(ISSUE_VIEW_INFLATE, node, context.getLocation(node), "error use View.inflate(),should use LayoutInflaterWrapper.inflate."); return; } }
@Override public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); if (evaluator.getParameterCount(method) == 0) { PsiMethod parent = PsiTreeUtil.getParentOfType(call, PsiMethod.class); if (parent != null) { if (evaluator.isMemberInClass(method, CLASS_DIRECTOR) && evaluator.isMemberInSubClassOf(parent, CLASS_DIRECTOR_BACK_HANDLER, false)) { context.report(ISSUE, call, context.getLocation(call), "Can't call Stage.handleBack() in Stage.BackHandler.handleBack()"); } else if (evaluator.isMemberInClass(method, CLASS_STAGE) && evaluator.isMemberInSubClassOf(parent, CLASS_STAGE_BACK_HANDLER, false)) { context.report(ISSUE, call, context.getLocation(call), "Can't call Director.handleBack() in Director.BackHandler.handleBack()"); } } } }
@Override public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) { super.visitMethod(context, visitor, call, method); if (isRxSubscribeableClass(method.getContainingClass()) && !PsiType.VOID.equals(method.getReturnType())) { PsiElement element = LintUtils.skipParentheses(call.getParent()); if (element instanceof PsiExpressionStatement) { String message; if (isRx2(method.getContainingClass())) { message = "No reference to the disposable is kept"; } else { message = "No reference to the subscription is kept"; } context.report(ISSUE, call, context.getLocation(call), message); } } }
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) { } @Override public void visitLocalVariable(PsiLocalVariable variable) { super.visitLocalVariable(variable); if (VariantPool.isJump()) { if (isFindYYY(variable.toString())) { holder.registerProblem(variable, DESCRIPTION_TEMPLATE, myQuickFix); log.info("isFindYYY" + variable ); } } } }; }
@Override public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) { PsiReferenceExpression methodExpression = call.getMethodExpression(); String fullyQualifiedMethodName = methodExpression.getQualifiedName(); if (fullyQualifiedMethodName.startsWith("android.util.Log") //Handle multiple overloaded out.print(and println, etc) methods. || fullyQualifiedMethodName.startsWith("java.lang.System.out.print")) { sHelper.reportIssue(context, ISSUE_LOG_CLASS, methodExpression); return; } if (fullyQualifiedMethodName.equals("java.lang.String.format")) { checkNestedStringFormat(context, call); return; } }
public final boolean value( PsiFile psiFile ) { final boolean[] hasPolygeneImportPackage = new boolean[]{ false }; psiFile.accept( new JavaElementVisitor() { @Override public final void visitImportStatement( PsiImportStatement statement ) { String packageName = statement.getQualifiedName(); if( packageName != null && packageName.startsWith( "org.apache.polygene" ) ) { hasPolygeneImportPackage[ 0 ] = true; } } @Override public void visitReferenceExpression( PsiReferenceExpression expression ) { // Ignore } } ); return hasPolygeneImportPackage[ 0 ]; }
@Override public JavaElementVisitor createPsiVisitor(final JavaContext context) { return new JavaElementVisitor() { @Override public void visitClass(PsiClass node) { node.accept(new R2UsageVisitor(context)); } }; }
@Override public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) { super.visitMethod(context, visitor, call, method); for (SubscriberCheck check : CHECKS) { if (check.isMissingOnError(method)) { context.report(ISSUE, call, context.getLocation(call), "Subscriber is missing onError"); return; } } }
@Override public JavaElementVisitor createPsiVisitor(JavaContext context) { return new JavaElementVisitor() { @Override public void visitMethodCallExpression(PsiMethodCallExpression node) { if (isRetrofitEndpoint(node.resolveMethod()) && !isCallResultUsed(node)) { context.report(ISSUE, context.getLocation(node), "Call object was created but never used."); } } }; }
@Override public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) { super.visitMethod(context, visitor, call, method); PsiElement errorLocation = isBuildingChildScope(call); if (errorLocation != null) { context.report(INCORRECT_CHILD_SCOPE_BUILDING, context.getLocation(errorLocation), "Scoper pattern error"); } }
@Override public JavaElementVisitor createPsiVisitor(@NonNull final JavaContext context) { return new JavaElementVisitor() { @Override public void visitLambdaExpression(PsiLambdaExpression expression) { if (!(expression.getParent() instanceof PsiExpressionList)) { return; } PsiExpressionList exprList = (PsiExpressionList) expression.getParent(); if (!(exprList.getParent() instanceof PsiMethodCallExpression)) { return; } PsiMethodCallExpression call = (PsiMethodCallExpression) exprList.getParent(); if (call.getType() == null) { return; } String callType = call.getType().getCanonicalText(); if (!callType.startsWith("de.mobilej.thinr.Thinr")) { return; } markLeakSuspects(expression, expression, context); } }; }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitDocTag(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitJavaToken(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitParameterList(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitAssertStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitReturnStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitBlockStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor){ if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitEmptyStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitExpression(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitAnnotationParameterList(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitExpressionListStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor){ if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitKeyword(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitThrowStatement(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitInlineDocTag(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitDocToken(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitDocTagValue(this); } else { visitor.visitElement(this); } }
@Override public void accept(@NotNull PsiElementVisitor visitor){ if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitParameterList(this); } else { visitor.visitElement(this); } }
@NotNull @Override protected LocalInspectionTool[] configureLocalInspectionTools() { return new LocalInspectionTool[]{new DefUseInspection(), new LocalInspectionTool() { @Override @Nls @NotNull public String getGroupDisplayName() { return "MyGroup"; } @Override @Nls @NotNull public String getDisplayName() { return "My"; } @Override @NonNls @NotNull public String getShortName() { return getDisplayName(); } @Override @NotNull public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitLiteralExpression(PsiLiteralExpression expression) { final String s = (String)expression.getValue(); if (s.contains("a")) holder.registerProblem(expression, "Look ma! This String contains 'a'"); if (s.contains("b")) holder.registerProblem(expression, "Look ma! This String contains 'b'"); } }; } }}; }
public JavaElementVisitor createPsiVisitor(final JavaContext context) { return new JavaElementVisitor() { public void visitMethod(PsiMethod method) { visitMethodDefinition(context, method); } }; }
@Override public final void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof JavaElementVisitor) { ((JavaElementVisitor)visitor).visitAnnotationArrayInitializer(this); } else { visitor.visitElement(this); } }