Skip to content

Commit

Permalink
[NETBEANS-5832] Fixing compilation of static initializer for vanilla …
Browse files Browse the repository at this point in the history
…indexing.
  • Loading branch information
jlahoda committed Jul 15, 2021
1 parent aae2033 commit e871c23
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public Void visitClass(ClassTree node, Void p) {
csym.members_field.remove(member);
}
}
if (errorClass || def.hasTag(JCTree.Tag.ERRONEOUS) || def.hasTag(JCTree.Tag.BLOCK)) {
if (errorClass || def.hasTag(JCTree.Tag.ERRONEOUS)) {
clazz.defs = com.sun.tools.javac.util.List.filter(clazz.defs, def);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,51 @@ public void testSuperCall() throws Exception {
assertEquals(expected, file2Fixed);
}

public void testStaticInit() throws Exception {
Map<String, String> file2Fixed = new HashMap<>();
VanillaCompileWorker.fixedListener = (file, cut) -> {
try {
FileObject source = URLMapper.findFileObject(file.toUri().toURL());
file2Fixed.put(FileUtil.getRelativePath(getRoot(), source), cut.toString());
} catch (MalformedURLException ex) {
throw new IllegalStateException(ex);
}
};
ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java",
"package test;\n" +
"public class Test {\n" +
" static {\n" +
" System.err.println();\n" +
" }\n" +
"}\n")),
Arrays.asList());

assertFalse(result.lowMemory);
assertTrue(result.success);

Set<String> createdFiles = new HashSet<String>();

for (File created : result.createdFiles) {
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
}

assertEquals(new HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test.sig")),
createdFiles);
Map<String, String> expected = Collections.singletonMap("test/Test.java",
"package test;\n" +
"\n" +
"public class Test {\n" +
" \n" +
" public Test() {\n" +
" super();\n" +
" }\n" +
" static {\n" +
" System.err.println();\n" +
" }\n" +
"}");
assertEquals(expected, file2Fixed);
}

public static void noop() {}

@Override
Expand Down

0 comments on commit e871c23

Please sign in to comment.