Search in sources :

Example 1 with StandardTypeReferenceOwner

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

the class XbaseLabelProvider method signature.

protected StyledString signature(final String simpleName, final JvmIdentifiableElement element) {
    JvmTypeReference _xifexpression = null;
    if ((element instanceof JvmOperation)) {
        _xifexpression = ((JvmOperation) element).getReturnType();
    } else {
        JvmTypeReference _xifexpression_1 = null;
        if ((element instanceof JvmField)) {
            _xifexpression_1 = ((JvmField) element).getType();
        } else {
            _xifexpression_1 = null;
        }
        _xifexpression = _xifexpression_1;
    }
    final JvmTypeReference returnType = _xifexpression;
    final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, element);
    String _xifexpression_2 = null;
    if ((returnType == null)) {
        _xifexpression_2 = "void";
    } else {
        _xifexpression_2 = owner.toLightweightTypeReference(returnType).getHumanReadableName();
    }
    final String returnTypeString = _xifexpression_2;
    String decoratedPart = (" : " + returnTypeString);
    String _elvis = null;
    String _typeParameters = this.uiStrings.typeParameters(element);
    if (_typeParameters != null) {
        _elvis = _typeParameters;
    } else {
        _elvis = "";
    }
    final String typeParam = _elvis;
    boolean _notEquals = (!Objects.equal(typeParam, ""));
    if (_notEquals) {
        decoratedPart = (((" " + typeParam) + " : ") + returnTypeString);
    }
    String _parameters = this.uiStrings.parameters(element);
    String _plus = (simpleName + _parameters);
    StyledString _styledString = new StyledString(_plus);
    StyledString _styledString_1 = new StyledString(decoratedPart, StyledString.DECORATIONS_STYLER);
    return _styledString.append(_styledString_1);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 2 with StandardTypeReferenceOwner

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

the class XbaseQuickfixProvider method fixUnreachableCatchBlock.

@Fix(IssueCodes.UNREACHABLE_CATCH_BLOCK)
public void fixUnreachableCatchBlock(final Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Remove catch block", "Remove catch block", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            remove(element, XCatchClause.class, context);
        }
    });
    acceptor.accept(issue, "Move catch block up", "Move catch block up", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XCatchClause catchClause = EcoreUtil2.getContainerOfType(element, XCatchClause.class);
            if (catchClause == null) {
                return;
            }
            ICompositeNode node = NodeModelUtils.findActualNodeFor(catchClause);
            if (node == null) {
                return;
            }
            XTryCatchFinallyExpression tryCatchFinallyExpression = EcoreUtil2.getContainerOfType(catchClause, XTryCatchFinallyExpression.class);
            if (tryCatchFinallyExpression == null) {
                return;
            }
            ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, tryCatchFinallyExpression);
            LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(catchClause.getDeclaredParam().getParameterType());
            for (XCatchClause previousCatchClause : tryCatchFinallyExpression.getCatchClauses()) {
                if (previousCatchClause == catchClause) {
                    return;
                }
                LightweightTypeReference previousTypeReference = owner.toLightweightTypeReference(previousCatchClause.getDeclaredParam().getParameterType());
                if (typesOrderUtil.isHandled(actualTypeReference, previousTypeReference)) {
                    ICompositeNode previousNode = NodeModelUtils.findActualNodeFor(previousCatchClause);
                    if (previousNode == null) {
                        return;
                    }
                    moveUp(node, previousNode, context);
                    return;
                }
            }
        }
    });
}
Also used : XCatchClause(org.eclipse.xtext.xbase.XCatchClause) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) 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 3 with StandardTypeReferenceOwner

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

the class XbaseQuickfixProvider method fixUnreachableIfBlock.

@Fix(IssueCodes.UNREACHABLE_IF_BLOCK)
public void fixUnreachableIfBlock(final Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Remove if block", "Remove if block", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XIfExpression ifExpression = EcoreUtil2.getContainerOfType(element, XIfExpression.class);
            if (ifExpression == null) {
                return;
            }
            ICompositeNode node = NodeModelUtils.findActualNodeFor(ifExpression);
            if (node == null) {
                return;
            }
            int[] offsetAndLength = getOffsetAndLength(ifExpression, node);
            context.getXtextDocument().replace(offsetAndLength[0], offsetAndLength[1], "");
        }
    });
    acceptor.accept(issue, "Move if block up", "Move if block up", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XIfExpression ifExpression = EcoreUtil2.getContainerOfType(element, XIfExpression.class);
            if (ifExpression == null) {
                return;
            }
            ICompositeNode node = NodeModelUtils.findActualNodeFor(ifExpression);
            if (node == null) {
                return;
            }
            XIfExpression firstIfExpression = getFirstIfExpression(ifExpression);
            if (firstIfExpression == null) {
                return;
            }
            XInstanceOfExpression actualIfPart = (XInstanceOfExpression) ifExpression.getIf();
            XAbstractFeatureCall actualFeatureCall = (XAbstractFeatureCall) actualIfPart.getExpression();
            JvmIdentifiableElement actualFeature = actualFeatureCall.getFeature();
            ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, firstIfExpression);
            LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(actualIfPart.getType());
            List<XExpression> ifParts = collectIfParts(firstIfExpression, new ArrayList<XExpression>());
            for (XExpression previousIfPart : ifParts) {
                if (actualIfPart == previousIfPart) {
                    return;
                }
                if (!(previousIfPart instanceof XInstanceOfExpression)) {
                    continue;
                }
                XInstanceOfExpression instanceOfExpression = (XInstanceOfExpression) previousIfPart;
                if (!(instanceOfExpression.getExpression() instanceof XAbstractFeatureCall)) {
                    continue;
                }
                XAbstractFeatureCall previousFeatureCall = (XAbstractFeatureCall) instanceOfExpression.getExpression();
                if (previousFeatureCall.getFeature() != actualFeature) {
                    continue;
                }
                LightweightTypeReference previousTypeReference = owner.toLightweightTypeReference(instanceOfExpression.getType());
                if (typesOrderUtil.isHandled(actualTypeReference, previousTypeReference)) {
                    ICompositeNode previousNode = NodeModelUtils.findActualNodeFor(instanceOfExpression.eContainer());
                    if (previousNode == null) {
                        return;
                    }
                    int[] offsetAndLength = getOffsetAndLength(ifExpression, node);
                    int offset = offsetAndLength[0];
                    int length = offsetAndLength[1];
                    int endOffset = offset + length;
                    String text = node.getRootNode().getText().substring(offset, endOffset).trim();
                    if (text.startsWith("else")) {
                        text = text.substring("else".length()).trim();
                    }
                    if (!text.endsWith("else")) {
                        text = text + " else ";
                    } else {
                        text = text + " ";
                    }
                    IXtextDocument document = context.getXtextDocument();
                    document.replace(offset, length, "");
                    document.replace(previousNode.getOffset(), 0, text);
                    return;
                }
            }
        }

        private XIfExpression getFirstIfExpression(XIfExpression ifExpression) {
            EObject container = ifExpression.eContainer();
            if (container instanceof XIfExpression) {
                XIfExpression parentIfExpression = (XIfExpression) container;
                if (parentIfExpression.getElse() == ifExpression) {
                    return getFirstIfExpression(parentIfExpression);
                }
            }
            return ifExpression;
        }

        private List<XExpression> collectIfParts(XIfExpression expression, List<XExpression> result) {
            result.add(expression.getIf());
            if (expression.getElse() instanceof XIfExpression) {
                collectIfParts((XIfExpression) expression.getElse(), result);
            }
            return result;
        }
    });
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) ArrayList(java.util.ArrayList) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) WrappedException(org.eclipse.emf.common.util.WrappedException) BadLocationException(org.eclipse.jface.text.BadLocationException) XInstanceOfExpression(org.eclipse.xtext.xbase.XInstanceOfExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XExpression(org.eclipse.xtext.xbase.XExpression) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 4 with StandardTypeReferenceOwner

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

the class TypeBasedSimpleBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
    XtextResourceSet resourceSet = new XtextResourceSet();
    ClassLoader loader = getClass().getClassLoader();
    resourceSet.setClasspathURIContext(loader);
    typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
    CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
    owner = new StandardTypeReferenceOwner(services, resourceSet);
}
Also used : XbaseStandaloneSetup(org.eclipse.xtext.xbase.XbaseStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 5 with StandardTypeReferenceOwner

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

the class CompilationUnitImpl method before.

public void before(final ActiveAnnotationContexts.AnnotationCallback phase) {
    this.lastPhase = phase;
    final StandardTypeReferenceOwner standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.services, this.xtendFile);
    boolean _equals = Objects.equal(ActiveAnnotationContexts.AnnotationCallback.INDEXING, phase);
    if (_equals) {
        IndexingLightweightTypeReferenceFactory _indexingLightweightTypeReferenceFactory = new IndexingLightweightTypeReferenceFactory(standardTypeReferenceOwner);
        this.typeRefFactory = _indexingLightweightTypeReferenceFactory;
    } else {
        LightweightTypeReferenceFactory _lightweightTypeReferenceFactory = new LightweightTypeReferenceFactory(standardTypeReferenceOwner);
        this.typeRefFactory = _lightweightTypeReferenceFactory;
    }
    boolean _equals_1 = Objects.equal(ActiveAnnotationContexts.AnnotationCallback.VALIDATION, phase);
    if (_equals_1) {
        this.problemSupport.validationPhaseStarted();
    }
}
Also used : IndexingLightweightTypeReferenceFactory(org.eclipse.xtext.xbase.typesystem.references.IndexingLightweightTypeReferenceFactory) IndexingLightweightTypeReferenceFactory(org.eclipse.xtext.xbase.typesystem.references.IndexingLightweightTypeReferenceFactory) LightweightTypeReferenceFactory(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReferenceFactory) 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 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)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