if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {
Scalar name = (Scalar) key;
ClassInstanceCreation filterClass = (ClassInstanceCreation) value;
CallArgumentsList ctorParams = filterClass.getCtorParams();
Object child = ctorParams.getChilds().get(0);
if (child instanceof VariableReference && ((VariableReference)child).getName().equals("$this") &&
filterClass.getClassName().toString().equals((TwigCoreConstants.TWIG_FILTER_METHOD))) {
if (ctorParams.getChilds().size() > 2 && ctorParams.getChilds().get(1) instanceof Scalar) {
Scalar internal = (Scalar) ctorParams.getChilds().get(1);
String elemName = name.getValue().replaceAll("['\"]", "");
Filter filter = new Filter(elemName);
filter.setInternalFunction(internal.getValue().replaceAll("['\"]", ""));
filter.setPhpClass(currentClass.getName());
filters.add(filter);
}
}
if (!(child instanceof Scalar)) {
return true;
}
Scalar internal = (Scalar) child;
if (filterClass.getClassName().toString().equals(TwigCoreConstants.TWIG_FILTER_FUNCTION)) {
String elemName = name.getValue().replaceAll("['\"]", "");
Filter filter = new Filter(elemName);
filter.setInternalFunction(internal.getValue()
.replaceAll("['\"]", ""));
filter.setPhpClass(currentClass.getName());
filters.add(filter);
}
}
return true;
}
});
} else if (inTwigExtension && TwigCoreConstants.GET_TESTS.equals(s.getName())) {
phpMethod.traverse(new PHPASTVisitor()
{
@Override
public boolean visit(ArrayElement s) throws Exception
{
Expression key = s.getKey();
Expression value = s.getValue();
if (key == null || value == null)
return false;
if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {
Scalar name = (Scalar) key;
ClassInstanceCreation functionClass = (ClassInstanceCreation) value;
CallArgumentsList args = functionClass.getCtorParams();
Scalar internalFunction = (Scalar) args.getChilds().get(0);
if (internalFunction == null)
return true;
if (functionClass.getClassName().toString().equals(TwigCoreConstants.TWIG_TEST_FUNCTION)) {
String elemName = name.getValue().replaceAll("['\"]", "");
JSONObject metadata = new JSONObject();
metadata.put(TwigType.PHPCLASS,currentClass.getName());
Test test = new Test(elemName);
test.setPhpClass(currentClass.getName());
test.setInternalFunction(internalFunction.getValue().replaceAll("['\"]", ""));
tests.add(test);
}
}
return true;
}
});
} else if (inTwigExtension&& TwigCoreConstants.GET_FUNCTIONS.equals(s.getName())) {
phpMethod.traverse(new PHPASTVisitor()
{
@Override
public boolean visit(ArrayElement s) throws Exception
{
Expression key = s.getKey();
Expression value = s.getValue();
if (key == null || value == null) {
return false;
}
if (key.getClass() == Scalar.class && value.getClass() == ClassInstanceCreation.class) {
Scalar name = (Scalar) key;
ClassInstanceCreation functionClass = (ClassInstanceCreation) value;
CallArgumentsList args = functionClass.getCtorParams();
String functionClassName = functionClass.getClassName().toString();
int index = -1;
if (functionClassName.equals(TwigCoreConstants.TWIG_FUNCTION_FUNCTION)) {
index = 0;
} else if (functionClassName.equals(TwigCoreConstants.TWIG_FUNCTION_METHOD)) {
index = 1;
}
if (index > -1 && args.getChilds().get(index) instanceof Scalar) {
Scalar internalFunction = (Scalar) args.getChilds().get(index);
if (internalFunction == null) {
return true;
}