Search in sources :

Example 16 with ITypeReferenceOwner

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;
                }
            }
        }
    });
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XCasePart(org.eclipse.xtext.xbase.XCasePart) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) WrappedException(org.eclipse.emf.common.util.WrappedException) BadLocationException(org.eclipse.jface.text.BadLocationException) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)11 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)6 EObject (org.eclipse.emf.ecore.EObject)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)4 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)3 WrappedException (org.eclipse.emf.common.util.WrappedException)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)3 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)3 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)3 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)3 ParameterizedTypeReference (org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2