KtAnnotationEntry#name is stubbed and is nullable
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.KtNodeTypes;
|
import org.jetbrains.kotlin.KtNodeTypes;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
|
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
||||||
|
|
||||||
@@ -121,4 +122,28 @@ public class KtAnnotationEntry extends KtElementImplStub<KotlinAnnotationEntrySt
|
|||||||
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Name getShortName() {
|
||||||
|
KotlinAnnotationEntryStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
String shortName = stub.getShortName();
|
||||||
|
if (shortName != null) {
|
||||||
|
return Name.identifier(shortName);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
KtTypeReference typeReference = getTypeReference();
|
||||||
|
assert typeReference != null : "Annotation entry hasn't typeReference " + getText();
|
||||||
|
KtTypeElement typeElement = typeReference.getTypeElement();
|
||||||
|
if (typeElement instanceof KtUserType) {
|
||||||
|
KtUserType userType = (KtUserType) typeElement;
|
||||||
|
String shortName = userType.getReferencedName();
|
||||||
|
if (shortName != null) {
|
||||||
|
return Name.identifier(shortName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,27 +174,12 @@ public class KtPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static Name getShortName(@NotNull KtAnnotationEntry annotation) {
|
|
||||||
KtTypeReference typeReference = annotation.getTypeReference();
|
|
||||||
assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
|
|
||||||
KtTypeElement typeElement = typeReference.getTypeElement();
|
|
||||||
if (typeElement instanceof KtUserType) {
|
|
||||||
KtUserType userType = (KtUserType) typeElement;
|
|
||||||
String shortName = userType.getReferencedName();
|
|
||||||
if (shortName != null) {
|
|
||||||
return Name.identifier(shortName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isDeprecated(@NotNull KtModifierListOwner owner) {
|
public static boolean isDeprecated(@NotNull KtModifierListOwner owner) {
|
||||||
KtModifierList modifierList = owner.getModifierList();
|
KtModifierList modifierList = owner.getModifierList();
|
||||||
if (modifierList != null) {
|
if (modifierList != null) {
|
||||||
List<KtAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
List<KtAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||||
for (KtAnnotationEntry annotation : annotationEntries) {
|
for (KtAnnotationEntry annotation : annotationEntries) {
|
||||||
Name shortName = getShortName(annotation);
|
Name shortName = annotation.getShortName();
|
||||||
if (KotlinBuiltIns.FQ_NAMES.deprecated.shortName().equals(shortName)) {
|
if (KotlinBuiltIns.FQ_NAMES.deprecated.shortName().equals(shortName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ interface KotlinObjectStub : KotlinClassOrObjectStub<KtObjectDeclaration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinAnnotationEntryStub : StubElement<KtAnnotationEntry> {
|
interface KotlinAnnotationEntryStub : StubElement<KtAnnotationEntry> {
|
||||||
fun getShortName(): String
|
fun getShortName(): String?
|
||||||
fun hasValueArguments(): Boolean
|
fun hasValueArguments(): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -40,8 +40,8 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
|
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
|
||||||
Name shortName = KtPsiUtil.getShortName(psi);
|
Name shortName = psi.getShortName();
|
||||||
String resultName = shortName != null ? shortName.asString() : psi.getText();
|
String resultName = shortName != null ? shortName.asString() : null;
|
||||||
KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
|
KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
|
||||||
boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
|
boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
|
||||||
return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments);
|
return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments);
|
||||||
|
|||||||
+2
-2
@@ -25,11 +25,11 @@ import com.intellij.psi.PsiElement
|
|||||||
|
|
||||||
class KotlinAnnotationEntryStubImpl(
|
class KotlinAnnotationEntryStubImpl(
|
||||||
parent: StubElement<out PsiElement>?,
|
parent: StubElement<out PsiElement>?,
|
||||||
private val shortName: StringRef,
|
private val shortName: StringRef?,
|
||||||
private val hasValueArguments: Boolean
|
private val hasValueArguments: Boolean
|
||||||
) : KotlinStubBaseImpl<KtAnnotationEntry>(parent, KtStubElementTypes.ANNOTATION_ENTRY), KotlinAnnotationEntryStub {
|
) : KotlinStubBaseImpl<KtAnnotationEntry>(parent, KtStubElementTypes.ANNOTATION_ENTRY), KotlinAnnotationEntryStub {
|
||||||
|
|
||||||
override fun getShortName() = shortName.string
|
override fun getShortName() = shortName?.string
|
||||||
|
|
||||||
override fun hasValueArguments() = hasValueArguments
|
override fun hasValueArguments() = hasValueArguments
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user