use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AbstractSingleEditorQueuedBuildTest method removeNestedTypesWithinDefaultPackage.
@Test
public void removeNestedTypesWithinDefaultPackage() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class Bar {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public class Foo { public class Foo3 {} }");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public static class Foo2 {}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
this.testHelper.createFile("Bar.java", _builder.toString());
final Procedure0 _function = () -> {
final Function1<ITextEditor, ITextEditor> _function_1 = (ITextEditor it) -> {
ITextEditor _xblockexpression = null;
{
this._javaEditorExtension.changeContent(it, "public class Foo { public class Foo3 {} }", "");
_xblockexpression = this._javaEditorExtension.changeContent(it, "public static class Foo2 {}", "");
}
return _xblockexpression;
};
this.save("Bar.java", _function_1);
};
this.assertThereAreDeltas(_function, "Bar", "Bar$Foo", "Bar$Foo2", "Bar$Foo$Foo3");
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class DependentElementsCalculatorTests method testDependentElements.
@Test
public void testDependentElements() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def Foo foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("new Foo()");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.testHelper.xtendFile("Foo", _builder.toString());
XtendTypeDeclaration _get = file.getXtendTypes().get(0);
final XtendClass fooClass = ((XtendClass) _get);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooClass, _nullProgressMonitor);
Assert.assertEquals(3, IterableExtensions.size(dependentElementURIs));
XtendMember _get_1 = fooClass.getMembers().get(0);
final XtendFunction fooFunction = ((XtendFunction) _get_1);
final Consumer<EObject> _function = (EObject it) -> {
final Function1<URI, Boolean> _function_1 = (URI element) -> {
URI _uRI = EcoreUtil.getURI(it);
return Boolean.valueOf(Objects.equal(element, _uRI));
};
Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_1));
};
CollectionLiterals.<EObject>newArrayList(fooFunction, this.associations.getInferredType(fooClass), this.associations.getInferredConstructor(fooClass)).forEach(_function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class MemberFromSuperImplementor method appendConstructorFromSuper.
public void appendConstructorFromSuper(final XtendClass overrider, final IResolvedConstructor superConstructor, final ISourceAppender appendable) {
final JvmGenericType inferredType = this.associations.getInferredType(overrider);
final AbstractConstructorBuilder constructorBuilder = this.codeBuilderFactory.createConstructorBuilder(inferredType);
this.initializeExecutableBuilder(constructorBuilder, inferredType, superConstructor);
final Procedure1<ISourceAppender> _function = (ISourceAppender it) -> {
boolean _isEmpty = superConstructor.getResolvedParameterTypes().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("super(");
final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it_1) -> {
return it_1.getSimpleName();
};
String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(superConstructor.getDeclaration().getParameters(), _function_1), ", ");
_builder.append(_join);
_builder.append(")");
it.append(_builder);
}
};
constructorBuilder.setBodyGenerator(_function);
boolean _isValid = constructorBuilder.isValid();
if (_isValid) {
constructorBuilder.build(appendable);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class JdtFindReferencesTest method testFindClassRef.
@Test
public void testFindClassRef() {
try {
Assert.assertTrue(this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { }").exists());
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class JavaRef {");
_builder.newLine();
_builder.append("\t");
_builder.append("private Xtend x;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public Xtend foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return null;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public void bar() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("new Xtend();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public void baz() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Xtend y;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Assert.assertTrue(this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString()).exists());
IResourcesSetupUtil.waitForBuild();
Assert.assertNotNull("Couldn\'t find \'src/Xtend.xtend\'.", this._workbenchTestHelper.getProject().findMember("/src/Xtend.xtend"));
Assert.assertNotNull("Couldn\'t find \'src/JavaRef.java\'.", this._workbenchTestHelper.getProject().findMember("/src/JavaRef.java"));
final IResource member = this._workbenchTestHelper.getProject().findMember("/xtend-gen/Xtend.java");
if ((member == null)) {
Assert.assertNotNull("Couldn\'t find \'xtend-gen/Xtend.java\'.", member);
}
IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
if ((type == null)) {
Assert.assertNotNull("Couldn\'t find type \'Xtend\'.", type);
}
final IMethod constructor = type.getMethod("Xtend", ((String[]) Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(), String.class)));
ArrayList<Object> _findReferences = this.findReferences(type, constructor);
final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
Assert.assertEquals(4, it.size());
final Function1<IField, Boolean> _function_1 = (IField it_1) -> {
String _elementName = it_1.getElementName();
return Boolean.valueOf(Objects.equal(_elementName, "x"));
};
Assert.assertTrue(IterableExtensions.<IField>exists(Iterables.<IField>filter(it, IField.class), _function_1));
final Function1<IMethod, Boolean> _function_2 = (IMethod it_1) -> {
String _elementName = it_1.getElementName();
return Boolean.valueOf(Objects.equal(_elementName, "foo"));
};
Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _function_2));
final Function1<IMethod, Boolean> _function_3 = (IMethod it_1) -> {
String _elementName = it_1.getElementName();
return Boolean.valueOf(Objects.equal(_elementName, "bar"));
};
Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _function_3));
final Function1<IMethod, Boolean> _function_4 = (IMethod it_1) -> {
String _elementName = it_1.getElementName();
return Boolean.valueOf(Objects.equal(_elementName, "baz"));
};
Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _function_4));
};
ObjectExtensions.<ArrayList<Object>>operator_doubleArrow(_findReferences, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class JdtFindReferencesTest method testBug387230.
@Test
public void testBug387230() {
try {
final XtendClass cls = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", "@Data class Xtend { String field }").getXtendTypes(), XtendClass.class));
IResourcesSetupUtil.waitForBuild();
Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(cls);
final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
Assert.assertEquals(2, IterableExtensions.size(it));
final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
return Boolean.valueOf(((it_1 instanceof IType) && Objects.equal(((IType) it_1).getElementName(), "Xtend")));
};
Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
final Function1<IJavaElement, Boolean> _function_2 = (IJavaElement it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "Xtend")));
};
Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_2));
};
ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations