CompilationUnit (final CompilerConfiguration config, final GroovyClassLoader classLoader, final GroovyClassLoader transformLoader, final Queue<? super Object> mailbox, final GroovyCompilerWrapper wrapper, final PrintStream out, final PrintStream err) { final JavaAwareCompilationUnit unit = new JavaAwareCompilationUnit(config, classLoader) { private boolean annoRemovedAdded; @Override public GroovyClassLoader getTransformLoader() { return transformLoader; } @Override public void addPhaseOperation(PrimaryClassNodeOperation op, int phase) { if (!annoRemovedAdded && mailbox == null && phase == Phases.CONVERSION && "true".equals(System.getProperty(GroovyRtConstants.GROOVYC_LEGACY_REMOVE_ANNOTATIONS)) && op.getClass().getName().startsWith("org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit$")) { annoRemovedAdded = true; super.addPhaseOperation(new PrimaryClassNodeOperation() { @Override public void call(final SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { final ClassCodeVisitorSupport annoRemover = new ClassCodeVisitorSupport() { @Override protected SourceUnit getSourceUnit() { return source; } @Override public void visitClass(ClassNode node) { if (node.isEnum()) { node.setModifiers(node.getModifiers() & ~Opcodes.ACC_FINAL); } super.visitClass(node); } @Override public void visitField(FieldNode fieldNode) { Expression valueExpr = fieldNode.getInitialValueExpression(); if (valueExpr instanceof ConstantExpression && ClassHelper.STRING_TYPE.equals(valueExpr.getType())) { fieldNode.setInitialValueExpression(new MethodCallExpression(valueExpr, "toString", new ListExpression())); } super.visitField(fieldNode); } @Override public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (!annotations.isEmpty()) { annotations.clear(); } super.visitAnnotations(node); } }; try { annoRemover.visitClass(classNode); } catch (LinkageError ignored) { } } @Override @SuppressWarnings("RedundantMethodOverride") public void doPhaseOperation(CompilationUnit unit) throws CompilationFailedException { super.doPhaseOperation(unit); } }, phase); } super.addPhaseOperation(op, phase); } @Override public void gotoPhase(int phase) throws CompilationFailedException { if (phase < Phases.SEMANTIC_ANALYSIS) { out.println(GroovyRtConstants.PRESENTABLE_MESSAGE + "Groovy stub generator: " + getPhaseDescription()); } else if (phase <= Phases.ALL) { out.println(GroovyRtConstants.PRESENTABLE_MESSAGE + "Groovyc: " + getPhaseDescription()); } super.gotoPhase(phase); } }; unit.setCompilerFactory(new JavaCompilerFactory() { @Override public JavaCompiler createCompiler(final CompilerConfiguration config) { return new JavaCompiler() { @Override public void compile(List<String> files, CompilationUnit cu) { if (mailbox != null) { reportCompiledItems( out, GroovyCompilerWrapper.getStubOutputItems(unit, (File)config.getJointCompilationOptions().get(STUB_DIR)) ); out.flush(); err.flush(); pauseAndWaitForJavac(mailbox); wrapper.onContinuation(); } } }; } }); unit.addSources(new String[]{"SomeClass.java"}); return unit; }