use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class XtendReferenceFinder method addReferenceToTypeFromStaticImport.
protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) {
final JvmIdentifiableElement feature = sourceCandidate.getFeature();
if ((feature instanceof JvmMember)) {
final JvmDeclaredType type = ((JvmMember) feature).getDeclaringType();
this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor);
}
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class SyntheticNameClashResolver method resolveNameClashes.
public void resolveNameClashes(JvmGenericType type) {
Multimap<String, JvmIdentifiableElement> classScope = HashMultimap.create();
List<JvmMember> renameableMembers = newArrayList();
int i = 1;
for (JvmMember member : type.getMembers()) {
String simpleName = member.getSimpleName();
if (simpleName != null) {
if (!isRenameable(member))
classScope.put(simpleName, member);
else
renameableMembers.add(member);
}
if (member instanceof JvmFeature) {
for (JvmGenericType localType : ((JvmFeature) member).getLocalClasses()) {
localType.setSimpleName(localType.getSimpleName() + '_' + (i++));
}
}
}
for (JvmMember renameable : renameableMembers) {
String simpleName = renameable.getSimpleName();
if (collides(renameable, simpleName, classScope)) {
int count = 0;
String currentName;
do {
if (count == Integer.MAX_VALUE)
throw new IllegalStateException("Cannot find a collision-free name for " + renameable.getIdentifier());
currentName = simpleName + "_" + ++count;
} while (collides(renameable, currentName, classScope));
renameable.setSimpleName(currentName);
classScope.put(currentName, renameable);
} else {
classScope.put(simpleName, renameable);
}
}
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class ResourceStorageTest method testConstantValueIsPersisted.
@Test
public void testConstantValueIsPersisted() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val CONSTANT = \'a\' + \'b\' + 0");
_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.assertTrue(field.isConstant());
Assert.assertTrue(field.isSetConstant());
Assert.assertEquals("ab0", field.getConstantValue());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_02.
@Test
public void testAnonymousClass_02() {
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("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.assertTrue(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(2, anonymous.getMembers().size());
final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
Assert.assertTrue((constructor instanceof JvmConstructor));
Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
final JvmMember overriding = IterableExtensions.<JvmMember>head(anonymous.getMembers());
Assert.assertTrue((overriding instanceof JvmOperation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class JvmModelTests method testEnumInAnnotationIsStatic.
@Test
public void testEnumInAnnotationIsStatic() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("enum E { L0, L1 }");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmAnnotationType inferred = this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString()));
JvmMember _head = IterableExtensions.<JvmMember>head(inferred.getMembers());
final JvmEnumerationType e = ((JvmEnumerationType) _head);
Assert.assertTrue(e.isStatic());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations