--- a/java.source/src/org/netbeans/api/java/source/TranslateIdentifier.java Thu Jun 21 09:30:48 2012 +0200 +++ a/java.source/src/org/netbeans/api/java/source/TranslateIdentifier.java Mon Jun 25 19:13:43 2012 +0200 @@ -398,6 +398,8 @@ } public Tree visitMethod(MethodTree node, Boolean p) { + if (unit != null && info.getTreeUtilities().isSynthetic(/*should not be used:*/unit, node)) return node; + BlockTree body = (BlockTree) translateTree(node.getBody()); Tree defaultValue = translateTree(node.getDefaultValue()); List parameters = translateTree(node.getParameters()); --- a/java.source/test/unit/src/org/netbeans/api/java/source/gen/FormRegressionTest.java Thu Jun 21 09:30:48 2012 +0200 +++ a/java.source/test/unit/src/org/netbeans/api/java/source/gen/FormRegressionTest.java Mon Jun 25 19:13:43 2012 +0200 @@ -217,6 +217,43 @@ System.err.println(res); assertEquals(golden, res); } + + public void testDontImportSyntheticConstructors() throws Exception { + testFile = new File(getWorkDir(), "Test.java"); + String originalCode = + "package test;\n" + + "public class Test {\n" + + " private void initComponents(java.util.ArrayList orig) {\n" + + " new java.util.ArrayList(orig) {};\n" + + " }\n" + + "}\n"; + TestUtilities.copyStringToFile(testFile, originalCode); + String golden = + "package test;\n\n" + + "import java.util.ArrayList;\n\n" + + "public class Test {\n" + + " private void initComponents(ArrayList orig) {\n" + + " new ArrayList(orig) {};\n" + + " }\n" + + "}\n"; + + JavaSource src = getJavaSource(testFile); + Task task = new Task() { + + public void run(WorkingCopy workingCopy) throws IOException { + workingCopy.toPhase(Phase.RESOLVED); + CompilationUnitTree cut = workingCopy.getCompilationUnit(); + GeneratorUtilities gu = GeneratorUtilities.get(workingCopy); + + workingCopy.rewrite(cut, gu.importFQNs(cut)); + } + + }; + src.runModificationTask(task).commit(); + String res = TestUtilities.copyFileToString(testFile); + System.err.println(res); + assertEquals(golden, res); + } String getGoldenPckg() { return "";