/** * Consumes an identifier token that may be a reserved word, i.e. * an IdentifierName, not necessarily an Identifier. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatIdOrKeywordAsId() { Token token = nextToken(); if (token.type == TokenType.IDENTIFIER) { return (IdentifierToken) token; } else if (Keywords.isKeyword(token.type)) { return new IdentifierToken( token.location, Keywords.get(token.type).toString()); } else { reportExpectedError(token, TokenType.IDENTIFIER); } return null; }
/** @return whether the next token is an identifier. */ private boolean peekId(int index) { TokenType type = peekType(index); // There are two special cases to handle here: // * outside of strict-mode code strict-mode keywords can be used as identifiers // * when configured to parse TypeScript code the scanner will return TypeScript // keyword token but these contextual keywords can always be used as idenifiers. return TokenType.IDENTIFIER == type || (config.parseTypeSyntax && Keywords.isTypeScriptSpecificKeyword(type)) || (!inStrictContext() && Keywords.isStrictKeyword(type)); }
private boolean shouldDeclareMethod(Method m) { return allowTypeReference(m.getDeclaringClass()) && (m.getAnnotation(JSDoc.class) != null || (allowTypeReference(m.getReturnType()) && Stream.of(m.getParameters()).allMatch(this::allowParameter) && Stream.of(Keywords.values()).noneMatch(kw->kw.value.equals(m.getName())))); }
/** Returns true if the string value should be treated as a keyword in the current context. */ private boolean isKeyword(String value) { return Keywords.isKeyword(value, config.parseTypeSyntax); }
private ParseTree parsePropertyNameAssignment() { SourcePosition start = getTreeStartLocation(); Token name = eatObjectLiteralPropertyName(); Token colon = eatOpt(TokenType.COLON); if (colon == null) { if (name.type != TokenType.IDENTIFIER) { reportExpectedError(peekToken(), TokenType.COLON); } else if (Keywords.isKeyword(name.asIdentifier().value) && !Keywords.isTypeScriptSpecificKeyword(name.asIdentifier().value)) { reportError(name, "Cannot use keyword in short object literal"); } else if (peek(TokenType.EQUAL)) { IdentifierExpressionTree idTree = new IdentifierExpressionTree( getTreeLocation(start), (IdentifierToken) name); eat(TokenType.EQUAL); ParseTree defaultValue = parseAssignmentExpression(); return new DefaultParameterTree(getTreeLocation(start), idTree, defaultValue); } } ParseTree value = colon == null ? null : parseAssignmentExpression(); return new PropertyNameAssignmentTree(getTreeLocation(start), name, value); }
public static boolean isKeyword(String value, boolean includeTypeScriptKeywords) { return get(value, includeTypeScriptKeywords) != null; }
if (Keywords.isKeyword(value)) { return new Token(Keywords.getTokenType(value), getTokenRange(beginToken));
Keywords(String value, TokenType type) { this.value = value; this.type = type; this.isTypeScriptSpecificKeyword = isTypeScriptSpecificKeyword(type); }
private boolean peekId(int index) { TokenType type = peekType(index); return EnumSet.of( TokenType.IDENTIFIER, TokenType.TYPE, TokenType.DECLARE, TokenType.MODULE, TokenType.NAMESPACE) .contains(type) || (!inStrictContext() && Keywords.isStrictKeyword(type)); }
private boolean peekPropertyName(int tokenIndex) { TokenType type = peekType(tokenIndex); switch (type) { case IDENTIFIER: case STRING: case NUMBER: return true; default: return Keywords.isKeyword(type); } }
if (!peek(TokenType.COLON)) { IdentifierToken idToken = (IdentifierToken) name; if (Keywords.isKeyword(idToken.value) && !Keywords.isTypeScriptSpecificKeyword(idToken.value)) { reportError("cannot use keyword '" + name + "' here.");
public static boolean isKeyword(TokenType token) { return get(token) != null; }
private boolean peekPropertyName(int tokenIndex) { TokenType type = peekType(tokenIndex); switch (type) { case IDENTIFIER: case STRING: case NUMBER: return true; default: return Keywords.isKeyword(type); } }
/** * Consumes an identifier token that may be a reserved word, i.e. * an IdentifierName, not necessarily an Identifier. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatIdOrKeywordAsId() { Token token = nextToken(); if (token.type == TokenType.IDENTIFIER) { return (IdentifierToken) token; } else if (Keywords.isKeyword(token.type)) { return new IdentifierToken( token.location, Keywords.get(token.type).toString()); } else { reportExpectedError(token, TokenType.IDENTIFIER); } return null; }
public static boolean isKeyword(String value) { return get(value) != null; }
if (!Modifier.isPublic(modifiers)) continue; if (Stream.of(Keywords.values()).anyMatch(kw->kw.value.equals(f.getName()))) continue; source.append("/** ");
private boolean peekIdOrKeyword() { TokenType type = peekType(); return TokenType.IDENTIFIER == type || Keywords.isKeyword(type); }
public static boolean isKeyword(TokenType token) { return get(token) != null; }