use of org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner in project xtext-eclipse by eclipse.
the class XbaseQuickfixProvider method fixUnreachableCase.
@Fix(IssueCodes.UNREACHABLE_CASE)
public void fixUnreachableCase(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove case", "Remove case", null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
remove(element, XCasePart.class, context);
}
});
acceptor.accept(issue, "Move case up", "Move case up", null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XCasePart casePart = EcoreUtil2.getContainerOfType(element, XCasePart.class);
if (casePart == null) {
return;
}
ICompositeNode caseNode = NodeModelUtils.findActualNodeFor(casePart);
if (caseNode == null) {
return;
}
XSwitchExpression switchExpression = EcoreUtil2.getContainerOfType(casePart, XSwitchExpression.class);
if (switchExpression == null) {
return;
}
ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, switchExpression);
LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(casePart.getTypeGuard());
for (XCasePart previousCasePart : switchExpression.getCases()) {
if (previousCasePart == casePart) {
return;
}
JvmTypeReference typeGuard = previousCasePart.getTypeGuard();
if (typeGuard == null || previousCasePart.getCase() != null) {
continue;
}
LightweightTypeReference previousTypeReference = owner.toLightweightTypeReference(typeGuard);
if (typesOrderUtil.isHandled(actualTypeReference, previousTypeReference)) {
ICompositeNode previousCaseNode = NodeModelUtils.findActualNodeFor(previousCasePart);
if (previousCaseNode == null) {
return;
}
moveUp(caseNode, previousCaseNode, context);
return;
}
}
}
});
}
Aggregations