From 71dc3a0f8857823e409dfbcdb5b70969ab535031 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 7 Jun 2013 18:26:14 +0400 Subject: [PATCH] SPI: containing package/class rename --- .../intellij/spi/parsing/SPIElementTypes.java | 3 +- .../spi/parsing/SPIParserDefinition.java | 11 +++- .../com/intellij/spi/psi/SPIPackElement.java | 66 +++++++++++++++++++ .../intellij/spi/psi/SPIProviderElement.java | 33 ++-------- 4 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 java/java-impl/src/com/intellij/spi/psi/SPIPackElement.java diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java b/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java index 228a8459d14f..585e11ecac88 100644 --- a/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java +++ b/java/java-impl/src/com/intellij/spi/parsing/SPIElementTypes.java @@ -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); } diff --git a/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java b/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java index 509209204df6..a123511bc72a 100644 --- a/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java +++ b/java/java-impl/src/com/intellij/spi/parsing/SPIParserDefinition.java @@ -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()); } } } diff --git a/java/java-impl/src/com/intellij/spi/psi/SPIPackElement.java b/java/java-impl/src/com/intellij/spi/psi/SPIPackElement.java new file mode 100644 index 000000000000..12fd2c5b0b67 --- /dev/null +++ b/java/java-impl/src/com/intellij/spi/psi/SPIPackElement.java @@ -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; + } +} diff --git a/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java b/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java index 6ad7e590015c..27c6557ed93a 100644 --- a/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java +++ b/java/java-impl/src/com/intellij/spi/psi/SPIProviderElement.java @@ -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