JAVA自动解析方法名与参数值

该博客围绕Java自动解析方法名与参数值展开,虽未给出具体内容,但可推测是关于Java在解析方法名和参数值方面的技术探讨,属于后端开发中Java技术的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import scala.collection.Map;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class JavaAnaylsis {
    private static String[] keyword =
            {"boolean", "byte", "char", "double", "false", "float", "int", "long",
                    "new", "null", "short", "true", "void", "instanceof", "break",
                    "case", "catch", "continue", "default", "do", "else", "for", "if",
                    "return", "switch", "try", "while", "finally", "throw", "this",
                    "super", "abstract", "final", "namtive", "private", "protected",
                    "public", "static", "synchronized", "transient", "volatile",
                    "class", "extends", "implements", "interface", "package", "import",
                    "throws"};
    static Vector vc;

    public JavaAnaylsis(String str) throws Exception {



    }

    /*
     * 判断读入的字符是否为字母
     */
    public static boolean isLetter(char c) {
        if ((c >= 'a' && c <= 'z') || (c > +'A' && c <= 'Z')) {
            return true;
        } else
            return false;
    }

    /*
     * 判断读入的字符是否为数字
     */
    public static boolean isDigit(char c) {
        if (c >= '0' && c <= '9') {
            return true;
        } else
            return false;
    }

    /*
     * 判断是否为关键字
     */
    public static boolean isKey(String ss) {
        int flag = 0;
        for (int i = 0; i < keyword.length; i++) {
            if (ss.equals(keyword[i])) {
                flag = 1;
                break;
            }
        }
        if (flag == 1) {
            return true;
        }
        return false;
    }

    /*
     * 判断是否为运算符
     */
    public static boolean isSpilt(char ch) {
        if (ch == '+' || ch == '-' || ch == '|' || ch == '=' || ch == '&') {
            return true;
        } else
            return false;
    }

    /*
     * 判断输入的字符并输出单词符号
     */
    public static Vector judgement(String string) throws Exception {
        String wordString;
        Vector vc = new Vector();
        char ch = 0;
        int m = 0;
        String str = null;
        for (int i = 0; i < string.length(); i++) {
            switch (m) {
                case 0:
                    ch = string.charAt(i);
                    if(ch == '\''){
                        str = "";
                        m = 10;
                    }
                    // 判断是否为运算符使用超前搜索
                    else if (ch == '+' || ch == '-' || ch == '*' || ch == '/'
                            || ch == '=' || ch == '>' || ch == '<' || ch == '!'
                            || ch == '%' || ch == '|') {
                        str = "";
                        str += ch;
                        if (ch == '+' || ch == '-' || ch == '>' || ch == '<'
                                || ch == '!' || ch == '|' || ch == '&') {
                            ch = string.charAt(i + 1); // 对下一个字符进行判断是否为运算符
                            if (isSpilt(ch)) {
                                str += ch;
                                m = 4;
                            } else {
                                ch = string.charAt(i - 1); // 不是运算符则进行回退操作
                                m = 4;
                            }

                        }
                    }
                    // 判断是否为界符
                    else if (ch == ',' || ch == ';' || ch == '{' || ch == '}'
                            || ch == '(' || ch == ')') {
                        str = "";
                        str+=ch;
                        m = 5;
                    }
                    // 判断是否数字
                    else if (isDigit((ch = string.charAt(i)))) {
                        str = "";
                        str += ch;
                        m = 3;
                    }
                    // 判断是否字母
                    else if (isLetter(ch = string.charAt(i))) {
                        str = "";
                        str += ch;
                        m = 2;
                    }
                    // 判断是否下划线或美元符号
                    else if (ch == '_' || ch == '$') {
                        str = "";
                        str += ch;
                        m = 2;
                    } else {
                    }
                    break;

                case 4:
                    i--;
                    wordString = str+"\0044";
                    vc.add(wordString);
                    m = 0;
                    break;

                case 5:
                    i--;
                    wordString = str+"\0045";
                    vc.add(wordString);
                    m = 0;
                    break;
                case 7:
                    i--;
                    wordString = str+"\0047";
                    vc.add(wordString);
                    m = 0;
                    break;
                case 2:
                    if (isLetter(ch = string.charAt(i))||isDigit(ch = string.charAt(i))) {
                        str += ch;
                    } else {
                        if (isKey(str)) {
                            wordString = str+"\0041";
                            vc.add(wordString);
                        } else {
                            wordString = str+"\0042";
                            vc.add(wordString);
                        }
                        i--;
                        m = 0;
                    }
                    break;

                case 3:
                    if (isDigit((ch = string.charAt(i)))) {
                        str += ch;
                    } else {
                        wordString = str+"\0043";
                        vc.add(wordString);
                        i--;
                        m = 0;
                    }
                    break;
                case 10:
                    ch = string.charAt(i);
                    if(ch == '\''){
                        wordString = str+"\00410";
                        vc.add(wordString);
                        m=0;
                    }else {
                        str += ch;
                    }
                    break;

            }
        }

        return vc;
    }


    public static void main(String[] args) throws Exception {
        String a = "a123('DSS','222a+',3)";
        JavaAnaylsis javaAnaylsis = new JavaAnaylsis(a);
        Vector judgement = JavaAnaylsis.judgement(a);
        System.out.println(judgement);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值