com.patternity.core.metamodel.ElementReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartrics-RestFixtureExtensions Show documentation
Show all versions of smartrics-RestFixtureExtensions Show documentation
Extensions of the RestFixture.
An extension is a RestFixture with some specific/bespoke behaviour not generic enough to make it to the RestFixture itself.
The newest version!
package com.patternity.core.metamodel;
/**
* Represents a reference to some member of a pattern
*
* @author cyrille martraire
*/
public class ElementReference implements Element, Definition {
private final String rolename;
public ElementReference(String rolename) {
this.rolename = rolename;
}
public String getRolename() {
return rolename;
}
public Element resolve(PatternOccurrence container) {
final Element resolved = container.get(rolename);
if (resolved == null) {
return null;
}
// return dig(resolved);
return resolved;
}
public final static Element dig(final Element member) {
if (member instanceof PatternOccurrence) {
final PatternOccurrence compound = (PatternOccurrence) member;
final Element resolved = ((PatternOccurrence) member).get("head");
if (resolved == null || resolved.equals(compound)) {
return resolved;// prevent cycle
}
return dig(resolved);
}
return member;
}
public String toString() {
return "Ref to " + rolename;
}
}