if (input == null || input.isNull()) {
return null;
}
final Match m2 = HASH_CODE_PATTERN.match(input);
if (!m2.success()) {
return null;
}
final InvocationExpression hashCodeCall = first(m2.<InvocationExpression>get("hashCodeCall"));
final MemberReference hashCodeMethod = hashCodeCall.getUserData(Keys.MEMBER_REFERENCE);
if (!(hashCodeMethod instanceof MethodReference &&
"java/lang/String".equals(hashCodeMethod.getDeclaringType().getInternalName()))) {
return null;
}
final List<Match> matches = new ArrayList<>();
final AstNodeCollection<SwitchSection> sections = node.getSwitchSections();
for (final SwitchSection section : sections) {
final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels();
if (caseLabels.isEmpty() ||
caseLabels.hasSingleElement() && caseLabels.firstOrNullObject().isNull()) {
//
// Eclipse does not emit default sections.
//
return null;
}
final Match m3 = CASE_BODY_PATTERN.match(section.getStatements().firstOrNullObject());
if (m3.success()) {
matches.add(m3);
}
else {
return null;
}
}
int matchIndex = 0;
BreakStatement defaultBreak = null;
for (final SwitchSection section : sections) {
final Match m = matches.get(matchIndex++);
final IfElseStatement test = first(m.<IfElseStatement>get("test"));
final List<PrimitiveExpression> stringValues = toList(m.<PrimitiveExpression>get("stringValue"));
final AstNodeCollection<CaseLabel> caseLabels = section.getCaseLabels();
if (defaultBreak == null) {
defaultBreak = firstOrDefault(m.<BreakStatement>get("defaultBreak"));
}
caseLabels.clear();
test.remove();