org.jetbrains.uast.UElement Java Examples

The following examples show how to use org.jetbrains.uast.UElement. 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: InvalidR2UsageDetector.java    From butterknife with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #2
Source File: CallNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 6 votes vote down vote up
/**
 * Generate method identifier from method information.
 *
 * @param node UCallExpression
 * @return className + methodName + parametersType
 */
@Nullable
private static String methodIdentifier(@NotNull UCallExpression node) {
    UElement element = node.getUastParent();
    while (element != null) {
        if (element instanceof UClass) {
            break;
        }
        element = element.getUastParent();
    }
    UClass uClass = (UClass) element;
    if (uClass == null || node.getMethodName() == null) {
        return null;
    }
    return uClass.getName() + COLON + node.getMethodName();
}
 
Example #3
Source File: InvalidR2UsageDetector.java    From butterknife with Apache License 2.0 5 votes vote down vote up
private static boolean isR2Expression(UElement node) {
  UElement parentNode = node.getUastParent();
  if (parentNode == null) {
    return false;
  }
  String text = node.asSourceString();
  UElement parent = LintUtils.skipParentheses(parentNode);
  return (text.equals(R2) || text.contains(".R2"))
      && parent instanceof UExpression
      && endsWithAny(parent.asSourceString(), SUPPORTED_TYPES);
}
 
Example #4
Source File: InvalidConfigGroupValuesDetector.java    From aircon with MIT License 5 votes vote down vote up
private boolean verifyConfigFieldReference(final UElement node, final PsiElement valueElement) {
	if (!ElementUtils.isFieldReference(valueElement)) {
		report(node);
		return false;
	}

	final PsiField configField = ElementUtils.getReferencedField(valueElement);
	if (!ConfigElementsUtils.isConfigField(configField)) {
		report(node);
		return false;
	}
	return true;
}
 
Example #5
Source File: IssueDetector.java    From aircon with MIT License 5 votes vote down vote up
protected LintFix addAnnotationFix(UElement target, String targetName, Class<? extends Annotation> clazz, String annotationContent) {
	final String source = target.asSourceString();
	return replaceFix(target).name(String.format(ADD_ANNOTATION_FIX_FORMAT, clazz.getSimpleName(), targetName))
	                         .text(source)
	                         .with("@" + clazz.getCanonicalName() + "(" + annotationContent + ")" + source)
	                         .build();
}
 
Example #6
Source File: ElementUtils.java    From aircon with MIT License 5 votes vote down vote up
public static UClass getContainingClass(UElement element) {
	if (element instanceof UClass) {
		return (UClass) element;
	}
	if (element == null) {
		return null;
	}

	return getContainingClass(element.getUastParent());
}
 
Example #7
Source File: CallNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 5 votes vote down vote up
/**
 * Generate method identifier from method information.
 *
 * @param node UMethod
 * @return className + methodName + parametersType
 */
@Nullable
private static String methodIdentifier(@NotNull UMethod node) {
    UElement parent = node.getUastParent();
    if (!(parent instanceof UClass)) {
        return null;
    }
    UClass uClass = (UClass) parent;
    return uClass.getName() + COLON + node.getName();
}
 
Example #8
Source File: InvalidSQLiteOperatorUsageDetector.java    From HighLite with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    final List<Class<? extends UElement>> ret = new ArrayList<>();
    ret.add(UClass.class);
    return ret;
}
 
Example #9
Source File: InvalidR2UsageDetector.java    From butterknife with Apache License 2.0 4 votes vote down vote up
@Override public List<Class<? extends UElement>> getApplicableUastTypes() {
  return Collections.singletonList(UClass.class);
}
 
Example #10
Source File: InjectedFieldInJobNotTransientDetector.java    From cathode with Apache License 2.0 4 votes vote down vote up
@Override public List<Class<? extends UElement>> getApplicableUastTypes() {
  return Collections.singletonList(UClass.class);
}
 
Example #11
Source File: DebugLintIssue.java    From Debug with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    //noinspection unchecked
    return (List) Collections.singletonList(UCallExpression.class);
}
 
Example #12
Source File: SampleCodeDetector.java    From android-custom-lint-rules with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.singletonList(ULiteralExpression.class);
}
 
Example #13
Source File: CallOnRequestPermissionsResultDetector.java    From PermissionsDispatcher with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #14
Source File: CallNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #15
Source File: NoCorrespondingNeedsPermissionDetector.java    From PermissionsDispatcher with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #16
Source File: NoDelegateOnResumeDetector.java    From PermissionsDispatcher with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #17
Source File: WrongRetentionDetector.java    From dagger-reflect with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
  return Collections.singletonList(UClass.class);
}
 
Example #18
Source File: PropertyDetector.java    From data-mediator with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #19
Source File: PropertyDetector.java    From data-mediator with Apache License 2.0 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
    return Collections.<Class<? extends UElement>>singletonList(UClass.class);
}
 
Example #20
Source File: AbstractDetector.java    From aircon with MIT License 4 votes vote down vote up
@Override
public List<Class<? extends UElement>> getApplicableUastTypes() {
	return Collections.<Class<? extends UElement>> singletonList(UClass.class);
}
 
Example #21
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected LintFix.ReplaceStringBuilder replaceFix(UElement target) {
	return fix().replace()
	            .range(mContext.getLocation(target))
	            .shortenNames()
	            .reformat(true);
}
 
Example #22
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node, String desc, LintFix lintFix) {
	if (REPORTED_ISSUES.get(node) != mIssue) {
		REPORTED_ISSUES.put(node, mIssue);
		mContext.report(mIssue, node, mContext.getLocation(node), desc, lintFix);
	}
}
 
Example #23
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node, String desc) {
	report(node, desc, null);
}
 
Example #24
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node, LintFix lintFix) {
	report(node, mIssue.getExplanation(TextFormat.RAW), lintFix);
}
 
Example #25
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
protected void report(final UElement node) {
	report(node, mIssue.getExplanation(TextFormat.RAW));
}
 
Example #26
Source File: MissingSourceDetector.java    From aircon with MIT License 4 votes vote down vote up
private LintFix addSourceAnnotationFix(UElement target, String targetName) {
	return addAnnotationFix(target, targetName, Source.class, "SomeConfigSource.class");
}