Search in sources :

Example 1 with SearchHints

use of com.android.tools.klint.detector.api.Location.SearchHints in project kotlin by JetBrains.

the class ClassContext method getLocation.

/**
     * Returns a location for the given {@link AbstractInsnNode}.
     *
     * @param instruction the instruction to look up the location for
     * @return a location pointing to the instruction, or as close to it
     *         as possible
     */
@NonNull
public Location getLocation(@NonNull AbstractInsnNode instruction) {
    SearchHints hints = SearchHints.create(FORWARD).matchJavaSymbol();
    String pattern = null;
    if (instruction instanceof MethodInsnNode) {
        MethodInsnNode call = (MethodInsnNode) instruction;
        if (call.name.equals(CONSTRUCTOR_NAME)) {
            pattern = call.owner;
            hints = hints.matchConstructor();
        } else {
            pattern = call.name;
        }
        int index = pattern.lastIndexOf('$');
        if (index != -1) {
            pattern = pattern.substring(index + 1);
        }
        index = pattern.lastIndexOf('/');
        if (index != -1) {
            pattern = pattern.substring(index + 1);
        }
    }
    int line = findLineNumber(instruction);
    return getLocationForLine(line, pattern, null, hints);
}
Also used : MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) SearchHints(com.android.tools.klint.detector.api.Location.SearchHints) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)1 SearchHints (com.android.tools.klint.detector.api.Location.SearchHints)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1