Search in sources :

Example 71 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class UTF8ParserErrorTest method testInvalidReference_02.

@Test
public void testInvalidReference_02() throws Exception {
    XtendFunction func = function("def m() { invalid\\u0020Part }");
    XBlockExpression block = (XBlockExpression) func.getExpression();
    XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
    String featureName = featureCall.getConcreteSyntaxFeatureName();
    assertEquals("invalid\\u0020Part", 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("invalidPart"));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 72 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class Bug409780Test method testConstraintsInfluenceType.

@Test
public void testConstraintsInfluenceType() throws Exception {
    XtendFile file = file("class C {\n" + "	def private 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<java.lang.Appendable>", type.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 73 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testTypeOfSuperInConstructor.

@Test
public void testTypeOfSuperInConstructor() throws Exception {
    XtendConstructor constructor = constructor("new() {\n" + "	super()\n" + "}\n");
    XBlockExpression body = (XBlockExpression) constructor.getExpression();
    XFeatureCall superCall = (XFeatureCall) body.getExpressions().get(0);
    assertEquals("void", getType(superCall).getIdentifier());
    assertNull(getExpectedType(superCall));
    assertNull(getExpectedReturnType(superCall));
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 74 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testExpectationRelevantExpressionType_05.

@Test
public void testExpectationRelevantExpressionType_05() throws Exception {
    String clazzString = "class C<T> {\n" + "  def String m(String s, Class<? super T>[] types) {\n" + "    this.m('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<? super T>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<? super T>>", getType(newArrayList).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 75 with XFeatureCall

use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testExpectationRelevantExpressionType_03.

@Test
public void testExpectationRelevantExpressionType_03() throws Exception {
    String clazzString = "class C {\n" + "  def m() {\n" + "    typeof(C).getMethod('', newArrayList)\n" + "  }\n" + "}";
    XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
    XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) function.getExpression();
    XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
    XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
    assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
    assertEquals("Class<?>[]", getExpectedType(newArrayList).getSimpleName());
    assertEquals("ArrayList<Class<?>>", getType(newArrayList).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Aggregations

XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)93 Test (org.junit.Test)81 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)72 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)67 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)62 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)29 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)26 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)19 XExpression (org.eclipse.xtext.xbase.XExpression)14 RichString (org.eclipse.xtend.core.xtend.RichString)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)6 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)5 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)5 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 EObject (org.eclipse.emf.ecore.EObject)4 XtendField (org.eclipse.xtend.core.xtend.XtendField)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)3