Small refactor in TypedScopeCreator
This shouldn't change behavior, just simplifies some conditions in the getDeclaredTypeInAnnotation method that were always true at one of its call sites.
@@ -759,15 +759,13 @@ final class TypedScopeCreator implements ScopeCreator, StaticSymbolTable<TypedVa
}
/**
- * Returns the type specified in a JSDoc annotation near a GETPROP or NAME.
+ * Returns the type specified in a JSDoc annotation near a GETPROP, NAME, member function, or
+ * object literal key.
*
- * Extracts type information from either the {@code @type} tag or from
- * the {@code @return} and {@code @param} tags.
+ * <p>Extracts type information from the {@code @type} tag.
*/
private JSType getDeclaredTypeInAnnotation(Node node, JSDocInfo info) {
- JSType jsType = null;
- if (info != null) {
- if (info.hasType()) {
+ checkArgument(info.hasType());
ImmutableList<TemplateType> ownerTypeKeys = ImmutableList.of();
Node ownerNode = NodeUtil.getBestLValueOwner(node);
@@ -776,11 +774,9 @@ final class TypedScopeCreator implements ScopeCreator, StaticSymbolTable<TypedVa
if (ownerName != null) {
TypedVar ownerVar = currentScope.getVar(ownerName);
if (ownerVar != null) {
- ownerType = getPrototypeOwnerType(
- ObjectType.cast(ownerVar.getType()));
+ ownerType = getPrototypeOwnerType(ObjectType.cast(ownerVar.getType()));
if (ownerType != null) {
- ownerTypeKeys =
- ownerType.getTemplateTypeMap().getTemplateKeys();
+ ownerTypeKeys = ownerType.getTemplateTypeMap().getTemplateKeys();
}
}
}
@@ -789,13 +785,7 @@ final class TypedScopeCreator implements ScopeCreator, StaticSymbolTable<TypedVa
!ownerTypeKeys.isEmpty()
? typeRegistry.createScopeWithTemplates(currentScope, ownerTypeKeys)
: currentScope;
- jsType = info.getType().evaluate(templateScope, typeRegistry);
- } else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
- String fnName = node.getQualifiedName();
- jsType = createFunctionTypeFromNodes(null, fnName, info, node);
- }
- }
- return jsType;
+ return info.getType().evaluate(templateScope, typeRegistry);
}
/**
@@ -1697,7 +1687,12 @@ final class TypedScopeCreator implements ScopeCreator, StaticSymbolTable<TypedVa
}
}
- return getDeclaredTypeInAnnotation(lValue, info);
+ if (info != null && FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
+ String fnName = lValue.getQualifiedName();
+ return createFunctionTypeFromNodes(null, fnName, info, lValue);
+ }
+
+ return null;
}
/**
