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


Java LintUtils.getPrevInstruction方法代码示例

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


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

示例1: checkSimpleDateFormat

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
private static void checkSimpleDateFormat(ClassContext context, MethodNode method,
        MethodInsnNode node, int minSdk) {
    if (minSdk >= 9) {
        // Already OK
        return;
    }
    if (node.name.equals(CONSTRUCTOR_NAME) && !node.desc.equals("()V")) { //$NON-NLS-1$
        // Check first argument
        AbstractInsnNode prev = LintUtils.getPrevInstruction(node);
        if (prev != null && !node.desc.equals("(Ljava/lang/String;)V")) { //$NON-NLS-1$
            prev = LintUtils.getPrevInstruction(prev);
        }
        if (prev != null && prev.getOpcode() == Opcodes.LDC) {
            LdcInsnNode ldc = (LdcInsnNode) prev;
            Object cst = ldc.cst;
            if (cst instanceof String) {
                String pattern = (String) cst;
                boolean isEscaped = false;
                for (int i = 0; i < pattern.length(); i++) {
                    char c = pattern.charAt(i);
                    if (c == '\'') {
                        isEscaped = !isEscaped;
                    } else  if (!isEscaped && (c == 'L' || c == 'c')) {
                        String message = String.format(
                                "The pattern character '%1$c' requires API level 9 (current " +
                                "min is %2$d) : \"`%3$s`\"", c, minSdk, pattern);
                        report(context, message, node, method, pattern, null,
                                SearchHints.create(FORWARD));
                        return;
                    }
                }
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:ApiDetector.java

示例2: checkInstruction

import com.android.tools.lint.detector.api.LintUtils; //导入方法依赖的package包/类
@Override
public void checkInstruction(@NonNull ClassContext context, @NonNull ClassNode classNode,
        @NonNull MethodNode method, @NonNull AbstractInsnNode instruction) {
    // As of Gingerbread/API 9, Dalvik performs this optimization automatically
    if (context.getProject().getMinSdk() >= 9) {
        return;
    }

    if ((method.access & Opcodes.ACC_STATIC) != 0) {
        // Not an instance method
        return;
    }

    if (instruction.getOpcode() != Opcodes.INVOKEVIRTUAL) {
        return;
    }

    MethodInsnNode node = (MethodInsnNode) instruction;
    String name = node.name;
    String owner = node.owner;

    AbstractInsnNode prev = LintUtils.getPrevInstruction(instruction);
    if (prev == null || prev.getOpcode() != Opcodes.ALOAD) {
        return;
    }
    VarInsnNode prevVar = (VarInsnNode) prev;
    if (prevVar.var != 0) { // Not on "this", variable 0 in instance methods?
        return;
    }

    if (((name.startsWith("get") && name.length() > 3     //$NON-NLS-1$
            && Character.isUpperCase(name.charAt(3)))
        || (name.startsWith("is") && name.length() > 2    //$NON-NLS-1$
            && Character.isUpperCase(name.charAt(2))))
            && owner.equals(classNode.name)) {
        // Calling a potential getter method on self. We now need to
        // investigate the method body of the getter call and make sure
        // it's really a plain getter, not just a method which happens
        // to have a method name like a getter, or a method which not
        // only returns a field but possibly computes it or performs
        // other initialization or side effects. This is done in a
        // second pass over the bytecode, initiated by the finish()
        // method.
        if (mPendingCalls == null) {
            mPendingCalls = new ArrayList<Entry>();
        }

        mPendingCalls.add(new Entry(name, node, method));
    }

    super.checkInstruction(context, classNode, method, instruction);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:53,代码来源:FieldGetterDetector.java


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