use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnLocalVar_01.
@Test
public void testExtensionOnLocalVar_01() throws Exception {
XtendClass clazz = clazz("class Foo { def m() { extension var s = '' } }");
assertEquals(1, clazz.getMembers().size());
XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
assertEquals(1, body.getExpressions().size());
XtendVariableDeclaration variableDeclaration = (XtendVariableDeclaration) body.getExpressions().get(0);
assertTrue(variableDeclaration.isWriteable());
assertTrue(variableDeclaration.isExtension());
}
use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.
the class ParserTest method testExtensionOnCatchClause_01.
@Test
public void testExtensionOnCatchClause_01() throws Exception {
XtendClass clazz = clazz("class Foo { def void m() { try {} catch(extension NullPointerException e) {} } }");
assertEquals(1, clazz.getMembers().size());
XtendFunction m = (XtendFunction) clazz.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
assertEquals(1, body.getExpressions().size());
XTryCatchFinallyExpression tryCatch = (XTryCatchFinallyExpression) body.getExpressions().get(0);
XCatchClause singleCatchClause = tryCatch.getCatchClauses().get(0);
XtendFormalParameter parameter = (XtendFormalParameter) singleCatchClause.getDeclaredParam();
assertTrue(parameter.isExtension());
}
use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.
the class UTF8ParserErrorTest method testInvalidReference_01.
@Test
public void testInvalidReference_01() throws Exception {
XtendFunction func = function("def m() { \\u0020invalidStart }");
XBlockExpression block = (XBlockExpression) func.getExpression();
XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
String featureName = featureCall.getConcreteSyntaxFeatureName();
assertEquals("\\u0020invalidStart", featureName);
assertTrue(featureCall.getFeature().eIsProxy());
List<Diagnostic> errorList = func.eResource().getErrors();
assertEquals(2, errorList.size());
XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.
the class Bug409780Test method testConstraintsInfluenceFeatureScope_02.
@Test
public void testConstraintsInfluenceFeatureScope_02() throws Exception {
XtendFile file = file("class C {\n" + " def private a(Iterable<CharSequence> it) {\n" + " map[ b.append('') ]\n" + " }\n" + " def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
assertTrue(featureCall.isStatic());
assertTrue(featureCall.isExtension());
assertFalse(featureCall.isTypeLiteral());
LightweightTypeReference type = getType(featureCall);
assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
use of org.eclipse.xtext.xbase.XBlockExpression in project xtext-xtend by eclipse.
the class Bug409780Test method testMissingTypeArgumentInference.
@Test
public void testMissingTypeArgumentInference() throws Exception {
XtendFile file = file("class C {\n" + " def private <T extends Appendable> Iterable<T> a(Iterable<CharSequence> it) {\n" + " map[ b ]\n" + " }\n" + " def private <T extends Appendable> T b(CharSequence c) {}\n" + "}");
XtendClass c = (XtendClass) file.getXtendTypes().get(0);
XtendFunction m = (XtendFunction) c.getMembers().get(0);
XBlockExpression body = (XBlockExpression) m.getExpression();
XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
JvmIdentifiableElement method = featureCall.getFeature();
assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
assertTrue(featureCall.isStatic());
assertTrue(featureCall.isExtension());
assertFalse(featureCall.isTypeLiteral());
LightweightTypeReference type = getType(featureCall);
assertEquals("java.lang.Iterable<T>", type.getIdentifier());
LightweightTypeReference expectedType = getExpectedType(featureCall);
assertEquals("java.lang.Iterable<T>", expectedType.getIdentifier());
}
Aggregations