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



上一篇:ZSD/ZSA 随机分布参数的定义 | 带你读《大规模天线波束赋形技术原理与设计 》之二十七


下一篇:阿里为什么要举全集团之力做 Serverless?