Search in sources :

Example 26 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class MutableJvmFieldDeclarationImpl method internalGenericSetConstantValue.

private void internalGenericSetConstantValue(final Object value) {
    this.checkMutable();
    Preconditions.checkArgument((value != null), "value cannot be null");
    JvmField _delegate = this.getDelegate();
    _delegate.setConstant(true);
    JvmField _delegate_1 = this.getDelegate();
    _delegate_1.setFinal(true);
    JvmField _delegate_2 = this.getDelegate();
    _delegate_2.setStatic(true);
    JvmField _delegate_3 = this.getDelegate();
    _delegate_3.setConstantValue(value);
}
Also used : JvmField(org.eclipse.xtext.common.types.JvmField)

Example 27 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class LinkingTest method testDeclaredConstructor_01.

@Test
public void testDeclaredConstructor_01() throws Exception {
    XtendClass clazz = clazz("class Foo { " + "  int i" + "  new(int i) { this.i = i }" + "}");
    assertEquals(2, clazz.getMembers().size());
    XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
    XAssignment assignment = (XAssignment) ((XBlockExpression) constructor.getExpression()).getExpressions().get(0);
    JvmField field = (JvmField) assignment.getFeature();
    assertEquals("i", field.getSimpleName());
    XFeatureCall target = (XFeatureCall) assignment.getAssignable();
    JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
    assertEquals("Foo", identifiableElement.getSimpleName());
    XFeatureCall value = (XFeatureCall) assignment.getValue();
    JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
    assertEquals("i", parameter.getSimpleName());
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) XAssignment(org.eclipse.xtext.xbase.XAssignment) Test(org.junit.Test)

Example 28 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testXtendField_01.

@Test
public void testXtendField_01() throws Exception {
    XtendFile xtendFile = file("class Foo { public String publicField protected String protectedField private String privateField }");
    JvmGenericType type = getInferredType(xtendFile);
    for (JvmField field : type.getDeclaredFields()) {
        assertEquals(JvmVisibility.get(field.getSimpleName().replace("Field", "").toUpperCase()), field.getVisibility());
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 29 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testNameClashWithAnonymousExtension_01.

@Test
public void testNameClashWithAnonymousExtension_01() throws Exception {
    XtendFile xtendFile = file("package foo import com.google.inject.Inject class Foo { @Inject extension String @Inject extension String }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmField extension0 = (JvmField) inferredType.getMembers().get(1);
    assertEquals("_string", extension0.getSimpleName());
    JvmField extension1 = (JvmField) inferredType.getMembers().get(2);
    assertEquals("_string_1", extension1.getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 30 with JvmField

use of org.eclipse.xtext.common.types.JvmField in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testFinalFunction.

@Test
public void testFinalFunction() throws Exception {
    XtendFile xtendFile = file("final class C { final String s = '' def final void m() {} }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    assertTrue(inferredType.isFinal());
    Iterable<JvmOperation> operations = inferredType.getDeclaredOperations();
    JvmOperation operation = operations.iterator().next();
    assertTrue(operation.isFinal());
    Iterable<JvmField> fields = inferredType.getDeclaredFields();
    JvmField field = fields.iterator().next();
    assertTrue(field.isFinal());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Aggregations

JvmField (org.eclipse.xtext.common.types.JvmField)36 Test (org.junit.Test)24 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)17 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 EObject (org.eclipse.emf.ecore.EObject)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)3 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Set (java.util.Set)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2