diff --git a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AAny.java b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AAny.java index 1029a76..6cb91b6 100644 --- a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AAny.java +++ b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AAny.java @@ -76,11 +76,11 @@ public final String get_class() { * */ protected enum AnyAttributes { - GETVALUE("getValue"), - PARENT("parent"), AST("ast"), CHILDREN("children"), - DESCENDANTS("descendants"); + DESCENDANTS("descendants"), + GETVALUE("getValue"), + PARENT("parent"); private String name; /** diff --git a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AApp.java b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AApp.java index feab2ac..cec1c9a 100644 --- a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AApp.java +++ b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AApp.java @@ -30,7 +30,7 @@ public AJoinPoint addAstImpl(AJoinPoint ast) { * Adds an AST to the current program, returns the inserted join point * @param ast */ - public final AJoinPoint addAst(AJoinPoint ast) { + public final Object addAst(AJoinPoint ast) { try { if(hasListeners()) { eventTrigger().triggerAction(Stage.BEGIN, "addAst", this, Optional.empty(), ast); @@ -39,7 +39,7 @@ public final AJoinPoint addAst(AJoinPoint ast) { if(hasListeners()) { eventTrigger().triggerAction(Stage.END, "addAst", this, Optional.ofNullable(result), ast); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { throw new ActionException(get_class(), "addAst", e); } @@ -106,11 +106,11 @@ public final String get_class() { * */ protected enum AppAttributes { - GETVALUE("getValue"), - PARENT("parent"), AST("ast"), CHILDREN("children"), - DESCENDANTS("descendants"); + DESCENDANTS("descendants"), + GETVALUE("getValue"), + PARENT("parent"); private String name; /** diff --git a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AJoinPoint.java b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AJoinPoint.java index 1136e4f..aec243b 100644 --- a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AJoinPoint.java +++ b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/joinpoints/AJoinPoint.java @@ -60,139 +60,137 @@ public void defImpl(String attribute, Object value) { */ @Override protected void fillWithActions(List actions) { + actions.add("detach()"); + actions.add("insertAfter(AJoinPoint node)"); + actions.add("insertAfter(String code)"); + actions.add("insertBefore(AJoinPoint node)"); + actions.add("insertBefore(String node)"); actions.add("replaceWith(AJoinPoint node)"); actions.add("replaceWith(String node)"); actions.add("replaceWith(AJoinPoint[] node)"); actions.add("replaceWithStrings(String[] node)"); - actions.add("insertBefore(AJoinPoint node)"); - actions.add("insertBefore(String node)"); - actions.add("insertAfter(AJoinPoint node)"); - actions.add("insertAfter(String code)"); - actions.add("detach()"); actions.add("setValue(String name, Object value)"); } /** - * Replaces this node with the given node - * @param node + * Removes the node associated to this joinpoint from the AST */ - public AJoinPoint replaceWithImpl(AJoinPoint node) { - throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); + public AJoinPoint detachImpl() { + throw new UnsupportedOperationException(get_class()+": Action detach not implemented "); } /** - * Replaces this node with the given node - * @param node + * Removes the node associated to this joinpoint from the AST */ - public final AJoinPoint replaceWith(AJoinPoint node) { + public final Object detach() { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), node); + eventTrigger().triggerAction(Stage.BEGIN, "detach", this, Optional.empty()); } - AJoinPoint result = this.replaceWithImpl(node); + AJoinPoint result = this.detachImpl(); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), node); + eventTrigger().triggerAction(Stage.END, "detach", this, Optional.ofNullable(result)); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "replaceWith", e); + throw new ActionException(get_class(), "detach", e); } } /** - * Overload which accepts a string + * Inserts the given join point after this join point * @param node */ - public AJoinPoint replaceWithImpl(String node) { - throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); + public AJoinPoint insertAfterImpl(AJoinPoint node) { + throw new UnsupportedOperationException(get_class()+": Action insertAfter not implemented "); } /** - * Overload which accepts a string + * Inserts the given join point after this join point * @param node */ - public final AJoinPoint replaceWith(String node) { + public final Object insertAfter(AJoinPoint node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), node); + eventTrigger().triggerAction(Stage.BEGIN, "insertAfter", this, Optional.empty(), node); } - AJoinPoint result = this.replaceWithImpl(node); + AJoinPoint result = this.insertAfterImpl(node); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), node); + eventTrigger().triggerAction(Stage.END, "insertAfter", this, Optional.ofNullable(result), node); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "replaceWith", e); + throw new ActionException(get_class(), "insertAfter", e); } } /** - * Overload which accepts a list of join points - * @param node + * Overload which accepts a string + * @param code */ - public AJoinPoint replaceWithImpl(AJoinPoint[] node) { - throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); + public AJoinPoint insertAfterImpl(String code) { + throw new UnsupportedOperationException(get_class()+": Action insertAfter not implemented "); } /** - * Overload which accepts a list of join points - * @param node + * Overload which accepts a string + * @param code */ - public final AJoinPoint replaceWith(AJoinPoint[] node) { + public final Object insertAfter(String code) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), new Object[] { node}); + eventTrigger().triggerAction(Stage.BEGIN, "insertAfter", this, Optional.empty(), code); } - AJoinPoint result = this.replaceWithImpl(node); + AJoinPoint result = this.insertAfterImpl(code); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), new Object[] { node}); + eventTrigger().triggerAction(Stage.END, "insertAfter", this, Optional.ofNullable(result), code); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "replaceWith", e); + throw new ActionException(get_class(), "insertAfter", e); } } /** - * Overload which accepts a list of strings + * Inserts the given join point before this join point * @param node */ - public AJoinPoint replaceWithStringsImpl(String[] node) { - throw new UnsupportedOperationException(get_class()+": Action replaceWithStrings not implemented "); + public AJoinPoint insertBeforeImpl(AJoinPoint node) { + throw new UnsupportedOperationException(get_class()+": Action insertBefore not implemented "); } /** - * Overload which accepts a list of strings + * Inserts the given join point before this join point * @param node */ - public final AJoinPoint replaceWithStrings(String[] node) { + public final Object insertBefore(AJoinPoint node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "replaceWithStrings", this, Optional.empty(), new Object[] { node}); + eventTrigger().triggerAction(Stage.BEGIN, "insertBefore", this, Optional.empty(), node); } - AJoinPoint result = this.replaceWithStringsImpl(node); + AJoinPoint result = this.insertBeforeImpl(node); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "replaceWithStrings", this, Optional.ofNullable(result), new Object[] { node}); + eventTrigger().triggerAction(Stage.END, "insertBefore", this, Optional.ofNullable(result), node); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "replaceWithStrings", e); + throw new ActionException(get_class(), "insertBefore", e); } } /** - * Inserts the given join point before this join point + * Overload which accepts a string * @param node */ - public AJoinPoint insertBeforeImpl(AJoinPoint node) { + public AJoinPoint insertBeforeImpl(String node) { throw new UnsupportedOperationException(get_class()+": Action insertBefore not implemented "); } /** - * Inserts the given join point before this join point + * Overload which accepts a string * @param node */ - public final AJoinPoint insertBefore(AJoinPoint node) { + public final Object insertBefore(String node) { try { if(hasListeners()) { eventTrigger().triggerAction(Stage.BEGIN, "insertBefore", this, Optional.empty(), node); @@ -201,115 +199,117 @@ public final AJoinPoint insertBefore(AJoinPoint node) { if(hasListeners()) { eventTrigger().triggerAction(Stage.END, "insertBefore", this, Optional.ofNullable(result), node); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { throw new ActionException(get_class(), "insertBefore", e); } } /** - * Overload which accepts a string + * Replaces this node with the given node * @param node */ - public AJoinPoint insertBeforeImpl(String node) { - throw new UnsupportedOperationException(get_class()+": Action insertBefore not implemented "); + public AJoinPoint replaceWithImpl(AJoinPoint node) { + throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); } /** - * Overload which accepts a string + * Replaces this node with the given node * @param node */ - public final AJoinPoint insertBefore(String node) { + public final Object replaceWith(AJoinPoint node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "insertBefore", this, Optional.empty(), node); + eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), node); } - AJoinPoint result = this.insertBeforeImpl(node); + AJoinPoint result = this.replaceWithImpl(node); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "insertBefore", this, Optional.ofNullable(result), node); + eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), node); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "insertBefore", e); + throw new ActionException(get_class(), "replaceWith", e); } } /** - * Inserts the given join point after this join point + * Overload which accepts a string * @param node */ - public AJoinPoint insertAfterImpl(AJoinPoint node) { - throw new UnsupportedOperationException(get_class()+": Action insertAfter not implemented "); + public AJoinPoint replaceWithImpl(String node) { + throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); } /** - * Inserts the given join point after this join point + * Overload which accepts a string * @param node */ - public final AJoinPoint insertAfter(AJoinPoint node) { + public final Object replaceWith(String node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "insertAfter", this, Optional.empty(), node); + eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), node); } - AJoinPoint result = this.insertAfterImpl(node); + AJoinPoint result = this.replaceWithImpl(node); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "insertAfter", this, Optional.ofNullable(result), node); + eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), node); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "insertAfter", e); + throw new ActionException(get_class(), "replaceWith", e); } } /** - * Overload which accepts a string - * @param code + * Overload which accepts a list of join points + * @param node */ - public AJoinPoint insertAfterImpl(String code) { - throw new UnsupportedOperationException(get_class()+": Action insertAfter not implemented "); + public AJoinPoint replaceWithImpl(AJoinPoint[] node) { + throw new UnsupportedOperationException(get_class()+": Action replaceWith not implemented "); } /** - * Overload which accepts a string - * @param code + * Overload which accepts a list of join points + * @param node */ - public final AJoinPoint insertAfter(String code) { + public final Object replaceWith(Object[] node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "insertAfter", this, Optional.empty(), code); + eventTrigger().triggerAction(Stage.BEGIN, "replaceWith", this, Optional.empty(), new Object[] { node}); } - AJoinPoint result = this.insertAfterImpl(code); + AJoinPoint result = this.replaceWithImpl(pt.up.fe.specs.util.SpecsCollections.cast(node, AJoinPoint.class)); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "insertAfter", this, Optional.ofNullable(result), code); + eventTrigger().triggerAction(Stage.END, "replaceWith", this, Optional.ofNullable(result), new Object[] { node}); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "insertAfter", e); + throw new ActionException(get_class(), "replaceWith", e); } } /** - * Removes the node associated to this joinpoint from the AST + * Overload which accepts a list of strings + * @param node */ - public AJoinPoint detachImpl() { - throw new UnsupportedOperationException(get_class()+": Action detach not implemented "); + public AJoinPoint replaceWithStringsImpl(String[] node) { + throw new UnsupportedOperationException(get_class()+": Action replaceWithStrings not implemented "); } /** - * Removes the node associated to this joinpoint from the AST + * Overload which accepts a list of strings + * @param node */ - public final AJoinPoint detach() { + public final Object replaceWithStrings(Object[] node) { try { if(hasListeners()) { - eventTrigger().triggerAction(Stage.BEGIN, "detach", this, Optional.empty()); + eventTrigger().triggerAction(Stage.BEGIN, "replaceWithStrings", this, Optional.empty(), new Object[] { node}); } - AJoinPoint result = this.detachImpl(); + AJoinPoint result = this.replaceWithStringsImpl(pt.up.fe.specs.util.SpecsCollections.cast(node, String.class)); if(hasListeners()) { - eventTrigger().triggerAction(Stage.END, "detach", this, Optional.ofNullable(result)); + eventTrigger().triggerAction(Stage.END, "replaceWithStrings", this, Optional.ofNullable(result), new Object[] { node}); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { - throw new ActionException(get_class(), "detach", e); + throw new ActionException(get_class(), "replaceWithStrings", e); } } @@ -336,7 +336,7 @@ public final Object setValue(String name, Object value) { if(hasListeners()) { eventTrigger().triggerAction(Stage.END, "setValue", this, Optional.ofNullable(result), name, value); } - return result; + return result!=null?result:getUndefinedValue(); } catch(Exception e) { throw new ActionException(get_class(), "setValue", e); } diff --git a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/weaver/AAnyWeaver.java b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/weaver/AAnyWeaver.java index 8d1b5c6..0939ea1 100644 --- a/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/weaver/AAnyWeaver.java +++ b/AnyWeaver/src/pt/up/fe/specs/anycompiler/weaver/abstracts/weaver/AAnyWeaver.java @@ -8,7 +8,7 @@ /** * Abstract Weaver Implementation for AnyWeaver
Since the generated abstract classes are always overwritten, their implementation should be done by extending those abstract classes with user-defined classes.
-The abstract class {@link pt.up.fe.specs.anycompiler.weaver.abstracts.AAnyWeaverJoinPoint} can be used to add user-defined methods and fields which the user intends to add for all join points and are not intended to be used in LARA aspects. +The abstract class {@link pt.up.fe.specs.anycompiler.weaver.abstracts.AAnyWeaverJoinPoint} contains attributes and actions common to all join points. * The implementation of the abstract methods is mandatory! * @author Lara C. */