开发者社区> 程序员诗人> 正文

Java 编译器代码定义的 Token 保留字

简介: Java 编译器代码定义的 Token 保留字 注释类型 public static enum CommentStyle { LINE, BLOCK, JAVADOC; ...
+关注继续查看

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



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
05.Java网络编程(代码实践)
计算机网络是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路链接起来,在网络操作系统,网络管理软件及网络通信协议的协调下,实现资源贡献和信息传递的计算机系统 网络编程就是用来实现网络互连的不同计算机上运行的程序间可以进行数据交换 网...
835 0
成为一个编译器之「使用 JavaScript 来制作编译器」
本文讲的是成为一个编译器之「使用 JavaScript 来制作编译器」,布希维克,布鲁克林,一个很棒的周日。我在书店里发现了一本书 John Maeda 写的 “Design by Numbers” 。
1164 0
编写高质量的 Java 代码
代码质量概述 代码质量所涉及的5个方面,编码标准、代码重复、代码覆盖率、依赖项分析、复杂度分析。这5方面很大程序上决定了一份代码的质量高低。 我们分别来看一下这5方面:编码标准:这个想必都很清楚,每个公司几乎都有一份编码规范,类命名、包命名、代码风格之类的东西都属于其中。
864 0
《Java遗传算法编程》—— 2.3 关于本书的代码示例
本书中的每一章都作为一个包,放在附带的Eclipse项目中。每个包都至少有4个类。 GeneticAlgorithm类,它抽象了遗传算法本身,为接口方法提供了针对问题的实现,如交叉、变异、适应度评估和终止条件检查。
1577 0
《Java遗传算法编程》—— 2.7 交叉伪代码
既然有了选择和交叉的方法,让我们来看一些伪代码,其中概述了要实现的交叉过程。
1471 0
+关注
程序员诗人
一个会写诗的程序员
828
文章
14
问答
文章排行榜
最热
最新
相关电子书
更多
JS零基础入门教程(上册)
立即下载
性能优化方法论
立即下载
手把手学习日志服务SLS,云启实验室实战指南
立即下载