use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class JvmElementAtOffsetHelperTest method testRef.
@Test
public void testRef() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class TestCase {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo(String a){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("ba|r(a)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar(String a){}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
final XtendFile file = this.file(content.replace("|", ""));
Resource _eResource = file.eResource();
JvmIdentifiableElement jvmIdentifiableElement = this.jvmElementAtOffsetHelper.getJvmIdentifiableElement(((XtextResource) _eResource), content.indexOf("|"));
Assert.assertTrue((jvmIdentifiableElement instanceof JvmOperation));
Assert.assertEquals("testPackage.TestCase.bar", jvmIdentifiableElement.getQualifiedName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend 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-xtend by eclipse.
the class NonOverridableTypesProviderTest method assertTypeParameterInScope.
protected void assertTypeParameterInScope(final String typeName, final JvmMember context) {
final JvmIdentifiableElement visibleType = this.typesFromHierarchy.getVisibleType(context, typeName);
Assert.assertNotNull(visibleType);
Assert.assertTrue((visibleType instanceof JvmTypeParameter));
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class AbstractOverloadedInstanceMethodTest method linksTo.
protected void linksTo(final String invocation, final String method) {
try {
final XtendFile file = this.file(this.inMethodBody(invocation), false);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final XtendClass c = ((XtendClass) _head);
XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction m = ((XtendFunction) _head_1);
XExpression _expression = m.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
JvmIdentifiableElement _feature = featureCall.getFeature();
final JvmOperation operation = ((JvmOperation) _feature);
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
Assert.assertEquals(method, resolved.getSimpleSignature());
Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
Assert.assertNotNull(featureCall.getImplicitReceiver());
Assert.assertNull(featureCall.getImplicitFirstArgument());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.
the class AbstractOverloadedStaticMethodTest method linksTo.
protected void linksTo(final String invocation, final String method) {
try {
final XtendFile file = this.file(this.inMethodBody(invocation), false);
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
final XtendClass c = ((XtendClass) _head);
XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
final XtendFunction m = ((XtendFunction) _head_1);
XExpression _expression = m.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
JvmIdentifiableElement _feature = featureCall.getFeature();
final JvmOperation operation = ((JvmOperation) _feature);
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
Assert.assertEquals(method, resolved.getSimpleSignature());
Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
Assert.assertNull(featureCall.getImplicitReceiver());
Assert.assertNull(featureCall.getImplicitFirstArgument());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations