Search in sources :

Example 1 with ToString

use of org.eclipse.xtend.lib.annotations.ToString in project xtext-lib by eclipse.

the class ToStringProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
    boolean _tripleNotEquals = (_findAnnotation != null);
    if (_tripleNotEquals) {
        return;
    }
    @Extension final ToStringProcessor.Util util = new ToStringProcessor.Util(context);
    final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(ToString.class));
    final ToStringConfiguration configuration = new ToStringConfiguration(annotation);
    boolean _hasToString = util.hasToString(it);
    if (_hasToString) {
        context.addWarning(annotation, "toString is already defined, this annotation has no effect.");
    } else {
        TypeReference _extendedClass = it.getExtendedClass();
        TypeReference _object = context.getObject();
        boolean _notEquals = (!Objects.equal(_extendedClass, _object));
        if (_notEquals) {
            util.addReflectiveToString(it, configuration);
        } else {
            final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
                return Boolean.valueOf(((context.isThePrimaryGeneratedJavaElement(it_1) && (!it_1.isStatic())) && (!it_1.isTransient())));
            };
            util.addToString(it, IterableExtensions.filter(it.getDeclaredFields(), _function), configuration);
        }
    }
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) ToStringConfiguration(org.eclipse.xtend.lib.annotations.ToStringConfiguration) Data(org.eclipse.xtend.lib.annotations.Data) Extension(org.eclipse.xtext.xbase.lib.Extension) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) ToString(org.eclipse.xtend.lib.annotations.ToString)

Aggregations

Data (org.eclipse.xtend.lib.annotations.Data)1 ToString (org.eclipse.xtend.lib.annotations.ToString)1 ToStringConfiguration (org.eclipse.xtend.lib.annotations.ToStringConfiguration)1 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)1 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)1 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1