use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendValidator method checkMemberNamesAreUnique.
@Check
public void checkMemberNamesAreUnique(XtendTypeDeclaration xtendType) {
final Multimap<String, XtendField> name2field = HashMultimap.create();
final Multimap<String, XtendTypeDeclaration> name2type = HashMultimap.create();
final Multimap<JvmType, XtendField> type2extension = HashMultimap.create();
for (XtendMember member : xtendType.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (isEmpty(field.getName())) {
if (field.isExtension()) {
JvmTypeReference typeReference = field.getType();
if (typeReference != null) {
JvmType type = typeReference.getType();
if (type != null)
type2extension.put(type, field);
}
}
} else {
name2field.put(field.getName(), field);
}
} else if (member instanceof XtendTypeDeclaration) {
String name = ((XtendTypeDeclaration) member).getName();
if (name != null && name.length() > 0) {
name2type.put(name, (XtendTypeDeclaration) member);
}
}
}
for (String name : name2field.keySet()) {
Collection<XtendField> fields = name2field.get(name);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate field " + name, field, XtendPackage.Literals.XTEND_FIELD__NAME, DUPLICATE_FIELD);
}
}
for (String name : name2type.keySet()) {
Collection<XtendTypeDeclaration> types = name2type.get(name);
if (types.size() > 1) {
for (XtendTypeDeclaration type : types) error("Duplicate nested type " + name, type, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, DUPLICATE_TYPE_NAME);
}
}
for (JvmType type : type2extension.keySet()) {
Collection<XtendField> fields = type2extension.get(type);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate extension with same type", field, XTEND_FIELD__TYPE, DUPLICATE_FIELD);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendParameterDeclarationImpl method getDeclaringExecutable.
@Override
public ExecutableDeclaration getDeclaringExecutable() {
EObject _eContainer = this.getDelegate().eContainer();
MemberDeclaration _xtendMemberDeclaration = this.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) _eContainer));
return ((ExecutableDeclaration) _xtendMemberDeclaration);
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class UnloadingTest method testProperUnloading.
@Test
public void testProperUnloading() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class B {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("new A(this)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String fileB = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class A {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("new (B b) {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final List<XtendFile> parsedFiles = IterableExtensions.<XtendFile>toList(this.files(true, _builder_1.toString(), fileB));
Resource _eResource = parsedFiles.get(1).eResource();
final DerivedStateAwareResource resource = ((DerivedStateAwareResource) _eResource);
final Resource resourceA = IterableExtensions.<XtendFile>head(parsedFiles).eResource();
resource.reparse(fileB);
EObject _head = IterableExtensions.<EObject>head(resourceA.getContents());
final XtendFile file = ((XtendFile) _head);
XtendTypeDeclaration _head_1 = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_2 = IterableExtensions.<XtendMember>head(((XtendClass) _head_1).getMembers());
Assert.assertNotNull(IterableExtensions.<XtendParameter>head(((XtendConstructor) _head_2).getParameters()).getParameterType().getType().eResource());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
for (JvmTypeReference intf : source.getExtends()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
transform(member, inferredJvmType, false);
}
}
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
boolean isStatic = source.isStatic() && !isTopLevel(source);
if (!isStatic) {
JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
if (declaringType instanceof JvmGenericType) {
if (((JvmGenericType) declaringType).isInterface())
isStatic = true;
} else if (declaringType instanceof JvmAnnotationType) {
isStatic = true;
}
}
inferredJvmType.setStatic(isStatic);
inferredJvmType.setAbstract(source.isAbstract());
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
JvmTypeReference extendsClause = source.getExtends();
if (extendsClause == null || extendsClause.getType() == null) {
JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
if (typeRefToObject != null)
inferredJvmType.getSuperTypes().add(typeRefToObject);
} else {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
}
for (JvmTypeReference intf : source.getImplements()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
addDefaultConstructor(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredJvmType, true);
}
}
appendSyntheticDispatchMethods(source, inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
Aggregations