当前位置: 首页>>代码示例>>Java>>正文


Java LintUtils.skipParentheses方法代码示例

本文整理汇总了Java中com.android.tools.lint.detector.api.LintUtils.skipParentheses方法的典型用法代码示例。如果您正苦于以下问题:Java LintUtils.skipParentheses方法的具体用法?Java LintUtils.skipParentheses怎么用?Java LintUtils.skipParentheses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.tools.lint.detector.api.LintUtils的用法示例。


在下文中一共展示了LintUtils.skipParentheses方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkNestedStringFormat

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void checkNestedStringFormat(JavaContext context, UCallExpression call) {
  UElement current = call;
  while (true) {
    current = LintUtils.skipParentheses(current.getUastParent());
    if (current == null || current instanceof UMethod) {
      // Reached AST root or code block node; String.format not inside Timber.X(..).
      return;
    }
    if (current instanceof UCallExpression) {
      UCallExpression maybeTimberLogCall = (UCallExpression) current;
      JavaEvaluator evaluator = context.getEvaluator();
      PsiMethod psiMethod = maybeTimberLogCall.resolve();
      if (Pattern.matches(TIMBER_TREE_LOG_METHOD_REGEXP, psiMethod.getName())
          && evaluator.isMemberInClass(psiMethod, "timber.log.Timber")) {
        LintFix fix = quickFixIssueFormat(call);
        context.report(ISSUE_FORMAT, call, context.getLocation(call),
            "Using 'String#format' inside of 'Timber'", fix);
        return;
      }
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:WrongTimberUsageDetector.java

示例2: visitMethod

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@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);
        }
    }
}
 
开发者ID:IlyaGulya,项目名称:rxlint,代码行数:17,代码来源:DanglingSubscriptionDetector.java

示例3: checkNestedStringFormat

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
 * Reports issue if this call is inside PLog.x().
 * Calling this method assumes actual calling method is 'String#format'.
 *
 * @see #ISSUE_NESTED_FORMAT
 */
private static void checkNestedStringFormat(JavaContext context, PsiMethodCallExpression call) {
    PsiElement current = call;
    while (true) {
        current = LintUtils.skipParentheses(current.getParent());
        if (current == null || current instanceof PsiCodeBlock) {
            // Reached AST root or code block node; String.format not inside PLog.X(..).
            return;
        }
        if (current instanceof PsiMethodCallExpression) {
            PsiMethodCallExpression expression = (PsiMethodCallExpression) current;
            if (Pattern.matches("org\\.mym\\.plog\\.PLog\\.(v|d|i|w|e)",
                    expression.getMethodExpression().getQualifiedName())) {
                sHelper.reportIssue(context, ISSUE_NESTED_FORMAT, call);
                return;
            }
        }
    }
}
 
开发者ID:JumeiRdGroup,项目名称:Android-PLog,代码行数:25,代码来源:LoggingIssueDetector.java

示例4: checkNestedStringFormat

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void checkNestedStringFormat(JavaContext context, UCallExpression call) {
  UElement current = call;
  while (true) {
    current = LintUtils.skipParentheses(current.getUastParent());
    if (current == null || current instanceof UMethod) {
      // Reached AST root or code block node; String.format not inside Timber.X(..).
      return;
    }
    if (UastExpressionUtils.isMethodCall(current)) {
      UCallExpression maybeTimberLogCall = (UCallExpression) current;
      JavaEvaluator evaluator = context.getEvaluator();
      PsiMethod psiMethod = maybeTimberLogCall.resolve();
      if (Pattern.matches(TIMBER_TREE_LOG_METHOD_REGEXP, psiMethod.getName())
          && evaluator.isMemberInClass(psiMethod, "timber.log.Timber")) {
        LintFix fix = quickFixIssueFormat(call);
        context.report(ISSUE_FORMAT, call, context.getLocation(call),
            "Using 'String#format' inside of 'Timber'", fix);
        return;
      }
    }
  }
}
 
开发者ID:JakeWharton,项目名称:timber,代码行数:23,代码来源:WrongTimberUsageDetector.java

示例5: isR2Expression

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static boolean isR2Expression(PsiElement node) {
  if (node.getParent() == null) {
    return false;
  }
  String text = node.getText();
  PsiElement parent = LintUtils.skipParentheses(node.getParent());
  return (text.equals(R2) || text.contains(".R2"))
      && parent instanceof PsiExpression
      && endsWithAny(parent.getText(), SUPPORTED_TYPES);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:InvalidR2UsageDetector.java

示例6: getElderBrother

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
 * 兄要素(ノード)取得
 * @param element ルートノード
 * @return 兄弟要素の兄分(左側)のリスト (空要素の場合もあります)
 */
public static @Nullable List<PsiElement> getElderBrother(@NonNull PsiElement element) {
    List<PsiElement> elderBrothers = new ArrayList<>();
    PsiElement parent = LintUtils.skipParentheses(element.getParent());
    if (parent == null) return elderBrothers;

    for (PsiElement brother : parent.getChildren()) {
        if (brother == element) break;
        elderBrothers.add(brother);
    }
    return elderBrothers;
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:17,代码来源:ElementUtil.java

示例7: getYoungerBrother

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
/**
 * 弟要素(ノード)取得
 * @param element ルートノード
 * @return 兄弟要素の弟分(右側)のリスト (空要素の場合もあります)
 */
public static @Nullable List<PsiElement> getYoungerBrother(@NonNull PsiElement element) {
    List<PsiElement> youngerBrothers = new ArrayList<>();
    PsiElement parent = LintUtils.skipParentheses(element.getParent());
    if (parent == null) return youngerBrothers;

    boolean isYounger = false;
    for (PsiElement brother : parent.getChildren()) {
        if (isYounger) youngerBrothers.add(brother);
        if (brother == element) isYounger = true;
    }
    return youngerBrothers;
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:18,代码来源:ElementUtil.java

示例8: seek

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void seek(PsiElement element, PsiIdentifier target, Find find) {
    while(!(element instanceof PsiMethod)) {
        seekElderBrother(element, target, find);
        if (!find.isEmpty()) return;
        element = LintUtils.skipParentheses(element.getParent());
    }
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:8,代码来源:ElementUtil.java

示例9: seekElderBrother

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void seekElderBrother(PsiElement element, PsiIdentifier target, Find find){
    PsiElement parent = LintUtils.skipParentheses(element.getParent());
    if (parent == null) return;

    int myIndex = getMyBrotherIndex(element);
    PsiElement[] brothers = parent.getChildren();
    for (int index = myIndex -1; index >= 0; index--) {
        PsiElement brother = brothers[index];
        // 兄弟のブロック内のノードは、アクセス不能なので除外
        if (brother instanceof PsiBlockStatement) continue;
        if (brother instanceof PsiLocalVariable) {
            PsiLocalVariable localVariable = (PsiLocalVariable) brother;
            if (isSameName(target, localVariable.getNameIdentifier())) {
                find.findLocalVariable = localVariable;
                return;
            }
        }
        if (brother instanceof PsiParameter) {
            PsiParameter parameter = (PsiParameter) brother;
            if (isSameName(target, parameter.getNameIdentifier())) {
                find.findParameter = parameter;
                return;
            }
        }
        seekChildren(brother, target, find);
        if (!find.isEmpty()) return;
    }
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:29,代码来源:ElementUtil.java

示例10: getMyBrotherIndex

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static int getMyBrotherIndex(PsiElement my) {
    PsiElement parent =LintUtils.skipParentheses( my.getParent());
    if (parent == null) return ERROR_INDEX;

    PsiElement[] brothers = parent.getChildren();
    for (int index = 0; index < brothers.length; index++) {
        if (brothers[index] == my) return index;
    }
    return ERROR_INDEX;
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:11,代码来源:ElementUtil.java

示例11: hasChainedMethodCall

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private boolean hasChainedMethodCall(PsiMethodCallExpression node) {
    for (PsiElement parent = LintUtils.skipParentheses(node.getParent()); parent != null; parent = LintUtils.skipParentheses(parent.getParent())) {
        if (parent instanceof PsiMethodCallExpression) {
            return true;
        } else if (!(parent instanceof PsiReferenceExpression)) {
            return false;
        }
    }
    return false;
}
 
开发者ID:technoir3,项目名称:retrofit2-lint,代码行数:11,代码来源:UnusedCallObjectDetector.java

示例12: isR2Expression

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
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);
}
 
开发者ID:JakeWharton,项目名称:butterknife,代码行数:12,代码来源:InvalidR2UsageDetector.java


注:本文中的com.android.tools.lint.detector.api.LintUtils.skipParentheses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。