Search in sources :

Example 21 with Type

use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.

the class TypeLookupImpl method findTypeGlobally.

@Override
public Type findTypeGlobally(final String typeName) {
    Type _elvis = null;
    Type _findType = this.findType(typeName);
    if (_findType != null) {
        _elvis = _findType;
    } else {
        final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
            return Boolean.valueOf(true);
        };
        Type _findTypeOnScope = this.findTypeOnScope(typeName, _function);
        _elvis = _findTypeOnScope;
    }
    return _elvis;
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType) Type(org.eclipse.xtend.lib.macro.declaration.Type) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 22 with Type

use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-xtend by eclipse.

the class TypeReferenceImpl method getType.

@Override
public Type getType() {
    Type _switchResult = null;
    LightweightTypeReference _delegate = this.getDelegate();
    final LightweightTypeReference it = _delegate;
    boolean _matched = false;
    boolean _isUnknown = it.isUnknown();
    if (_isUnknown) {
        _matched = true;
        CompilationUnitImpl _compilationUnit = this.getCompilationUnit();
        String _packageName = this.getCompilationUnit().getPackageName();
        String _plus = (_packageName + ".");
        String _simpleName = it.getSimpleName();
        String _plus_1 = (_plus + _simpleName);
        _switchResult = new UnknownType(_compilationUnit, _plus_1);
    }
    if (!_matched) {
        _switchResult = this.getCompilationUnit().toType(it.getType());
    }
    return _switchResult;
}
Also used : UnknownType(org.eclipse.xtend.core.macro.declaration.UnknownType) UnknownType(org.eclipse.xtend.core.macro.declaration.UnknownType) Type(org.eclipse.xtend.lib.macro.declaration.Type) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)

Example 23 with Type

use of org.eclipse.xtend.lib.macro.declaration.Type in project xtext-core by eclipse.

the class TracedAccessorsProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    annotatedClass.setExtendedClass(context.newTypeReference(TracingSugar.class));
    final TypeReference iterableType = context.newTypeReference(Iterable.class, context.newWildcardTypeReference());
    final TypeReference annotationType = context.newTypeReference(TracedAccessors.class);
    AnnotationReference _findAnnotation = annotatedClass.findAnnotation(annotationType.getType());
    TypeReference[] _classArrayValue = null;
    if (_findAnnotation != null) {
        _classArrayValue = _findAnnotation.getClassArrayValue("value");
    }
    final TypeReference[] factories = _classArrayValue;
    if ((factories == null)) {
        return;
    }
    final Function1<TypeReference, Type> _function = (TypeReference it) -> {
        return it.getType();
    };
    Iterable<InterfaceDeclaration> _filter = Iterables.<InterfaceDeclaration>filter(ListExtensions.<TypeReference, Type>map(((List<TypeReference>) Conversions.doWrapArray(factories)), _function), InterfaceDeclaration.class);
    for (final InterfaceDeclaration f : _filter) {
        final Function1<MethodDeclaration, Boolean> _function_1 = (MethodDeclaration it) -> {
            return Boolean.valueOf((it.getSimpleName().startsWith("create") && IterableExtensions.isEmpty(it.getParameters())));
        };
        final Function1<MethodDeclaration, TypeReference> _function_2 = (MethodDeclaration it) -> {
            return it.getReturnType();
        };
        Iterable<TypeReference> _map = IterableExtensions.map(IterableExtensions.filter(f.getDeclaredMethods(), _function_1), _function_2);
        for (final TypeReference t : _map) {
            final Function1<ResolvedMethod, Boolean> _function_3 = (ResolvedMethod it) -> {
                return Boolean.valueOf(this.isSupportedGetter(it));
            };
            final Function1<ResolvedMethod, Boolean> _function_4 = (ResolvedMethod it) -> {
                boolean _isAssignableFrom = iterableType.isAssignableFrom(it.getDeclaration().getReturnType());
                return Boolean.valueOf((!_isAssignableFrom));
            };
            Iterable<? extends ResolvedMethod> _filter_1 = IterableExtensions.filter(IterableExtensions.filter(t.getAllResolvedMethods(), _function_3), _function_4);
            for (final ResolvedMethod getter : _filter_1) {
                {
                    final TypeReference rt = getter.getResolvedReturnType();
                    boolean _contains = TracedAccessorsProcessor.TYPES_WITH_GOOD_TO_STRING.contains(rt.getType().getSimpleName().toLowerCase());
                    if (_contains) {
                        final Procedure1<MutableMethodDeclaration> _function_5 = (MutableMethodDeclaration it) -> {
                            it.setReturnType(context.newTypeReference(IGeneratorNode.class));
                            it.addParameter("target", t);
                            StringConcatenationClient _client = new StringConcatenationClient() {

                                @Override
                                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                    _builder.append(EStructuralFeature.class);
                                    _builder.append(" feature = target.eClass().getEStructuralFeature(\"");
                                    String _featureName = TracedAccessorsProcessor.this.featureName(getter);
                                    _builder.append(_featureName);
                                    _builder.append("\");");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append(ILocationData.class);
                                    _builder.append(" location = this.location(target, feature, -1);");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append(CompositeGeneratorNode.class);
                                    _builder.append(" trace = this.trace(location);");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("this.append(trace, target.");
                                    String _simpleName = getter.getDeclaration().getSimpleName();
                                    _builder.append(_simpleName);
                                    _builder.append("());");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("return trace;");
                                    _builder.newLine();
                                }
                            };
                            it.setBody(_client);
                        };
                        annotatedClass.addMethod(this.tracerName(getter), _function_5);
                        final Procedure1<MutableMethodDeclaration> _function_6 = (MutableMethodDeclaration it) -> {
                            it.setReturnType(context.newTypeReference(IGeneratorNode.class));
                            it.addParameter("target", t);
                            it.addParameter("useForDebugging", context.newTypeReference(Boolean.TYPE));
                            StringConcatenationClient _client = new StringConcatenationClient() {

                                @Override
                                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                    _builder.append(EStructuralFeature.class);
                                    _builder.append(" feature = target.eClass().getEStructuralFeature(\"");
                                    String _featureName = TracedAccessorsProcessor.this.featureName(getter);
                                    _builder.append(_featureName);
                                    _builder.append("\");");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append(ILocationData.class);
                                    _builder.append(" location = this.location(target, feature, -1);");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append(CompositeGeneratorNode.class);
                                    _builder.append(" trace = this.trace(location, useForDebugging);");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("this.append(trace, target.");
                                    String _simpleName = getter.getDeclaration().getSimpleName();
                                    _builder.append(_simpleName);
                                    _builder.append("());");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("return trace;");
                                    _builder.newLine();
                                }
                            };
                            it.setBody(_client);
                        };
                        annotatedClass.addMethod(this.tracerName(getter), _function_6);
                    }
                    final Procedure1<MutableMethodDeclaration> _function_7 = (MutableMethodDeclaration it) -> {
                        it.setReturnType(context.newTypeReference(IGeneratorNode.class));
                        it.addParameter("target", t);
                        final TypeReference stringProvider = context.newTypeReference(Function.class, rt, context.getString());
                        it.addParameter("stringProvider", stringProvider);
                        StringConcatenationClient _client = new StringConcatenationClient() {

                            @Override
                            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                                _builder.append(EStructuralFeature.class);
                                _builder.append(" feature = target.eClass().getEStructuralFeature(\"");
                                String _featureName = TracedAccessorsProcessor.this.featureName(getter);
                                _builder.append(_featureName);
                                _builder.append("\");");
                                _builder.newLineIfNotEmpty();
                                _builder.append(ILocationData.class);
                                _builder.append(" location = this.location(target, feature, -1);");
                                _builder.newLineIfNotEmpty();
                                _builder.append(CompositeGeneratorNode.class);
                                _builder.append(" trace = this.trace(location);");
                                _builder.newLineIfNotEmpty();
                                _builder.append("this.append(trace, stringProvider.apply(target.");
                                String _simpleName = getter.getDeclaration().getSimpleName();
                                _builder.append(_simpleName);
                                _builder.append("()));");
                                _builder.newLineIfNotEmpty();
                                _builder.append("return trace;");
                                _builder.newLine();
                            }
                        };
                        it.setBody(_client);
                    };
                    annotatedClass.addMethod(this.tracerName(getter), _function_7);
                }
            }
        }
    }
}
Also used : MethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MethodDeclaration) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) MutableMethodDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMethodDeclaration) InterfaceDeclaration(org.eclipse.xtend.lib.macro.declaration.InterfaceDeclaration) IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) Type(org.eclipse.xtend.lib.macro.declaration.Type) ResolvedMethod(org.eclipse.xtend.lib.macro.declaration.ResolvedMethod) TracingSugar(org.eclipse.xtext.generator.trace.node.TracingSugar) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference)

Aggregations

Type (org.eclipse.xtend.lib.macro.declaration.Type)23 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 Test (org.junit.Test)11 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)10 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)10 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)9 JvmType (org.eclipse.xtext.common.types.JvmType)7 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)5 MutableEnumerationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableEnumerationTypeDeclaration)5 List (java.util.List)4 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)4 MutableInterfaceDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableInterfaceDeclaration)3 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)3 Serializable (java.io.Serializable)2 Consumer (java.util.function.Consumer)2 EObject (org.eclipse.emf.ecore.EObject)2 XtendCompilerTester (org.eclipse.xtend.core.compiler.batch.XtendCompilerTester)2 AbstractActiveAnnotationTest (org.eclipse.xtend.core.tests.macro.AbstractActiveAnnotationTest)2 TransformationContext (org.eclipse.xtend.lib.macro.TransformationContext)2