Search in sources :

Example 1 with UFile

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextRange(com.intellij.openapi.util.TextRange) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UFile(org.jetbrains.uast.UFile) PsiJavaFile(com.intellij.psi.PsiJavaFile) File(java.io.File) UFile(org.jetbrains.uast.UFile) NonNull(com.android.annotations.NonNull)

Aggregations

NonNull (com.android.annotations.NonNull)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 File (java.io.File)1 UFile (org.jetbrains.uast.UFile)1