use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel in project intellij-community by JetBrains.
the class GroovyDuplicateSwitchBranchInspection method collectCaseLabels.
private static GrCaseLabel[] collectCaseLabels(final GrSwitchStatement containingStatelent) {
final Set<GrCaseLabel> labels = new HashSet<>();
final GroovyRecursiveElementVisitor visitor = new GroovyRecursiveElementVisitor() {
@Override
public void visitCaseLabel(@NotNull GrCaseLabel grCaseLabel) {
super.visitCaseLabel(grCaseLabel);
labels.add(grCaseLabel);
}
@Override
public void visitSwitchStatement(@NotNull GrSwitchStatement grSwitchStatement) {
if (containingStatelent.equals(grSwitchStatement)) {
super.visitSwitchStatement(grSwitchStatement);
}
}
};
containingStatelent.accept(visitor);
return labels.toArray(new GrCaseLabel[labels.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel in project intellij-community by JetBrains.
the class GrCreateMissingSwitchBranchesIntention method findUnusedConstants.
private static List<PsiEnumConstant> findUnusedConstants(GrSwitchStatement switchStatement) {
final GrExpression condition = switchStatement.getCondition();
if (condition == null)
return Collections.emptyList();
final PsiType type = condition.getType();
if (!(type instanceof PsiClassType))
return Collections.emptyList();
final PsiClass resolved = ((PsiClassType) type).resolve();
if (resolved == null || !resolved.isEnum())
return Collections.emptyList();
final PsiField[] fields = resolved.getFields();
final List<PsiEnumConstant> constants = ContainerUtil.findAll(fields, PsiEnumConstant.class);
final GrCaseSection[] sections = switchStatement.getCaseSections();
for (GrCaseSection section : sections) {
for (GrCaseLabel label : section.getCaseLabels()) {
final GrExpression value = label.getValue();
if (value instanceof GrReferenceExpression) {
final PsiElement r = ((GrReferenceExpression) value).resolve();
constants.remove(r);
}
}
}
return constants;
}
Aggregations