mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SPI: containing package/class rename
This commit is contained in:
@@ -24,7 +24,8 @@ public interface SPIElementTypes {
|
||||
|
||||
IFileElementType FILE = new IFileElementType(SPILanguage.INSTANCE);
|
||||
IElementType PROVIDER = new IElementType("PROVIDER", SPILanguage.INSTANCE);
|
||||
IElementType PACK = new IElementType("PACK", SPILanguage.INSTANCE);
|
||||
|
||||
IElementType PROVIDERS_LIST = new IElementType("ROVIDER_LIST", SPILanguage.INSTANCE);
|
||||
IElementType PROVIDERS_LIST = new IElementType("PROVIDER_LIST", SPILanguage.INSTANCE);
|
||||
TokenSet PROVIDERS = TokenSet.create(PROVIDER);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.IFileElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.spi.psi.SPIPackElement;
|
||||
import com.intellij.spi.psi.SPIProviderElement;
|
||||
import com.intellij.spi.psi.SPIProvidersElementList;
|
||||
import com.intellij.spi.psi.SPIFile;
|
||||
@@ -99,6 +100,9 @@ public class SPIParserDefinition implements ParserDefinition {
|
||||
if (elementType == SPIElementTypes.PROVIDER) {
|
||||
return new SPIProviderElement(node);
|
||||
}
|
||||
if (elementType == SPIElementTypes.PACK) {
|
||||
return new SPIPackElement(node);
|
||||
}
|
||||
return PsiUtilCore.NULL_PSI_ELEMENT;
|
||||
}
|
||||
|
||||
@@ -116,7 +120,7 @@ public class SPIParserDefinition implements ParserDefinition {
|
||||
if (builder.getTokenType() == JavaTokenType.IDENTIFIER) {
|
||||
final PsiBuilder.Marker prop = builder.mark();
|
||||
|
||||
parseProviderChar(builder);
|
||||
parseProviderChar(builder, builder.mark());
|
||||
prop.done(SPIElementTypes.PROVIDER);
|
||||
}
|
||||
else {
|
||||
@@ -125,15 +129,16 @@ public class SPIParserDefinition implements ParserDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseProviderChar(final PsiBuilder builder) {
|
||||
private static void parseProviderChar(final PsiBuilder builder, PsiBuilder.Marker pack) {
|
||||
final IElementType initialTokenType = builder.getTokenType();
|
||||
if (initialTokenType == null) return;
|
||||
LOG.assertTrue(initialTokenType == JavaTokenType.IDENTIFIER);
|
||||
builder.advanceLexer();
|
||||
pack.done(SPIElementTypes.PACK);
|
||||
final IElementType tokenType = builder.getTokenType();
|
||||
if (tokenType == JavaTokenType.DOT || tokenType == SPITokenType.DOLLAR) {
|
||||
builder.advanceLexer();
|
||||
parseProviderChar(builder);
|
||||
parseProviderChar(builder, pack.precede());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.spi.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
public class SPIPackElement extends SPIProviderElement {
|
||||
public SPIPackElement(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(getText());
|
||||
if (aPackage != null) {
|
||||
return aPackage;
|
||||
}
|
||||
return super.resolve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
if (element instanceof PsiPackage) {
|
||||
return handleElementRename(((PsiPackage)element).getQualifiedName());
|
||||
}
|
||||
return super.bindToElement(element);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
if (element instanceof PsiPackage) {
|
||||
return getText().equals(((PsiPackage)element).getQualifiedName());
|
||||
}
|
||||
return super.isReferenceTo(element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,9 @@ import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.ClassCandidateInfo;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.spi.SPIFileType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -32,41 +31,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaReference {
|
||||
public class SPIProviderElement extends ASTWrapperPsiElement implements PsiReference {
|
||||
public SPIProviderElement(ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processVariants(PsiScopeProcessor processor) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult advancedResolve(boolean incompleteCode) {
|
||||
final PsiElement resolve = resolve();
|
||||
if (resolve instanceof PsiClass) {
|
||||
return new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
return JavaResolveResult.EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
|
||||
final PsiElement resolve = resolve();
|
||||
if (resolve instanceof PsiClass) {
|
||||
return new JavaResolveResult[]{new ClassCandidateInfo(resolve, PsiSubstitutor.EMPTY)};
|
||||
}
|
||||
return JavaResolveResult.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return this;
|
||||
@@ -74,7 +48,8 @@ public class SPIProviderElement extends ASTWrapperPsiElement implements PsiJavaR
|
||||
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
return new TextRange(0, getTextLength());
|
||||
final PsiElement last = PsiTreeUtil.getDeepestLast(this);
|
||||
return new TextRange(last.getStartOffsetInParent(), getTextLength());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user