From cb830bc1db1f5595638cb328214fa6242de74f74 Mon Sep 17 00:00:00 2001 From: Matthias Villiger Date: Fri, 21 Jan 2022 11:56:02 +0100 Subject: [PATCH] Code cleanup --- .../FormDataAnnotationDescriptor.java | 62 +++++++++---------- .../s/dto/CompositeFormDataGenerator.java | 12 +--- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/annotation/FormDataAnnotationDescriptor.java b/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/annotation/FormDataAnnotationDescriptor.java index cbbf99ec3..ff6970b34 100644 --- a/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/annotation/FormDataAnnotationDescriptor.java +++ b/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/annotation/FormDataAnnotationDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2021 BSI Business Systems Integration AG. + * Copyright (c) 2010-2022 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -42,9 +42,9 @@ protected FormDataAnnotationDescriptor() { } public static FormDataAnnotationDescriptor of(IType type) { - var anot = new FormDataAnnotationDescriptor(); + var descriptor = new FormDataAnnotationDescriptor(); if (type == null) { - return anot; + return descriptor; } var scoutApi = type.javaEnvironment().requireApi(IScoutApi.class); if (type.isInstanceOf(scoutApi.IFormExtension()) || type.isInstanceOf(scoutApi.IFormFieldExtension())) { @@ -52,19 +52,19 @@ public static FormDataAnnotationDescriptor of(IType type) { var dataAnnotation = DataAnnotationDescriptor.of(type); dataAnnotation.ifPresent(dataAnnotationDescriptor -> { - anot.setAnnotationOwner(type); - anot.setDefaultSubtypeSdkCommand(DefaultSubtypeSdkCommand.CREATE); - anot.setFormDataType(dataAnnotationDescriptor.getDataType()); - anot.setGenericOrdinal(-1); - anot.setSdkCommand(SdkCommand.CREATE); - anot.setSuperType(dataAnnotationDescriptor.getSuperDataType() + descriptor.setAnnotationOwner(type); + descriptor.setDefaultSubtypeSdkCommand(DefaultSubtypeSdkCommand.CREATE); + descriptor.setFormDataType(dataAnnotationDescriptor.getDataType()); + descriptor.setGenericOrdinal(-1); + descriptor.setSdkCommand(SdkCommand.CREATE); + descriptor.setSuperType(dataAnnotationDescriptor.getSuperDataType() .orElseGet(() -> type.javaEnvironment().findType(scoutApi.AbstractFormFieldData()).orElse(null))); }); } else { - parseFormDataAnnotationRec(anot, type, scoutApi, true); + parseFormDataAnnotationRec(descriptor, type, scoutApi, true); } - return anot; + return descriptor; } private static void parseFormDataAnnotationRec(FormDataAnnotationDescriptor descriptorToFill, IType type, IScoutApi api, boolean isOwner) { @@ -72,7 +72,7 @@ private static void parseFormDataAnnotationRec(FormDataAnnotationDescriptor desc return; } - var replaceAnnotationFqn = type.javaEnvironment().requireApi(IScoutApi.class).Replace().fqn(); + var replaceAnnotationFqn = api.Replace().fqn(); var replaceAnnotationPresent = type.annotations().withName(replaceAnnotationFqn).existsAny(); var superType = type.superClass().orElse(null); @@ -185,43 +185,43 @@ else if (element instanceof IMethod) { } } - public static boolean isCreate(FormDataAnnotationDescriptor anot) { - if (anot == null) { + public static boolean isCreate(FormDataAnnotationDescriptor descriptor) { + if (descriptor == null) { return false; } - return (anot.getSdkCommand() == SdkCommand.CREATE) || (anot.getSdkCommand() == null && anot.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.CREATE); + return (descriptor.getSdkCommand() == SdkCommand.CREATE) || (descriptor.getSdkCommand() == null && descriptor.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.CREATE); } - public static boolean isIgnore(FormDataAnnotationDescriptor anot) { - return (anot.getSdkCommand() == SdkCommand.IGNORE) || (anot.getSdkCommand() == null && anot.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.IGNORE); + public static boolean isIgnore(FormDataAnnotationDescriptor descriptor) { + return (descriptor.getSdkCommand() == SdkCommand.IGNORE) || (descriptor.getSdkCommand() == null && descriptor.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.IGNORE); } - public static boolean isSdkCommandDefault(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getSdkCommand() == SdkCommand.DEFAULT; + public static boolean isSdkCommandDefault(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getSdkCommand() == SdkCommand.DEFAULT; } - public static boolean isSdkCommandCreate(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getSdkCommand() == SdkCommand.CREATE; + public static boolean isSdkCommandCreate(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getSdkCommand() == SdkCommand.CREATE; } - public static boolean isSdkCommandUse(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getSdkCommand() == SdkCommand.USE; + public static boolean isSdkCommandUse(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getSdkCommand() == SdkCommand.USE; } - public static boolean isSdkCommandIgnore(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getSdkCommand() == SdkCommand.IGNORE; + public static boolean isSdkCommandIgnore(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getSdkCommand() == SdkCommand.IGNORE; } - public static boolean isDefaultSubtypeSdkCommandCreate(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.CREATE; + public static boolean isDefaultSubtypeSdkCommandCreate(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.CREATE; } - public static boolean isDefaultSubtypeSdkCommandIgnore(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.IGNORE; + public static boolean isDefaultSubtypeSdkCommandIgnore(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.IGNORE; } - public static boolean isDefaultSubtypeSdkCommandDefault(FormDataAnnotationDescriptor anot) { - return anot != null && anot.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.DEFAULT; + public static boolean isDefaultSubtypeSdkCommandDefault(FormDataAnnotationDescriptor descriptor) { + return descriptor != null && descriptor.getDefaultSubtypeSdkCommand() == DefaultSubtypeSdkCommand.DEFAULT; } /** diff --git a/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/dto/CompositeFormDataGenerator.java b/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/dto/CompositeFormDataGenerator.java index ad2abea35..242510549 100644 --- a/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/dto/CompositeFormDataGenerator.java +++ b/org.eclipse.scout.sdk.core.s/src/main/java/org/eclipse/scout/sdk/core/s/dto/CompositeFormDataGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2021 BSI Business Systems Integration AG. + * Copyright (c) 2010-2022 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -76,14 +76,7 @@ protected void processFormField(IType formField) { var fieldExtendsTemplateField = false; var isCompositeField = formField.isInstanceOf(scoutApi.ICompositeField()); if (FormDataAnnotationDescriptor.isCreate(fieldAnnotation)) { - var formDataType = fieldAnnotation.getFormDataType(); - String formDataTypeName; - if (formDataType == null) { - formDataTypeName = removeFieldSuffix(formField.elementName()); - } - else { - formDataTypeName = formDataType.elementName(); - } + var formDataTypeName = removeFieldSuffix(formField.elementName()); ITypeGenerator dtoGenerator; if (fieldAnnotation.getSuperType().isInstanceOf(scoutApi.AbstractTableFieldBeanData())) { @@ -96,7 +89,6 @@ else if (isCompositeField && !formField.isInstanceOf(scoutApi.IValueField())) { dtoGenerator = new CompositeFormDataGenerator<>(formField, fieldAnnotation, targetEnvironment()); } else { - dtoGenerator = new FormDataGenerator<>(formField, fieldAnnotation, targetEnvironment()); // special case if a property has the same name as a form field -> show warning