Search in sources :

Example 56 with JvmConstructor

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

the class JvmModelTests method testJvmTypeParameter_04.

@Test
public void testJvmTypeParameter_04() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new <T>() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmConstructor member = IterableExtensions.<JvmConstructor>head(Iterables.<JvmConstructor>filter(clazz.getMembers(), JvmConstructor.class));
        EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertEquals(_plus, 1, member.getTypeParameters().size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 57 with JvmConstructor

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

the class JvmModelTests method testJvmTypeParameter_03.

@Test
public void testJvmTypeParameter_03() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new <() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmConstructor member = IterableExtensions.<JvmConstructor>head(Iterables.<JvmConstructor>filter(clazz.getMembers(), JvmConstructor.class));
        EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertTrue(_plus, member.getTypeParameters().isEmpty());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 58 with JvmConstructor

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

the class JvmTypeDeclarationImpl method addConstructor.

public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
    this.checkMutable();
    Preconditions.checkArgument((initializer != null), "initializer cannot be null");
    final Function1<JvmConstructor, Boolean> _function = (JvmConstructor it) -> {
        return Boolean.valueOf(this.getCompilationUnit().getTypeExtensions().isSingleSyntheticDefaultConstructor(it));
    };
    final JvmConstructor constructor = IterableExtensions.<JvmConstructor>findFirst(Iterables.<JvmConstructor>filter(this.getDelegate().getMembers(), JvmConstructor.class), _function);
    if ((constructor != null)) {
        EcoreUtil.remove(constructor);
    }
    final JvmConstructor newConstructor = TypesFactory.eINSTANCE.createJvmConstructor();
    newConstructor.setVisibility(JvmVisibility.PUBLIC);
    newConstructor.setSimpleName(this.getSimpleName());
    this.getDelegate().getMembers().add(newConstructor);
    MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newConstructor);
    final MutableConstructorDeclaration mutableConstructorDeclaration = ((MutableConstructorDeclaration) _memberDeclaration);
    initializer.apply(mutableConstructorDeclaration);
    return mutableConstructorDeclaration;
}
Also used : MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) MutableConstructorDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableConstructorDeclaration) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Example 59 with JvmConstructor

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

the class RenameStrategyTest method testInferredClassRenamed.

@Test
public void testInferredClassRenamed() throws Exception {
    XtendClass fooClass = (XtendClass) testHelper.xtendFile("Foo", "class Foo { }").getXtendTypes().get(0);
    IRenameStrategy renameStrategy = createRenameStrategy(fooClass);
    renameStrategy.applyDeclarationChange("Bar", fooClass.eResource().getResourceSet());
    JvmGenericType inferredType = associations.getInferredType(fooClass);
    JvmConstructor inferredConstructor = associations.getInferredConstructor(fooClass);
    assertEquals("Bar", fooClass.getName());
    assertEquals("Bar", inferredType.getSimpleName());
    assertEquals("Bar", inferredConstructor.getSimpleName());
    renameStrategy.revertDeclarationChange(fooClass.eResource().getResourceSet());
    inferredType = associations.getInferredType(fooClass);
    inferredConstructor = associations.getInferredConstructor(fooClass);
    assertEquals("Foo", fooClass.getName());
    assertEquals("Foo", inferredType.getSimpleName());
    assertEquals("Foo", inferredConstructor.getSimpleName());
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Example 60 with JvmConstructor

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

the class XtendValidationTest method testSyntheticallyInitializedField.

@Test
public void testSyntheticallyInitializedField() throws Exception {
    XtendClass clazz = clazz("class X { new() {} final String foo }");
    JvmDeclaredType jvmType = (JvmDeclaredType) clazz.eResource().getContents().get(1);
    JvmConstructor constructor = (JvmConstructor) jvmType.getMembers().get(0);
    EObject field = jvmType.getMembers().get(1);
    readAndWriteTracking.markReadAccess(field);
    readAndWriteTracking.markInitialized(field, constructor);
    helper.assertNoIssues(clazz.eContainer());
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Test(org.junit.Test)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)82 Test (org.junit.Test)42 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)33 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)18 JvmMember (org.eclipse.xtext.common.types.JvmMember)17 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)15 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)9 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)9 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 JvmField (org.eclipse.xtext.common.types.JvmField)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 Predicate (com.google.common.base.Predicate)5 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)5