use of spoon.reflect.path.impl.CtNamedPathElement in project spoon by INRIA.
the class CtPathBuilder method name.
/**
* Add a name matcher to this path.
*
* @param name
* @param args
* @return
*/
public CtPathBuilder name(String name, String[]... args) {
CtNamedPathElement e = new CtNamedPathElement(name);
if (args != null) {
for (String[] arg : args) {
e.addArgument(arg[0], arg[1]);
}
}
elements.add(e);
return this;
}
use of spoon.reflect.path.impl.CtNamedPathElement in project spoon by INRIA.
the class CtPathStringBuilder method fromString.
/**
* Build path from a string representation.
*
* for example:
* new CtPathBuilder().fromString(".spoon.test.path.Foo.foo#statement[index=0]")
* Match the first statement of method foo from class spoon.test.path.Foo.
*
* Some specials characters
* . : match with the given name
* # : match with a CtPathRole
* / : match with a element type (for example, to match all classes, use /CtClass
*/
public CtPath fromString(String pathStr) throws CtPathException {
Matcher matcher = pathPattern.matcher(pathStr);
CtPathImpl path = new CtPathImpl();
while (matcher.find()) {
String kind = matcher.group(1);
CtPathElement pathElement = null;
if (CtNamedPathElement.STRING.equals(kind)) {
pathElement = new CtNamedPathElement(matcher.group(2));
} else if (CtTypedNameElement.STRING.equals(kind)) {
pathElement = new CtTypedNameElement(load(matcher.group(2)));
} else if (CtRolePathElement.STRING.equals(kind)) {
pathElement = new CtRolePathElement(CtRole.fromName(matcher.group(2)));
}
String args = matcher.group(4);
if (args != null) {
for (String arg : args.split(";")) {
Matcher argmatcher = argumentPattern.matcher(arg);
if (argmatcher.matches()) {
pathElement.addArgument(argmatcher.group(1), argmatcher.group(2));
}
}
}
path.addLast(pathElement);
}
return path;
}
Aggregations