Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ugly hacks in ActionStartEntryParser #4

Open
skiwi2 opened this issue Feb 9, 2015 · 0 comments
Open

Fix ugly hacks in ActionStartEntryParser #4

skiwi2 opened this issue Feb 9, 2015 · 0 comments

Comments

@skiwi2
Copy link
Owner

skiwi2 commented Feb 9, 2015

In the parse method in the ActionStartEntryParser class there currently is this block of code:

        //TODO clean this up
        Set<EntryParser> innerEntryParsers;
        try {
            innerEntryParsers = entryParsers.stream()
                .map(Object::getClass)
                .map(clazz -> {
                    try {
                        if (restrictIndentation) {
                            if (clazz.equals(ActionStartEntryParser.class)) {
                                Method method = clazz.getDeclaredMethod("createForIndentation", int.class, Set.class);
                                return (EntryParser)method.invoke(null, indentation + 4, entryParsers);
                            }
                            Method method = clazz.getDeclaredMethod("createForIndentation", int.class);
                            return (EntryParser)method.invoke(null, indentation + 4);
                        }
                        if (clazz.equals(ActionStartEntryParser.class)) {
                            Method method = clazz.getDeclaredMethod("create", Set.class);
                            return (EntryParser)method.invoke(null, entryParsers);
                        }
                        Method method = clazz.getDeclaredMethod("create");
                        return (EntryParser)method.invoke(null);
                    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
                        throw new RuntimeException(ex);
                    }
                })
                .collect(Collectors.toSet());
        } catch (RuntimeException ex) {
            throw new NotParsableException(ex);
        }

The goal is to instantiate the supplied set of entry parsers with the correct indentation level.

The best solution may be to use a factory pattern and supply the factories instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant