Search in sources :

Example 1 with DefaultPosition

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

the class JavaParser method getNameLocation.

/**
     * Returns a {@link Location} for the given node. This attempts to pick a shorter
     * location range than the entire node; for a class or method for example, it picks
     * the name node (if found). For statement constructs such as a {@code switch} statement
     * it will highlight the keyword, etc.
     *
     * @param context information about the file being parsed
     * @param node the node to create a location for
     * @return a location for the given node
     * @deprecated Use {@link #getNameLocation(JavaContext, PsiElement)} instead
     */
@Deprecated
@NonNull
public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) {
    Node nameNode = JavaContext.findNameNode(node);
    if (nameNode != null) {
        node = nameNode;
    } else {
        if (node instanceof Switch || node instanceof For || node instanceof If || node instanceof While || node instanceof Throw || node instanceof Return) {
            // Lint doesn't want to highlight the entire statement/block associated
            // with this node, it wants to just highlight the keyword.
            Location location = getLocation(context, node);
            Position start = location.getStart();
            if (start != null) {
                // The Lombok classes happen to have the same length as the target keyword
                int length = node.getClass().getSimpleName().length();
                return Location.create(location.getFile(), start, new DefaultPosition(start.getLine(), start.getColumn() + length, start.getOffset() + length));
            }
        }
    }
    return getLocation(context, node);
}
Also used : Return(lombok.ast.Return) Switch(lombok.ast.Switch) Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) Throw(lombok.ast.Throw) Node(lombok.ast.Node) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) For(lombok.ast.For) While(lombok.ast.While) If(lombok.ast.If) Location(com.android.tools.klint.detector.api.Location) NonNull(com.android.annotations.NonNull)

Example 2 with DefaultPosition

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

the class DomPsiParser method getLocation.

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node, int startDelta, int endDelta) {
    TextRange textRange = DomPsiConverter.getTextRange(node);
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset() + startDelta);
    Position end = new DefaultPosition(-1, -1, textRange.getStartOffset() + endDelta);
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 3 with DefaultPosition

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

the class DomPsiParser method getValueLocation.

@NonNull
@Override
public Location getValueLocation(@NonNull XmlContext context, @NonNull Attr node) {
    TextRange textRange = DomPsiConverter.getTextValueRange(node);
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
    Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 4 with DefaultPosition

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

the class DomPsiParser method getLocation.

@NonNull
@Override
public Location getLocation(@NonNull XmlContext context, @NonNull Node node) {
    TextRange textRange = DomPsiConverter.getTextRange(node);
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
    Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Example 5 with DefaultPosition

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

the class DomPsiParser method getNameLocation.

@NonNull
@Override
public Location getNameLocation(@NonNull XmlContext context, @NonNull Node node) {
    TextRange textRange = DomPsiConverter.getTextNameRange(node);
    Position start = new DefaultPosition(-1, -1, textRange.getStartOffset());
    Position end = new DefaultPosition(-1, -1, textRange.getEndOffset());
    return Location.create(context.file, start, end);
}
Also used : Position(com.android.tools.klint.detector.api.Position) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) DefaultPosition(com.android.tools.klint.detector.api.DefaultPosition) TextRange(com.intellij.openapi.util.TextRange) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)5 DefaultPosition (com.android.tools.klint.detector.api.DefaultPosition)5 Position (com.android.tools.klint.detector.api.Position)5 TextRange (com.intellij.openapi.util.TextRange)4 Location (com.android.tools.klint.detector.api.Location)1 For (lombok.ast.For)1 If (lombok.ast.If)1 Node (lombok.ast.Node)1 Return (lombok.ast.Return)1 Switch (lombok.ast.Switch)1 Throw (lombok.ast.Throw)1 While (lombok.ast.While)1