use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AnnotationReferenceProviderImpl method newAnnotationReference.
@Override
public AnnotationReference newAnnotationReference(final AnnotationReference annotationReference, final Procedure1<AnnotationReferenceBuildContext> initializer) {
Object _xblockexpression = null;
{
this.compilationUnit.checkCanceled();
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotationReference cannot be null");
Preconditions.checkArgument((annotationReference != null), _builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("initializer cannot be null");
Preconditions.checkArgument((initializer != null), _builder_1);
if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
final JvmAnnotationReference baseJvmAnnotationReference = ((JvmAnnotationReferenceImpl) annotationReference).getDelegate();
ConditionUtils.notRemoved(baseJvmAnnotationReference, "annotationReference");
final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(baseJvmAnnotationReference.getAnnotation());
AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
it.setDelegate(newJvmAnnotationReference);
it.setCompilationUnit(this.compilationUnit);
};
final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
final Function1<JvmAnnotationValue, String> _function_1 = (JvmAnnotationValue it) -> {
String _elvis = null;
String _valueName = it.getValueName();
if (_valueName != null) {
_elvis = _valueName;
} else {
_elvis = "value";
}
return _elvis;
};
List<String> _map = ListExtensions.<JvmAnnotationValue, String>map(baseJvmAnnotationReference.getExplicitValues(), _function_1);
for (final String valueName : _map) {
{
final Object value = ((JvmAnnotationReferenceImpl) annotationReference).getValue(valueName);
buildContext.set(valueName, value);
}
}
initializer.apply(buildContext);
return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
}
_xblockexpression = null;
}
return ((AnnotationReference) _xblockexpression);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class JvmTypeDeclarationImpl method findDeclaredConstructor.
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
ConstructorDeclaration _xblockexpression = null;
{
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(parameterTypes)), "parameterTypes");
final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
return it.getType();
};
List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>) Conversions.doWrapArray(parameterTypes)));
return Boolean.valueOf(Objects.equal(_list, _list_1));
};
_xblockexpression = IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class ResourceStorageTest method testFailedWrite.
@Test(expected = IOException.class)
public void testFailedWrite() throws Exception {
final XtendFile file = this.file("class C{}");
ByteArrayOutputStream _byteArrayOutputStream = new ByteArrayOutputStream();
Resource _eResource = file.eResource();
new BatchLinkableResourceStorageWritable(_byteArrayOutputStream, false) {
@Override
protected void writeAssociationsAdapter(final BatchLinkableResource resource, final OutputStream zipOut) throws IOException {
final Function1<Adapter, Boolean> _function = (Adapter it) -> {
return Boolean.valueOf((it instanceof JvmModelAssociator.Adapter));
};
final Adapter removeMe = IterableExtensions.<Adapter>findFirst(resource.eAdapters(), _function);
Assert.assertTrue(resource.eAdapters().remove(removeMe));
super.writeAssociationsAdapter(resource, zipOut);
}
}.writeResource(((StorageAwareResource) _eResource));
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testParameterAnnotation.
@Test
public void testParameterAnnotation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableParameterDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.RegisterGlobalsContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(typeof(ParamProcessor))");
_builder.newLine();
_builder.append("annotation Param { }");
_builder.newLine();
_builder.append("class ParamProcessor implements TransformationParticipant<MutableParameterDeclaration>, RegisterGlobalsParticipant<ParameterDeclaration> {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(List<? extends MutableParameterDeclaration> params, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("params.forEach[");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("simpleName = simpleName+\'foo\'");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doRegisterGlobals(List<? extends ParameterDeclaration> annotatedSourceElements, extension RegisterGlobalsContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("annotatedSourceElements.forEach [");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("context.registerInterface(\"demo.I\"+it.simpleName.toFirstUpper)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/AbstractAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("class MyClass {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def void foo(@myannotation.Param String a, @myannotation.Param String b) {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final MutableClassDeclaration clazz = it.getTypeLookup().findClass("myusercode.MyClass");
final Function1<MutableParameterDeclaration, Boolean> _function_1 = (MutableParameterDeclaration it_1) -> {
return Boolean.valueOf(it_1.getSimpleName().endsWith("foo"));
};
Assert.assertTrue(IterableExtensions.forall(IterableExtensions.head(clazz.getDeclaredMethods()).getParameters(), _function_1));
Assert.assertNotNull(it.getTypeLookup().findInterface("demo.IA"));
Assert.assertNotNull(it.getTypeLookup().findInterface("demo.IB"));
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AccessObjectProcessorTest method testWithoutPackage.
@Test
public void testWithoutPackage() {
StringConcatenation _builder = new StringConcatenation();
_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("A");
Assert.assertNotNull(classA.findDeclaredMethod("getField"));
final MutableClassDeclaration classPA = ctx.findClass("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("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);
}
Aggregations