下面列出了怎么用com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference的API类实例代码及写法,或者点击链接到github查看源代码。
@RequiredWriteAction
public static NonCodeUsageInfo[] retargetUsages(UsageInfo[] usages)
{
final List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for(UsageInfo usageInfo : usages)
{
if(usageInfo instanceof MyUsageInfo)
{
MyUsageInfo info = (MyUsageInfo) usageInfo;
DotNetNamedElement declaration = info.myDeclarationAndResolveTargetCouple.getFirst();
if(info.getReference() instanceof FileReference || info.getReference() instanceof PsiDynaReference)
{
final PsiElement usageElement = info.getElement();
if(usageElement != null)
{
final PsiFile usageFile = usageElement.getContainingFile();
final PsiFile psiFile = usageFile.getViewProvider().getPsi(usageFile.getViewProvider().getBaseLanguage());
if(psiFile != null && psiFile.equals(declaration.getContainingFile()))
{
continue; // already processed in MoveFilesOrDirectoriesUtil.doMoveFile
}
}
}
final PsiElement refElement = info.myReference.getElement();
if(refElement != null && refElement.isValid())
{
info.myReference.bindToElement(info.myDeclarationAndResolveTargetCouple.getFirst());
}
}
else if(usageInfo instanceof NonCodeUsageInfo)
{
nonCodeUsages.add((NonCodeUsageInfo) usageInfo);
}
}
return nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
}
/**
* Returns last reference of the current element's references.
*
* @return last {@link FileReference}
*/
@Nullable
public FileReference getLastReference() {
FileReference lastReference = super.getLastReference();
if (lastReference != null && lastReference.getCanonicalText().endsWith(getSeparatorString())) {
return this.myReferences != null && this.myReferences.length > 1 ?
this.myReferences[this.myReferences.length - 2] : null;
}
return lastReference;
}
@Override
public PsiElement bindToElement(@Nonnull PsiElement element) throws IncorrectOperationException {
for (PsiReference reference : myReferences) {
if (reference instanceof FileReference) {
return reference.bindToElement(element);
}
}
return myElement;
}
protected void retargetUsages(UsageInfo[] usages, Map<PsiElement, PsiElement> oldToNewMap) {
final List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for (UsageInfo usageInfo : usages) {
if (usageInfo instanceof MyUsageInfo) {
final MyUsageInfo info = (MyUsageInfo)usageInfo;
final PsiElement element = myElementsToMove[info.myIndex];
if (info.getReference() instanceof FileReference || info.getReference() instanceof PsiDynaReference) {
final PsiElement usageElement = info.getElement();
if (usageElement != null) {
final PsiFile usageFile = usageElement.getContainingFile();
final PsiFile psiFile = usageFile.getViewProvider().getPsi(usageFile.getViewProvider().getBaseLanguage());
if (psiFile != null && psiFile.equals(element)) {
continue; // already processed in MoveFilesOrDirectoriesUtil.doMoveFile
}
}
}
final PsiElement refElement = info.myReference.getElement();
if (refElement != null && refElement.isValid()) {
info.myReference.bindToElement(element);
}
} else if (usageInfo instanceof NonCodeUsageInfo) {
nonCodeUsages.add((NonCodeUsageInfo)usageInfo);
}
}
for (PsiFile movedFile : myFoundUsages.keySet()) {
MoveFileHandler.forElement(movedFile).retargetUsages(myFoundUsages.get(movedFile), oldToNewMap);
}
myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
}
/**
* Parses entry, searches for file references and stores them in {@link #myReferences}.
*/
@Override
protected void reparse() {
ProgressManager.checkCanceled();
String str = StringUtil.trimEnd(getPathString(), getSeparatorString());
final List<FileReference> referencesList = new ArrayList<>();
String separatorString = getSeparatorString(); // separator's length can be more then 1 char
int sepLen = separatorString.length();
int currentSlash = -sepLen;
int startInElement = getStartInElement();
// skip white space
while (currentSlash + sepLen < str.length() && Character.isWhitespace(str.charAt(currentSlash + sepLen))) {
currentSlash++;
}
if (currentSlash + sepLen + sepLen < str.length() && str.substring(currentSlash + sepLen,
currentSlash + sepLen + sepLen).equals(separatorString)) {
currentSlash += sepLen;
}
int index = 0;
if (str.equals(separatorString)) {
final FileReference fileReference = createFileReference(
new TextRange(startInElement, startInElement + sepLen),
index++,
separatorString
);
referencesList.add(fileReference);
}
while (true) {
ProgressManager.checkCanceled();
final int nextSlash = str.indexOf(separatorString, currentSlash + sepLen);
final String subReferenceText = nextSlash > 0 ? str.substring(0, nextSlash) : str;
TextRange range = new TextRange(startInElement + currentSlash + sepLen, startInElement +
(nextSlash > 0 ? nextSlash : str.length()));
final FileReference ref = createFileReference(range, index++, subReferenceText);
referencesList.add(ref);
if ((currentSlash = nextSlash) < 0) {
break;
}
}
myReferences = referencesList.toArray(new FileReference[0]);
}
public MyCreateFileFix(boolean isdirectory, String newFileName, PsiDirectory directory, FileReference reference) {
super(isdirectory, newFileName, directory);
isDirectory = isdirectory;
myNewFileTemplateName = isDirectory ? null : reference.getNewFileTemplateName();
}
public RenameFileReferenceIntentionAction(final String existingElementName, final FileReference fileReference) {
myExistingElementName = existingElementName;
myFileReference = fileReference;
}
/**
* Creates {@link IgnoreReference} instance basing on passed text value.
*
* @param range text range
* @param index start index
* @param text string text
* @return file reference
*/
@Override
public FileReference createFileReference(TextRange range, int index, String text) {
return new IgnoreReference(this, range, index, text);
}