Search in sources :

Example 41 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class LineNumberMappingTests method getTraceRegion.

public AbstractTraceRegion getTraceRegion(final CharSequence xtendCode) {
    try {
        final XtendClass clazz = super.clazz(xtendCode.toString());
        final AbstractTraceRegionFSA fsa = new AbstractTraceRegionFSA();
        this.generator.doGenerate(clazz.eResource(), fsa);
        final AbstractTraceRegion result = ((ITraceRegionProvider) fsa.charSequence).getTraceRegion();
        this.print(result, fsa.charSequence.toString());
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : AbstractTraceRegionFSA(org.eclipse.xtend.core.tests.debug.AbstractTraceRegionFSA) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider)

Example 42 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_02.

@Test
public void testIgnoreVoidInParameterTypeInferrence_02() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(Number n, Void v) {null}" + " def dispatch foo(Void ignore, Object o) {null}" + "}");
    JvmGenericType type = associations.getInferredType(clazz);
    JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
    JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
    assertEquals("java.lang.Number", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
    assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 43 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class DispatchHelperTest method testVisibility_00.

@Test
public void testVisibility_00() throws Exception {
    XtendClass superClazz = clazz("class Super {\n" + "  def private dispatch foo(Object x) {} \n" + "}");
    Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
    subResource.load(new StringInputStream("class Sub extends Super {\n" + "  def dispatch foo(String x) {}\n" + "  def dispatch foo(Number x) {}\n" + "}"), null);
    JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
    assertEquals(2, list.size());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 44 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class DispatchHelperTest method testSort_02.

@Test
public void testSort_02() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(int a, String b) {null}" + " def dispatch foo(Boolean i, Object b) {null}" + " def dispatch foo(Object i, String b) {null}" + "}");
    JvmGenericType type = associations.getInferredType(clazz);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 2));
    Iterator<JvmOperation> i = list.iterator();
    assertEquals(Integer.TYPE.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(Boolean.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
    assertEquals(Object.class.getName(), i.next().getParameters().get(0).getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 45 with XtendClass

use of org.eclipse.xtend.core.xtend.XtendClass in project xtext-xtend by eclipse.

the class DispatchHelperTest method testIgnoreVoidInParameterTypeInferrence_03.

@Test
public void testIgnoreVoidInParameterTypeInferrence_03() throws Exception {
    XtendClass clazz = clazz("class X {\n" + " def dispatch foo(String n, Void v) {null}" + " def dispatch foo(Integer i, Void v) {null}" + "}");
    JvmGenericType type = associations.getInferredType(clazz);
    JvmOperation dispatchMethod = dispatchHelper.getDispatcherOperation(type, new DispatchHelper.DispatchSignature("foo", 2));
    JvmFormalParameter firstParameter = dispatchMethod.getParameters().get(0);
    assertEquals("java.lang.Object", firstParameter.getParameterType().getIdentifier());
    JvmFormalParameter secondParameter = dispatchMethod.getParameters().get(1);
    assertEquals("java.lang.Object", secondParameter.getParameterType().getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Aggregations

XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1017 Test (org.junit.Test)988 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)249 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)229 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)169 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)129 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)104 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)101 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)74 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)73 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)63 XExpression (org.eclipse.xtext.xbase.XExpression)62 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)62 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)37 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)36 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)35 XAssignment (org.eclipse.xtext.xbase.XAssignment)19 EObject (org.eclipse.emf.ecore.EObject)18 RichString (org.eclipse.xtend.core.xtend.RichString)17