Search in sources :

Example 26 with StandardTypeReferenceOwner

use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner 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)

Example 27 with StandardTypeReferenceOwner

use of org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner in project xtext-eclipse by eclipse.

the class JavaTypeQuickfixes method getVisibilityHelper.

protected ContextualVisibilityHelper getVisibilityHelper(final JvmDeclaredType contextType) {
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, contextType);
    final ParameterizedTypeReference contextTypeRef = owner.newParameterizedTypeReference(contextType);
    final ContextualVisibilityHelper visibilityHelper = new ContextualVisibilityHelper(contextTypeRef);
    return visibilityHelper;
}
Also used : ContextualVisibilityHelper(org.eclipse.xtext.xbase.typesystem.util.ContextualVisibilityHelper) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Aggregations

StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)27 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)11 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)6 XExpression (org.eclipse.xtext.xbase.XExpression)6 ParameterizedTypeReference (org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference)6 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)4 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)4 CommonTypeComputationServices (org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices)4 Injector (com.google.inject.Injector)3 WrappedException (org.eclipse.emf.common.util.WrappedException)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3