private static List<ZenCodingFilter> getFilters(ZenCodingNode node, PsiElement context) { List<ZenCodingFilter> result = new ArrayList<ZenCodingFilter>(); while (node instanceof FilterNode) { FilterNode filterNode = (FilterNode) node; String filterSuffix = filterNode.getFilter(); boolean filterFound = false; for (ZenCodingFilter filter : ZenCodingFilter.getInstances()) { if (filter.isMyContext(context) && filter.getSuffix().equals(filterSuffix)) { filterFound = true; result.add(filter); } } assert filterFound; node = filterNode.getNode(); } for (ZenCodingFilter filter : ZenCodingFilter.getInstances()) { if (filter.isMyContext(context) && filter.isAppliedByDefault(context)) { result.add(filter); } } Collections.reverse(result); return result; }
@Nullable private static ZenCodingGenerator findApplicableGenerator( ZenCodingNode node, PsiElement context, boolean wrapping) { ZenCodingGenerator defaultGenerator = null; List<ZenCodingGenerator> generators = ZenCodingGenerator.getInstances(); for (ZenCodingGenerator generator : generators) { if (defaultGenerator == null && generator.isMyContext(context, wrapping) && generator.isAppliedByDefault(context)) { defaultGenerator = generator; } } while (node instanceof FilterNode) { FilterNode filterNode = (FilterNode) node; String suffix = filterNode.getFilter(); for (ZenCodingGenerator generator : generators) { if (generator.isMyContext(context, wrapping)) { if (suffix != null && suffix.equals(generator.getSuffix())) { return generator; } } } node = filterNode.getNode(); } return defaultGenerator; }