Search in sources :

Example 1 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-eclipse by eclipse.

the class Oven method fireproof.

public void fireproof(final String input) throws Exception {
    try {
        final EObject file = this._parseHelper.parse(input);
        final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
        Assert.assertNotNull(resolvedTypes);
        if ((file != null)) {
            Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
            for (final EObject content : _iterable) {
                boolean _matched = false;
                if (content instanceof XAbstractFeatureCall) {
                    _matched = true;
                    this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
                    boolean _tripleNotEquals = (_implicitReceiver != null);
                    if (_tripleNotEquals) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
                    }
                    XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
                    boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
                    if (_tripleNotEquals_1) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof XClosure) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                        final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
                            this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
                        };
                        ((XClosure) content).getImplicitFormalParameters().forEach(_function);
                    }
                }
                if (!_matched) {
                    if (content instanceof XExpression) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof JvmIdentifiableElement) {
                        _matched = true;
                        this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
                    }
                }
            }
        }
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            String _message = e.getMessage();
            final ComparisonFailure error = new ComparisonFailure(_message, input, "");
            error.setStackTrace(e.getStackTrace());
            throw error;
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 2 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-eclipse by eclipse.

the class AbstractJvmElementHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
    if (editor != null) {
        final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
        editor.getDocument().priorityReadOnly(new IUnitOfWork<Void, XtextResource>() {

            @Override
            public java.lang.Void exec(XtextResource resource) throws Exception {
                JvmIdentifiableElement jvmIdentifiable = jvmElementAtOffsetHelper.getJvmIdentifiableElement(resource, selection.getOffset());
                if (jvmIdentifiable != null) {
                    IJavaElement javaType = javaElementFinder.findElementFor(jvmIdentifiable);
                    if (javaType != null)
                        openPresentation(editor, javaType, jvmIdentifiable);
                }
                return null;
            }
        });
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextSelection(org.eclipse.jface.text.ITextSelection) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 3 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-eclipse by eclipse.

the class DomainmodelLabelProvider method doGetImage.

@Override
protected Object doGetImage(final Object element) {
    if (((element instanceof EObject) && (!(element instanceof JvmIdentifiableElement)))) {
        StringConcatenation _builder = new StringConcatenation();
        String _name = ((EObject) element).eClass().getName();
        _builder.append(_name);
        _builder.append(".gif");
        return _builder;
    }
    return super.doGetImage(element);
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-eclipse by eclipse.

the class XbaseHoverProvider method getHoverInfo.

@Override
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion, XtextBrowserInformationControlInput previous) {
    // TODO remove this check when the typesystem works without a java project
    if (isValidationDisabled(element))
        return null;
    EObject objectToView = getObjectToView(element);
    if (objectToView == null || objectToView.eIsProxy())
        return null;
    String html = getHoverInfoAsHtml(element, objectToView, hoverRegion);
    if (html != null) {
        StringBuffer buffer = new StringBuffer(html);
        ColorRegistry registry = JFaceResources.getColorRegistry();
        // $NON-NLS-1$
        RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND");
        // $NON-NLS-1$
        RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND");
        if (fgRGB != null && bgRGB != null) {
            HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
        } else {
            HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
        }
        HTMLPrinter.addPageEpilog(buffer);
        html = buffer.toString();
        IJavaElement javaElement = null;
        if (objectToView != element && objectToView instanceof JvmIdentifiableElement) {
            javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) objectToView);
        }
        return new XbaseInformationControlInput(previous, objectToView, javaElement, html, labelProvider);
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ColorRegistry(org.eclipse.jface.resource.ColorRegistry) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) EObject(org.eclipse.emf.ecore.EObject) RGB(org.eclipse.swt.graphics.RGB)

Example 5 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksForCrossRef.

protected void createHyperlinksForCrossRef(XtextResource resource, INode crossRefNode, final IHyperlinkAcceptor acceptor) {
    EObject containedElementAt = getEObjectAtOffsetHelper().resolveContainedElementAt(resource, crossRefNode.getOffset());
    if (containedElementAt instanceof XAbstractFeatureCall) {
        IResolvedTypes resolveTypes = typeResolver.resolveTypes(resource);
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) containedElementAt;
        final JvmIdentifiableElement targetElement = featureCall.getFeature();
        if (targetElement instanceof JvmType || featureCall.getFeature() instanceof JvmEnumerationLiteral) {
            return;
        }
        IJavaElement javaElement = javaElementFinder.findExactElementFor(targetElement);
        if (sourceViewer != null && javaElement != null && (javaElement.getElementType() == IJavaElement.METHOD && canBeOverridden((IMethod) javaElement))) {
            acceptor.accept(new XbaseImplementatorsHyperlink(javaElement, new Region(crossRefNode.getOffset(), crossRefNode.getLength()), sourceViewer, implOpener));
        }
        LightweightTypeReference typeReference = resolveTypes.getActualType(featureCall);
        if (typeReference == null || typeReference.isPrimitive() || typeReference.isPrimitiveVoid()) {
            return;
        }
        final JvmType type = typeReference.getType();
        if (type != null)
            createHyperlinksTo(resource, crossRefNode, type, new IHyperlinkAcceptor() {

                @Override
                public void accept(IHyperlink hyperlink) {
                    if (hyperlink instanceof AbstractHyperlink) {
                        String target = labelForTargetElement(targetElement);
                        ((AbstractHyperlink) hyperlink).setHyperlinkText("Open " + target + " Type - " + type.getSimpleName());
                    }
                    acceptor.accept(hyperlink);
                }

                private String labelForTargetElement(final JvmIdentifiableElement targetElement) {
                    String target = "Return";
                    if (targetElement instanceof JvmField) {
                        target = "Field";
                    } else if (targetElement instanceof JvmFormalParameter) {
                        // special case for variables in switch and for loops
                        if (targetElement.eContainer() instanceof XSwitchExpression || targetElement.eContainer() instanceof XForLoopExpression) {
                            target = "Variable";
                        } else {
                            target = "Parameter";
                        }
                    } else if (targetElement instanceof XVariableDeclaration) {
                        target = "Variable";
                    }
                    return target;
                }
            });
    }
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) IJavaElement(org.eclipse.jdt.core.IJavaElement) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) AbstractHyperlink(org.eclipse.xtext.ui.editor.hyperlinking.AbstractHyperlink) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IHyperlinkAcceptor(org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) EObject(org.eclipse.emf.ecore.EObject) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) IMethod(org.eclipse.jdt.core.IMethod) JvmField(org.eclipse.xtext.common.types.JvmField) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression)

Aggregations

JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)112 Test (org.junit.Test)65 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)60 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)58 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)27 EObject (org.eclipse.emf.ecore.EObject)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)13 XExpression (org.eclipse.xtext.xbase.XExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 IJavaElement (org.eclipse.jdt.core.IJavaElement)10 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)8 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 JvmType (org.eclipse.xtext.common.types.JvmType)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 XtendField (org.eclipse.xtend.core.xtend.XtendField)5 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)5 JvmMember (org.eclipse.xtext.common.types.JvmMember)5