use of com.sun.source.tree.ArrayTypeTree in project error-prone by google.
the class MixedArrayDimensions method checkArrayDimensions.
private Description checkArrayDimensions(Tree tree, Tree type, VisitorState state) {
if (!(type instanceof ArrayTypeTree)) {
return NO_MATCH;
}
CharSequence source = state.getSourceCode();
for (; type instanceof ArrayTypeTree; type = ((ArrayTypeTree) type).getType()) {
Tree elemType = ((ArrayTypeTree) type).getType();
int start = state.getEndPosition(elemType);
int end = state.getEndPosition(type);
if (start >= end) {
continue;
}
String dim = source.subSequence(start, end).toString();
if (dim.isEmpty()) {
continue;
}
ImmutableList<ErrorProneToken> tokens = ErrorProneTokens.getTokens(dim.trim(), state.context);
if (tokens.size() > 2 && tokens.get(0).kind() == TokenKind.IDENTIFIER) {
int nonWhitespace = CharMatcher.isNot(' ').indexIn(dim);
int idx = dim.indexOf("[]", nonWhitespace);
if (idx > nonWhitespace) {
String replacement = dim.substring(idx, dim.length()) + dim.substring(0, idx);
return describeMatch(tree, SuggestedFix.replace(start, end, replacement));
}
}
}
return NO_MATCH;
}
Aggregations