use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class TransformationContextImpl method doAddMethod.
private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
if (method instanceof GrLightMethodBuilder) {
((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
} else if (method instanceof LightMethodBuilder) {
((LightMethodBuilder) method).setContainingClass(myCodeClass);
}
MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
if (signatures.add(signature)) {
if (prepend) {
myMethods.addFirst(method);
} else {
myMethods.addLast(method);
}
}
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.
private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
final String name = prototype.getName();
if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
return;
final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
final PsiType returnType;
if (getter instanceof GrMethod) {
returnType = ((GrMethod) getter).getInferredReturnType();
} else if (getter instanceof GrAccessorMethod) {
returnType = ((GrAccessorMethod) getter).getInferredReturnType();
} else {
return;
}
if (!(returnType instanceof GrClosureType))
return;
final GrSignature signature = ((GrClosureType) returnType).getSignature();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
final GrClosureParameter[] params = signature.getParameters();
final PsiType[] types = prototypeSignature.getParameterTypes();
if (types.length != params.length)
continue;
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
continue NextSignature;
}
}
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
}
}
});
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForMethodSignatureOverload.
private static void checkForMethodSignatureOverload(PsiClass clazz, GrMethod prototype, GrMethod refactoredMethod, MultiMap<PsiElement, String> conflicts, boolean excludeJavaConflicts, List<MethodSignature> prototypeSignatures) {
if (excludeJavaConflicts) {
prototypeSignatures.remove(prototype.getSignature(PsiSubstitutor.EMPTY));
}
String newName = prototype.getName();
PsiMethod[] methods = clazz.findMethodsByName(newName, false);
MultiMap<MethodSignature, PsiMethod> signatures = GrClosureSignatureUtil.findRawMethodSignatures(methods, clazz);
for (MethodSignature prototypeSignature : prototypeSignatures) {
for (PsiMethod method : signatures.get(prototypeSignature)) {
if (method != refactoredMethod) {
String signaturePresentation = GroovyPresentationUtil.getSignaturePresentation(prototypeSignature);
conflicts.putValue(method, GroovyRefactoringBundle.message("method.duplicate", signaturePresentation, RefactoringUIUtil.getDescription(clazz, false)));
break;
}
}
}
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GroovyOverrideImplementExploreUtil method collectMethodsToImplement.
public static void collectMethodsToImplement(PsiClass aClass, Map<MethodSignature, PsiMethod> abstracts, Map<MethodSignature, PsiMethod> finals, Map<MethodSignature, PsiMethod> concretes, Map<MethodSignature, CandidateInfo> result) {
for (Map.Entry<MethodSignature, PsiMethod> entry : abstracts.entrySet()) {
MethodSignature signature = entry.getKey();
PsiMethod abstractOne = entry.getValue();
PsiMethod concrete = concretes.get(signature);
if (concrete == null || PsiUtil.getAccessLevel(concrete.getModifierList()) < PsiUtil.getAccessLevel(abstractOne.getModifierList()) || !abstractOne.getContainingClass().isInterface() && abstractOne.getContainingClass().isInheritor(concrete.getContainingClass(), true) || isDefaultMethod(abstractOne)) {
if (finals.get(signature) == null) {
PsiSubstitutor subst = OverrideImplementExploreUtil.correctSubstitutor(abstractOne, signature.getSubstitutor());
CandidateInfo info = new CandidateInfo(abstractOne, subst);
result.put(signature, info);
}
}
}
for (final PsiMethod method : new GroovyMethodImplementor().getMethodsToImplement(aClass)) {
MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), method.getTypeParameterList(), PsiSubstitutor.EMPTY, method.isConstructor());
CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY);
result.put(signature, info);
}
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class ClosureToSamConverter method doFindSingleAbstractMethodClass.
@Nullable
private static MethodSignature doFindSingleAbstractMethodClass(@NotNull PsiClass aClass) {
Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(aClass);
if (toImplement.size() > 1)
return null;
MethodSignature abstractSignature = toImplement.isEmpty() ? null : toImplement.iterator().next();
for (PsiMethod method : aClass.getMethods()) {
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (abstractSignature != null)
return null;
abstractSignature = method.getSignature(PsiSubstitutor.EMPTY);
}
}
return abstractSignature;
}
Aggregations