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


Java XmlContext.getLocation方法代码示例

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


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

示例1: visitAttribute

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
@Override
public void visitAttribute(XmlContext context, Attr attribute) {
    super.visitAttribute(context, attribute);

    String value = attribute.getValue();
    if (Utils.stringIsEmpty(value)) return;

    //onClick 属性被赋值
    Element element = attribute.getOwnerElement();
    boolean has = element.hasAttributeNS(SdkConstants.ANDROID_URI, SdkConstants.ATTR_ID);
    if (!has) {

        Location location = context.getLocation(attribute);
        context.report(ISSUE_MISSING_ID, location, "the view with onClick attribute set should has id attribute");
    }
}
 
开发者ID:jessie345,项目名称:CustomLintRules,代码行数:17,代码来源:AutoPointLayoutOnclickDetector.java

示例2: checkInnerClass

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
private static void checkInnerClass(XmlContext context, Element element, String pkg,
        Node classNameNode, String className) {
    if (pkg != null && className.indexOf('$') == -1 && className.indexOf('.', 1) > 0) {
        boolean haveUpperCase = false;
        for (int i = 0, n = pkg.length(); i < n; i++) {
            if (Character.isUpperCase(pkg.charAt(i))) {
                haveUpperCase = true;
                break;
            }
        }
        if (!haveUpperCase) {
            String fixed = className.charAt(0) + className.substring(1).replace('.','$');
            String message = "Use '$' instead of '.' for inner classes " +
                    "(or use only lowercase letters in package names); replace \"" +
                    className + "\" with \"" + fixed + "\"";
            Location location = context.getLocation(classNameNode);
            context.report(INNERCLASS, element, location, message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MissingClassDetector.java

示例3: visitElement

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
@Override
public void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    Node parentNode = element.getParentNode();
    if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
        Element parent = (Element)parentNode;
        Attr width = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_WIDTH);
        Attr height = parent.getAttributeNodeNS(ANDROID_URI, ATTR_LAYOUT_HEIGHT);
        Attr attr = null;
        if (width != null && VALUE_WRAP_CONTENT.equals(width.getValue())) {
            attr = width;
        }
        if (height != null && VALUE_WRAP_CONTENT.equals(height.getValue())) {
            attr = height;
        }
        if (attr != null) {
            String message = String.format("Placing a `<WebView>` in a parent element that "
                    + "uses a `wrap_content %1$s` can lead to subtle bugs; use `match_parent` "
                    + "instead", attr.getLocalName());
            Location location = context.getLocation(element);
            Location secondary = context.getLocation(attr);
            secondary.setMessage("`wrap_content` here may not work well with WebView below");
            location.setSecondary(secondary);
            context.report(ISSUE, element, location, message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:WebViewDetector.java

示例4: reportRepeatedWord

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
/** Reports a repeated word */
private static void reportRepeatedWord(XmlContext context, Node node, String text,
        int lastWordBegin,
        int begin, int end) {
    String message = String.format(
            "Repeated word \"%1$s\" in message: possible typo",
            text.substring(begin, end));
    Location location = context.getLocation(node, lastWordBegin, end);
    context.report(ISSUE, node, location, message);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:TypoDetector.java

示例5: reportMismatch

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
private static void reportMismatch(XmlContext context, Attr idNode, Node inputTypeNode,
        String message) {
    Location location;
    if (inputTypeNode != null) {
        location = context.getLocation(inputTypeNode);
        Location secondary = context.getLocation(idNode);
        secondary.setMessage("id defined here");
        location.setSecondary(secondary);
    } else {
        location = context.getLocation(idNode);
    }
    context.report(ISSUE, idNode.getOwnerElement(), location, message);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:TextFieldDetector.java

示例6: visitAttribute

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    String name = attribute.getValue();
    for (int i = 0, n = name.length(); i < n; i++) {
        char c = name.charAt(i);
        if (c == '\uFEFF') {
            Location location = context.getLocation(attribute);
            String message = "Found byte-order-mark in the middle of a file";
            context.report(BOM, null, location, message);
            break;
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ByteOrderMarkDetector.java

示例7: isMainActivity

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
/**
 * Returns true if the XML node is an activity with a launcher intent.
 *
 * @param node is the node to check.
 * @return true if the node is an activity with a launcher intent, false if not.
 */
private boolean isMainActivity(XmlContext context, Node node) {

    if (TAG_APPLICATION.equals(node.getNodeName())) {
        mApplicationTagLocation = context.getLocation(node);
    }

    if (TAG_ACTIVITY.equals(node.getNodeName())) {

        mHasActivity = true;

        for (Element activityChild : LintUtils.getChildren(node)) {
            if (TAG_INTENT_FILTER.equals(activityChild.getNodeName())) {

                boolean hasLauncherCategory = false;
                boolean hasMainAction = false;

                for (Element intentFilterChild : LintUtils.getChildren(activityChild)) {
                    // Check for category tag)
                    if (NODE_CATEGORY.equals(intentFilterChild.getNodeName())
                            && Constants.CATEGORY_NAME_LAUNCHER.equals(
                            intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
                        hasLauncherCategory = true;
                    }
                    // Check for action tag
                    if (NODE_ACTION.equals(intentFilterChild.getNodeName())
                            && Constants.ACTION_NAME_MAIN.equals(
                            intentFilterChild.getAttributeNS(ANDROID_URI, ATTR_NAME))) {
                        hasMainAction = true;
                    }
                }

                if (hasLauncherCategory && hasMainAction) {
                    if (mHasLauncherActivity) {
                        context.report(ISSUE_MORE_THAN_ONE_LAUNCHER, context.getLocation(node),
                                "Expecting " + ANDROID_MANIFEST_XML + " to have only one activity with a launcher intent.");
                    }

                    // if it is a library
                    if (context.getProject() == context.getMainProject() && context.getMainProject().isLibrary()) {
                        context.report(ISSUE_LAUNCHER_ACTIVITY_IN_LIBRARY, context.getLocation(node),
                                "Expecting " + ANDROID_MANIFEST_XML + " not to have an activity with a launcher intent.");
                    }

                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:inaka,项目名称:lewis,代码行数:57,代码来源:LauncherActivityDetector.java

示例8: visitAttribute

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    // Ignore tools:background and any other custom attribute that isn't actually the
    // android View background attribute
    if (!ANDROID_URI.equals(attribute.getNamespaceURI())) {
        return;
    }

    // Only consider the root element's background
    Element documentElement = attribute.getOwnerDocument().getDocumentElement();
    if (documentElement == attribute.getOwnerElement()) {
        // If the drawable is a non-repeated pattern then the overdraw might be
        // intentional since the image isn't covering the whole screen
        String background = attribute.getValue();
        if (mValidDrawables != null && mValidDrawables.contains(background)) {
            return;
        }

        if (background.equals(TRANSPARENT_COLOR) || background.equals(NULL_RESOURCE)) {
            return;
        }

        if (background.startsWith("@android:drawable/")) { //$NON-NLS-1$
            // We haven't had a chance to study the builtin drawables the way we
            // check the project local ones in scanBitmap() and beforeCheckFile(),
            // but many of these are not bitmaps, so ignore these
            return;
        }

        String name = context.file.getName();
        if (name.contains("list_") || name.contains("_item")) { //$NON-NLS-1$ //$NON-NLS-2$
            // Canonical list_item layout name: don't warn about these, it's
            // pretty common to want to paint custom list item backgrounds
            return;
        }

        if (!context.getProject().getReportIssues()) {
            // If this is a library project not being analyzed, ignore it
            return;
        }

        Location location = context.getLocation(attribute);
        location.setClientData(attribute);
        if (mRootAttributes == null) {
            mRootAttributes = new ArrayList<Pair<Location,String>>();
        }
        mRootAttributes.add(Pair.of(location, attribute.getValue()));

        String activity = documentElement.getAttributeNS(TOOLS_URI, ATTR_CONTEXT);
        if (activity != null && !activity.isEmpty()) {
            if (activity.startsWith(".")) { //$NON-NLS-1$
                activity = context.getProject().getPackage() + activity;
            }
            registerLayoutActivity(LintUtils.getLayoutName(context.file), activity);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:58,代码来源:OverdrawDetector.java

示例9: afterCheckFile

import com.android.tools.lint.detector.api.XmlContext; //导入方法依赖的package包/类
@Override
public void afterCheckFile(@NonNull Context context) {
    if (mTextFields != null) {
        if (mLabels == null) {
            mLabels = Collections.emptySet();
        }

        for (Element element : mTextFields) {
            if (element.hasAttributeNS(ANDROID_URI, ATTR_HINT)) {
                continue;
            }
            String id = element.getAttributeNS(ANDROID_URI, ATTR_ID);
            boolean missing = true;
            if (mLabels.contains(id)) {
                missing = false;
            } else if (id.startsWith(NEW_ID_PREFIX)) {
                missing = !mLabels.contains(ID_PREFIX + stripIdPrefix(id));
            } else if (id.startsWith(ID_PREFIX)) {
                missing = !mLabels.contains(NEW_ID_PREFIX + stripIdPrefix(id));
            }

            if (missing) {
                XmlContext xmlContext = (XmlContext) context;
                Location location = xmlContext.getLocation(element);
                String message;
                if (id == null || id.isEmpty()) {
                    message = "No label views point to this text field with a " +
                            "`labelFor` attribute";
                } else {
                    message = String.format("No label views point to this text field with " +
                            "an `android:labelFor=\"@+id/%1$s\"` attribute", id);
                }
                xmlContext.report(ISSUE, element, location, message);
            }

        }
    }

    mLabels = null;
    mTextFields = null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:42,代码来源:LabelForDetector.java


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