⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javacodeanalyzer.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                printOut();            }             return;        }         if (aNode instanceof CatchStatement) {            // catch on same line as last closed bracket            // JCC 7.9            addToOut( "catch (" );            // exception as FormalParameter            FormalParameter fp = ((CatchStatement)aNode).getException();            addToOut( eh.getTypeString( fp.getType() ) + " " + fp.getName() + ")" );            //            printOut();                        //            jco.increaseIndent();            parseObject( ((CatchStatement)aNode).getBlock() );            //            jco.decreaseIndent();            //            setToOut( "} " );            return;        }         // throw        if (aNode instanceof ThrowStatement) {            setToOut( "throw " );            eh.addSuperConditionString( ((ThrowStatement)aNode).getExpression() );            printOut( ";" );            return;        }                 // reserved words        // continue        if (aNode instanceof ContinueStatement) {            printOut( "continue;" );            return;        }         // break        if (aNode instanceof BreakStatement) {            printOut( "break;" );            return;        }         //                        // expression only in other method        if (aNode instanceof Expression) {            setToOut( "" );            eh.addSuperConditionString( (Expression)aNode );            addToOut( ";" );            printOut();            return;        }         //        printErr( aNode, "parseObject Node " + aNode + " not found on line " + aNode.getBeginLine() );        return;    }             /**     *     */    private void insertBlockStatement( Node node ) {        //        System.err.println("insertBlockStatement");        if (node instanceof BlockStatement) {            //            System.err.println("insertBlockStatement is block");            parseObject( node );        } else {            printOut( " {" );            jco.increaseIndent();            parseObject( node );            jco.decreaseIndent();            setToOut( "} " );        }     }             /**     * Prints nested if-then-else.     */    private void printNestedIfThenElse( Node aNode ) {        // nested if-then-else        if (aNode instanceof IfThenElseStatement) {            addToOut( "else if (" );            eh.addSuperConditionString( ((IfThenElseStatement)aNode).getCondition() );            addToOut( ")" );            //            jco.increaseIndent();            insertBlockStatement( ((IfThenElseStatement)aNode).getThenStatement() );            //            jco.decreaseIndent();            if (((IfThenElseStatement)aNode).getElseStatement() instanceof IfThenElseStatement) {                printNestedIfThenElse( ((IfThenElseStatement)aNode).getElseStatement() );            } else {                // the else is an if-then-else                addToOut( "else" );                //                jco.increaseIndent();                insertBlockStatement( ((IfThenElseStatement)aNode).getElseStatement() );            //                jco.decreaseIndent();            }         } else {            // aNode is not an if-then-else            addToOut( "else" );            //            jco.increaseIndent();            insertBlockStatement( aNode );        //            jco.decreaseIndent();        }     }             /**     * Help method to encapsulate a often used loop in parseObject(declarations).     *     * @return A String consist of several parameters in a List separated by     * ',MiddleSplitLevel ' with a LowSplitLevel if more than one element in it     *     */    private String getParametersString( List someParameters ) {        boolean findSome = false;        String ret = "";        if (someParameters != null) {            //		  if (someParameters.size()>1) {            ret += jco.getLowSplitLevel();            //			}            ListIterator it = someParameters.listIterator();            while (it.hasNext()) {                findSome = true;                ret += " ";                FormalParameter param = (FormalParameter)it.next();                if (param.isFinal()) {                    ret += "final ";                }                 ret += eh.getTypeString( param.getType() ) + " " + param.getName() + "," + jco.getMiddleSplitLevel();            }             if (ret.endsWith( "," + jco.getMiddleSplitLevel() )) {                ret = ret.substring( 0, ret.length() - ("," + jco.getMiddleSplitLevel()).length() );            }         }         if (findSome) {            ret += " ";        }         return ret;    }             /**     * Help method to encapsulate a used loop in parseObject(ForStatement).     *     * A String consist of several parameters in a List separated by     * ',MiddleSplitLevel ' with a LowSplitLevel if more than one element in it     *     */    private void addVariableDeclarationListString( List someParameters ) {        Node node;        if (someParameters != null) {            //		  if (someParameters.size()>1) {            addToOut( jco.getLowSplitLevel() );            //			}            ListIterator it = someParameters.listIterator();            if (it.hasNext()) {                // VariableDeclarations or SimpleAssignmentExpression                node = (Node)it.next();                if (node instanceof VariableDeclaration) {                    VariableDeclaration vd = (VariableDeclaration)node;                    if (vd.isFinal()) {                        addToOut( "final " );                    }                     // type                    addToOut( eh.getTypeString( vd.getType() ) + " " );                    // name                    addToOut( vd.getName() );                    // initializer                    if (vd.getInitializer() != null) {                        addToOut( " = " + jco.getHighSplitLevel() );                        eh.addSuperConditionString( vd.getInitializer() );                    }                 } else {                    eh.addSuperConditionString( (Expression)node );                }                 addToOut( "," + jco.getMiddleSplitLevel() + " " );            }             while (it.hasNext()) {                // VariableDeclarations or SimpleAssignmentExpression                node = (Node)it.next();                if (node instanceof VariableDeclaration) {                    VariableDeclaration vd = (VariableDeclaration)node;                    // name                    addToOut( vd.getName() );                    // initializer                    if (vd.getInitializer() != null) {                        addToOut( " = " + jco.getHighSplitLevel() );                        eh.addSuperConditionString( vd.getInitializer() );                    }                 } else {                    eh.addSuperConditionString( (Expression)node );                }                 addToOut( "," + jco.getMiddleSplitLevel() + " " );            }             if (getOut().endsWith( "," + jco.getMiddleSplitLevel() + " " )) {                setToOut( getOut().substring( 0,                        getOut().length() - ("," + jco.getMiddleSplitLevel() + " ").length() ) );            }         }     }             //    // out line management    //            /**     * Adds the specified string to the global variable LineOut     * @param add The String to add.     */    public void addToOut( String add ) {        outLine += add;    }             public void setToOut( String string ) {        outLine = string;    }             public void printOut() {        jco.println( outLine );        setToOut( "" );    }             /**     * Adds the specified String and invoke the println method in the Outputclass.     * Set the lineOut class member to ""     *     * @param add The String to add.     */    public void printOut( String add ) {        addToOut( add );        printOut();    }             public String getOut() {        return outLine;    }             /**     * This method logs warnings on code violations.     * @param aLine     *     */    private void printLog( Node aNode, String aLine ) {        //		 System.err.println(getClass()+" Log line "+aNode.getBeginLine()+": "+aLine);        ;    }             private void printLog( String aLine ) {        //		 System.err.println(getClass()+" Log: "+aLine);        ;    }             /**     * This method print debug messages.     * @param aLine     *     */    private void printErr( Node aNode, String aLine ) {        System.err.println( getClass() + " ERROR: " + aLine );    }             /** */    public static void printHelp() {        System.out.println( "usage: jAnalyzer [-o=<outputfile>|-] [-linelength=<number>] [-h|-?|-help] inputfile" );    }             /**     *     *     */    public static void main( String[] argv ) {        String fileIn = null;        String fileOut = null;        String lineLength = null;                int i = 0;        if (argv.length > 0) {            for (i = 0; i < argv.length; i++) {                if (argv[i].startsWith( "-o=" )) {                    fileOut = argv[i].substring( "-o=".length() );                    continue;                }                 if (argv[i].startsWith( "-linelength=" )) {                    lineLength = argv[i].substring( "-linelength=".length() );                    continue;                }                 if (argv[i].equals( "-h" ) || argv[i].equals( "-?" ) || argv[i].equals( "-help" )) {                    printHelp();                    System.exit( 0 );                }                 // no parameter, must be inputfile                fileIn = argv[i];                break;            }         }         if (fileIn == null) {            printHelp();            System.exit( 0 );        }         if (fileOut != null && fileOut.equals( "-" )) {            new JavaCodeAnalyzer( fileIn, fileIn, lineLength );        } else {            new JavaCodeAnalyzer( fileIn, fileOut, lineLength );        }                         // more than one inputfile        if (fileOut != null && fileOut.equals( "-" )) {            while (i < argv.length) {                new JavaCodeAnalyzer( argv[i], argv[i], lineLength );                i++;            }         } else {            while (i < argv.length) {                new JavaCodeAnalyzer( argv[i], fileOut, lineLength );                i++;            }         }     } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -