📄 javacodeanalyzer.java
字号:
if (aNode instanceof ConstructorDeclaration) { ConstructorDeclaration constructorNode = (ConstructorDeclaration)aNode; jco.printConstructorComment( constructorNode ); jco.setCommentStart( aNode.getBeginLine() ); // access_flags setToOut( ConstantsManager.getModifierString( constructorNode.getAccessFlags() ) ); // name + parameterlist addToOut( constructorNode.getName() + "(" + getParametersString( constructorNode.getParameters() ) + ") " ); // Exceptions it = constructorNode.getExceptions().listIterator(); if (it.hasNext()) { addToOut( jco.getHighSplitLevel() + "throws " ); } while (it.hasNext()) { addToOut( (String)it.next() + "," + jco.getMiddleSplitLevel() + " " ); } if (getOut().endsWith( "," + jco.getMiddleSplitLevel() + " " )) { setToOut( getOut().substring( 0, getOut().length() - ("," + jco.getMiddleSplitLevel() + " ").length() ) ); } addToOut( "{" ); printOut(); // jco.increaseIndent(); // this or super constructor invocation as first statement if (constructorNode.getConstructorInvocation() != null) { parseObject( constructorNode.getConstructorInvocation() ); } // // all constructor statements it = constructorNode.getStatements().listIterator(); while (it.hasNext()) { parseObject( (Node)it.next() ); } jco.setCommentEnd( aNode.getEndLine() ); jco.printComment(); jco.setCommentStart( aNode.getEndLine() ); jco.decreaseIndent(); printOut( "}" ); return; } // return if (aNode instanceof ConstructorInvocation) { ConstructorInvocation ci = (ConstructorInvocation)aNode; if (ci.isSuper()) { setToOut( "super(" ); } else { setToOut( "this(" ); } eh.addConditionListString( ci.getArguments() ); printOut( ");" ); return; } // class initializer static { } if (aNode instanceof ClassInitializer) { ClassInitializer ci = (ClassInitializer)aNode; jco.printComment(); jco.setCommentStart( aNode.getBeginLine() ); setToOut( "static" ); // printOut(); // // jco.increaseIndent(); // the contained block if (ci.getBlock() != null) { parseObject( ci.getBlock() ); } // jco.setCommentEnd( aNode.getEndLine() ); jco.printComment(); jco.setCommentStart( aNode.getEndLine() ); // jco.decreaseIndent(); printOut(); return; } // // statements // // common block // not really a statement so no comment must be printed out if (aNode instanceof BlockStatement) { printOut( " {" ); jco.increaseIndent(); it = ((BlockStatement)aNode).getStatements().listIterator(); while (it.hasNext()) { parseObject( (Node)it.next() ); } // printOut(); jco.decreaseIndent(); setToOut( "} " ); // following comments jco.setCommentEnd( aNode.getEndLine() ); jco.printComment(); jco.setCommentStart( aNode.getEndLine() ); return; } // no comment could be created from here, therefore no extra function jco.printComment(); jco.setCommentStart( aNode.getBeginLine() ); // all known 16 statements // a sweet semikolon only if (aNode instanceof EmptyStatement) { printLog( aNode, "empty statement." ); printOut( ";" ); return; } // return if (aNode instanceof ReturnStatement) { setToOut( "return" ); if (((ReturnStatement)aNode).getExpression() != null) { addToOut( " " + jco.getMiddleSplitLevel() ); eh.addSuperConditionString( ((ReturnStatement)aNode).getExpression() ); } addToOut( ";" ); printOut(); return; } if (aNode instanceof IfThenElseStatement) { // binary expressions start with ( and end with ) // it should be delete in if ((binaryExpression)) setToOut( "if (" ); eh.addSuperConditionString( ((IfThenElseStatement)aNode).getCondition() ); addToOut( ")" ); insertBlockStatement( ((IfThenElseStatement)aNode).getThenStatement() ); // nested if-then-else printNestedIfThenElse( ((IfThenElseStatement)aNode).getElseStatement() ); printOut(); return; } if (aNode instanceof IfThenStatement) { // binary expressions start with ( and end with ) // it should be delete in if ((binaryExpression)) setToOut( "if (" ); eh.addSuperConditionString( ((IfThenStatement)aNode).getCondition() ); addToOut( ")" ); // check if blockstatement otherwise include { } insertBlockStatement( ((IfThenStatement)aNode).getThenStatement() ); printOut(); return; } // synchronized(var) if (aNode instanceof SynchronizedStatement) { // binary expressions start with ( and end with ) // it should be delete in if ((binaryExpression)) setToOut( "synchronized (" ); eh.addSuperConditionString( ((SynchronizedStatement)aNode).getLock() ); addToOut( ")" ); // printOut(); // jco.increaseIndent(); parseObject( ((SynchronizedStatement)aNode).getBody() ); // jco.decreaseIndent(); printOut(); return; } // loops // while if (aNode instanceof WhileStatement) { WhileStatement ws = (WhileStatement)aNode; setToOut( "while (" ); eh.addSuperConditionString( ws.getCondition() ); addToOut( ")" ); // empty while only if (ws.getBody() instanceof EmptyStatement || ws.getBody() instanceof BlockStatement && ((BlockStatement)ws.getBody()).getStatements().size() < 1) { printOut( ";" ); } else { insertBlockStatement( ws.getBody() ); printOut(); } return; } // do if (aNode instanceof DoStatement) { setToOut( "do" ); // jco.increaseIndent(); parseObject( ((DoStatement)aNode).getBody() ); // jco.decreaseIndent(); addToOut( "while (" ); eh.addSuperConditionString( ((DoStatement)aNode).getCondition() ); addToOut( ");" ); printOut(); return; } // for(i=0;i<j;i++) if (aNode instanceof ForStatement) { ForStatement fs = (ForStatement)aNode; setToOut( "for (" ); // i=0 addVariableDeclarationListString( fs.getInitialization() ); addToOut( ";" ); if (fs.getCondition() != null) { addToOut( " " ); } // i<j eh.addSuperConditionString( fs.getCondition() ); addToOut( ";" ); // i++ eh.addConditionListString( fs.getUpdate(), false ); addToOut( ")" ); // empty loop? if (fs.getBody() instanceof EmptyStatement || fs.getBody() instanceof BlockStatement && ((BlockStatement)fs.getBody()).getStatements().size() < 1) { printOut( ";" ); } else { insertBlockStatement( fs.getBody() ); // addToOut( " {" ); printOut(); // body // jco.increaseIndent(); // parseObject( fs.getBody() ); // jco.decreaseIndent(); // printOut(); } return; } // switch if (aNode instanceof SwitchStatement) { SwitchStatement ss = (SwitchStatement)aNode; setToOut( "switch (" ); eh.addSuperConditionString( ss.getSelector() ); addToOut( ") {" ); printOut(); // empty while only it = ss.getBindings().listIterator(); // case lines while (it.hasNext()) { parseObject( (Node)it.next() ); } jco.setCommentEnd( aNode.getEndLine() ); jco.printComment(); jco.setCommentStart( aNode.getEndLine() ); printOut( "}" ); return; } // switch if (aNode instanceof SwitchBlock) { SwitchBlock sb = (SwitchBlock)aNode; if (sb.getExpression() != null) { setToOut( "case " ); eh.addSuperConditionString( sb.getExpression() ); addToOut( ":" ); } else { setToOut( "default:" ); } // printOut(); if (sb.getStatements() != null) { // jco.increaseIndent(); it = sb.getStatements().listIterator(); // case lines if (it.hasNext()) { Node node = (Node)it.next(); if (node instanceof BlockStatement) { // printOut inside blockstatement parseObject( node ); jco.increaseIndent(); printOut(); jco.decreaseIndent(); } else { printOut(); jco.increaseIndent(); parseObject( node ); jco.decreaseIndent(); } } // case lines while (it.hasNext()) { Node node = (Node)it.next(); jco.increaseIndent(); parseObject( node ); jco.decreaseIndent(); if (node instanceof BlockStatement) { // printOut inside blockstatement jco.increaseIndent(); printOut(); jco.decreaseIndent(); } } // following comments jco.setCommentEnd( aNode.getEndLine() ); jco.printComment(); jco.setCommentStart( aNode.getEndLine() ); // jco.decreaseIndent(); } else { // no statements printOut(); } return; } // try catch finally if (aNode instanceof TryStatement) { TryStatement tryS = (TryStatement)aNode; // try setToOut( "try" ); // jco.increaseIndent(); parseObject( tryS.getTryBlock() ); // jco.decreaseIndent(); // setToOut( "} " ); // catch it = tryS.getCatchStatements().listIterator(); while (it.hasNext()) { parseObject( (Node)it.next() ); } // finally if (tryS.getFinallyBlock() != null) { addToOut( "finally" ); // jco.increaseIndent(); parseObject( ((TryStatement)aNode).getFinallyBlock() ); // jco.decreaseIndent(); printOut(); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -