/** * Returns a location for the given node range (from the starting offset of the first node to * the ending offset of the second node). * * @param from the AST node to get a starting location from * @param fromDelta Offset delta to apply to the starting offset * @param length The number of characters to add from the delta * @return a location for the given node */ @NonNull public Location getRangeLocation( @NonNull PsiElement from, int fromDelta, int length) { return parser.getRangeLocation(this, from, fromDelta, fromDelta + length); }
/** * 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 element the AST node to create a location for * @return a location for the given node */ @NonNull public Location getNameLocation(@NonNull PsiElement element) { if (element instanceof PsiSwitchStatement) { // Just use keyword return parser.getRangeLocation(this, element, 0, 6); // 6: "switch".length() } return parser.getNameLocation(this, element); }
/** * Returns a location for the given node range (from the starting offset of the first node to * the ending offset of the second node). * * @param from the AST node to get a starting location from * @param fromDelta Offset delta to apply to the starting offset * @param to the AST node to get a ending location from * @param toDelta Offset delta to apply to the ending offset * @return a location for the given node */ @NonNull public Location getRangeLocation( @NonNull Node from, int fromDelta, @NonNull Node to, int toDelta) { return parser.getRangeLocation(this, from, fromDelta, to, toDelta); }
/** * Returns a location for the given node range (from the starting offset of the first node to * the ending offset of the second node). * * @param from the AST node to get a starting location from * @param fromDelta Offset delta to apply to the starting offset * @param to the AST node to get a ending location from * @param toDelta Offset delta to apply to the ending offset * @return a location for the given node */ @NonNull public Location getRangeLocation( @NonNull PsiElement from, int fromDelta, @NonNull PsiElement to, int toDelta) { return parser.getRangeLocation(this, from, fromDelta, to, toDelta); }
/** * Like {@link #getRangeLocation(JavaContext, PsiElement, int, PsiElement, int)} * but both offsets are relative to the starting offset of the given node. This is * sometimes more convenient than operating relative to the ending offset when you * have a fixed range in mind. * * @param context information about the file being parsed * @param from the AST node to get a starting location from * @param fromDelta Offset delta to apply to the starting offset * @param toDelta Offset delta to apply to the starting offset * @return a location for the given node */ @SuppressWarnings("MethodMayBeStatic") // subclasses may want to override/optimize @NonNull public Location getRangeLocation( @NonNull JavaContext context, @NonNull PsiElement from, int fromDelta, int toDelta) { return getRangeLocation(context, from, fromDelta, from, -(from.getTextRange().getLength() - toDelta)); }