Search in sources :

Example 1 with SwitchExpression

use of org.eclipse.jdt.core.dom.SwitchExpression in project eclipse.jdt.ls by eclipse.

the class LocalCorrectionsSubProcessor method addMissingDefaultCaseProposal.

public static void addMissingDefaultCaseProposal(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode instanceof Expression) {
        StructuralPropertyDescriptor locationInParent = selectedNode.getLocationInParent();
        ASTNode parent = selectedNode.getParent();
        List<Statement> statements;
        if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) {
            statements = ((SwitchStatement) parent).statements();
        } else if (locationInParent == SwitchExpression.EXPRESSION_PROPERTY) {
            statements = ((SwitchExpression) parent).statements();
        } else {
            return;
        }
        for (Statement statement : statements) {
            if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) {
                return;
            }
        }
        createMissingDefaultProposal(context, parent, proposals);
    }
}
Also used : SwitchCase(org.eclipse.jdt.core.dom.SwitchCase) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) Statement(org.eclipse.jdt.core.dom.Statement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) StructuralPropertyDescriptor(org.eclipse.jdt.core.dom.StructuralPropertyDescriptor)

Example 2 with SwitchExpression

use of org.eclipse.jdt.core.dom.SwitchExpression in project eclipse.jdt.ls by eclipse.

the class LocalCorrectionsSubProcessor method createMissingCaseProposals.

@SuppressWarnings("deprecation")
public static void createMissingCaseProposals(IInvocationContext context, ASTNode parent, ArrayList<String> enumConstNames, Collection<ChangeCorrectionProposal> proposals) {
    List<Statement> statements;
    Expression expression;
    if (parent instanceof SwitchStatement) {
        SwitchStatement switchStatement = (SwitchStatement) parent;
        statements = switchStatement.statements();
        expression = switchStatement.getExpression();
    } else if (parent instanceof SwitchExpression) {
        SwitchExpression switchExpression = (SwitchExpression) parent;
        statements = switchExpression.statements();
        expression = switchExpression.getExpression();
    } else {
        return;
    }
    int defaultIndex = statements.size();
    for (int i = 0; i < statements.size(); i++) {
        Statement curr = statements.get(i);
        if (curr instanceof SwitchCase) {
            SwitchCase switchCase = (SwitchCase) curr;
            if (ASTHelper.isSwitchCaseExpressionsSupportedInAST(switchCase.getAST())) {
                if (switchCase.expressions().size() == 0) {
                    defaultIndex = i;
                    break;
                }
            } else if (switchCase.getExpression() == null) {
                defaultIndex = i;
                break;
            }
        }
    }
    boolean hasDefault = defaultIndex < statements.size();
    AST ast = parent.getAST();
    if (enumConstNames.size() > 0) {
        ASTRewrite astRewrite = ASTRewrite.create(ast);
        ListRewrite listRewrite;
        if (parent instanceof SwitchStatement) {
            listRewrite = astRewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
        } else {
            listRewrite = astRewrite.getListRewrite(parent, SwitchExpression.STATEMENTS_PROPERTY);
        }
        String label = CorrectionMessages.LocalCorrectionsSubProcessor_add_missing_cases_description;
        LinkedCorrectionProposal proposal = new LinkedCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_MISSING_CASE_STATEMENTS);
        for (int i = 0; i < enumConstNames.size(); i++) {
            SwitchCase newSwitchCase = ast.newSwitchCase();
            String enumConstName = enumConstNames.get(i);
            Name newName = ast.newName(enumConstName);
            if (ASTHelper.isSwitchCaseExpressionsSupportedInAST(ast)) {
                newSwitchCase.expressions().add(newName);
            } else {
                newSwitchCase.setExpression(newName);
            }
            listRewrite.insertAt(newSwitchCase, defaultIndex, null);
            defaultIndex++;
            if (!hasDefault) {
                if (ASTHelper.isSwitchExpressionNodeSupportedInAST(ast)) {
                    if (statements.size() > 0) {
                        Statement firstStatement = statements.get(0);
                        SwitchCase switchCase = (SwitchCase) firstStatement;
                        boolean isArrow = switchCase.isSwitchLabeledRule();
                        newSwitchCase.setSwitchLabeledRule(isArrow);
                        if (isArrow || parent instanceof SwitchExpression) {
                            ThrowStatement newThrowStatement = getThrowForUnsupportedCase(expression, ast, astRewrite);
                            listRewrite.insertLast(newThrowStatement, null);
                            proposal.addLinkedPosition(astRewrite.track(newThrowStatement), true, enumConstName);
                        } else {
                            listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
                        }
                    } else {
                        listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
                    }
                } else {
                    listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
                }
                defaultIndex++;
            }
        }
        if (!hasDefault) {
            SwitchCase newSwitchCase = ast.newSwitchCase();
            listRewrite.insertAt(newSwitchCase, defaultIndex, null);
            defaultIndex++;
            if (ASTHelper.isSwitchExpressionNodeSupportedInAST(ast)) {
                if (statements.size() > 0) {
                    Statement firstStatement = statements.get(0);
                    SwitchCase switchCase = (SwitchCase) firstStatement;
                    boolean isArrow = switchCase.isSwitchLabeledRule();
                    newSwitchCase.setSwitchLabeledRule(isArrow);
                    if (isArrow || parent instanceof SwitchExpression) {
                        ThrowStatement newThrowStatement = getThrowForUnexpectedDefault(expression, ast, astRewrite);
                        listRewrite.insertLast(newThrowStatement, null);
                        // $NON-NLS-1$
                        proposal.addLinkedPosition(astRewrite.track(newThrowStatement), true, "defaultCase");
                    } else {
                        listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
                    }
                } else {
                    listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
                }
            } else {
                newSwitchCase.setExpression(null);
                listRewrite.insertAt(ast.newBreakStatement(), defaultIndex, null);
            }
        }
        proposals.add(proposal);
    }
    if (!hasDefault) {
        createMissingDefaultProposal(context, parent, proposals);
    }
}
Also used : AST(org.eclipse.jdt.core.dom.AST) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) Statement(org.eclipse.jdt.core.dom.Statement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) SwitchCase(org.eclipse.jdt.core.dom.SwitchCase) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement)

Example 3 with SwitchExpression

use of org.eclipse.jdt.core.dom.SwitchExpression in project eclipse.jdt.ls by eclipse.

the class UnresolvedElementsSubProcessor method getVariableProposals.

public static void getVariableProposals(IInvocationContext context, IProblemLocationCore problem, IVariableBinding resolvedField, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();
    CompilationUnit astRoot = context.getASTRoot();
    ASTNode selectedNode = problem.getCoveredNode(astRoot);
    if (selectedNode == null) {
        return;
    }
    // type that defines the variable
    ITypeBinding binding = null;
    ITypeBinding declaringTypeBinding = Bindings.getBindingOfParentTypeContext(selectedNode);
    if (declaringTypeBinding == null) {
        return;
    }
    // possible type kind of the node
    boolean suggestVariableProposals = true;
    int typeKind = 0;
    while (selectedNode instanceof ParenthesizedExpression) {
        selectedNode = ((ParenthesizedExpression) selectedNode).getExpression();
    }
    Name node = null;
    switch(selectedNode.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
            node = (SimpleName) selectedNode;
            ASTNode parent = node.getParent();
            StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
            if (locationInParent == ExpressionMethodReference.EXPRESSION_PROPERTY) {
                typeKind = TypeKinds.REF_TYPES;
            } else if (locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
                if (JavaModelUtil.is1d8OrHigher(cu.getJavaProject())) {
                    typeKind = TypeKinds.CLASSES | TypeKinds.INTERFACES | TypeKinds.ENUMS;
                } else {
                    typeKind = TypeKinds.CLASSES;
                }
            } else if (locationInParent == FieldAccess.NAME_PROPERTY) {
                Expression expression = ((FieldAccess) parent).getExpression();
                if (expression != null) {
                    binding = expression.resolveTypeBinding();
                    if (binding == null) {
                        node = null;
                    }
                }
            } else if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
                suggestVariableProposals = false;
                typeKind = TypeKinds.REF_TYPES_AND_VAR;
            } else if (parent instanceof QualifiedName) {
                Name qualifier = ((QualifiedName) parent).getQualifier();
                if (qualifier != node) {
                    binding = qualifier.resolveTypeBinding();
                } else {
                    typeKind = TypeKinds.REF_TYPES;
                }
                ASTNode outerParent = parent.getParent();
                while (outerParent instanceof QualifiedName) {
                    outerParent = outerParent.getParent();
                }
                if (outerParent instanceof SimpleType || outerParent instanceof NameQualifiedType) {
                    typeKind = TypeKinds.REF_TYPES;
                    suggestVariableProposals = false;
                }
            } else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY || locationInParent == SwitchCase.EXPRESSIONS2_PROPERTY) {
                ASTNode caseParent = node.getParent().getParent();
                ITypeBinding switchExp = null;
                if (caseParent instanceof SwitchStatement) {
                    switchExp = ((SwitchStatement) caseParent).getExpression().resolveTypeBinding();
                } else if (caseParent instanceof SwitchExpression) {
                    switchExp = ((SwitchExpression) caseParent).getExpression().resolveTypeBinding();
                }
                if (switchExp != null && switchExp.isEnum()) {
                    binding = switchExp;
                }
            } else if (locationInParent == SuperFieldAccess.NAME_PROPERTY) {
                binding = declaringTypeBinding.getSuperclass();
            }
            break;
        case ASTNode.QUALIFIED_NAME:
            QualifiedName qualifierName = (QualifiedName) selectedNode;
            ITypeBinding qualifierBinding = qualifierName.getQualifier().resolveTypeBinding();
            if (qualifierBinding != null) {
                node = qualifierName.getName();
                binding = qualifierBinding;
            } else {
                node = qualifierName.getQualifier();
                typeKind = TypeKinds.REF_TYPES;
                suggestVariableProposals = node.isSimpleName();
            }
            if (selectedNode.getParent() instanceof SimpleType || selectedNode.getParent() instanceof NameQualifiedType) {
                typeKind = TypeKinds.REF_TYPES;
                suggestVariableProposals = false;
            }
            break;
        case ASTNode.FIELD_ACCESS:
            FieldAccess access = (FieldAccess) selectedNode;
            Expression expression = access.getExpression();
            if (expression != null) {
                binding = expression.resolveTypeBinding();
                if (binding != null) {
                    node = access.getName();
                }
            }
            break;
        case ASTNode.SUPER_FIELD_ACCESS:
            binding = declaringTypeBinding.getSuperclass();
            node = ((SuperFieldAccess) selectedNode).getName();
            break;
        default:
    }
    if (node == null) {
        return;
    }
    // add type proposals
    if (typeKind != 0) {
        if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
            typeKind &= ~(TypeKinds.ANNOTATIONS | TypeKinds.ENUMS | TypeKinds.VARIABLES);
        }
        int relevance = Character.isUpperCase(ASTNodes.getSimpleNameIdentifier(node).charAt(0)) ? IProposalRelevance.VARIABLE_TYPE_PROPOSAL_1 : IProposalRelevance.VARIABLE_TYPE_PROPOSAL_2;
        addSimilarTypeProposals(typeKind, cu, node, relevance + 1, proposals);
        typeKind &= ~TypeKinds.ANNOTATIONS;
        addNewTypeProposals(cu, node, typeKind, relevance, proposals);
    }
    if (!suggestVariableProposals) {
        return;
    }
    SimpleName simpleName = node.isSimpleName() ? (SimpleName) node : ((QualifiedName) node).getName();
    boolean isWriteAccess = ASTResolving.isWriteAccess(node);
    // similar variables
    addSimilarVariableProposals(cu, astRoot, binding, resolvedField, simpleName, isWriteAccess, proposals);
    if (binding == null) {
        addStaticImportFavoriteProposals(context, simpleName, false, proposals);
    }
    if (resolvedField == null || binding == null || resolvedField.getDeclaringClass() != binding.getTypeDeclaration() && Modifier.isPrivate(resolvedField.getModifiers())) {
        // new fields
        addNewFieldProposals(cu, astRoot, binding, declaringTypeBinding, simpleName, isWriteAccess, proposals);
        // new parameters and local variables
        if (binding == null) {
            addNewVariableProposals(cu, node, simpleName, proposals);
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) SimpleName(org.eclipse.jdt.core.dom.SimpleName) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name) SimpleType(org.eclipse.jdt.core.dom.SimpleType) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) StructuralPropertyDescriptor(org.eclipse.jdt.core.dom.StructuralPropertyDescriptor)

Example 4 with SwitchExpression

use of org.eclipse.jdt.core.dom.SwitchExpression in project eclipse.jdt.ls by eclipse.

the class NavigateToDefinitionHandler method computeBreakContinue.

private Location computeBreakContinue(ITypeRoot typeRoot, int line, int column) throws CoreException {
    int offset = JsonRpcHelpers.toOffset(typeRoot.getBuffer(), line, column);
    if (offset >= 0) {
        CompilationUnit unit = SharedASTProviderCore.getAST(typeRoot, SharedASTProviderCore.WAIT_YES, null);
        if (unit == null) {
            return null;
        }
        ASTNode selectedNode = NodeFinder.perform(unit, offset, 0);
        ASTNode node = null;
        SimpleName label = null;
        if (selectedNode instanceof BreakStatement) {
            node = selectedNode;
            label = ((BreakStatement) node).getLabel();
        } else if (selectedNode instanceof ContinueStatement) {
            node = selectedNode;
            label = ((ContinueStatement) node).getLabel();
        } else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof BreakStatement) {
            node = selectedNode.getParent();
            label = ((BreakStatement) node).getLabel();
        } else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof ContinueStatement) {
            node = selectedNode.getParent();
            label = ((ContinueStatement) node).getLabel();
        }
        if (node != null) {
            ASTNode parent = node.getParent();
            ASTNode target = null;
            while (parent != null) {
                if (parent instanceof MethodDeclaration || parent instanceof Initializer) {
                    break;
                }
                if (label == null) {
                    if (parent instanceof ForStatement || parent instanceof EnhancedForStatement || parent instanceof WhileStatement || parent instanceof DoStatement) {
                        target = parent;
                        break;
                    }
                    if (node instanceof BreakStatement) {
                        if (parent instanceof SwitchStatement || parent instanceof SwitchExpression) {
                            target = parent;
                            break;
                        }
                    }
                    if (node instanceof LabeledStatement) {
                        target = parent;
                        break;
                    }
                } else if (LabeledStatement.class.isInstance(parent)) {
                    LabeledStatement ls = (LabeledStatement) parent;
                    if (ls.getLabel().getIdentifier().equals(label.getIdentifier())) {
                        target = ls;
                        break;
                    }
                }
                parent = parent.getParent();
            }
            if (target != null) {
                int start = target.getStartPosition();
                int end = new TokenScanner(unit.getTypeRoot()).getNextEndOffset(node.getStartPosition(), true) - start;
                if (start >= 0 && end >= 0) {
                    return JDTUtils.toLocation((ICompilationUnit) typeRoot, start, end);
                }
            }
        }
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TokenScanner(org.eclipse.jdt.internal.corext.dom.TokenScanner) DoStatement(org.eclipse.jdt.core.dom.DoStatement) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) SimpleName(org.eclipse.jdt.core.dom.SimpleName) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) BreakStatement(org.eclipse.jdt.core.dom.BreakStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) Initializer(org.eclipse.jdt.core.dom.Initializer) ASTNode(org.eclipse.jdt.core.dom.ASTNode) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) ContinueStatement(org.eclipse.jdt.core.dom.ContinueStatement)

Example 5 with SwitchExpression

use of org.eclipse.jdt.core.dom.SwitchExpression in project eclipse.jdt.ls by eclipse.

the class LocalCorrectionsSubProcessor method createMissingDefaultProposal.

@SuppressWarnings("deprecation")
private static void createMissingDefaultProposal(IInvocationContext context, ASTNode parent, Collection<ChangeCorrectionProposal> proposals) {
    List<Statement> statements;
    Expression expression;
    if (parent instanceof SwitchStatement) {
        SwitchStatement switchStatement = (SwitchStatement) parent;
        statements = switchStatement.statements();
        expression = switchStatement.getExpression();
    } else if (parent instanceof SwitchExpression) {
        SwitchExpression switchExpression = (SwitchExpression) parent;
        statements = switchExpression.statements();
        expression = switchExpression.getExpression();
    } else {
        return;
    }
    AST ast = parent.getAST();
    ASTRewrite astRewrite = ASTRewrite.create(ast);
    ListRewrite listRewrite;
    if (parent instanceof SwitchStatement) {
        listRewrite = astRewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY);
    } else {
        listRewrite = astRewrite.getListRewrite(parent, SwitchExpression.STATEMENTS_PROPERTY);
    }
    String label = CorrectionMessages.LocalCorrectionsSubProcessor_add_default_case_description;
    LinkedCorrectionProposal proposal = new LinkedCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), astRewrite, IProposalRelevance.ADD_MISSING_DEFAULT_CASE);
    SwitchCase newSwitchCase = ast.newSwitchCase();
    listRewrite.insertLast(newSwitchCase, null);
    if (ASTHelper.isSwitchCaseExpressionsSupportedInAST(ast)) {
        if (statements.size() > 0) {
            Statement firstStatement = statements.get(0);
            SwitchCase switchCase = (SwitchCase) firstStatement;
            boolean isArrow = switchCase.isSwitchLabeledRule();
            newSwitchCase.setSwitchLabeledRule(isArrow);
            if (isArrow || parent instanceof SwitchExpression) {
                ThrowStatement newThrowStatement = getThrowForUnexpectedDefault(expression, ast, astRewrite);
                listRewrite.insertLast(newThrowStatement, null);
                proposal.addLinkedPosition(astRewrite.track(newThrowStatement), true, null);
            } else {
                listRewrite.insertLast(ast.newBreakStatement(), null);
            }
        } else {
            listRewrite.insertLast(ast.newBreakStatement(), null);
        }
    } else {
        newSwitchCase.setExpression(null);
        listRewrite.insertLast(ast.newBreakStatement(), null);
    }
    proposals.add(proposal);
}
Also used : AST(org.eclipse.jdt.core.dom.AST) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) Statement(org.eclipse.jdt.core.dom.Statement) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) TryStatement(org.eclipse.jdt.core.dom.TryStatement) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) EmptyStatement(org.eclipse.jdt.core.dom.EmptyStatement) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) SwitchCase(org.eclipse.jdt.core.dom.SwitchCase) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) Expression(org.eclipse.jdt.core.dom.Expression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) SwitchExpression(org.eclipse.jdt.core.dom.SwitchExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) ThrowStatement(org.eclipse.jdt.core.dom.ThrowStatement)

Aggregations

SwitchExpression (org.eclipse.jdt.core.dom.SwitchExpression)7 SwitchStatement (org.eclipse.jdt.core.dom.SwitchStatement)7 CastExpression (org.eclipse.jdt.core.dom.CastExpression)5 Expression (org.eclipse.jdt.core.dom.Expression)5 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)5 ForStatement (org.eclipse.jdt.core.dom.ForStatement)5 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)5 Statement (org.eclipse.jdt.core.dom.Statement)5 ThrowStatement (org.eclipse.jdt.core.dom.ThrowStatement)5 TryStatement (org.eclipse.jdt.core.dom.TryStatement)5 WhileStatement (org.eclipse.jdt.core.dom.WhileStatement)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)4 EmptyStatement (org.eclipse.jdt.core.dom.EmptyStatement)4 IfStatement (org.eclipse.jdt.core.dom.IfStatement)4 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)4 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)4 SwitchCase (org.eclipse.jdt.core.dom.SwitchCase)4 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)4 SimpleName (org.eclipse.jdt.core.dom.SimpleName)3