@@ -560,44 +560,55 @@ private void processField(final FieldNode field, final MethodNode initializer, f
560560 }
561561
562562 private MethodNode processMethod (final ClassNode traitClass , final ClassNode traitHelperClass , final MethodNode methodNode , final ClassNode fieldHelper , final Collection <String > knownFields ) {
563- Parameter [] initialParams = methodNode .getParameters ();
564- Parameter [] newParams = new Parameter [initialParams .length + 1 ];
565- newParams [0 ] = createSelfParameter (traitClass , methodNode .isStatic ());
566- System .arraycopy (initialParams , 0 , newParams , 1 , initialParams .length );
567- final int mod = methodNode .isPrivate () ? ACC_PRIVATE : ACC_PUBLIC | (methodNode .isFinal () ? ACC_FINAL : 0 );
563+ boolean isAbstractMethod = methodNode .isAbstract ();
564+ boolean isPrivateMethod = methodNode .isPrivate ();
565+ boolean isStaticMethod = methodNode .isStatic ();
566+
567+ int modifiers = ACC_PUBLIC ;
568+ if (isAbstractMethod ) {
569+ modifiers |= ACC_ABSTRACT ;
570+ } else {
571+ // public or private
572+ if (isPrivateMethod ) {
573+ modifiers ^= ACC_PUBLIC | (!isStaticMethod ? ACC_PRIVATE : ACC_PROTECTED ); // GROOVY-7214, GROOVY-11776
574+ }
575+ // static or final (maybe)
576+ if (methodNode .isFinal () && !isStaticMethod ) {
577+ modifiers |= ACC_FINAL ;
578+ }
579+ modifiers |= ACC_STATIC ;
580+ }
581+
582+ Parameter [] methodParams = methodNode .getParameters ();
583+ Parameter [] helperParams = new Parameter [methodParams .length + 1 ];
584+ helperParams [0 ] = createSelfParameter (traitClass , isStaticMethod );
585+ System .arraycopy (methodParams , 0 , helperParams , 1 , methodParams .length );
586+
568587 MethodNode mNode = new MethodNode (
569588 methodNode .getName (),
570- mod | ACC_STATIC ,
589+ modifiers ,
571590 methodNode .getReturnType (),
572- newParams ,
591+ helperParams ,
573592 methodNode .getExceptions (),
574- processBody (varX (newParams [0 ]), methodNode .getCode (), traitClass , traitHelperClass , fieldHelper , knownFields )
593+ processBody (varX (helperParams [0 ]), methodNode .getCode (), traitClass , traitHelperClass , fieldHelper , knownFields )
575594 );
576- mNode .setSourcePosition (methodNode );
577- mNode .addAnnotations (filterAnnotations (methodNode .getAnnotations ()));
595+ for (AnnotationNode annotation : methodNode .getAnnotations ()) {
596+ if (!annotation .getClassNode ().equals (OVERRIDE_CLASSNODE )) {
597+ mNode .addAnnotation (annotation );
598+ }
599+ }
578600 mNode .setGenericsTypes (methodNode .getGenericsTypes ());
579- if ( methodNode . isAbstract ()) {
580- mNode . setModifiers ( ACC_PUBLIC | ACC_ABSTRACT );
581- } else {
601+ mNode . setSourcePosition ( methodNode );
602+
603+ if (! isAbstractMethod ) {
582604 methodNode .addAnnotation (new AnnotationNode (Traits .IMPLEMENTED_CLASSNODE ));
583605 }
584- methodNode .setCode (null );
585-
586- if (!methodNode .isPrivate () && !methodNode .isStatic ()) {
606+ if (!isPrivateMethod && !isStaticMethod ) {
587607 methodNode .setModifiers (ACC_PUBLIC | ACC_ABSTRACT );
588608 }
589- return mNode ;
590- }
591-
592- private static List <AnnotationNode > filterAnnotations (final List <AnnotationNode > annotations ) {
593- List <AnnotationNode > result = new ArrayList <>(annotations .size ());
594- for (AnnotationNode annotation : annotations ) {
595- if (!OVERRIDE_CLASSNODE .equals (annotation .getClassNode ())) {
596- result .add (annotation );
597- }
598- }
609+ methodNode .setCode (null );
599610
600- return result ;
611+ return mNode ;
601612 }
602613
603614 private static Parameter createSelfParameter (final ClassNode traitClass , boolean isStatic ) {
0 commit comments