Search in sources :

Example 1 with KtKeywordToken

use of org.jetbrains.kotlin.lexer.KtKeywordToken in project kotlin by JetBrains.

the class GenerateKeywordStrings method generate.

@NotNull
public static String generate() throws IOException {
    StringBuilder sb = new StringBuilder();
    Printer p = new Printer(sb);
    p.println(FileUtil.loadFile(new File("license/LICENSE.txt")));
    p.println("package org.jetbrains.kotlin.renderer;");
    p.println();
    p.println("import java.util.Arrays;");
    p.println("import java.util.Set;");
    p.println("import java.util.HashSet;");
    p.println();
    p.println("/** This class is generated by {@link \"org.jetbrains.kotlin.generators.frontend.GenerateKeywordStrings\"}. DO NOT MODIFY MANUALLY */");
    p.println("public class KeywordStringsGenerated {");
    p.pushIndent();
    p.println("private KeywordStringsGenerated() {}");
    p.println();
    p.println("public static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(");
    p.pushIndent();
    List<String> strings = new ArrayList<String>();
    for (IElementType type : KtTokens.KEYWORDS.getTypes()) {
        assert type instanceof KtKeywordToken : "Not a keyword in KtTokens.KEYWORDS: " + type;
        KtKeywordToken keyword = (KtKeywordToken) type;
        assert !keyword.isSoft() : "Soft keyword in KtTokens.KEYWORDS: " + keyword.getValue();
        if (keyword != KtTokens.AS_SAFE && keyword != KtTokens.NOT_IN && keyword != KtTokens.NOT_IS) {
            strings.add(keyword.getValue());
        }
    }
    for (Iterator<String> iterator = strings.iterator(); iterator.hasNext(); ) {
        String string = iterator.next();
        p.println("\"" + string + "\"" + (iterator.hasNext() ? "," : ""));
    }
    p.popIndent();
    p.println("));");
    p.popIndent();
    p.println("}");
    return sb.toString();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ArrayList(java.util.ArrayList) Printer(org.jetbrains.kotlin.utils.Printer) File(java.io.File) KtKeywordToken(org.jetbrains.kotlin.lexer.KtKeywordToken) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with KtKeywordToken

use of org.jetbrains.kotlin.lexer.KtKeywordToken in project kotlin by JetBrains.

the class KotlinParsing method parseAnnotationTargetIfNeeded.

// Returns true if we should continue parse annotation
private boolean parseAnnotationTargetIfNeeded(AnnotationParsingMode mode) {
    String expectedAnnotationTargetBeforeColon = "Expected annotation target before ':'";
    if (at(COLON)) {
        // recovery for "@:ann"
        // COLON
        errorAndAdvance(expectedAnnotationTargetBeforeColon);
        return true;
    }
    KtKeywordToken targetKeyword = atTargetKeyword();
    if (mode == FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED && !(targetKeyword == FILE_KEYWORD && lookahead(1) == COLON)) {
        return false;
    }
    if (lookahead(1) == COLON && targetKeyword == null && at(IDENTIFIER)) {
        // recovery for "@fil:ann"
        // IDENTIFIER
        errorAndAdvance(expectedAnnotationTargetBeforeColon);
        // COLON
        advance();
        return true;
    }
    if (targetKeyword == null && mode.isFileAnnotationParsingMode) {
        parseAnnotationTarget(mode, FILE_KEYWORD);
    } else if (targetKeyword != null) {
        parseAnnotationTarget(mode, targetKeyword);
    }
    return true;
}
Also used : KtKeywordToken(org.jetbrains.kotlin.lexer.KtKeywordToken)

Aggregations

KtKeywordToken (org.jetbrains.kotlin.lexer.KtKeywordToken)2 IElementType (com.intellij.psi.tree.IElementType)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Printer (org.jetbrains.kotlin.utils.Printer)1