use of org.jetbrains.uast.UFile in project kotlin by JetBrains.
the class JavaParser method getLocation.
/**
* Returns a {@link Location} for the given element
*
* @param context information about the file being parsed
* @param element the element to create a location for
* @return a location for the given node
*/
// subclasses may want to override/optimize
@SuppressWarnings("MethodMayBeStatic")
@NonNull
public Location getLocation(@NonNull JavaContext context, @NonNull PsiElement element) {
TextRange range = element.getTextRange();
UFile uFile = (UFile) getUastContext().convertElementWithParent(element.getContainingFile(), UFile.class);
if (uFile == null) {
return Location.NONE;
}
PsiFile containingFile = uFile.getPsi();
File file = context.file;
if (containingFile != context.getUFile().getPsi()) {
// Reporting an error in a different file.
if (context.getDriver().getScope().size() == 1) {
// Don't bother with this error if it's in a different file during single-file analysis
return Location.NONE;
}
VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile == null) {
return Location.NONE;
}
file = VfsUtilCore.virtualToIoFile(virtualFile);
}
return Location.create(file, context.getContents(), range.getStartOffset(), range.getEndOffset());
}
Aggregations