Search in sources :

Example 1 with SearchDirection

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

the class ClassContext method getLocation.

/**
     * Returns a location for the given {@link MethodNode}.
     *
     * @param methodNode the class in the current context
     * @param classNode the class containing the method
     * @return a location pointing to the class declaration, or as close to it
     *         as possible
     */
@NonNull
public Location getLocation(@NonNull MethodNode methodNode, @NonNull ClassNode classNode) {
    // Attempt to find a proper location for this class. This is tricky
    // since classes do not have line number entries in the class file; we need
    // to find a method, look up the corresponding line number then search
    // around it for a suitable tag, such as the class name.
    String pattern;
    SearchDirection searchMode;
    if (methodNode.name.equals(CONSTRUCTOR_NAME)) {
        searchMode = EOL_BACKWARD;
        if (isAnonymousClass(classNode.name)) {
            pattern = classNode.superName.substring(classNode.superName.lastIndexOf('/') + 1);
        } else {
            pattern = classNode.name.substring(classNode.name.lastIndexOf('$') + 1);
        }
    } else {
        searchMode = BACKWARD;
        pattern = methodNode.name;
    }
    return getLocationForLine(findLineNumber(methodNode), pattern, null, SearchHints.create(searchMode).matchJavaSymbol());
}
Also used : SearchDirection(com.android.tools.klint.detector.api.Location.SearchDirection) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)1 SearchDirection (com.android.tools.klint.detector.api.Location.SearchDirection)1