use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.
the class ResourceStorageTest method testConstantValueIsPersisted_01.
@Test
public void testConstantValueIsPersisted_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val CONSTANT = Object");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String contents = _builder.toString();
final XtendFile file = this.file(contents);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
Resource _eResource = file.eResource();
this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
final StorageAwareResource resource = ((StorageAwareResource) _createResource);
final InMemoryURIConverter converter = new InMemoryURIConverter();
converter.addModel(resource.getURI().toString(), contents);
ResourceSet _resourceSet = resource.getResourceSet();
_resourceSet.setURIConverter(converter);
EList<Resource> _resources = file.eResource().getResourceSet().getResources();
_resources.add(resource);
resource.loadFromStorage(in);
EObject _get = resource.getContents().get(1);
final JvmGenericType jvmClass = ((JvmGenericType) _get);
JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
final JvmField field = ((JvmField) _last);
Assert.assertFalse(field.isConstant());
Assert.assertTrue(field.isSetConstant());
Assert.assertNull(field.getConstantValue());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_01.
@Test
public void testAnonymousClass_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("int field");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
this.typeResolver.resolveTypes(operation.eResource());
Assert.assertEquals(1, operation.getLocalClasses().size());
final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
Assert.assertTrue(anonymous.isFinal());
Assert.assertFalse(anonymous.isStatic());
Assert.assertTrue(anonymous.isLocal());
Assert.assertFalse(anonymous.isAnonymous());
Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
Assert.assertEquals(2, anonymous.getSuperTypes().size());
Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
Assert.assertEquals(3, anonymous.getMembers().size());
final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
Assert.assertTrue((constructor instanceof JvmConstructor));
Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
JvmMember _head = IterableExtensions.<JvmMember>head(anonymous.getMembers());
Assert.assertTrue((_head instanceof JvmField));
final JvmMember overriding = anonymous.getMembers().get(1);
Assert.assertTrue((overriding instanceof JvmOperation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_05.
@Test
public void testInferredFunction_05() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<? extends CharSequence> create result: newArrayList(s) newList(String s) {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
EList<JvmMember> jvmMembers = inferredType.getMembers();
assertEquals(4, jvmMembers.size());
JvmMember jvmMember = jvmMembers.get(1);
assertTrue(jvmMember instanceof JvmOperation);
XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
assertEquals("java.lang.Iterable<? extends java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
JvmField cacheVar = (JvmField) jvmMembers.get(2);
assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<? extends java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testNameClashWithCreateExtension_00.
@Test
public void testNameClashWithCreateExtension_00() throws Exception {
XtendFile xtendFile = file("package foo class Foo { def create new String() s(String x) { '' } String _createCache_s }");
JvmGenericType inferredType = getInferredType(xtendFile);
JvmField cacheVar = (JvmField) inferredType.getMembers().get(2);
assertEquals("_createCache_s_1", cacheVar.getSimpleName());
JvmOperation initializer = (JvmOperation) inferredType.getMembers().get(3);
assertEquals("_init_s", initializer.getSimpleName());
JvmField field = (JvmField) inferredType.getMembers().get(4);
assertEquals("_createCache_s", field.getSimpleName());
}
use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredFunction_04.
@Test
public void testInferredFunction_04() throws Exception {
XtendFile xtendFile = file("class Foo { def Iterable<CharSequence> create result: newArrayList(s) newList(String s) {} }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
EList<JvmMember> jvmMembers = inferredType.getMembers();
assertEquals(4, jvmMembers.size());
JvmMember jvmMember = jvmMembers.get(1);
assertTrue(jvmMember instanceof JvmOperation);
XtendFunction xtendFunction = (XtendFunction) xtendClass.getMembers().get(0);
assertEquals(xtendFunction.getName(), jvmMember.getSimpleName());
assertEquals(JvmVisibility.PUBLIC, jvmMember.getVisibility());
assertEquals("java.lang.Iterable<java.lang.CharSequence>", ((JvmOperation) jvmMember).getReturnType().getIdentifier());
JvmField cacheVar = (JvmField) jvmMembers.get(2);
assertEquals("_createCache_" + xtendFunction.getName(), cacheVar.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, cacheVar.getVisibility());
assertEquals("java.util.HashMap<java.util.ArrayList<? extends java.lang.Object>, java.lang.Iterable<java.lang.CharSequence>>", cacheVar.getType().getIdentifier());
JvmOperation privateInitializer = (JvmOperation) jvmMembers.get(3);
assertEquals("_init_" + xtendFunction.getName(), privateInitializer.getSimpleName());
assertEquals(JvmVisibility.PRIVATE, privateInitializer.getVisibility());
// This used to be a bogus assertion since Iterable<CharSequence> is not assignable from ArrayList<String>
// assertEquals("java.util.ArrayList<java.lang.String>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.util.ArrayList<java.lang.CharSequence>", privateInitializer.getParameters().get(0).getParameterType().getIdentifier());
assertEquals("java.lang.String", privateInitializer.getParameters().get(1).getParameterType().getIdentifier());
}
Aggregations