/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.plugins.groovy.lang.resolve;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;

import java.util.Collection;
import java.util.List;

/**
 * @author Max Medvedev
 */
public abstract class AstTransformContributor {
  private static final ExtensionPointName<AstTransformContributor> EP_NAME = ExtensionPointName.create("org.intellij.groovy.astTransformContributor");

  public abstract void getMethods(@NotNull final GrTypeDefinition clazz, Collection<PsiMethod> collector);


  public static Collection<PsiMethod> runContributors(@NotNull final GrTypeDefinition clazz, List<PsiMethod> collector) {
    for (final AstTransformContributor contributor : EP_NAME.getExtensions()) {
      contributor.getMethods(clazz, collector);
    }
    return collector;
  }
}

@@ -915,19 +915,67 @@
 va.util.
-Lis
+HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0A/**%0A
@@ -1310,16 +1310,130 @@
 ctor);%0A%0A
+  private static final ThreadLocal%3CSet%3CGrTypeDefinition%3E%3E IN_PROGRESS = new ThreadLocal%3CSet%3CGrTypeDefinition%3E%3E();%0A
 %0A  publi
@@ -1543,24 +1543,280 @@
 ollector) %7B%0A
+    Set%3CGrTypeDefinition%3E inProgress = IN_PROGRESS.get();%0A    if (inProgress == null) %7B%0A      inProgress = new HashSet%3CGrTypeDefinition%3E();%0A      IN_PROGRESS.set(inProgress);%0A    %7D%0A%0A    boolean added = inProgress.add(clazz);%0A    assert added;%0A%0A    try %7B%0A  
     for (fin
@@ -1889,16 +1889,18 @@
 %7B%0A      
+  
 contribu
@@ -1937,17 +1937,244 @@
 r);%0A    
+ 
-%7D
+ %7D%0A    %7D%0A    finally %7B%0A      inProgress.remove(clazz);%0A      //if (inProgress.isEmpty()) %7B%0A      //  IN_PROGRESS.remove();       Don't remove empty set, ThreadLocal automatically removes value when thread stop.%0A      //%7D%0A    %7D%0A
 %0A    ret

Add assertion for recursive call of AstTransformContributor.runContributors()