Search in sources :

Example 6 with XtendField

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);
        }
    }
}
Also used : XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) JvmType(org.eclipse.xtext.common.types.JvmType) XtendField(org.eclipse.xtend.core.xtend.XtendField) Check(org.eclipse.xtext.validation.Check)

Example 7 with XtendField

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;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 8 with XtendField

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 9 with XtendField

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 10 with XtendField

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

XtendField (org.eclipse.xtend.core.xtend.XtendField)71 Test (org.junit.Test)50 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)38 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)33 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)29 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)23 XExpression (org.eclipse.xtext.xbase.XExpression)23 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)14 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)12 EObject (org.eclipse.emf.ecore.EObject)8 RichString (org.eclipse.xtend.core.xtend.RichString)7 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 XClosure (org.eclipse.xtext.xbase.XClosure)6 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)5 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)5 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3