protected GoType[] resolveTypes() {
GoLiteral literal = getLiteral();
if (literal == null)
return GoType.EMPTY_ARRAY;
final GoTypes types = getInstance(getProject());
GoNamesCache namesCache = GoNamesCache.getInstance(getProject());
switch (literal.getType()) {
case Bool:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Boolean, literal.getValue())};
case Int:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Integer, literal.getValue())};
case Float:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Float, literal.getValue())};
case Char:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Rune, literal.getValue())};
case ImaginaryInt:
case ImaginaryFloat:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.Complex, literal.getValue())};
case RawString:
case InterpretedString:
return new GoType[]{GoTypes.constant(GoTypeConstant.Kind.String, literal.getValue())};
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();