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);
}
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);
}
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);
}
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);
}
Aggregations