• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Location类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Location类属于com.android.tools.lint.detector.api包,在下文中一共展示了Location类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: visitAttribute

import com.android.tools.lint.detector.api.Location; //导入依赖的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: reportSeparateByIsolatedGroup

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportSeparateByIsolatedGroup(@NonNull WriteFieldGroupMethod method, @NonNull List<WriteFieldGroupMethod> groupMethods) {
    // ISSUE レポート
    String contents = mContext.getJavaFile().getText();
    int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
    int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
    String groups = getSharedMethodNames(groupMethods);
    String fieldNames = getWriteFieldNames(method);
    String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全共有かつクラス唯一です。\n"
            + "これはメソッドの責務(役割)が共有されている、責務合体したクラスであることを示すので、\n"
            + "他のメソッド " + groups + " と共に、"
            + "メソッドの利用先が適切であるかを確認して、変更するフイールド変数(状態)の分割をおすすめします。\n"
            + fieldNames;
    Location location = createLocation(mContext.file, contents, startOffset, endOffset);

    mContext.report(SEPARATE_BY_ISOLATED_GROUP_ISSUE, location, message);
    Debug.report("SeparateByIsolateGroup", method);
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:18,代码来源:SharingGroupClassificationDetector.java


示例3: reportSeparateByGroup

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportSeparateByGroup(@NonNull WriteFieldGroupMethod method, @NonNull List<WriteFieldGroupMethod> groupMethods) {
    // ISSUE レポート
    String contents = mContext.getJavaFile().getText();
    int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
    int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
    String groups = getSharedMethodNames(groupMethods);
    String fieldNames = getWriteFieldNames(method);
    String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全共有ですがクラス唯一でありません。\n"
            + "これはメソッドの責務(役割)が共有されていますが、責務混在したクラスであることを示すので、\n"
            + "他のメソッド " + groups + " と、"
            + "メソッドが変更するフィールド変数(状態)ごと新クラスへの分離をおすすめします。\n"
            + fieldNames;
    Location location = createLocation(mContext.file, contents, startOffset, endOffset);

    mContext.report(SEPARATE_BY_GROUP_ISSUE, location, message);
    Debug.report("SeparateByGroup", method);
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:18,代码来源:SharingGroupClassificationDetector.java


示例4: reportTrySeparateByRole

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportTrySeparateByRole(@NonNull WriteFieldGroupMethod method) {
    // ISSUE レポート
    String contents = mContext.getJavaFile().getText();
    int startOffset = method.getMethod().getNameIdentifier().getTextRange().getStartOffset();
    int endOffset = method.getMethod().getNameIdentifier().getTextRange().getEndOffset();
    String fieldNames = getWriteFieldNames(method);
    String message = "メソッドが変更するフィールド変数(状態)は、他のメソッドと完全独立でも完全共有でもありません。\n"
            + "このメソッドが変更するフィールド変数(状態)は、他のメソッドとの間で共有の一部に過不足があります。\n"
            + "これはメソッドの責務(役割)が明確に区別されておらず、責務(役割)が混在していることを示すので、\n"
            + "先ずはメソッドや変更フィールド変数(状態)の分割や統合をおすすめします。\n"
            + fieldNames;
    Location location = createLocation(mContext.file, contents, startOffset, endOffset);

    mContext.report(TRY_SEPARATE_BY_ROLE_ISSUE, location, message);
    Debug.report("TrySeparateByRole", method);
}
 
开发者ID:cch-robo,项目名称:Android_Lint_SRP_Practice_Example,代码行数:17,代码来源:SharingGroupClassificationDetector.java


示例5: visitAnnotation

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public boolean visitAnnotation(Annotation node) {
  String type = node.astAnnotationTypeReference().getTypeName();
  if (DAGGER_MODULE.equals(type)) {
    Node parent = node.getParent();
    if (parent instanceof Modifiers) {
      parent = parent.getParent();
      if (parent instanceof ClassDeclaration) {
        int flags = ((ClassDeclaration) parent).astModifiers().getEffectiveModifierFlags();
        if ((flags & Modifier.ABSTRACT) == 0) {
          context.report(ISSUE, Location.create(context.file), ISSUE.getBriefDescription(TextFormat.TEXT));
        }
      }
    }
  }

  return super.visitAnnotation(node);
}
 
开发者ID:ashdavies,项目名称:dagger-lint,代码行数:19,代码来源:ConcreteModuleDetector.java


示例6: checkExtendsClass

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void checkExtendsClass(ClassContext context, ClassNode classNode, int classMinSdk,
        String signature) {
    int api = mApiDatabase.getClassVersion(signature);
    if (api > classMinSdk) {
        String fqcn = ClassContext.getFqcn(signature);
        String message = String.format(
                "Class requires API level %1$d (current min is %2$d): `%3$s`",
                api, classMinSdk, fqcn);

        String name = signature.substring(signature.lastIndexOf('/') + 1);
        name = name.substring(name.lastIndexOf('$') + 1);
        SearchHints hints = SearchHints.create(BACKWARD).matchJavaSymbol();
        int lineNumber = ClassContext.findLineNumber(classNode);
        Location location = context.getLocationForLine(lineNumber, name, null,
                hints);
        context.report(UNSUPPORTED, location, message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ApiDetector.java


示例7: resolve

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@NonNull
@Override
public Location resolve() {
  if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
    return ApplicationManager.getApplication().runReadAction(new Computable<Location>() {
      @Override
      public Location compute() {
        return resolve();
      }
    });
  }
  TextRange textRange = DomPsiConverter.getTextRange(myNode);
  Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
  Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
  return Location.create(myFile, start, end);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DomPsiParser.java


示例8: visitSelect

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public boolean visitSelect(Select node) {
    String description = node.astIdentifier().astValue();
    boolean isIfRoom = description.equals("SHOW_AS_ACTION_IF_ROOM"); //$NON-NLS-1$
    boolean isAlways = description.equals("SHOW_AS_ACTION_ALWAYS");  //$NON-NLS-1$
    if ((isIfRoom || isAlways)
            && node.astOperand().toString().equals("MenuItem")) { //$NON-NLS-1$
        if (isAlways) {
            if (mContext.getDriver().isSuppressed(mContext, ISSUE, node)) {
                return super.visitSelect(node);
            }
            if (mAlwaysFields == null) {
                mAlwaysFields = new ArrayList<Location>();
            }
            mAlwaysFields.add(mContext.getLocation(node));
        } else {
            mHasIfRoomRefs = true;
        }
    }

    return super.visitSelect(node);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AlwaysShowActionDetector.java


示例9: beforeCheckFile

import com.android.tools.lint.detector.api.Location; //导入依赖的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


示例10: visitDocument

import com.android.tools.lint.detector.api.Location; //导入依赖的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


示例11: checkLauncherShape

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
/**
 * Check that launcher icons do not fill every pixel in the image
 */
private void checkLauncherShape(Context context, File file) {
    try {
        BufferedImage image = getImage(file);
        if (image != null) {
            // TODO: see if the shape is rectangular but inset from outer rectangle; if so
            // that's probably not right either!
            for (int y = 0, height = image.getHeight(); y < height; y++) {
                for (int x = 0, width = image.getWidth(); x < width; x++) {
                    int rgb = image.getRGB(x, y);
                    if ((rgb & 0xFF000000) == 0) {
                        return;
                    }
                }
            }

            String message = "Launcher icons should not fill every pixel of their square " +
                             "region; see the design guide for details";
            context.report(ICON_LAUNCHER_SHAPE, Location.create(file),
                    message);
        }
    } catch (IOException e) {
        // Pass: ignore files we can't read
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:IconDetector.java


示例12: checkInnerClass

import com.android.tools.lint.detector.api.Location; //导入依赖的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


示例13: visitElement

import com.android.tools.lint.detector.api.Location; //导入依赖的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


示例14: reportMap

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private void reportMap(Context context, Issue issue, Map<String, Location> map) {
    if (map != null) {
        for (Map.Entry<String, Location> entry : map.entrySet()) {
            Location location = entry.getValue();
            String name = entry.getKey();
            String message = mDescriptions.get(name);

            if (location == null) {
                location = Location.create(context.getProject().getDir());
            }

            // We were prepending locations, but we want to prefer the base folders
            location = Location.reverse(location);

            context.report(issue, location, message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TranslationDetector.java


示例15: run

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void run(@NonNull Context context) {
    if (!context.getProject().getReportIssues()) {
        // If this is a library project not being analyzed, ignore it
        return;
    }

    File file = context.file;
    if (isPrivateKeyFile(file)) {
        String fileName = file.getParentFile().getName() + File.separator
            + file.getName();
        String message = String.format(
            "The `%1$s` file seems to be a private key file. " +
            "Please make sure not to embed this in your APK file.", fileName);
        context.report(ISSUE, Location.create(file), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PrivateKeyDetector.java


示例16: refineLocation

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
private static Location refineLocation(Context context, Location location,
        String formatString, int substringStart, int substringEnd) {
    Position startLocation = location.getStart();
    Position endLocation = location.getEnd();
    if (startLocation != null && endLocation != null) {
        int startOffset = startLocation.getOffset();
        int endOffset = endLocation.getOffset();
        if (startOffset >= 0) {
            String contents = context.getClient().readFile(location.getFile());
            if (endOffset <= contents.length() && startOffset < endOffset) {
                int formatOffset = contents.indexOf(formatString, startOffset);
                if (formatOffset != -1 && formatOffset <= endOffset) {
                    return Location.create(location.getFile(), contents,
                            formatOffset + substringStart, formatOffset + substringEnd);
                }
            }
        }
    }

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


示例17: afterCheckProject

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void afterCheckProject(@NonNull Context context) {
    if (mPending != null && mWhitelistedLayouts != null) {
        // Process all the root FrameLayouts that are eligible, and generate
        // suggestions for <merge> replacements for any layouts that are included
        // from other layouts
        for (Pair<String, Handle> pair : mPending) {
            String layout = pair.getFirst();
            if (mWhitelistedLayouts.contains(layout)) {
                Handle handle = pair.getSecond();

                Object clientData = handle.getClientData();
                if (clientData instanceof Node) {
                    if (context.getDriver().isSuppressed(null, ISSUE, (Node) clientData)) {
                        return;
                    }
                }

                Location location = handle.resolve();
                context.report(ISSUE, location,
                        "This `<FrameLayout>` can be replaced with a `<merge>` tag");
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:MergeRootFrameLayoutDetector.java


示例18: checkClass

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
public void checkClass(@NonNull JavaContext context, @Nullable ClassDeclaration declaration,
        @NonNull Node node, @NonNull ResolvedClass cls) {
    if (!isInnerClass(declaration)) {
        return;
    }

    if (isStaticClass(declaration)) {
        return;
    }

    // Only flag handlers using the default looper
    if (hasLooperConstructorParameter(cls)) {
        return;
    }

    Node locationNode = node instanceof ClassDeclaration
            ? ((ClassDeclaration) node).astName() : node;
    Location location = context.getLocation(locationNode);
    context.report(ISSUE, location, String.format(
            "This Handler class should be static or leaks might occur (%1$s)",
            cls.getName()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:HandlerDetector.java


示例19: getValueLocation

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
@Override
@NonNull
public Location getValueLocation(@NonNull XmlContext context, @NonNull Attr node) {
    Location location = getLocation(context, node);
    Position start = location.getStart();
    Position end = location.getEnd();
    if (start == null || end == null) {
        return location;
    }
    int totalLength = end.getOffset() - start.getOffset();
    int length = node.getValue().length();
    int delta = totalLength - 1 - length;
    int startOffset = start.getOffset() + delta;
    int startColumn = start.getColumn() + delta;
    return Location.create(location.getFile(),
            new DefaultPosition(start.getLine(), startColumn, startOffset),
            new DefaultPosition(end.getLine(), startColumn + length, startOffset + length));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LintCliXmlParser.java


示例20: afterCheckClass

import com.android.tools.lint.detector.api.Location; //导入依赖的package包/类
public void afterCheckClass(Context context) {

        if (mMethods.size() == 0) return;

        JavaContext javaContext = (JavaContext) context;
        JavaEvaluator evaluator = javaContext.getEvaluator();
        if (evaluator == null) return;

        StringBuilder sb = new StringBuilder();

        boolean methodInDataAdapter = false;
        for (PsiMethod method : mMethods) {
            PsiClass pc = method.getContainingClass();
            boolean isSubclass = evaluator.implementsInterface(pc, CLASS_DATA_ADAPTER, false);

            methodInDataAdapter = methodInDataAdapter || isSubclass;

            if (!isSubclass) {
                sb.append(method.getName())
                        .append(",");
            }
        }

        if (!methodInDataAdapter) {
            context.report(ISSUE_VIEW_GROUP, Location.create(context.file), "the Custom ViewGroup with data bind should extend DataAdapter,method names:" + sb.toString());
        }
    }
 
开发者ID:jessie345,项目名称:CustomLintRules,代码行数:28,代码来源:AutoPointCustomViewGroupDetector.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RMAppAttemptStatusupdateEvent类代码示例发布时间:2022-05-22
下一篇:
Java MinguoEra类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap