@Test public void nullsInJava12SyntaxFile() throws Exception { Assert.assertThat( new JavaSourceFile( "public class Test {\n", " enum Day {\n", " MON, TUE, WED, THUR, FRI, SAT, SUN\n", " };\n", " @SuppressWarnings(\"preview\")\n", " public String getDay_1 (Day today) {\n", " String day = switch(today) {\n", " case MON, TUE, WED, THUR, FRI -> \"Weekday\";\n", " case SAT, SUN -> \"Weekend\";\n", " };\n", " return day;\n", " }\n", "}" ).nulls().asList().size(), IsEqual.equalTo(0) ); }
@Override public Nulls nulls() throws NullfreeException { try (final InputStream stream = source.execute()) { final List<Null> result = new ArrayList<>(); final ParseResult<CompilationUnit> parsed = parser.parse(stream); if (parsed.isSuccessful()) { final Optional<CompilationUnit> optionalUnit = parsed.getResult(); if (optionalUnit.isPresent()) { for (NullLiteralExpr nullLiteralExpr : optionalUnit.get().findAll(NullLiteralExpr.class)) { result.add(new JavaNull(nullLiteralExpr)); } } } else { final StringBuilder problems = new StringBuilder(); for (final Problem problem : parsed.getProblems()) { problems.append(problem.toString()); problems.append("\n"); } throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors: \n%s", descriptor, problems.toString() ) ); } return new SimpleNulls(result); } catch (final IOException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'.", descriptor ), e ); } catch (ParseProblemException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors and try again.", descriptor ), e ); } }
JavaSourceFile implements SourceFile { @Override public Nulls nulls() throws NullfreeException { try (final InputStream stream = source.execute()) { final List<Null> result = new ArrayList<>(); final ParseResult<CompilationUnit> parsed = parser.parse(stream); if (parsed.isSuccessful()) { final Optional<CompilationUnit> optionalUnit = parsed.getResult(); if (optionalUnit.isPresent()) { for (NullLiteralExpr nullLiteralExpr : optionalUnit.get().findAll(NullLiteralExpr.class)) { result.add(new JavaNull(nullLiteralExpr)); } } } else { final StringBuilder problems = new StringBuilder(); for (final Problem problem : parsed.getProblems()) { problems.append(problem.toString()); problems.append("\n"); } throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors: \n%s", descriptor, problems.toString() ) ); } return new SimpleNulls(result); } catch (final IOException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'.", descriptor ), e ); } catch (ParseProblemException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors and try again.", descriptor ), e ); } } }
JavaSourceFile implements SourceFile { @Override public Nulls nulls() throws NullfreeException { try (final InputStream stream = source.execute()) { final List<Null> result = new ArrayList<>(); final ParseResult<CompilationUnit> parsed = parser.parse(stream); if (parsed.isSuccessful()) { final Optional<CompilationUnit> optionalUnit = parsed.getResult(); if (optionalUnit.isPresent()) { for (NullLiteralExpr nullLiteralExpr : optionalUnit.get().findAll(NullLiteralExpr.class)) { result.add(new JavaNull(nullLiteralExpr)); } } } else { final StringBuilder problems = new StringBuilder(); for (final Problem problem : parsed.getProblems()) { problems.append(problem.toString()); problems.append("\n"); } throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors: \n%s", descriptor, problems.toString() ) ); } return new SimpleNulls(result); } catch (final IOException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'.", descriptor ), e ); } catch (ParseProblemException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors and try again.", descriptor ), e ); } } JavaSourceFile(final String... lines);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String... lines);  JavaSourceFile(final JavaParser parser, final String... lines);  JavaSourceFile(final String source);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String source);  JavaSourceFile(final JavaParser parser, final String source);  JavaSourceFile(final File file);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final File file);  JavaSourceFile(final JavaParser parser, final File file);  JavaSourceFile(
        final JavaParser parser,
        final Function0<InputStream, NullfreeException> source,
        final String descriptor
    ); }
JavaSourceFile implements SourceFile { @Override public Nulls nulls() throws NullfreeException { try (final InputStream stream = source.execute()) { final List<Null> result = new ArrayList<>(); final ParseResult<CompilationUnit> parsed = parser.parse(stream); if (parsed.isSuccessful()) { final Optional<CompilationUnit> optionalUnit = parsed.getResult(); if (optionalUnit.isPresent()) { for (NullLiteralExpr nullLiteralExpr : optionalUnit.get().findAll(NullLiteralExpr.class)) { result.add(new JavaNull(nullLiteralExpr)); } } } else { final StringBuilder problems = new StringBuilder(); for (final Problem problem : parsed.getProblems()) { problems.append(problem.toString()); problems.append("\n"); } throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors: \n%s", descriptor, problems.toString() ) ); } return new SimpleNulls(result); } catch (final IOException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'.", descriptor ), e ); } catch (ParseProblemException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors and try again.", descriptor ), e ); } } JavaSourceFile(final String... lines);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String... lines);  JavaSourceFile(final JavaParser parser, final String... lines);  JavaSourceFile(final String source);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String source);  JavaSourceFile(final JavaParser parser, final String source);  JavaSourceFile(final File file);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final File file);  JavaSourceFile(final JavaParser parser, final File file);  JavaSourceFile(
        final JavaParser parser,
        final Function0<InputStream, NullfreeException> source,
        final String descriptor
    ); @Override Nulls nulls(); }
JavaSourceFile implements SourceFile { @Override public Nulls nulls() throws NullfreeException { try (final InputStream stream = source.execute()) { final List<Null> result = new ArrayList<>(); final ParseResult<CompilationUnit> parsed = parser.parse(stream); if (parsed.isSuccessful()) { final Optional<CompilationUnit> optionalUnit = parsed.getResult(); if (optionalUnit.isPresent()) { for (NullLiteralExpr nullLiteralExpr : optionalUnit.get().findAll(NullLiteralExpr.class)) { result.add(new JavaNull(nullLiteralExpr)); } } } else { final StringBuilder problems = new StringBuilder(); for (final Problem problem : parsed.getProblems()) { problems.append(problem.toString()); problems.append("\n"); } throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors: \n%s", descriptor, problems.toString() ) ); } return new SimpleNulls(result); } catch (final IOException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'.", descriptor ), e ); } catch (ParseProblemException e) { throw new NullfreeException( String.format( "Can not count nulls in: '%s'. \nPlease, fix java syntax errors and try again.", descriptor ), e ); } } JavaSourceFile(final String... lines);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String... lines);  JavaSourceFile(final JavaParser parser, final String... lines);  JavaSourceFile(final String source);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final String source);  JavaSourceFile(final JavaParser parser, final String source);  JavaSourceFile(final File file);  JavaSourceFile(final ParserConfiguration.LanguageLevel level, final File file);  JavaSourceFile(final JavaParser parser, final File file);  JavaSourceFile(
        final JavaParser parser,
        final Function0<InputStream, NullfreeException> source,
        final String descriptor
    ); @Override Nulls nulls();  }