PY-18816 Rename PyAnnotationOwner#getAnnotationContent() to getAnnotationValue()

in order to be consistent with existing PyAnnotation#getValue() API.
This commit is contained in:
Mikhail Golubev
2017-07-19 19:28:31 +03:00
parent 1f48d16790
commit ca6c7ce90f
11 changed files with 21 additions and 15 deletions
@@ -24,6 +24,12 @@ public interface PyAnnotationOwner {
@Nullable
PyAnnotation getAnnotation();
/**
* Returns the text of the annotation with the leading colon and arrow stripped.
* <p>
* It's supposed to be the same value as one can get by calling {@code elem.getAnnotation().getValue().getText()},
* but taken from the corresponding stub instead of AST.
*/
@Nullable
String getAnnotationContent();
String getAnnotationValue();
}
@@ -46,7 +46,7 @@ public class PyTypeDeclarationStatementImpl extends PyElementImpl implements PyT
@Nullable
@Override
public String getAnnotationContent() {
public String getAnnotationValue() {
return getAnnotationContentFromPsi(this);
}
@@ -201,7 +201,7 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
@Nullable
private static Ref<PyType> getParameterTypeFromAnnotation(@NotNull PyNamedParameter parameter, @NotNull TypeEvalContext context) {
final Ref<PyType> annotationValueTypeRef = Optional
.ofNullable(parameter.getAnnotationContent())
.ofNullable(parameter.getAnnotationValue())
.map(text -> getStringBasedType(text, parameter, context))
.orElse(null);
@@ -258,7 +258,7 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
@Nullable
private static PyExpression getReturnTypeAnnotation(@NotNull PyFunction function) {
final String annotation = function.getAnnotationContent();
final String annotation = function.getAnnotationValue();
if (annotation != null) {
return createExpressionFromFragment(annotation, function);
}
@@ -303,7 +303,7 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
if (GENERIC.equals(target.getQualifiedName())) {
return createTypingGenericType();
}
final String annotation = target.getAnnotationContent();
final String annotation = target.getAnnotationValue();
if (annotation != null) {
return Ref.deref(getStringBasedType(annotation, target, context));
}
@@ -104,7 +104,7 @@ public class PyAssignmentStatementImpl extends PyElementImpl implements PyAssign
@Nullable
@Override
public String getAnnotationContent() {
public String getAnnotationValue() {
return getAnnotationContentFromPsi(this);
}
@@ -601,7 +601,7 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Nullable
@Override
public String getAnnotationContent() {
public String getAnnotationValue() {
return getAnnotationContentFromStubOrPsi(this);
}
@@ -193,7 +193,7 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
@Nullable
@Override
public String getAnnotationContent() {
public String getAnnotationValue() {
return getAnnotationContentFromStubOrPsi(this);
}
@@ -242,7 +242,7 @@ public class PyTargetExpressionImpl extends PyBaseElementImpl<PyTargetExpression
@Nullable
@Override
public String getAnnotationContent() {
public String getAnnotationValue() {
return getAnnotationContentFromStubOrPsi(this);
}
@@ -60,7 +60,7 @@ public class PyFunctionElementType extends PyStubElementType<PyFunctionStub, PyF
final String message = function.extractDeprecationMessage();
final PyStringLiteralExpression docStringExpression = function.getDocStringExpression();
final String typeComment = function.getTypeCommentAnnotation();
final String annotationContent = function.getAnnotationContent();
final String annotationContent = function.getAnnotationValue();
return new PyFunctionStubImpl(psi.getName(),
PyPsiUtils.strValue(docStringExpression),
message,
@@ -56,7 +56,7 @@ public class PyNamedParameterElementType extends PyStubElementType<PyNamedParame
@NotNull
public PyNamedParameterStub createStub(@NotNull final PyNamedParameter psi, final StubElement parentStub) {
return new PyNamedParameterStubImpl(psi.getName(), psi.isPositionalContainer(), psi.isKeywordContainer(), psi.hasDefaultValue(),
psi.getTypeCommentAnnotation(), psi.getAnnotationContent() , parentStub, getStubElementType());
psi.getTypeCommentAnnotation(), psi.getAnnotationValue() , parentStub, getStubElementType());
}
@NotNull
@@ -74,7 +74,7 @@ public class PyTargetExpressionElementType extends PyStubElementType<PyTargetExp
final PyExpression assignedValue = psi.findAssignedValue();
final String docString = DocStringUtil.getDocStringValue(psi);
final String typeComment = psi.getTypeCommentAnnotation();
final String annotation = psi.getAnnotationContent();
final String annotation = psi.getAnnotationValue();
for (CustomTargetExpressionStubType customStubType : getCustomStubTypes()) {
CustomTargetExpressionStub customStub = customStubType.createStub(psi);
@@ -729,7 +729,7 @@ public class PyStubsTest extends PyTestCase {
final PyFile file = getTestFile();
final PyFunction func = file.findTopLevelFunction("func");
final PyNamedParameter param = func.getParameterList().findParameterByName("x");
final String annotation = param.getAnnotationContent();
final String annotation = param.getAnnotationValue();
assertEquals("int", annotation);
assertNotParsed(file);
final TypeEvalContext context = TypeEvalContext.codeInsightFallback(myFixture.getProject());
@@ -743,7 +743,7 @@ public class PyStubsTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON30, () -> {
final PyFile file = getTestFile();
final PyFunction func = file.findTopLevelFunction("func");
final String annotation = func.getAnnotationContent();
final String annotation = func.getAnnotationValue();
assertEquals("int", annotation);
assertNotParsed(file);
assertType("() -> int", func, TypeEvalContext.codeInsightFallback(myFixture.getProject()));
@@ -756,7 +756,7 @@ public class PyStubsTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON36, () -> {
final PyFile file = getTestFile();
final PyTargetExpression var = file.findTopLevelAttribute("x");
final String annotation = var.getAnnotationContent();
final String annotation = var.getAnnotationValue();
assertEquals("int", annotation);
assertNotParsed(file);
assertType("int", var, TypeEvalContext.codeInsightFallback(myFixture.getProject()));