case Function:
return new GoType[]{GoTypes.fromPsi((GoLiteralFunction) literal)};
case Identifier:
final GoLiteralIdentifier identifier = (GoLiteralIdentifier) literal;
if (identifier.isNil())
return new GoType[]{GoType.Nil};
if (identifier.isIota())
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Integer, identifier.getIotaValue())};
GoPsiElement resolved = GoPsiUtils.resolveSafely(identifier, GoPsiElement.class);
if (resolved == null) {
return GoType.EMPTY_ARRAY;
}
return resolved.accept(new GoElementVisitorWithData<GoType[]>(GoType.EMPTY_ARRAY) {
GoLiteralIdentifier resolvedIdent = null;
@Override
public void visitImportDeclaration(GoImportDeclaration declaration) {
setData(GoTypes.getPackageType(declaration));
}
@Override
public void visitFunctionDeclaration(GoFunctionDeclaration declaration) {
setData(new GoType[]{GoTypes.fromPsi(declaration)});
}
@Override
public void visitTypeSpec(GoTypeSpec typeSpec) {
setData(new GoType[]{GoTypes.fromPsi(typeSpec.getTypeNameDeclaration())});
}
@Override
public void visitLiteralIdentifier(GoLiteralIdentifier identifier) {
this.resolvedIdent = identifier;
((GoPsiElement) identifier.getParent()).accept(this);
}
@Override
public void visitVarDeclaration(GoVarDeclaration declaration) {
if (resolvedIdent != null) {
GoType identifierType = declaration.getIdentifierType(resolvedIdent);
if (identifierType != null)
setData(new GoType[]{identifierType});
}
}
@Override
public void visitConstDeclaration(GoConstDeclaration declaration) {
if (resolvedIdent != null) {
GoType declaredType = types.fromPsiType(declaration.getIdentifiersType());
GoExpr expr = declaration.getExpression(resolvedIdent);
if (expr != null) {
GoType[] exprType = expr.getType();
if ((exprType.length != 1 || !(exprType[0] instanceof GoTypeConstant)))
setData(new GoType[]{declaredType});
if (exprType.length == 1 && exprType[0] instanceof GoTypeConstant) {
GoTypeConstant constant = (GoTypeConstant) exprType[0];
if (declaredType != GoType.Unknown)
setData(new GoType[]{GoTypes.constant(constant.getKind(), constant.getValue(), declaredType)});
else
setData(new GoType[]{constant});
}
}
}
}
@Override
public void visitFunctionParameter(GoFunctionParameter parameter) {
GoPsiType typeForBody = parameter.getTypeForBody();
if (typeForBody != null)
setData(new GoType[]{GoTypes.fromPsi(typeForBody)});
}
@Override
public void visitMethodReceiver(GoMethodReceiver receiver) {
GoPsiType type = receiver.getType();
if (type != null)
setData(new GoType[]{GoTypes.fromPsi(type)});
}
@Override
public void visitSwitchTypeGuard(GoSwitchTypeGuard typeGuard) {
GoSwitchTypeStatement switchStatement = (GoSwitchTypeStatement) typeGuard.getParent();
TextRange litRange = identifier.getTextRange();
for (GoSwitchTypeClause clause : switchStatement.getClauses()) {
TextRange clauseTextRange = clause.getTextRange();
if (clauseTextRange.contains(litRange)) {
setData(GoTypes.fromPsiType(clause.getTypes()));
}