Search in sources :

Example 1 with TypeNameTree

use of com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree in project closure-compiler by google.

the class Parser method parseTypeName.

private TypeNameTree parseTypeName() {
    SourcePosition start = getTreeStartLocation();
    // for 'void'.
    IdentifierToken token = eatIdOrKeywordAsId();
    return new TypeNameTree(getTreeLocation(start), buildIdentifierPath(token));
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 2 with TypeNameTree

use of com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree in project closure-compiler by google.

the class Parser method parseTypeReference.

private ParseTree parseTypeReference() {
    SourcePosition start = getTreeStartLocation();
    TypeNameTree typeName = parseTypeName();
    if (!peek(TokenType.OPEN_ANGLE)) {
        return typeName;
    }
    return parseTypeArgumentList(start, typeName);
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition)

Example 3 with TypeNameTree

use of com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree in project closure-compiler by google.

the class Parser method parseType.

private ParseTree parseType() {
    SourcePosition start = getTreeStartLocation();
    if (!peekId() && !EnumSet.of(TokenType.VOID, TokenType.OPEN_PAREN, TokenType.OPEN_CURLY, TokenType.TYPEOF).contains(peekType())) {
        reportError("Unexpected token '%s' in type expression", peekType());
        return new TypeNameTree(getTreeLocation(start), ImmutableList.of("error"));
    }
    ParseTree typeExpression = parseFunctionTypeExpression();
    if (!peek(TokenType.BAR)) {
        return typeExpression;
    }
    ImmutableList.Builder<ParseTree> unionType = ImmutableList.builder();
    unionType.add(typeExpression);
    do {
        eat(TokenType.BAR);
        unionType.add(parseArrayTypeExpression());
    } while (peek(TokenType.BAR));
    return new UnionTypeTree(getTreeLocation(start), unionType.build());
}
Also used : TypeNameTree(com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree) ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) UnionTypeTree(com.google.javascript.jscomp.parsing.parser.trees.UnionTypeTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Aggregations

TypeNameTree (com.google.javascript.jscomp.parsing.parser.trees.TypeNameTree)3 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)3 ImmutableList (com.google.common.collect.ImmutableList)1 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)1 UnionTypeTree (com.google.javascript.jscomp.parsing.parser.trees.UnionTypeTree)1