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


Java LintUtils类代码示例

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


LintUtils类属于com.android.tools.lint.detector.api包,在下文中一共展示了LintUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCacheFileName

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@VisibleForTesting
@NonNull
static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) {
    if (LintUtils.endsWith(xmlFileName, DOT_XML)) {
        xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length());
    }

    StringBuilder sb = new StringBuilder(100);
    sb.append(xmlFileName);

    // Incorporate version number in the filename to avoid upgrade filename
    // conflicts on Windows (such as issue #26663)
    sb.append('-').append(BINARY_FORMAT_VERSION);

    if (platformVersion != null) {
        sb.append('-').append(platformVersion);
    }

    sb.append(".bin");
    return sb.toString();
}
 
开发者ID:evant,项目名称:silent-support,代码行数:22,代码来源:ApiLookup.java

示例4: 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

示例5: addIds

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
private void addIds(Set<String> ids, Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
        if (id != null && !id.isEmpty()) {
            ids.add(LintUtils.stripIdPrefix(id));
        }

        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String value = attribute.getValue();
            if (value.startsWith(NEW_ID_PREFIX)) {
                ids.add(value.substring(NEW_ID_PREFIX.length()));
            }
        }
    }

    NodeList children = node.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        addIds(ids, child);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LintDetectorTest.java

示例6: addViewTags

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
private static void addViewTags(Multimap<String, String> map, Element element) {
    String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
    if (id != null && !id.isEmpty()) {
        id = LintUtils.stripIdPrefix(id);
        if (!map.containsEntry(id, element.getTagName())) {
            map.put(id, element.getTagName());
        }
    }

    NodeList children = element.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            addViewTags(map, (Element) child);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ViewTypeDetector.java

示例7: beforeCheckFile

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@Override
public void beforeCheckFile(@NonNull Context context) {
    if (mPrefix != null && context instanceof XmlContext) {
        XmlContext xmlContext = (XmlContext) context;
        ResourceFolderType folderType = xmlContext.getResourceFolderType();
        if (folderType != null && folderType != ResourceFolderType.VALUES) {
            String name = LintUtils.getBaseName(context.file.getName());
            if (!name.startsWith(mPrefix)) {
                // Attempt to report the error on the root tag of the associated
                // document to make suppressing the error with a tools:suppress
                // attribute etc possible
                if (xmlContext.document != null) {
                    Element root = xmlContext.document.getDocumentElement();
                    if (root != null) {
                        xmlContext.report(ISSUE, root, xmlContext.getLocation(root),
                                getErrorMessage(name));
                        return;
                    }
                }
                context.report(ISSUE, Location.create(context.file),
                        getErrorMessage(name));
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ResourcePrefixDetector.java

示例8: visitElement

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    if (mPrefix == null || context.getResourceFolderType() != ResourceFolderType.VALUES) {
        return;
    }

    for (Element item : LintUtils.getChildren(element)) {
        Attr nameAttribute = item.getAttributeNode(ATTR_NAME);
        if (nameAttribute != null) {
            String name = nameAttribute.getValue();
            if (!name.startsWith(mPrefix)) {
                String message = getErrorMessage(name);
                context.report(ISSUE, nameAttribute, context.getLocation(nameAttribute),
                        message);
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ResourcePrefixDetector.java

示例9: visitDocument

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@Override
public void visitDocument(@NonNull XmlContext context, @NonNull Document document) {
    Element root = document.getDocumentElement();
    if (root != null) {
        if (context.getPhase() == 1) {
            // Map from ids to types
            Map<String,String> fileMap = Maps.newHashMapWithExpectedSize(10);
            addIds(root, fileMap);

            getFileMapList(context).add(Pair.of(context.file, fileMap));
        } else {
            String name = LintUtils.getLayoutName(context.file);
            Map<String, List<Location>> map = mLocations.get(name);
            if (map != null) {
                lookupLocations(context, root, map);
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:LayoutConsistencyDetector.java

示例10: getCacheFileName

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@VisibleForTesting
@NonNull
static String getCacheFileName(@NonNull String xmlFileName, @Nullable String platformVersion) {
    if (LintUtils.endsWith(xmlFileName, DOT_XML)) {
        xmlFileName = xmlFileName.substring(0, xmlFileName.length() - DOT_XML.length());
    }

    StringBuilder sb = new StringBuilder(100);
    sb.append(xmlFileName);

    // Incorporate version number in the filename to avoid upgrade filename
    // conflicts on Windows (such as issue #26663)
    sb.append('-').append(BINARY_FORMAT_VERSION);

    if (platformVersion != null) {
        sb.append('-').append(platformVersion);
    }

    sb.append(".bin"); //$NON-NLS-1$
    return sb.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ApiLookup.java

示例11: isWearableBindListener

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
private static boolean isWearableBindListener(@NonNull Element element) {
    // Checks whether a service has an Android Wear bind listener
    for (Element child : LintUtils.getChildren(element)) {
        if (child.getTagName().equals(TAG_INTENT_FILTER)) {
            for (Element innerChild : LintUtils.getChildren(child)) {
                if (innerChild.getTagName().equals(NODE_ACTION)) {
                    String name = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    if ("com.google.android.gms.wearable.BIND_LISTENER".equals(name)) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SecurityDetector.java

示例12: isStandardReceiver

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
private static boolean isStandardReceiver(Element element) {
    // Play Services also the following receiver which we'll consider standard
    // in the sense that it doesn't require a separate permission
    String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
    if ("com.google.android.gms.tagmanager.InstallReferrerReceiver".equals(name)) {
        return true;
    }

    // Checks whether a broadcast receiver receives a standard Android action
    for (Element child : LintUtils.getChildren(element)) {
        if (child.getTagName().equals(TAG_INTENT_FILTER)) {
            for (Element innerChild : LintUtils.getChildren(child)) {
                if (innerChild.getTagName().equals(NODE_ACTION)) {
                    String categoryString = innerChild.getAttributeNS(ANDROID_URI, ATTR_NAME);
                    return categoryString.startsWith("android."); //$NON-NLS-1$
                }
            }
        }
    }

    return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:SecurityDetector.java

示例13: visitElement

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Element> children = LintUtils.getChildren(element);
    boolean isHorizontal = HORIZONTAL_SCROLL_VIEW.equals(element.getTagName());
    String attributeName = isHorizontal ? ATTR_LAYOUT_WIDTH : ATTR_LAYOUT_HEIGHT;
    for (Element child : children) {
        Attr sizeNode = child.getAttributeNodeNS(ANDROID_URI, attributeName);
        if (sizeNode == null) {
            return;
        }
        String value = sizeNode.getValue();
        if (VALUE_FILL_PARENT.equals(value) || VALUE_MATCH_PARENT.equals(value)) {
            String msg = String.format("This %1$s should use `android:%2$s=\"wrap_content\"`",
                    child.getTagName(), attributeName);
            context.report(ISSUE, sizeNode, context.getLocation(sizeNode), msg);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ScrollViewChildDetector.java

示例14: getOldValue

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
/**
 * Given an error message produced by this lint detector,
 * returns the old value to be replaced in the source code.
 * <p>
 * Intended for IDE quickfix implementations.
 *
 * @param errorMessage the error message associated with the error
 * @param format the format of the error message
 * @return the corresponding old value, or null if not recognized
 */
@Nullable
public static String getOldValue(@NonNull String errorMessage,
        @NonNull TextFormat format) {
    errorMessage = format.toText(errorMessage);
    String attribute = LintUtils.findSubstring(errorMessage, " should use ", " ");
    if (attribute == null) {
        attribute = LintUtils.findSubstring(errorMessage, " should use ", null);
    }
    if (attribute != null) {
        int index = attribute.indexOf(':');
        if (index != -1) {
            return ANDROID_NS_NAME + attribute.substring(index);
        }
    }

    return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:GridLayoutDetector.java

示例15: visitDocument

import com.android.tools.lint.detector.api.LintUtils; //导入依赖的package包/类
@Override
public void visitDocument(@NonNull XmlContext context, @NonNull Document document) {
    Element root = document.getDocumentElement();
    if (root != null) {
        NamedNodeMap attributes = root.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            if (attribute.getLocalName() != null
                    && attribute.getLocalName().startsWith(ATTR_LAYOUT_RESOURCE_PREFIX)) {
                if (mLayoutsWithRootLayoutParams == null) {
                    mLayoutsWithRootLayoutParams = Sets.newHashSetWithExpectedSize(20);
                }
                mLayoutsWithRootLayoutParams.add(LintUtils.getBaseName(context.file.getName()));
                break;
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LayoutInflationDetector.java


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