new DefaultPosition(-1, -1, startOffset), new DefaultPosition(-1, -1, endOffset)); for (int offset = 0; offset <= size; offset++) { if (offset == startOffset) { start = new DefaultPosition(line, offset - lineOffset, offset); Position end = new DefaultPosition(line, offset - lineOffset, offset); return new Location(file, start, end);
start = new DefaultPosition(line, column, offset); location = Location.create(context.file, start, location.getEnd());
start = new DefaultPosition(line, column, offset); location = Location.create(context.file, start, location.getEnd());
/** * Creates a new location for the given file and SourcePosition. * * @param file the file containing the positions * @param position the source position * @return a new location */ @NonNull public static Location create( @NonNull File file, @NonNull SourcePosition position) { if (position.equals(SourcePosition.UNKNOWN)) { return new Location(file, null /*start*/, null /*end*/); } return new Location(file, new DefaultPosition( position.getStartLine(), position.getStartColumn(), position.getStartOffset()), new DefaultPosition( position.getEndLine(), position.getEndColumn(), position.getEndOffset())); }
@Override protected Location createLocation(@NonNull Context context, @NonNull Object cookie) { ASTNode node = (ASTNode) cookie; Pair<Integer, Integer> offsets = getOffsets(node, context); int fromLine = node.getLineNumber() - 1; int fromColumn = node.getColumnNumber() - 1; int toLine = node.getLastLineNumber() - 1; int toColumn = node.getLastColumnNumber() - 1; return Location.create(context.file, new DefaultPosition(fromLine, fromColumn, offsets.getFirst()), new DefaultPosition(toLine, toColumn, offsets.getSecond())); } }
@Override @NonNull public Location getNameLocation(@NonNull XmlContext context, @NonNull Node node) { Location location = getLocation(context, node); Position start = location.getStart(); Position end = location.getEnd(); if (start == null || end == null) { return location; } int delta = node instanceof Element ? 1 : 0; // Elements: skip "<" int length = node.getNodeName().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)); }
@Override protected Location createLocation(@NonNull Context context, @NonNull Object cookie) { ASTNode node = (ASTNode) cookie; Pair<Integer, Integer> offsets = getOffsets(node, context); int fromLine = node.getLineNumber() - 1; int fromColumn = node.getColumnNumber() - 1; int toLine = node.getLastLineNumber() - 1; int toColumn = node.getLastColumnNumber() - 1; return Location.create(context.file, new DefaultPosition(fromLine, fromColumn, offsets.getFirst()), new DefaultPosition(toLine, toColumn, offsets.getSecond())); } }
int end = indexOf(contents, patternEnd, offset + patternStart.length()); if (end != -1) { return new Location(file, new DefaultPosition(line, column, index), new DefaultPosition(line, -1, end + patternEnd.length())); patternStart = SUPER_KEYWORD; return new Location(file, new DefaultPosition(line, column, index), new DefaultPosition(line, column + patternStart.length(), index + patternStart.length())); return new Location(file, new DefaultPosition(line, column, index), new DefaultPosition(line, column, index + patternStart.length())); Position position = new DefaultPosition(line, -1, offset); return new Location(file, position, position);
@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)); }
new DefaultPosition(start.getLine(), start.getColumn() + length, start.getOffset() + length));
int startColumn = start.getColumn(); int startLine = start.getLine(); start = new DefaultPosition(startLine, startColumn + startOffset - start.getOffset(), startOffset); int fqcnLength = fqcn.length(); Position end = new DefaultPosition(startLine, start.getColumn() + fqcnLength, start.getOffset() + fqcnLength);
new DefaultPosition(0, 0, 0), new DefaultPosition(0, firstLineEnd, firstLineEnd)); } else { location = Location.create(context.file);
@Override @NonNull public Location getNameLocation(@NonNull JavaContext context, @NonNull Node node) { // The range on method name identifiers is wrong in the ECJ nodes; just take start of // name + length of name if (node instanceof MethodDeclaration) { MethodDeclaration declaration = (MethodDeclaration) node; Identifier identifier = declaration.astMethodName(); Location location = getLocation(context, identifier); com.android.tools.lint.detector.api.Position start = location.getStart(); com.android.tools.lint.detector.api.Position end = location.getEnd(); int methodNameLength = identifier.astValue().length(); if (start != null && end != null && end.getOffset() - start.getOffset() > methodNameLength) { end = new DefaultPosition(start.getLine(), start.getColumn() + methodNameLength, start.getOffset() + methodNameLength); return Location.create(location.getFile(), start, end); } return location; } return super.getNameLocation(context, node); }