KtAnnotationEntry#name is stubbed and is nullable

This commit is contained in:
Pavel V. Talanov
2018-02-08 18:51:12 +01:00
parent 8600add7f7
commit 8f8cbfcfa5
5 changed files with 31 additions and 21 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.KtNodeTypes;
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.elements.KtStubElementTypes;
@@ -121,4 +122,28 @@ public class KtAnnotationEntry extends KtElementImplStub<KotlinAnnotationEntrySt
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) {
KtModifierList modifierList = owner.getModifierList();
if (modifierList != null) {
List<KtAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
for (KtAnnotationEntry annotation : annotationEntries) {
Name shortName = getShortName(annotation);
Name shortName = annotation.getShortName();
if (KotlinBuiltIns.FQ_NAMES.deprecated.shortName().equals(shortName)) {
return true;
}
@@ -57,7 +57,7 @@ interface KotlinObjectStub : KotlinClassOrObjectStub<KtObjectDeclaration> {
}
interface KotlinAnnotationEntryStub : StubElement<KtAnnotationEntry> {
fun getShortName(): String
fun getShortName(): String?
fun hasValueArguments(): Boolean
}
@@ -40,8 +40,8 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
@Override
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
Name shortName = KtPsiUtil.getShortName(psi);
String resultName = shortName != null ? shortName.asString() : psi.getText();
Name shortName = psi.getShortName();
String resultName = shortName != null ? shortName.asString() : null;
KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments);
@@ -25,11 +25,11 @@ import com.intellij.psi.PsiElement
class KotlinAnnotationEntryStubImpl(
parent: StubElement<out PsiElement>?,
private val shortName: StringRef,
private val shortName: StringRef?,
private val hasValueArguments: Boolean
) : KotlinStubBaseImpl<KtAnnotationEntry>(parent, KtStubElementTypes.ANNOTATION_ENTRY), KotlinAnnotationEntryStub {
override fun getShortName() = shortName.string
override fun getShortName() = shortName?.string
override fun hasValueArguments() = hasValueArguments
}