disable introduce refactorings for expr with not inferred types

This commit is contained in:
anna
2012-10-26 18:59:46 +02:00
parent 812616c8e2
commit 337235214d
4 changed files with 7 additions and 3 deletions
@@ -103,7 +103,7 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
}
final PsiType tempType = getTypeByExpression(selectedExpr);
if (tempType == null) {
if (tempType == null || LambdaUtil.notInferredType(tempType)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("unknown.expression.type"));
CommonRefactoringUtil.showErrorHint(project, editor, message, getRefactoringName(), getHelpID());
return false;
@@ -151,7 +151,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method)) return false;
final PsiType typeByExpression = invokedOnDeclaration ? null : RefactoringUtil.getTypeByExpressionWithExpectedType(expr);
if (!invokedOnDeclaration && typeByExpression == null) {
if (!invokedOnDeclaration && (typeByExpression == null || LambdaUtil.notInferredType(typeByExpression))) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("type.of.the.selected.expression.cannot.be.determined"));
showErrorMessage(project, message, editor);
return false;
@@ -501,7 +501,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
final PsiType originalType = RefactoringUtil.getTypeByExpressionWithExpectedType(expr);
if (originalType == null) {
if (originalType == null || LambdaUtil.notInferredType(originalType)) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("unknown.expression.type"));
showErrorMessage(project, editor, message);
return false;
@@ -847,6 +847,10 @@ public class LambdaUtil {
return psiSubstitutor;
}
public static boolean notInferredType(PsiType typeByExpression) {
return typeByExpression instanceof PsiMethodReferenceType || typeByExpression instanceof PsiLambdaExpressionType || typeByExpression instanceof PsiLambdaParameterType;
}
private static class TypeParamsChecker extends PsiTypeVisitor<Boolean> {
private PsiMethod myMethod;
private final PsiClass myClass;