Search in sources :

Example 1 with GenericTypeListTree

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

the class Parser method parseInterfaceDeclaration.

private ParseTree parseInterfaceDeclaration() {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.INTERFACE);
    IdentifierToken name = eatId();
    GenericTypeListTree generics = maybeParseGenericTypes();
    ImmutableList.Builder<ParseTree> superTypes = ImmutableList.builder();
    if (peek(TokenType.EXTENDS)) {
        eat(TokenType.EXTENDS);
        ParseTree type = parseType();
        superTypes.add(type);
        while (peek(TokenType.COMMA)) {
            eat(TokenType.COMMA);
            type = parseType();
            if (type != null) {
                superTypes.add(type);
            }
        }
    }
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> elements = parseInterfaceElements();
    eat(TokenType.CLOSE_CURLY);
    return new InterfaceDeclarationTree(getTreeLocation(start), name, generics, superTypes.build(), elements);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) InterfaceDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.InterfaceDeclarationTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 2 with GenericTypeListTree

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

the class Parser method maybeParseGenericTypes.

private GenericTypeListTree maybeParseGenericTypes() {
    if (!peek(TokenType.OPEN_ANGLE)) {
        return null;
    }
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.OPEN_ANGLE);
    scanner.incTypeParameterLevel();
    LinkedHashMap<IdentifierToken, ParseTree> types = new LinkedHashMap<>();
    do {
        IdentifierToken name = eatId();
        ParseTree bound = null;
        if (peek(TokenType.EXTENDS)) {
            eat(TokenType.EXTENDS);
            bound = parseType();
        }
        types.put(name, bound);
        if (peek(TokenType.COMMA)) {
            eat(TokenType.COMMA);
        }
    } while (peekId());
    eat(TokenType.CLOSE_ANGLE);
    scanner.decTypeParameterLevel();
    return new GenericTypeListTree(getTreeLocation(start), types);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with GenericTypeListTree

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

the class Parser method parseCallSignature.

private CallSignatureTree parseCallSignature(boolean isNew) {
    SourcePosition start = getTreeStartLocation();
    if (isNew) {
        eat(TokenType.NEW);
    }
    GenericTypeListTree generics = maybeParseGenericTypes();
    FormalParameterListTree params = parseFormalParameterList(ParamContext.SIGNATURE);
    ParseTree returnType = maybeParseColonType();
    return new CallSignatureTree(getTreeLocation(start), isNew, generics, params, returnType);
}
Also used : SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) CallSignatureTree(com.google.javascript.jscomp.parsing.parser.trees.CallSignatureTree) FormalParameterListTree(com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree)

Example 4 with GenericTypeListTree

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

the class Parser method parseClass.

private ParseTree parseClass(boolean isExpression, boolean isAmbient) {
    SourcePosition start = getTreeStartLocation();
    eat(TokenType.CLASS);
    IdentifierToken name = null;
    if (!isExpression || peekId()) {
        name = eatId();
    }
    GenericTypeListTree generics = maybeParseGenericTypes();
    ParseTree superClass = null;
    if (peek(TokenType.EXTENDS)) {
        eat(TokenType.EXTENDS);
        superClass = parseExpression();
    }
    ImmutableList.Builder<ParseTree> interfaces = ImmutableList.builder();
    if (config.parseTypeSyntax && peek(TokenType.IMPLEMENTS)) {
        eat(TokenType.IMPLEMENTS);
        ParseTree type = parseType();
        interfaces.add(type);
        while (peek(TokenType.COMMA)) {
            eat(TokenType.COMMA);
            type = parseType();
            if (type != null) {
                interfaces.add(type);
            }
        }
    }
    eat(TokenType.OPEN_CURLY);
    ImmutableList<ParseTree> elements = parseClassElements(isAmbient);
    eat(TokenType.CLOSE_CURLY);
    return new ClassDeclarationTree(getTreeLocation(start), name, generics, superClass, interfaces.build(), elements);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePosition(com.google.javascript.jscomp.parsing.parser.util.SourcePosition) GenericTypeListTree(com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree) ParseTree(com.google.javascript.jscomp.parsing.parser.trees.ParseTree) ClassDeclarationTree(com.google.javascript.jscomp.parsing.parser.trees.ClassDeclarationTree)

Aggregations

GenericTypeListTree (com.google.javascript.jscomp.parsing.parser.trees.GenericTypeListTree)4 ParseTree (com.google.javascript.jscomp.parsing.parser.trees.ParseTree)4 SourcePosition (com.google.javascript.jscomp.parsing.parser.util.SourcePosition)4 ImmutableList (com.google.common.collect.ImmutableList)2 CallSignatureTree (com.google.javascript.jscomp.parsing.parser.trees.CallSignatureTree)1 ClassDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.ClassDeclarationTree)1 FormalParameterListTree (com.google.javascript.jscomp.parsing.parser.trees.FormalParameterListTree)1 InterfaceDeclarationTree (com.google.javascript.jscomp.parsing.parser.trees.InterfaceDeclarationTree)1 LinkedHashMap (java.util.LinkedHashMap)1