Search in sources :

Example 1 with AccessorType

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

the class DataProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
    @Extension final DataProcessor.Util util = new DataProcessor.Util(context);
    @Extension final AccessorsProcessor.Util getterUtil = new AccessorsProcessor.Util(context);
    @Extension final EqualsHashCodeProcessor.Util ehUtil = new EqualsHashCodeProcessor.Util(context);
    @Extension final ToStringProcessor.Util toStringUtil = new ToStringProcessor.Util(context);
    @Extension final FinalFieldsConstructorProcessor.Util requiredArgsUtil = new FinalFieldsConstructorProcessor.Util(context);
    final Consumer<MutableFieldDeclaration> _function = (MutableFieldDeclaration it_1) -> {
        Element _primarySourceElement = context.getPrimarySourceElement(it_1);
        boolean _contains = ((FieldDeclaration) _primarySourceElement).getModifiers().contains(Modifier.VAR);
        if (_contains) {
            context.addError(it_1, "Cannot use the \'var\' keyword on a data field");
        }
        it_1.setFinal(true);
    };
    util.getDataFields(it).forEach(_function);
    if ((requiredArgsUtil.needsFinalFieldConstructor(it) || (it.findAnnotation(context.findTypeGlobally(FinalFieldsConstructor.class)) != null))) {
        requiredArgsUtil.addFinalFieldsConstructor(it);
    }
    boolean _hasHashCode = ehUtil.hasHashCode(it);
    boolean _not = (!_hasHashCode);
    if (_not) {
        ehUtil.addHashCode(it, util.getDataFields(it), ehUtil.hasSuperHashCode(it));
    }
    boolean _hasEquals = ehUtil.hasEquals(it);
    boolean _not_1 = (!_hasEquals);
    if (_not_1) {
        ehUtil.addEquals(it, util.getDataFields(it), ehUtil.hasSuperEquals(it));
    }
    boolean _hasToString = toStringUtil.hasToString(it);
    boolean _not_2 = (!_hasToString);
    if (_not_2) {
        ResolvedConstructor _superConstructor = requiredArgsUtil.getSuperConstructor(it);
        boolean _tripleEquals = (_superConstructor == null);
        if (_tripleEquals) {
            Iterable<? extends MutableFieldDeclaration> _dataFields = util.getDataFields(it);
            ToStringConfiguration _elvis = null;
            ToStringConfiguration _toStringConfig = toStringUtil.getToStringConfig(it);
            if (_toStringConfig != null) {
                _elvis = _toStringConfig;
            } else {
                ToStringConfiguration _toStringConfiguration = new ToStringConfiguration();
                _elvis = _toStringConfiguration;
            }
            toStringUtil.addToString(it, _dataFields, _elvis);
        } else {
            ToStringConfiguration _elvis_1 = null;
            ToStringConfiguration _toStringConfig_1 = toStringUtil.getToStringConfig(it);
            if (_toStringConfig_1 != null) {
                _elvis_1 = _toStringConfig_1;
            } else {
                ToStringConfiguration _toStringConfiguration_1 = new ToStringConfiguration();
                _elvis_1 = _toStringConfiguration_1;
            }
            toStringUtil.addReflectiveToString(it, _elvis_1);
        }
    }
    final Consumer<MutableFieldDeclaration> _function_1 = (MutableFieldDeclaration it_1) -> {
        boolean _shouldAddGetter = getterUtil.shouldAddGetter(it_1);
        if (_shouldAddGetter) {
            Visibility _elvis_2 = null;
            AccessorType _getterType = getterUtil.getGetterType(it_1);
            Visibility _visibility = null;
            if (_getterType != null) {
                _visibility = getterUtil.toVisibility(_getterType);
            }
            if (_visibility != null) {
                _elvis_2 = _visibility;
            } else {
                _elvis_2 = Visibility.PUBLIC;
            }
            getterUtil.addGetter(it_1, _elvis_2);
        }
    };
    util.getDataFields(it).forEach(_function_1);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) AccessorsProcessor(org.eclipse.xtend.lib.annotations.AccessorsProcessor) Element(org.eclipse.xtend.lib.macro.declaration.Element) ToStringConfiguration(org.eclipse.xtend.lib.annotations.ToStringConfiguration) EqualsHashCodeProcessor(org.eclipse.xtend.lib.annotations.EqualsHashCodeProcessor) FinalFieldsConstructorProcessor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructorProcessor) MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) FieldDeclaration(org.eclipse.xtend.lib.macro.declaration.FieldDeclaration) ResolvedConstructor(org.eclipse.xtend.lib.macro.declaration.ResolvedConstructor) Extension(org.eclipse.xtext.xbase.lib.Extension) ToStringProcessor(org.eclipse.xtend.lib.annotations.ToStringProcessor) FinalFieldsConstructor(org.eclipse.xtend.lib.annotations.FinalFieldsConstructor) Visibility(org.eclipse.xtend.lib.macro.declaration.Visibility) AccessorType(org.eclipse.xtend.lib.annotations.AccessorType)

Aggregations

AccessorType (org.eclipse.xtend.lib.annotations.AccessorType)1 AccessorsProcessor (org.eclipse.xtend.lib.annotations.AccessorsProcessor)1 EqualsHashCodeProcessor (org.eclipse.xtend.lib.annotations.EqualsHashCodeProcessor)1 FinalFieldsConstructor (org.eclipse.xtend.lib.annotations.FinalFieldsConstructor)1 FinalFieldsConstructorProcessor (org.eclipse.xtend.lib.annotations.FinalFieldsConstructorProcessor)1 ToStringConfiguration (org.eclipse.xtend.lib.annotations.ToStringConfiguration)1 ToStringProcessor (org.eclipse.xtend.lib.annotations.ToStringProcessor)1 Element (org.eclipse.xtend.lib.macro.declaration.Element)1 FieldDeclaration (org.eclipse.xtend.lib.macro.declaration.FieldDeclaration)1 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)1 ResolvedConstructor (org.eclipse.xtend.lib.macro.declaration.ResolvedConstructor)1 Visibility (org.eclipse.xtend.lib.macro.declaration.Visibility)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1