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);
}
}
}
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;
}
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);
}
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;
}
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;
}
});
}
}
Aggregations