use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AccessObjectProcessorTest method testWithPackage.
@Test
public void testWithPackage() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package my.pack");
_builder.newLine();
_builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
_builder.newLine();
_builder.newLine();
_builder.append("@org.eclipse.xtend.core.tests.macro.AccessObjectAnn");
_builder.newLine();
_builder.append("class A {");
_builder.newLine();
_builder.append("\t");
_builder.append("String field");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final TransformationContext ctx = it.getTransformationContext();
final MutableClassDeclaration classA = ctx.findClass("my.pack.A");
Assert.assertNotNull(classA.findDeclaredMethod("getField"));
final MutableClassDeclaration classPA = ctx.findClass("my.pack.PA");
final Function1<TypeReference, Boolean> _function_1 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classPA.getImplementedInterfaces(), _function_1));
final MutableClassDeclaration classGA = ctx.findClass("my.pack.GA");
final Function1<TypeReference, Boolean> _function_2 = (TypeReference it_1) -> {
Type _type = it_1.getType();
Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
return Boolean.valueOf(Objects.equal(_type, _type_1));
};
Assert.assertNotNull(IterableExtensions.findFirst(classGA.getImplementedInterfaces(), _function_2));
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class Bug456264Test method testAddError.
@Test
public void testAddError() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@org.eclipse.xtend.core.tests.macro.Bug456264 class C {}");
_builder.newLine();
final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
final List<? extends Problem> problems = it.getAllProblems();
final Function1<Problem, String> _function_1 = (Problem it_1) -> {
return it_1.getMessage();
};
Assert.assertEquals(ListExtensions.map(problems, _function_1).toString(), 1, problems.size());
Assert.assertEquals("My error message", IterableExtensions.head(problems).getMessage());
final List<? extends Problem> specificProblems = it.getProblems(IterableExtensions.head(it.getCompilationUnit().getSourceTypeDeclarations()));
Assert.assertEquals(specificProblems.toString(), 1, problems.size());
Assert.assertEquals("My error message", IterableExtensions.head(specificProblems).getMessage());
};
this._xtendCompilerTester.compile(_builder, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class ActualTypeArgumentCollectorTest method operation.
protected JvmOperation operation(final String typeParameters, final String... alternatingTypeReferences) {
try {
JvmOperation _xblockexpression = null;
{
StringConcatenation _builder = new StringConcatenation();
_builder.append("def ");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("<");
_builder.append(typeParameters);
_builder.append(">");
}
}
_builder.append(" void method(");
final Function1<String, CharSequence> _function = (String it) -> {
return it;
};
String _join = IterableExtensions.<String>join(((Iterable<String>) Conversions.doWrapArray(alternatingTypeReferences)), null, " p, ", " p", _function);
_builder.append(_join);
_builder.append(") {}");
final String signature = _builder.toString();
final XtendFunction function = this.function(signature.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
_xblockexpression = operation;
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_138.
@Test
public void testErrorModel_138() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package test");
_builder.newLine();
_builder.append("class Bar<T> extends test.Bar.Foo<T> {}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
final Procedure1<EList<Resource.Diagnostic>> _function = (EList<Resource.Diagnostic> it) -> {
final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> {
return Boolean.valueOf(it_1.getMessage().startsWith("Cyclic "));
};
Assert.assertFalse(it.toString(), IterableExtensions.<Resource.Diagnostic>exists(it, _function_1));
};
ObjectExtensions.<EList<Resource.Diagnostic>>operator_doubleArrow(_errors, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class ResolvedExecutableImpl method getResolvedParameters.
@Override
public Iterable<? extends ResolvedParameter> getResolvedParameters() {
Iterable<? extends ResolvedParameter> _xblockexpression = null;
{
if ((this.resolvedParameters == null)) {
int _size = this.getDelegate().getDeclaration().getParameters().size();
final Function1<Integer, ResolvedParameterImpl> _function = (Integer i) -> {
ParameterDeclaration _parameterDeclaration = this.getCompilationUnit().toParameterDeclaration(this.getDelegate().getDeclaration().getParameters().get((i).intValue()));
TypeReference _typeReference = this.getCompilationUnit().toTypeReference(this.getDelegate().getResolvedParameterTypes().get((i).intValue()));
return new ResolvedParameterImpl(_parameterDeclaration, _typeReference);
};
this.resolvedParameters = IterableExtensions.<Integer, ResolvedParameterImpl>map(new ExclusiveRange(0, _size, true), _function);
}
_xblockexpression = this.resolvedParameters;
}
return _xblockexpression;
}
Aggregations