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);
}
}
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;
}
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());
}
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());
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class EObjectLocationTests method testSignificantLocationInFile.
@Test
public void testSignificantLocationInFile() throws Exception {
String model = "class Foo extends Object { def Foo foo() {this} }";
XtendClass clazz = clazz(model);
JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
assertEquals(locationInFileProvider.getSignificantTextRegion(clazz), locationInFileProvider.getSignificantTextRegion(inferredType));
JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
assertEquals(locationInFileProvider.getSignificantTextRegion(clazz), locationInFileProvider.getSignificantTextRegion(inferredConstructor));
XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
assertEquals(locationInFileProvider.getSignificantTextRegion(xtendFunction), locationInFileProvider.getSignificantTextRegion(inferredOperation));
}
Aggregations