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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial inclusion of a live template #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MysterAitch
Copy link
Owner

This "live template" creates a complete boilerplate for parsing and handling String parse input.

  • While I'm not 100% on the actual content of the template and it can probably be improved (suggestions/issues/pull requests welcome!), it's a start showing it can be done! 馃憤 馃榿

  • As an aside, it highlights how much the StaticJavaParser hides from you and the logic paths/branches that are not handled/able to be handled if using it...

Here is a sample of the output (note it will auto-format based on your editor settings):

        String inputToParse = "class X {}";
        JavaParser javaParser = new JavaParser();
        ParseResult<CompilationUnit> parseResult = javaParser.parse(inputToParse);
        if (parseResult.isSuccessful()) {
            if (parseResult.getResult().isPresent()) {
                CompilationUnit compilationUnit = parseResult.getResult().get();
                // Do things with the compilation unit

            } else {
                System.out.println("Warning: Parsing was successful, but no CompilationUnit found. ");
            }
        } else {
            System.out.println("Warning: Parse was unsuccessful. Attempts to inspect/alter the AST may be possible, but may lead to unintended outputs.");
            if (parseResult.getResult().isPresent()) {
                CompilationUnit compilationUnitWithParseError = parseResult.getResult().get();
                // Do things with the compilation unit (with parse error)

            } else {
                System.out.println("Warning: Parsing was successful, but no CompilationUnit found. ");
            }
        }

Here's a screenshot showing the places where input is prompted for.

image


Here's a screenshot showing how it reacts to parsing an Expression instead of a full CompilationUnit.

Note the auto-suggested variable names update based on the previous selections.

image


Here's a screenshot showing how it reacts to using a different variable name

Note here that I manually tweak it to expr instead of expression, and further down the variable has updated to exprWithParseError.

image

@MysterAitch
Copy link
Owner Author

closes #210

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

Successfully merging this pull request may close these issues.

None yet

1 participant