From a80f37f7d9c4d53e4b9233c4742657f1d07a7dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Wed, 1 Jan 2025 15:11:00 +0000 Subject: [PATCH] [WeaverGenerator] Replaces more uses of LangSpecV1 with LangSpecV2 --- .../AbstractJoinPointClassGenerator.java | 6 +- .../generator/java/utils/GeneratorUtils.java | 70 ++++--------------- 2 files changed, 15 insertions(+), 61 deletions(-) diff --git a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/helpers/AbstractJoinPointClassGenerator.java b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/helpers/AbstractJoinPointClassGenerator.java index 12cb5b9d..a2713452 100644 --- a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/helpers/AbstractJoinPointClassGenerator.java +++ b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/helpers/AbstractJoinPointClassGenerator.java @@ -125,9 +125,9 @@ public JavaClass generate() { GeneratorUtils.createDefImpl(javaC, isFinal, allDefinableAttributes, javaGenerator); } - GeneratorUtils.createListOfAvailableAttributes(javaC, langSpec, joinPoint, joinPointV2, superTypeName, isFinal); - GeneratorUtils.createListOfAvailableSelects(javaC, joinPoint, superTypeName, isFinal); - GeneratorUtils.createListOfAvailableActions(javaC, joinPoint, superTypeName, langSpec, isFinal); + GeneratorUtils.createListOfAvailableAttributes(javaC, joinPointV2, superTypeName, isFinal); + GeneratorUtils.createListOfAvailableSelects(javaC, joinPointV2, superTypeName, isFinal); + GeneratorUtils.createListOfAvailableActions(javaC, joinPointV2, superTypeName, isFinal); generateGet_Class(javaC, isFinal); diff --git a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/utils/GeneratorUtils.java b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/utils/GeneratorUtils.java index 0eea77ed..a2b08d28 100644 --- a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/utils/GeneratorUtils.java +++ b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/utils/GeneratorUtils.java @@ -21,7 +21,6 @@ import org.lara.interpreter.weaver.interf.NamedEnum; import org.lara.interpreter.weaver.interf.SelectOp; import org.lara.interpreter.weaver.interf.events.Stage; -import org.lara.language.specification.LanguageSpecification; import org.lara.language.specification.actionsmodel.schema.Action; import org.lara.language.specification.actionsmodel.schema.Parameter; import org.lara.language.specification.artifactsmodel.schema.Artifact; @@ -59,46 +58,8 @@ private static String ln() { return SpecsIo.getNewline(); } - /** - * @param javaC - * @param langSpec - * @param joinPoint - * @param superName - * @param isFinal - * @deprecated - */ - public static void createListOfAvailableAttributes(JavaClass javaC, LanguageSpecification langSpec, - JoinPointType joinPoint, String superName, boolean isFinal) { - // javaC.addImport(List.class.getCanonicalName()); - final String fillAttributesName = GenConstants.fillWAttrMethodName(); - final Method listSelects = new Method(JavaTypeFactory.getVoidType(), fillAttributesName, Privacy.PROTECTED); - listSelects.add(Annotation.OVERRIDE); - if (isFinal) { - listSelects.add(Modifier.FINAL); - } - final JavaType listStringType = JavaTypeFactory.getListStringJavaType(); - listSelects.addArgument(listStringType, "attributes"); - if (superName != null) { - - listSelects.appendCode("this." + superName + "." + fillAttributesName + "(attributes);" + ln()); - } else { - listSelects.appendCode("super." + fillAttributesName + "(attributes);" + ln()); - } - - final Artifact artifact = langSpec.getArtifacts().getArtifact(joinPoint.getClazz()); - if (artifact != null) { - for (final Attribute attribute : artifact.getAttribute()) { - - listSelects.appendCode("attributes.add(\"" + attribute.getName() + "\");" + ln()); - } - } - - javaC.add(listSelects); - } - - public static void createListOfAvailableAttributes(JavaClass javaC, LanguageSpecification langSpec, - JoinPointType joinPoint, JoinPointClass joinPointV2, String superName, boolean isFinal) { + public static void createListOfAvailableAttributes(JavaClass javaC, JoinPointClass joinPoint, String superName, boolean isFinal) { final String fillAttributesName = GenConstants.fillWAttrMethodName(); final Method listSelects = new Method(JavaTypeFactory.getVoidType(), fillAttributesName, Privacy.PROTECTED); @@ -116,16 +77,16 @@ public static void createListOfAvailableAttributes(JavaClass javaC, LanguageSpec listSelects.appendCode("super." + fillAttributesName + "(attributes);" + ln()); } - for (var attribute : joinPointV2.getAttributesSelf()) { + for (var attribute : joinPoint.getAttributesSelf()) { listSelects.appendCode("attributes.add(\"" + attribute.getName() + "\");" + ln()); } javaC.add(listSelects); } - public static void createListOfAvailableSelects(JavaClass javaC, JoinPointType joinPoint, String superName, + public static void createListOfAvailableSelects(JavaClass javaC, JoinPointClass joinPointV2, String superName, boolean isFinal) { - // javaC.addImport(List.class.getCanonicalName()); + final String fillSelectsName = GenConstants.fillWSelMethodName(); final Method listSelects = new Method(JavaTypeFactory.getVoidType(), fillSelectsName, Privacy.PROTECTED); listSelects.add(Annotation.OVERRIDE); @@ -143,9 +104,8 @@ public static void createListOfAvailableSelects(JavaClass javaC, JoinPointType j listSelects.appendCode("super." + fillSelectsName + "(selects);" + ln()); } - for (final Select sel : joinPoint.getSelect()) { - - listSelects.appendCode("selects.add(\"" + sel.getAlias() + "\");" + ln()); + for (var sel : joinPointV2.getSelectsSelf()) { + listSelects.appendCode("selects.add(\"" + sel.getSelectName() + "\");" + ln()); } javaC.add(listSelects); @@ -193,9 +153,8 @@ public static void createSelectByName(JavaClass javaC, JoinPointClass joinPointV } - public static void createListOfAvailableActions(JavaClass javaC, JoinPointType joinPoint, String superName, - LanguageSpecification langSpec, boolean isFinal) { - // javaC.addImport(List.class.getCanonicalName()); + public static void createListOfAvailableActions(JavaClass javaC, JoinPointClass joinPointV2, String superName, boolean isFinal) { + final String fillActionsName = GenConstants.fillWActMethodName(); final Method listActions = new Method(JavaTypeFactory.getVoidType(), fillActionsName, Privacy.PROTECTED); @@ -215,22 +174,17 @@ public static void createListOfAvailableActions(JavaClass javaC, JoinPointType j } listActions.appendCode("." + fillActionsName + "(actions);" + ln()); - for (final Action act : langSpec.getActionModel().getJoinPointOwnActions(joinPoint.getClazz())) { - - listActions.appendCode("actions.add(\"" + act.getReturn() + " " + act.getName() + "("); - final String joinedParams = StringUtils.join(act.getParameter(), Parameter::getType, ", "); + for (var act : joinPointV2.getActionsSelf()) { + listActions.appendCode("actions.add(\"" + act.getReturnType() + " " + act.getName() + "("); + final String joinedParams = StringUtils.join(act.getParameters(), org.lara.language.specification.dsl.Parameter::getType, ", "); listActions.appendCode(joinedParams); listActions.appendCode(")\");" + ln()); } + javaC.add(listActions); } - // public static void addSuperMethods(JavaClass javaC, String fieldName, JavaAbstractsGenerator generator, - // JoinPointType current) { - // addSuperMethods(javaC, fieldName, generator, current, false); - // } - /** * Add methods of the super join point to the java class *