Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardcoded replicated information regarding LaraJoinPoint #42

Open
lm-sousa opened this issue Aug 23, 2023 · 0 comments
Open

Hardcoded replicated information regarding LaraJoinPoint #42

lm-sousa opened this issue Aug 23, 2023 · 0 comments
Labels

Comments

@lm-sousa
Copy link
Member

All these code snippets show the same information replicated across the codebase.
These should be consolidated into a single source of truth.

LaraJoinPointSpecification.add(Attribute.getActionsAttribute());
LaraJoinPointSpecification.add(Attribute.getAttributesAttribute());
LaraJoinPointSpecification.add(Attribute.getSelectsAttribute());
// JoinPointSpecification.add(new Attribute(null, "srcCode"));
LaraJoinPointSpecification.add(new Attribute(PrimitiveClasses.STRING, "dump"));
LaraJoinPointSpecification.add(new Attribute(PrimitiveClasses.STRING, "joinPointType"));
LaraJoinPointSpecification.add(new Attribute(PrimitiveClasses.OBJECT, "node"));
LaraJoinPointSpecification.add(new Attribute(new JPType(LaraJoinPointSpecification), "self"));
LaraJoinPointSpecification.add(new Attribute(new JPType(LaraJoinPointSpecification), "super"));
LaraJoinPointSpecification.add(new Attribute(new ArrayType(new JPType(LaraJoinPointSpecification)), "children"));
LaraJoinPointSpecification.add(new Attribute(new ArrayType(new JPType(LaraJoinPointSpecification)), "descendants"));
LaraJoinPointSpecification.add(new Attribute(new ArrayType(new JPType(LaraJoinPointSpecification)), "scopeNodes"));
LaraJoinPointSpecification.add(new Action(new JPType(LaraJoinPointSpecification), "insert", Arrays.asList(
new Parameter(new LiteralEnum("Position", Arrays.asList("before", "after", "replace")), "position"),
new Parameter(PrimitiveClasses.STRING, "code"))));
LaraJoinPointSpecification.add(new Action(new JPType(LaraJoinPointSpecification), "insert", Arrays.asList(
new Parameter(new LiteralEnum("Position", Arrays.asList("before", "after", "replace")), "position"),
new Parameter(new JPType(LaraJoinPointSpecification), "joinpoint"))));
LaraJoinPointSpecification.add(new Action(PrimitiveClasses.VOID, "def", Arrays.asList(
new Parameter(PrimitiveClasses.STRING, "attribute"),
new Parameter(PrimitiveClasses.OBJECT, "value"))));
LaraJoinPointSpecification.add(new Action(PrimitiveClasses.STRING, "toString"));
LaraJoinPointSpecification.add(new Action(PrimitiveClasses.BOOLEAN, "equals", Arrays.asList(
new Parameter(new JPType(LaraJoinPointSpecification), "jp"))));
LaraJoinPointSpecification.add(new Action(PrimitiveClasses.BOOLEAN, "instanceOf", Arrays.asList(
new Parameter(PrimitiveClasses.STRING, "name"))));

public Map<String, ActionArgument> createInsertParameters() {
final Map<String, ActionArgument> args = new LinkedHashMap<>();
final ActionArgument when = new ActionArgument(POSITION_ARGUMENT_NAME, "string", this);
args.put(POSITION_ARGUMENT_NAME, when);
final ActionArgument code = new ActionArgument(CODE_ARGUMENT_NAME, "template", this);
args.put(CODE_ARGUMENT_NAME, code);
return args;
}
public Map<String, ActionArgument> createDefParameters() {
final Map<String, ActionArgument> args = new LinkedHashMap<>();
final ActionArgument attribute = new ActionArgument(ATTRIBUTE_ARGUMENT_NAME, "string", this);
args.put(ATTRIBUTE_ARGUMENT_NAME, attribute);
final ActionArgument value = new ActionArgument(VALUE_ARGUMENT_NAME, "Object", this);
args.put(VALUE_ARGUMENT_NAME, value);
return args;
}

// Add default insert action
final Action insertAct = new Action();
insertAct.setName("insert");
insertAct.setClazz("*");
// action 'insert' returns an array of join points
insertAct.setReturn("Joinpoint[]");
final Parameter positionParam = new Parameter();
positionParam.setName("position");
positionParam.setType("String");
insertAct.getParameter().add(positionParam);
final Parameter codeParam = new Parameter();
codeParam.setName("code");
codeParam.setType("String");
insertAct.getParameter().add(codeParam);
actions.add(insertAct);
// Add default insert action overload that receives a JoinPoint
final Action insertActJp = new Action();
insertActJp.setName("insert");
insertActJp.setClazz("*");
// action 'insert' returns an array of join points
insertActJp.setReturn("Joinpoint[]");
final Parameter positionParam2 = new Parameter();
positionParam2.setName("position");
positionParam2.setType("String");
insertActJp.getParameter().add(positionParam2);
final Parameter codeParam2 = new Parameter();
codeParam2.setName("code");
codeParam2.setType("JoinpointInterface");
insertActJp.getParameter().add(codeParam2);
actions.add(insertActJp);
// Add default define (def) action
final Action defAct = new Action();
defAct.setName("def");
defAct.setClazz("*");
final Parameter attParam = new Parameter();
attParam.setName("attribute");
attParam.setType("String");
defAct.getParameter().add(attParam);
final Parameter valueParam = new Parameter();
valueParam.setName("value");
valueParam.setType("Object");
defAct.getParameter().add(valueParam);
actions.add(defAct);

INSERT = new Action(Primitive.VOID, "insert");
Action.INSERT.addParameter(new LiteralEnum("", "{before,after,replace}"), "position");
Action.INSERT.addParameter(PrimitiveClasses.STRING, "code");
DEF = new Action(Primitive.VOID, "def");
Action.DEF.addParameter(PrimitiveClasses.STRING, "attribute");
Action.DEF.addParameter(PrimitiveClasses.OBJECT, "value");

PrimitiveClasses string = PrimitiveClasses.STRING;
ArrayType stringA = new ArrayType(string);
ATTRIBUTES = new Attribute(stringA, "attributes");
SELECTS = new Attribute(stringA, "selects");
ACTIONS = new Attribute(stringA, "actions");

globalNode.add(Attribute.getAttributesAttribute());
globalNode.add(Attribute.getSelectsAttribute());
globalNode.add(Attribute.getActionsAttribute());
globalNode.add(Action.getInsertAction());
globalNode.add(Action.getDefAction());

https://github.com/specs-feup/lara-framework/blob/af1ab2e7b36777f19ae96bc1ef0bdf546e37b3d9/WeaverGenerator/src/org/lara/interpreter/weaver/generator/generator/java/helpers/SuperAbstractJoinPointGenerator.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant