Java 編譯器代碼定義的 Token 保留字

Java 編譯器代碼定義的 Token 保留字

注釋類型

public static enum CommentStyle {
            LINE,
            BLOCK,
            JAVADOC;

            private CommentStyle() {
            }
        }

Java語言保留字:

public static enum TokenKind implements Formattable, Filter<Tokens.TokenKind> {
        EOF,
        ERROR,
        IDENTIFIER(Tokens.Token.Tag.NAMED),
        ABSTRACT("abstract"),
        ASSERT("assert", Tokens.Token.Tag.NAMED),
        BOOLEAN("boolean", Tokens.Token.Tag.NAMED),
        BREAK("break"),
        BYTE("byte", Tokens.Token.Tag.NAMED),
        CASE("case"),
        CATCH("catch"),
        CHAR("char", Tokens.Token.Tag.NAMED),
        CLASS("class"),
        CONST("const"),
        CONTINUE("continue"),
        DEFAULT("default"),
        DO("do"),
        DOUBLE("double", Tokens.Token.Tag.NAMED),
        ELSE("else"),
        ENUM("enum", Tokens.Token.Tag.NAMED),
        EXTENDS("extends"),
        FINAL("final"),
        FINALLY("finally"),
        FLOAT("float", Tokens.Token.Tag.NAMED),
        FOR("for"),
        GOTO("goto"),
        IF("if"),
        IMPLEMENTS("implements"),
        IMPORT("import"),
        INSTANCEOF("instanceof"),
        INT("int", Tokens.Token.Tag.NAMED),
        INTERFACE("interface"),
        LONG("long", Tokens.Token.Tag.NAMED),
        NATIVE("native"),
        NEW("new"),
        PACKAGE("package"),
        PRIVATE("private"),
        PROTECTED("protected"),
        PUBLIC("public"),
        RETURN("return"),
        SHORT("short", Tokens.Token.Tag.NAMED),
        STATIC("static"),
        STRICTFP("strictfp"),
        SUPER("super", Tokens.Token.Tag.NAMED),
        SWITCH("switch"),
        SYNCHRONIZED("synchronized"),
        THIS("this", Tokens.Token.Tag.NAMED),
        THROW("throw"),
        THROWS("throws"),
        TRANSIENT("transient"),
        TRY("try"),
        VOID("void", Tokens.Token.Tag.NAMED),
        VOLATILE("volatile"),
        WHILE("while"),
        INTLITERAL(Tokens.Token.Tag.NUMERIC),
        LONGLITERAL(Tokens.Token.Tag.NUMERIC),
        FLOATLITERAL(Tokens.Token.Tag.NUMERIC),
        DOUBLELITERAL(Tokens.Token.Tag.NUMERIC),
        CHARLITERAL(Tokens.Token.Tag.NUMERIC),
        STRINGLITERAL(Tokens.Token.Tag.STRING),
        TRUE("true", Tokens.Token.Tag.NAMED),
        FALSE("false", Tokens.Token.Tag.NAMED),
        NULL("null", Tokens.Token.Tag.NAMED),
        UNDERSCORE("_", Tokens.Token.Tag.NAMED),
        ARROW("->"),
        COLCOL("::"),
        LPAREN("("),
        RPAREN(")"),
        LBRACE("{"),
        RBRACE("}"),
        LBRACKET("["),
        RBRACKET("]"),
        SEMI(";"),
        COMMA(","),
        DOT("."),
        ELLIPSIS("..."),
        EQ("="),
        GT(">"),
        LT("<"),
        BANG("!"),
        TILDE("~"),
        QUES("?"),
        COLON(":"),
        EQEQ("=="),
        LTEQ("<="),
        GTEQ(">="),
        BANGEQ("!="),
        AMPAMP("&&"),
        BARBAR("||"),
        PLUSPLUS("++"),
        SUBSUB("--"),
        PLUS("+"),
        SUB("-"),
        STAR("*"),
        SLASH("/"),
        AMP("&"),
        BAR("|"),
        CARET("^"),
        PERCENT("%"),
        LTLT("<<"),
        GTGT(">>"),
        GTGTGT(">>>"),
        PLUSEQ("+="),
        SUBEQ("-="),
        STAREQ("*="),
        SLASHEQ("/="),
        AMPEQ("&="),
        BAREQ("|="),
        CARETEQ("^="),
        PERCENTEQ("%="),
        LTLTEQ("<<="),
        GTGTEQ(">>="),
        GTGTGTEQ(">>>="),
        MONKEYS_AT("@"),
        CUSTOM;

....

}

源碼:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.sun.tools.javac.parser;

import com.sun.tools.javac.api.Formattable;
import com.sun.tools.javac.api.Messages;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Filter;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Context.Key;
import java.util.Iterator;
import java.util.Locale;

public class Tokens {
    private final Names names;
    private final Tokens.TokenKind[] key;
    private int maxKey = 0;
    private Name[] tokenName = new Name[Tokens.TokenKind.values().length];
    public static final Key<Tokens> tokensKey = new Key();
    public static final Tokens.Token DUMMY;

    public static Tokens instance(Context var0) {
        Tokens var1 = (Tokens)var0.get(tokensKey);
        if(var1 == null) {
            var1 = new Tokens(var0);
        }

        return var1;
    }

    protected Tokens(Context var1) {
        var1.put(tokensKey, this);
        this.names = Names.instance(var1);
        Tokens.TokenKind[] var2 = Tokens.TokenKind.values();
        int var3 = var2.length;

        int var4;
        Tokens.TokenKind var5;
        for(var4 = 0; var4 < var3; ++var4) {
            var5 = var2[var4];
            if(var5.name != null) {
                this.enterKeyword(var5.name, var5);
            } else {
                this.tokenName[var5.ordinal()] = null;
            }
        }

        this.key = new Tokens.TokenKind[this.maxKey + 1];

        for(int var6 = 0; var6 <= this.maxKey; ++var6) {
            this.key[var6] = Tokens.TokenKind.IDENTIFIER;
        }

        var2 = Tokens.TokenKind.values();
        var3 = var2.length;

        for(var4 = 0; var4 < var3; ++var4) {
            var5 = var2[var4];
            if(var5.name != null) {
                this.key[this.tokenName[var5.ordinal()].getIndex()] = var5;
            }
        }

    }

    private void enterKeyword(String var1, Tokens.TokenKind var2) {
        Name var3 = this.names.fromString(var1);
        this.tokenName[var2.ordinal()] = var3;
        if(var3.getIndex() > this.maxKey) {
            this.maxKey = var3.getIndex();
        }

    }

    Tokens.TokenKind lookupKind(Name var1) {
        return var1.getIndex() > this.maxKey?Tokens.TokenKind.IDENTIFIER:this.key[var1.getIndex()];
    }

    Tokens.TokenKind lookupKind(String var1) {
        return this.lookupKind(this.names.fromString(var1));
    }

    static {
        DUMMY = new Tokens.Token(Tokens.TokenKind.ERROR, 0, 0, (List)null);
    }

    static final class NumericToken extends Tokens.StringToken {
        public final int radix;

        public NumericToken(Tokens.TokenKind var1, int var2, int var3, String var4, int var5, List<Tokens.Comment> var6) {
            super(var1, var2, var3, var4, var6);
            this.radix = var5;
        }

        protected void checkKind() {
            if(this.kind.tag != Tokens.Token.Tag.NUMERIC) {
                throw new AssertionError("Bad token kind - expected " + Tokens.Token.Tag.NUMERIC);
            }
        }

        public int radix() {
            return this.radix;
        }
    }

    static class StringToken extends Tokens.Token {
        public final String stringVal;

        public StringToken(Tokens.TokenKind var1, int var2, int var3, String var4, List<Tokens.Comment> var5) {
            super(var1, var2, var3, var5);
            this.stringVal = var4;
        }

        protected void checkKind() {
            if(this.kind.tag != Tokens.Token.Tag.STRING) {
                throw new AssertionError("Bad token kind - expected " + Tokens.Token.Tag.STRING);
            }
        }

        public String stringVal() {
            return this.stringVal;
        }
    }

    static final class NamedToken extends Tokens.Token {
        public final Name name;

        public NamedToken(Tokens.TokenKind var1, int var2, int var3, Name var4, List<Tokens.Comment> var5) {
            super(var1, var2, var3, var5);
            this.name = var4;
        }

        protected void checkKind() {
            if(this.kind.tag != Tokens.Token.Tag.NAMED) {
                throw new AssertionError("Bad token kind - expected " + Tokens.Token.Tag.NAMED);
            }
        }

        public Name name() {
            return this.name;
        }
    }

    public static class Token {
        public final Tokens.TokenKind kind;
        public final int pos;
        public final int endPos;
        public final List<Tokens.Comment> comments;

        Token(Tokens.TokenKind var1, int var2, int var3, List<Tokens.Comment> var4) {
            this.kind = var1;
            this.pos = var2;
            this.endPos = var3;
            this.comments = var4;
            this.checkKind();
        }

        Tokens.Token[] split(Tokens var1) {
            if(this.kind.name.length() >= 2 && this.kind.tag == Tokens.Token.Tag.DEFAULT) {
                Tokens.TokenKind var2 = var1.lookupKind(this.kind.name.substring(0, 1));
                Tokens.TokenKind var3 = var1.lookupKind(this.kind.name.substring(1));
                if(var2 != null && var3 != null) {
                    return new Tokens.Token[]{new Tokens.Token(var2, this.pos, this.pos + var2.name.length(), this.comments), new Tokens.Token(var3, this.pos + var2.name.length(), this.endPos, (List)null)};
                } else {
                    throw new AssertionError("Cant split - bad subtokens");
                }
            } else {
                throw new AssertionError("Cant split" + this.kind);
            }
        }

        protected void checkKind() {
            if(this.kind.tag != Tokens.Token.Tag.DEFAULT) {
                throw new AssertionError("Bad token kind - expected " + Tokens.Token.Tag.STRING);
            }
        }

        public Name name() {
            throw new UnsupportedOperationException();
        }

        public String stringVal() {
            throw new UnsupportedOperationException();
        }

        public int radix() {
            throw new UnsupportedOperationException();
        }

        public Tokens.Comment comment(Tokens.Comment.CommentStyle var1) {
            List var2 = this.getComments(Tokens.Comment.CommentStyle.JAVADOC);
            return var2.isEmpty()?null:(Tokens.Comment)var2.head;
        }

        public boolean deprecatedFlag() {
            Iterator var1 = this.getComments(Tokens.Comment.CommentStyle.JAVADOC).iterator();

            Tokens.Comment var2;
            do {
                if(!var1.hasNext()) {
                    return false;
                }

                var2 = (Tokens.Comment)var1.next();
            } while(!var2.isDeprecated());

            return true;
        }

        private List<Tokens.Comment> getComments(Tokens.Comment.CommentStyle var1) {
            if(this.comments == null) {
                return List.nil();
            } else {
                ListBuffer var2 = new ListBuffer();
                Iterator var3 = this.comments.iterator();

                while(var3.hasNext()) {
                    Tokens.Comment var4 = (Tokens.Comment)var3.next();
                    if(var4.getStyle() == var1) {
                        var2.add(var4);
                    }
                }

                return var2.toList();
            }
        }

        static enum Tag {
            DEFAULT,
            NAMED,
            STRING,
            NUMERIC;

            private Tag() {
            }
        }
    }

    public interface Comment {
        String getText();

        int getSourcePos(int var1);

        Tokens.Comment.CommentStyle getStyle();

        boolean isDeprecated();

        public static enum CommentStyle {
            LINE,
            BLOCK,
            JAVADOC;

            private CommentStyle() {
            }
        }
    }

    public static enum TokenKind implements Formattable, Filter<Tokens.TokenKind> {
        EOF,
        ERROR,
        IDENTIFIER(Tokens.Token.Tag.NAMED),
        ABSTRACT("abstract"),
        ASSERT("assert", Tokens.Token.Tag.NAMED),
        BOOLEAN("boolean", Tokens.Token.Tag.NAMED),
        BREAK("break"),
        BYTE("byte", Tokens.Token.Tag.NAMED),
        CASE("case"),
        CATCH("catch"),
        CHAR("char", Tokens.Token.Tag.NAMED),
        CLASS("class"),
        CONST("const"),
        CONTINUE("continue"),
        DEFAULT("default"),
        DO("do"),
        DOUBLE("double", Tokens.Token.Tag.NAMED),
        ELSE("else"),
        ENUM("enum", Tokens.Token.Tag.NAMED),
        EXTENDS("extends"),
        FINAL("final"),
        FINALLY("finally"),
        FLOAT("float", Tokens.Token.Tag.NAMED),
        FOR("for"),
        GOTO("goto"),
        IF("if"),
        IMPLEMENTS("implements"),
        IMPORT("import"),
        INSTANCEOF("instanceof"),
        INT("int", Tokens.Token.Tag.NAMED),
        INTERFACE("interface"),
        LONG("long", Tokens.Token.Tag.NAMED),
        NATIVE("native"),
        NEW("new"),
        PACKAGE("package"),
        PRIVATE("private"),
        PROTECTED("protected"),
        PUBLIC("public"),
        RETURN("return"),
        SHORT("short", Tokens.Token.Tag.NAMED),
        STATIC("static"),
        STRICTFP("strictfp"),
        SUPER("super", Tokens.Token.Tag.NAMED),
        SWITCH("switch"),
        SYNCHRONIZED("synchronized"),
        THIS("this", Tokens.Token.Tag.NAMED),
        THROW("throw"),
        THROWS("throws"),
        TRANSIENT("transient"),
        TRY("try"),
        VOID("void", Tokens.Token.Tag.NAMED),
        VOLATILE("volatile"),
        WHILE("while"),
        INTLITERAL(Tokens.Token.Tag.NUMERIC),
        LONGLITERAL(Tokens.Token.Tag.NUMERIC),
        FLOATLITERAL(Tokens.Token.Tag.NUMERIC),
        DOUBLELITERAL(Tokens.Token.Tag.NUMERIC),
        CHARLITERAL(Tokens.Token.Tag.NUMERIC),
        STRINGLITERAL(Tokens.Token.Tag.STRING),
        TRUE("true", Tokens.Token.Tag.NAMED),
        FALSE("false", Tokens.Token.Tag.NAMED),
        NULL("null", Tokens.Token.Tag.NAMED),
        UNDERSCORE("_", Tokens.Token.Tag.NAMED),
        ARROW("->"),
        COLCOL("::"),
        LPAREN("("),
        RPAREN(")"),
        LBRACE("{"),
        RBRACE("}"),
        LBRACKET("["),
        RBRACKET("]"),
        SEMI(";"),
        COMMA(","),
        DOT("."),
        ELLIPSIS("..."),
        EQ("="),
        GT(">"),
        LT("<"),
        BANG("!"),
        TILDE("~"),
        QUES("?"),
        COLON(":"),
        EQEQ("=="),
        LTEQ("<="),
        GTEQ(">="),
        BANGEQ("!="),
        AMPAMP("&&"),
        BARBAR("||"),
        PLUSPLUS("++"),
        SUBSUB("--"),
        PLUS("+"),
        SUB("-"),
        STAR("*"),
        SLASH("/"),
        AMP("&"),
        BAR("|"),
        CARET("^"),
        PERCENT("%"),
        LTLT("<<"),
        GTGT(">>"),
        GTGTGT(">>>"),
        PLUSEQ("+="),
        SUBEQ("-="),
        STAREQ("*="),
        SLASHEQ("/="),
        AMPEQ("&="),
        BAREQ("|="),
        CARETEQ("^="),
        PERCENTEQ("%="),
        LTLTEQ("<<="),
        GTGTEQ(">>="),
        GTGTGTEQ(">>>="),
        MONKEYS_AT("@"),
        CUSTOM;

        public final String name;
        public final Tokens.Token.Tag tag;

        private TokenKind() {
            this((String)null, Tokens.Token.Tag.DEFAULT);
        }

        private TokenKind(String var3) {
            this(var3, Tokens.Token.Tag.DEFAULT);
        }

        private TokenKind(Tokens.Token.Tag var3) {
            this((String)null, var3);
        }

        private TokenKind(String var3, Tokens.Token.Tag var4) {
            this.name = var3;
            this.tag = var4;
        }

        public String toString() {
            switch(null.$SwitchMap$com$sun$tools$javac$parser$Tokens$TokenKind[this.ordinal()]) {
            case 1:
                return "token.identifier";
            case 2:
                return "token.character";
            case 3:
                return "token.string";
            case 4:
                return "token.integer";
            case 5:
                return "token.long-integer";
            case 6:
                return "token.float";
            case 7:
                return "token.double";
            case 8:
                return "token.bad-symbol";
            case 9:
                return "token.end-of-input";
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
                return "'" + this.name + "'";
            default:
                return this.name;
            }
        }

        public String getKind() {
            return "Token";
        }

        public String toString(Locale var1, Messages var2) {
            return this.name != null?this.toString():var2.getLocalizedString(var1, "compiler.misc." + this.toString(), new Object[0]);
        }

        public boolean accepts(Tokens.TokenKind var1) {
            return this == var1;
        }
    }
}



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末朋蔫,一起剝皮案震驚了整個(gè)濱河市改抡,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌票堵,老刑警劉巖凳忙,帶你破解...
    沈念sama閱讀 211,743評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件栗恩,死亡現(xiàn)場離奇詭異男窟,居然都是意外死亡势决,警方通過查閱死者的電腦和手機(jī)步淹,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,296評論 3 385
  • 文/潘曉璐 我一進(jìn)店門从隆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人缭裆,你說我怎么就攤上這事键闺。” “怎么了澈驼?”我有些...
    開封第一講書人閱讀 157,285評論 0 348
  • 文/不壞的土叔 我叫張陵辛燥,是天一觀的道長。 經(jīng)常有香客問我缝其,道長挎塌,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,485評論 1 283
  • 正文 為了忘掉前任内边,我火速辦了婚禮榴都,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘漠其。我一直安慰自己嘴高,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,581評論 6 386
  • 文/花漫 我一把揭開白布辉懒。 她就那樣靜靜地躺著阳惹,像睡著了一般谍失。 火紅的嫁衣襯著肌膚如雪眶俩。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,821評論 1 290
  • 那天快鱼,我揣著相機(jī)與錄音颠印,去河邊找鬼。 笑死抹竹,一個(gè)胖子當(dāng)著我的面吹牛线罕,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播窃判,決...
    沈念sama閱讀 38,960評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼钞楼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了袄琳?” 一聲冷哼從身側(cè)響起询件,我...
    開封第一講書人閱讀 37,719評論 0 266
  • 序言:老撾萬榮一對情侶失蹤燃乍,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后宛琅,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體刻蟹,經(jīng)...
    沈念sama閱讀 44,186評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,516評論 2 327
  • 正文 我和宋清朗相戀三年嘿辟,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了舆瘪。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,650評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡红伦,死狀恐怖英古,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情色建,我是刑警寧澤哺呜,帶...
    沈念sama閱讀 34,329評論 4 330
  • 正文 年R本政府宣布,位于F島的核電站箕戳,受9級特大地震影響某残,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜陵吸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,936評論 3 313
  • 文/蒙蒙 一玻墅、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧壮虫,春花似錦澳厢、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,757評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至饶唤,卻和暖如春徐伐,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背募狂。 一陣腳步聲響...
    開封第一講書人閱讀 31,991評論 1 266
  • 我被黑心中介騙來泰國打工办素, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人祸穷。 一個(gè)月前我還...
    沈念sama閱讀 46,370評論 2 360
  • 正文 我出身青樓性穿,卻偏偏與公主長得像,于是被迫代替她去往敵國和親雷滚。 傳聞我的和親對象是個(gè)殘疾皇子需曾,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,527評論 2 349

推薦閱讀更多精彩內(nèi)容