mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SPI: support rename of providers
This commit is contained in:
@@ -20,7 +20,7 @@ import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.lang.spi.SPILanguage;
|
||||
|
||||
interface SPIElementTypes {
|
||||
public interface SPIElementTypes {
|
||||
|
||||
IFileElementType FILE = new IFileElementType(SPILanguage.INSTANCE);
|
||||
IElementType PROVIDER = new IElementType("PROVIDER", SPILanguage.INSTANCE);
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.ClassCandidateInfo;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.spi.SPIFileType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,7 +37,8 @@ public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaR
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processVariants(PsiScopeProcessor processor) {}
|
||||
public void processVariants(PsiScopeProcessor processor) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -53,7 +55,7 @@ public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaR
|
||||
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final PsiElement resolve = resolve();
|
||||
if (resolve instanceof PsiClass) {
|
||||
return new JavaResolveResult[] {new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY)};
|
||||
return new JavaResolveResult[]{new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY)};
|
||||
}
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
@@ -82,11 +84,20 @@ public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaR
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
return null;
|
||||
final SPIProvidersElementList firstChild =
|
||||
(SPIProvidersElementList)PsiFileFactory.getInstance(getProject())
|
||||
.createFileFromText("spi_dummy", SPIFileType.INSTANCE, newElementName).getFirstChild();
|
||||
return replace(firstChild.getElements().get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
if (element instanceof PsiClass) {
|
||||
final String className = ClassUtil.getJVMClassName((PsiClass)element);
|
||||
if (className != null) {
|
||||
return handleElementRename(className);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,12 @@ package com.intellij.spi.psi;
|
||||
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.spi.parsing.SPIElementType;
|
||||
import com.intellij.spi.parsing.SPIElementTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
@@ -26,4 +30,8 @@ public class SPIProvidersElementList extends ASTWrapperPsiElement {
|
||||
public SPIProvidersElementList(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public List<SPIProviderElement> getElements() {
|
||||
return findChildrenByType(SPIElementTypes.PROVIDER);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user