com.android.tools.lint.client.api.UElementHandler Java Examples

The following examples show how to use com.android.tools.lint.client.api.UElementHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleCodeDetector.java    From android-custom-lint-rules with Apache License 2.0 6 votes vote down vote up
@Override
public UElementHandler createUastHandler(JavaContext context) {
    // Note: Visiting UAST nodes is a pretty general purpose mechanism;
    // Lint has specialized support to do common things like "visit every class
    // that extends a given super class or implements a given interface", and
    // "visit every call site that calls a method by a given name" etc.
    // Take a careful look at UastScanner and the various existing lint check
    // implementations before doing things the "hard way".
    // Also be aware of context.getJavaEvaluator() which provides a lot of
    // utility functionality.
    return new UElementHandler() {
        @Override
        public void visitLiteralExpression(ULiteralExpression expression) {
            String string = UastLiteralUtils.getValueIfStringLiteral(expression);
            if (string == null) {
                return;
            }

            if (string.contains("lint") && string.matches(".*\\blint\\b.*")) {
                context.report(ISSUE, expression, context.getLocation(expression),
                        "This code mentions `lint`: **Congratulations**");
            }
        }
    };
}
 
Example #2
Source File: DebugLintIssue.java    From Debug with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public UElementHandler createUastHandler(@NotNull final JavaContext context) {
    return new UElementHandler() {
        @Override
        public void visitCallExpression(@NotNull UCallExpression node) {

            final PsiMethod psiMethod = node.resolve();
            if (psiMethod != null
                    && context.getEvaluator().isMemberInClass(psiMethod, "io.noties.debug.Debug")) {

                final String name = node.getMethodName();
                if (name != null && METHODS.contains(name)) {
                    process(context, node);
                }
            }
        }
    };
}
 
Example #3
Source File: WrongRetentionDetector.java    From dagger-reflect with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(@NotNull JavaContext context) {
  return new UElementHandler() {
    @Override
    public void visitClass(@NotNull UClass node) {
      if (!node.isAnnotationType()) {
        return;
      }

      final UAnnotation qualifierAnnotation = node.findAnnotation(ANNOTATION_QUALIFIER);
      final UAnnotation mapKeyAnnotation = node.findAnnotation(ANNOTATION_MAP_KEY);
      if (qualifierAnnotation == null && mapKeyAnnotation == null) {
        return;
      }

      final boolean isKotlin = Lint.isKotlin(node);
      final UAnnotation retentionAnnotation =
          node.findAnnotation(isKotlin ? ANNOTATION_RETENTION_KOTLIN : ANNOTATION_RETENTION_JAVA);
      if (retentionAnnotation == null) {
        final UAnnotation reflectRelatedAnnotation =
            qualifierAnnotation != null ? qualifierAnnotation : mapKeyAnnotation;
        reportMissingRetention(context, isKotlin, node, reflectRelatedAnnotation);
      } else {
        final String retentionPolicy = getRetentionPolicy(context, isKotlin, retentionAnnotation);
        if (!"RUNTIME".equals(retentionPolicy)) {
          reportWrongRetentionType(context, isKotlin, retentionAnnotation, retentionPolicy);
        }
      }
    }
  };
}
 
Example #4
Source File: AbstractDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(@Nonnull final JavaContext context) {
	return new UElementHandler() {
		@Override
		public void visitClass(@Nonnull UClass node) {
			final UastVisitor uastVisitor = getUastVisitor(context);
			node.accept(uastVisitor);
			uastVisitor.onClassVisited(node);
		}
	};
}
 
Example #5
Source File: InvalidSQLiteOperatorUsageDetector.java    From HighLite with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(final JavaContext context) {
    return new UElementHandler() {
        @Override
        public void visitClass(UClass uClass) {
            uClass.accept(new FromMethodVisitor(context));
        }
    };
}
 
Example #6
Source File: NoDelegateOnResumeDetector.java    From PermissionsDispatcher with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(final JavaContext context) {
    return new UElementHandler() {
        @Override
        public void visitClass(UClass node) {
            if (node.findAnnotation("permissions.dispatcher.RuntimePermissions") != null) {
                node.accept(new Checker(context));
            }
        }
    };
}
 
Example #7
Source File: NoCorrespondingNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(final JavaContext context) {
    return new UElementHandler() {
        @Override public void visitClass(UClass node) {
            node.accept(new AnnotationChecker(context));
        }
    };
}
 
Example #8
Source File: CallNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(@NotNull final JavaContext context) {
    return new UElementHandler() {
        @Override
        public void visitClass(@NotNull UClass node) {
            node.accept(new AnnotationChecker(context));
        }
    };
}
 
Example #9
Source File: CallOnRequestPermissionsResultDetector.java    From PermissionsDispatcher with Apache License 2.0 5 votes vote down vote up
@Override
public UElementHandler createUastHandler(final JavaContext context) {
    return new UElementHandler() {
        @Override
        public void visitClass(UClass node) {
            node.accept(new OnRequestPermissionsResultChecker(context, node));
        }
    };
}
 
Example #10
Source File: InjectedFieldInJobNotTransientDetector.java    From cathode with Apache License 2.0 5 votes vote down vote up
@Override public UElementHandler createUastHandler(final JavaContext context) {
  return new UElementHandler() {
    @Override public void visitClass(UClass node) {
      node.accept(new JobVisitor(context));
    }
  };
}
 
Example #11
Source File: InvalidR2UsageDetector.java    From butterknife with Apache License 2.0 5 votes vote down vote up
@Override public UElementHandler createUastHandler(final JavaContext context) {
  return new UElementHandler() {
    @Override public void visitClass(UClass node) {
      node.accept(new R2UsageVisitor(context));
    }
  };
}
 
Example #12
Source File: PropertyDetector.java    From data-mediator with Apache License 2.0 4 votes vote down vote up
@Override
public UElementHandler createUastHandler(JavaContext context) {
    return new UElementHandlerImpl(context);
}
 
Example #13
Source File: PropertyDetector.java    From data-mediator with Apache License 2.0 4 votes vote down vote up
@Override
public UElementHandler createUastHandler(JavaContext context) {
    return new UElementHandlerImpl(context);
}