use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class JdtFindReferencesTest method testFieldJavaElements.
@Test
public void testFieldJavaElements() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Xtend {");
_builder.newLine();
_builder.append("\t");
_builder.append("int foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendMember field = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers());
IResourcesSetupUtil.waitForBuild();
Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(field);
final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
Assert.assertEquals(1, IterableExtensions.size(it));
final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "foo")));
};
Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
};
ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _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 testFindFieldRef.
@Test
public void testFindFieldRef() {
try {
this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { public int foo = 0 }");
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class JavaRef extends Xtend {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private int bar = foo;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public int baz() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return foo;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public void fooBar_0() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return new Xtend().foo;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public void fooBar_1() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return new JavaRef().foo;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString());
IResourcesSetupUtil.waitForBuild();
final IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
final IField field = type.getField("foo");
ArrayList<Object> _findReferences = this.findReferences(field);
final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
Assert.assertEquals(4, it.size());
final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "bar")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "baz")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
final Function1<Object, Boolean> _function_3 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "fooBar_0")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_3));
final Function1<Object, Boolean> _function_4 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "fooBar_1")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _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 testFindMethodRef.
@Test
public void testFindMethodRef() {
try {
this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { def foo() { 0 }}");
StringConcatenation _builder = new StringConcatenation();
_builder.append("public class JavaRef {");
_builder.newLine();
_builder.append("\t");
_builder.append("private Xtend x = new Xtend();");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private int y = x.foo();");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public int bar() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return x.foo();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString());
IResourcesSetupUtil.waitForBuild();
final IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
final IMethod method = type.getMethod("foo", ((String[]) Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(), String.class)));
ArrayList<Object> _findReferences = this.findReferences(method);
final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
Assert.assertEquals(2, it.size());
final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "y")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "bar")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
};
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 testJavaClassRef.
@Test
public void testJavaClassRef() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Xtend { ");
_builder.newLine();
_builder.append("\t");
_builder.append("Java foo");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("def Java bar() { ");
_builder.newLine();
_builder.append("\t\t");
_builder.append("null");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("def void baz() { ");
_builder.newLine();
_builder.append("\t\t");
_builder.append("new Java()");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
this._workbenchTestHelper.createFile("Xtend.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("public class Java {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this._workbenchTestHelper.createFile("Java.java", _builder_1.toString());
IResourcesSetupUtil.waitForBuild();
final IType javaType = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Java");
ArrayList<Object> _findReferences = this.findReferences(javaType);
final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
Assert.assertEquals(3, it.size());
final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "foo")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "bar")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
final Function1<Object, Boolean> _function_3 = (Object it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "baz")));
};
Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_3));
};
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 testPropertyJavaElements.
@Test
public void testPropertyJavaElements() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Xtend {");
_builder.newLine();
_builder.append("\t");
_builder.append("@Property int foo");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendMember field = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers());
IResourcesSetupUtil.waitForBuild();
Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(field);
final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
Assert.assertEquals(3, IterableExtensions.size(it));
final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "getFoo")));
};
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(), "setFoo")));
};
Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_2));
final Function1<IJavaElement, Boolean> _function_3 = (IJavaElement it_1) -> {
return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "_foo")));
};
Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_3));
};
ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations