Skip to content

Commit

Permalink
[WeaverGenerator] Replaces more uses of LangSpecV1 with LangSpecV2
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobispo committed Jan 1, 2025
1 parent cc1d4d8 commit a80f37f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
*
Expand Down

0 comments on commit a80f37f

Please sign in to comment.