correct PsiEnumConstant#isDeprecated (IDEA-168740)

This commit is contained in:
peter
2017-02-27 12:25:37 +01:00
parent 85696d7125
commit fb5be8bdac
3 changed files with 18 additions and 11 deletions
@@ -194,14 +194,7 @@ public class PsiEnumConstantImpl extends JavaStubPsiElement<PsiFieldStub> implem
@Override
public boolean isDeprecated() {
final PsiFieldStub stub = getGreenStub();
if (stub != null) {
return stub.isDeprecated();
}
PsiDocComment docComment = getDocComment();
return docComment != null && docComment.findTagByName("deprecated") != null ||
getModifierList().findAnnotation("java.lang.Deprecated") != null;
return PsiFieldImpl.isFieldDeprecated(this, getGreenStub());
}
@Override
@@ -299,12 +299,15 @@ public class PsiFieldImpl extends JavaStubPsiElement<PsiFieldStub> implements Ps
@Override
public boolean isDeprecated() {
final PsiFieldStub stub = getGreenStub();
return isFieldDeprecated(this, getGreenStub());
}
static boolean isFieldDeprecated(@NotNull PsiField field, @Nullable PsiFieldStub stub) {
if (stub != null) {
return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(field);
}
return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
return PsiImplUtil.isDeprecatedByDocTag(field) || PsiImplUtil.isDeprecatedByAnnotation(field);
}
@Override
@@ -159,4 +159,15 @@ import java.lang.annotation.*;
assert list.parametersCount == list.parameters.size()
}
void "test deprecated enum constant"() {
def cls = myFixture.addClass("enum Foo { c1, @Deprecated c2, /** @deprecated */ c3 }")
assert !((PsiFileImpl) cls.containingFile).contentsLoaded
assert !cls.fields[0].deprecated
assert cls.fields[1].deprecated
assert cls.fields[2].deprecated
assert !((PsiFileImpl) cls.containingFile).contentsLoaded
}
}