Emitter { static boolean endsWithJavadoc(CharSequence usercode) { Matcher matcher = JAVADOC_COMMENT_AND_MAYBE_ANNOTATIONS_PATTERN.matcher(usercode); return matcher.matches() && !matcher.group(1).contains("*/"); } Emitter(String outputFileName, File inputFile, LexParse parser, DFA dfa, PrintWriter writer); static File normalize(String name, File input); static String sourceFileString(File file); void emit();  }
@Test public void testJavadoc() { StringBuilder usercode = new StringBuilder(""); assertThat(!Emitter.endsWithJavadoc(usercode)).isTrue(); usercode.append("import bla; "); assertThat(Emitter.endsWithJavadoc(usercode)).isTrue(); usercode.append("bla"); assertThat(!Emitter.endsWithJavadoc(usercode)).isTrue(); usercode.setLength(usercode.length() - "bla".length()); String nonJavadocComment = "\n\n"; usercode.append(nonJavadocComment); assertThat(!Emitter.endsWithJavadoc(usercode)).isTrue(); usercode.setLength(usercode.length() - nonJavadocComment.length()); List<String> annotations = Arrays.asList( "@Deprecated", "@SuppressWarnings(\"deprecation\")", "@SomeOtherSingleArrayParamAnnotation( {\"one\", \"two and \\\"three\\\"\" })", "@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE,\n" + " java.lang.annotation.ElementType.FIELD,\n" + " java.lang.annotation.ElementType.METHOD,\n" + " java.lang.annotation.ElementType.PARAMETER,\n" + " java.lang.annotation.ElementType.CONSTRUCTOR,\n" + " java.lang.annotation.ElementType.LOCAL_VARIABLE})\n", " @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)", "@ClassPreamble (\n" + " author = \"John Doe\",\n" + " date = \"3/17/2002\",\n" + " currentRevision = 6,\n" + " lastModified = \"4/12/2004\",\n" + " lastModifiedBy = \"Jane Doe\",\n" + " reviewers = { \"Alice\", \"Bob\",\n" + " \"Cindy\"}\n" + ")", "@org.example.Custom_76\n" + " ( a_333= 5L , b___ = \n" + " 189,f=SOMETHING_ELSE, c=')', d=\"(parenthesized)\"\n" + ", e=.378e-8f, f=0x88_87,g=0b1111_0011, h=\"\" )", "@A(\"\")"); Collections.shuffle(annotations); for (String annotation : annotations) { usercode.append("\n ").append(annotation); assertWithMessage( "Problematic annotation: '" + annotation + "' in '" + usercode.toString() + "'") .that(Emitter.endsWithJavadoc(usercode)) .isTrue(); } usercode.append("\n").append(nonJavadocComment); assertThat(!Emitter.endsWithJavadoc(usercode)).isTrue(); }