diff --git a/siaras/SkillserverInterface.jrag b/siaras/SkillserverInterface.jrag index 074d0ab036baa7f6b5d488e3ec44f99cd3227dde..0ccf0b0bb8a50c8b3b0a8a4acac37d9baead1a4c 100644 --- a/siaras/SkillserverInterface.jrag +++ b/siaras/SkillserverInterface.jrag @@ -33,18 +33,64 @@ aspect Misc { public String Thing.id() { for (int i=0; i<getNumElement(); i++) { if (getElement(i).isIdentifier()) { - Identifier ident = ((ClassUse) getElement(i)).decl(); - return ident.getElement(0).id(); + Identifier ident = (Identifier) ((ClassUse) getElement(i)).decl(); + return ((StringElement) ident.getElement(0)).getLITERAL(); } } return null; } - public String ValueElement.id() { - return getElement(0).getLITERAL(); - } - syn boolean Element.isIdentifier() = false; eq Identifier.isIdentifier() = true; eq ClassUse.isIdentifier() = decl().isIdentifier(); } + + +aspect Decl { + syn lazy Thing ClassUse.decl() { + String id = getAttribute(0).getValue().getSTRING_LITERAL(); + return rootNode().findDecl(id); + } + + Start ASTNode.rootNode() { + ASTNode parent = getParent(); + while (!(parent instanceof Start)) { + parent = parent.getParent(); + } + return (Start) parent; + } + + syn Thing Start.findDecl(String id) { + for (int i=0; i<getNumElement(); i++) { + if (getElement(i).findDecl(id) != null) { + return (Thing) getElement(i); + } + } + return null; + } + syn Thing Element.findDecl(String id) = null; + eq ComplexElement.findDecl(String id) { + for (int i=0; i<getNumElement(); i++) { + if (getElement(i).findDecl(id) != null) { + return (Thing) getElement(i); + } + } + return null; + } + eq Thing.findDecl(String id) { + for (int i=0; i<getNumAttribute(); i++) { + if (getAttribute(i).isEqualId(id)) { + return this; + } + } + return null; + } + + syn boolean Attribute.isEqualId(String id) = false; + eq RdfId.isEqualId(String id) { + if (getValue().getSTRING_LITERAL().equals(id)) { + return true; + } + return false; + } +}