From: Alexander Kriegisch Date: Sun, 25 Jul 2021 11:35:36 +0000 (+0700) Subject: Add AJDT support for printing switch expressions X-Git-Tag: V1_9_8_RC1~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0a1a66397b71d0e81270856db8eb30c55ec7adbd;p=aspectj.git Add AJDT support for printing switch expressions Signed-off-by: Alexander Kriegisch --- diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/CommonPrinter.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/CommonPrinter.java index 43f98336d..47be96344 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/CommonPrinter.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/CommonPrinter.java @@ -61,6 +61,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Statement; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SwitchExpression; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SwitchStatement; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ThrowStatement; @@ -617,6 +618,8 @@ public class CommonPrinter { return output; } else if (statement instanceof LocalDeclaration) { return printLocalDeclaration((LocalDeclaration) statement, indent); + } else if (statement instanceof SwitchExpression) { + return printSwitchExpression((SwitchExpression) statement, indent); } else if (statement instanceof SwitchStatement) { return printSwitchStatement((SwitchStatement) statement, indent); } else if (statement instanceof CaseStatement) { @@ -754,22 +757,44 @@ public class CommonPrinter { } private StringBuilder printBreakStatement(BreakStatement statement, int indent) { - printIndent(indent).append("break "); //$NON-NLS-1$ + printIndent(indent).append("break"); //$NON-NLS-1$ if (statement.label != null) { - output.append(statement.label); + output.append(' ').append(statement.label); } return output.append(';'); } private StringBuilder printCaseStatement(CaseStatement statement, int indent) { printIndent(indent); - if (statement.constantExpression == null) { - output.append("default : "); //$NON-NLS-1$ + if (statement.constantExpressions == null) { + output.append("default "); //$NON-NLS-1$ + output.append(statement.isExpr ? "->" : ":"); //$NON-NLS-1$ //$NON-NLS-2$ } else { output.append("case "); //$NON-NLS-1$ - printExpression(statement.constantExpression).append(" : "); //$NON-NLS-1$ + for (int i = 0, l = statement.constantExpressions.length; i < l; ++i) { + printExpression(statement.constantExpressions[i]); + if (i < l -1) output.append(','); + } + output.append(statement.isExpr ? " ->" : " :"); //$NON-NLS-1$ //$NON-NLS-2$ } - return output;// output.append(';'); + return output; + } + + private StringBuilder printSwitchExpression(SwitchExpression statement, int indent) { + printIndent(indent).append("switch ("); //$NON-NLS-1$ + printExpression(statement.expression).append(") {"); //$NON-NLS-1$ + if (statement.statements != null) { + for (int i = 0; i < statement.statements.length; i++) { + output.append('\n'); + if (statement.statements[i] instanceof CaseStatement) { + printCaseStatement((CaseStatement) statement.statements[i], indent); + } else { + printStatement(statement.statements[i], indent + 2); + } + } + } + output.append("\n"); //$NON-NLS-1$ + return printIndent(indent).append('}'); } private StringBuilder printSwitchStatement(SwitchStatement statement, int indent) { @@ -779,7 +804,7 @@ public class CommonPrinter { for (int i = 0; i < statement.statements.length; i++) { output.append('\n'); if (statement.statements[i] instanceof CaseStatement) { - printStatement(statement.statements[i], indent); + printCaseStatement((CaseStatement) statement.statements[i], indent); } else { printStatement(statement.statements[i], indent + 2); }