use of org.eclipse.xtend.core.xtend.XtendField 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.XtendField in project xtext-xtend by eclipse.
the class ProblemSupportImpl method getSignificantFeature.
public EStructuralFeature getSignificantFeature(final EObject obj) {
EStructuralFeature _switchResult = null;
boolean _matched = false;
if (obj instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendTypeDeclaration_Name();
}
if (!_matched) {
if (obj instanceof XtendField) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendField_Name();
}
}
if (!_matched) {
if (obj instanceof XtendFunction) {
_matched = true;
_switchResult = XtendPackage.eINSTANCE.getXtendFunction_Name();
}
}
if (!_matched) {
if (obj instanceof JvmFormalParameter) {
_matched = true;
_switchResult = TypesPackage.eINSTANCE.getJvmFormalParameter_Name();
}
}
if (!_matched) {
if (obj instanceof XAnnotation) {
_matched = true;
_switchResult = XAnnotationsPackage.eINSTANCE.getXAnnotation_AnnotationType();
}
}
return _switchResult;
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testEnumLiteral_WithStaticImport.
@Test
public void testEnumLiteral_WithStaticImport() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static test.Enum1.* ");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("Enum1 testFoo = RED");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField field = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
Object _evaluate = this.interpreter.evaluate(field.getInitialValue(), field.getType());
final JvmEnumerationLiteral blue = ((JvmEnumerationLiteral) _evaluate);
Assert.assertEquals("RED", blue.getSimpleName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testConstants_WithStaticImport.
@Test
public void testConstants_WithStaticImport() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static test.Constants1.* ");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("val someString = STRING_CONSTANT");
_builder.newLine();
_builder.append("\t");
_builder.append("val someInt = INT_CONSTANT");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
final XtendField intField = ((XtendField[]) Conversions.unwrapArray(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class), XtendField.class))[1];
Assert.assertEquals(Constants1.STRING_CONSTANT, this.interpreter.evaluate(stringField.getInitialValue(), null));
Assert.assertEquals(Integer.valueOf(Constants1.INT_CONSTANT), this.interpreter.evaluate(intField.getInitialValue(), null));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testConstants_WithStaticImport_01.
@Test
public void testConstants_WithStaticImport_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static test.Constants1.* ");
_builder.newLine();
_builder.append("import static MyConstants.*");
_builder.newLine();
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("val someString = STRING_CONSTANT+\'-\'+MY_CONST");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class MyConstants {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val MY_CONST = STRING_CONSTANT");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
Assert.assertEquals(((Constants1.STRING_CONSTANT + "-") + Constants1.STRING_CONSTANT), this.interpreter.evaluate(stringField.getInitialValue(), null));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations