mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find file reference by element
This commit is contained in:
+17
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.paths.PsiDynaReference;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -64,4 +65,19 @@ public class FileReferenceUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FileReference findFileReference(@NotNull PsiElement element) {
|
||||
final PsiReference[] references = element.getReferences();
|
||||
for (int i = references.length - 1; i >= 0; i--) {
|
||||
PsiReference ref = references[i];
|
||||
if (ref instanceof PsiDynaReference) {
|
||||
ref = ((PsiDynaReference)ref).getLastFileReference();
|
||||
}
|
||||
if (ref instanceof FileReference) {
|
||||
return (FileReference)references[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user