Merge branch 'dany/groovy-transformations'
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Tue, 3 May 2016 17:34:02 +0000 (20:34 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Tue, 3 May 2016 17:34:02 +0000 (20:34 +0300)
# Conflicts:
# plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java

1  2 
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java

index e539b02ea6a2b19c8b99a701445c6771147319cf,eda7273bbc7f22658e8a060c71f3999eea276878..19603ba15a965cac3037d3fc3ca8a5f524e52ce8
@@@ -96,12 -97,15 +96,12 @@@ import org.jetbrains.plugins.groovy.lan
  import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
  import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
  import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.modifiers.GrAnnotationCollector;
 -import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
  import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
  import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass;
 -import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
 -import org.jetbrains.plugins.groovy.lang.psi.util.GrTraitUtil;
 -import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
 +import org.jetbrains.plugins.groovy.lang.psi.util.*;
  import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
  import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
- import org.jetbrains.plugins.groovy.lang.resolve.ast.GrInheritConstructorContributor;
+ import org.jetbrains.plugins.groovy.lang.resolve.ast.InheritConstructorContributor;
  
  import java.util.*;
  
index cb20e0bf2a87b157a22c7152289d0a87720e359e,600e7ac1482c6d991afe6cc054202d6f1d1bd316..2cb7806cd3a2f6969f6de1a4d9858f0233553dfd
@@@ -638,28 -690,63 +691,88 @@@ public class GrClassImplUtil 
      });
    }
  
 +  @NotNull
 +  public static Map<PsiMethod, MethodSignature> getDuplicatedMethods(@NotNull PsiClass clazz) {
 +    return CachedValuesManager.getCachedValue(clazz, () -> {
 +      PsiElementFactory factory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
 +
 +      MostlySingularMultiMap<MethodSignature, PsiMethod> signatures = MostlySingularMultiMap.newMap();
 +      for (PsiMethod method : clazz.getMethods()) {
 +        MethodSignature signature = method.getSignature(factory.createRawSubstitutor(method));
 +        signatures.add(signature, method);
 +      }
 +
 +      Map<PsiMethod, MethodSignature> result = ContainerUtil.newHashMap();
 +      for (MethodSignature signature : signatures.keySet()) {
 +        if (signatures.valuesForKey(signature) > 1) {
 +          signatures.processForKey(signature, m -> {
 +            result.put(m, signature);
 +            return true;
 +          });
 +        }
 +      }
 +
 +      return CachedValueProvider.Result.create(result, clazz);
 +    });
 +  }
++
+   public static GrAccessorMethod findSetter(GrField field) {
+     return CachedValuesManager.getCachedValue(field, () -> CachedValueProvider.Result.create(
+       doGetSetter(field), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
+     ));
+   }
+   @Nullable
+   private static GrAccessorMethod doGetSetter(GrField field) {
+     PsiClass containingClass = field.getContainingClass();
+     if (containingClass == null) return null;
+     PsiMethod[] setters = containingClass.findMethodsByName(GroovyPropertyUtils.getSetterName(field.getName()), false);
+     for (PsiMethod setter : setters) {
+       if (setter instanceof GrAccessorMethod) {
+         return (GrAccessorMethod)setter;
+       }
+     }
+     return null;
+   }
+   public static GrAccessorMethod[] findGetters(GrField field) {
+     return CachedValuesManager.getCachedValue(field, () -> CachedValueProvider.Result.create(
+       doGetGetters(field), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
+     ));
+   }
+   @NotNull
+   private static GrAccessorMethod[] doGetGetters(GrField field) {
+     PsiClass containingClass = field.getContainingClass();
+     if (containingClass == null) return GrAccessorMethod.EMPTY_ARRAY;
+     GrAccessorMethod getter = null;
+     GrAccessorMethod booleanGetter = null;
+     PsiMethod[] getters = containingClass.findMethodsByName(GroovyPropertyUtils.getGetterNameNonBoolean(field.getName()), false);
+     for (PsiMethod method : getters) {
+       if (method instanceof GrAccessorMethod) {
+         getter = (GrAccessorMethod)method;
+         break;
+       }
+     }
+     PsiMethod[] booleanGetters = containingClass.findMethodsByName(GroovyPropertyUtils.getGetterNameBoolean(field.getName()), false);
+     for (PsiMethod method : booleanGetters) {
+       if (method instanceof GrAccessorMethod) {
+         booleanGetter = (GrAccessorMethod)method;
+         break;
+       }
+     }
+     if (getter != null && booleanGetter != null) {
+       return new GrAccessorMethod[]{getter, booleanGetter};
+     }
+     else if (getter != null) {
+       return new GrAccessorMethod[]{getter};
+     }
+     else {
+       return GrAccessorMethod.EMPTY_ARRAY;
+     }
+   }
  }