Yes dear HighlightInfo may be null

This commit is contained in:
Roman Shevchenko
2012-07-06 16:50:46 +02:00
parent ee20b95762
commit 786aafde73
7 changed files with 33 additions and 27 deletions
@@ -300,6 +300,7 @@ public class HighlightMethodUtil {
return false;
}
@Nullable
static HighlightInfo checkMethodCall(PsiMethodCallExpression methodCall, PsiResolveHelper resolveHelper) {
PsiExpressionList list = methodCall.getArgumentList();
PsiReferenceExpression referenceToMethod = methodCall.getMethodExpression();
@@ -338,8 +339,10 @@ public class HighlightMethodUtil {
String toolTip = parent instanceof PsiClass && !ApplicationManager.getApplication().isUnitTestMode() ?
createMismatchedArgumentsHtmlTooltip(candidateInfo, list) : description;
highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, list, description, toolTip);
registerMethodCallIntentions(highlightInfo, methodCall, list, resolveHelper);
highlightInfo.navigationShift = +1;
if (highlightInfo != null) {
registerMethodCallIntentions(highlightInfo, methodCall, list, resolveHelper);
highlightInfo.navigationShift = +1;
}
}
else {
PsiReferenceExpression methodExpression = methodCall.getMethodExpression();
@@ -389,6 +392,7 @@ public class HighlightMethodUtil {
return isDummy;
}
@Nullable
static HighlightInfo checkAmbiguousMethodCall(final PsiReferenceExpression referenceToMethod,
JavaResolveResult[] resolveResults,
final PsiExpressionList list,
@@ -483,9 +487,10 @@ public class HighlightMethodUtil {
return candidateList.toArray(new MethodCandidateInfo[candidateList.size()]);
}
private static void registerMethodCallIntentions(HighlightInfo highlightInfo,
private static void registerMethodCallIntentions(@Nullable HighlightInfo highlightInfo,
PsiMethodCallExpression methodCall,
PsiExpressionList list, PsiResolveHelper resolveHelper) {
PsiExpressionList list,
PsiResolveHelper resolveHelper) {
TextRange fixRange = getFixRange(methodCall);
QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, new CreateMethodFromUsageFix(methodCall));
QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, new CreateAbstractMethodFromUsageFix(methodCall));
@@ -244,8 +244,9 @@ public class HighlightUtil {
*/
static void registerAccessQuickFixAction(@NotNull PsiMember refElement,
@NotNull PsiJavaCodeReferenceElement place,
@NotNull HighlightInfo errorResult,
@Nullable HighlightInfo errorResult,
final PsiElement fileResolveScope) {
if (errorResult == null) return;
PsiClass accessObjectClass = null;
PsiElement qualifier = place.getQualifier();
if (qualifier instanceof PsiExpression) {
@@ -434,16 +435,11 @@ public class HighlightUtil {
private static void registerChangeVariableTypeFixes(@NotNull PsiExpression expression,
@NotNull PsiType type,
@NotNull HighlightInfo highlightInfo) {
if (!(expression instanceof PsiReferenceExpression)){
return;
}
@Nullable HighlightInfo highlightInfo) {
if (highlightInfo == null || !(expression instanceof PsiReferenceExpression)) return;
final PsiElement element = ((PsiReferenceExpression)expression).resolve();
if (element == null || !(element instanceof PsiVariable)){
return;
}
if (element == null || !(element instanceof PsiVariable)) return;
registerChangeVariableTypeFixes((PsiVariable)element, type, highlightInfo);
}
@@ -453,7 +453,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP
public static void registerIntentions(@NotNull JavaResolveResult[] candidates,
@NotNull PsiExpressionList list,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange) {
if (candidates.length == 0) return;
PsiExpression[] expressions = list.getExpressions();
@@ -463,7 +463,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP
}
private static void registerIntention(@NotNull PsiExpression[] expressions,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange,
@NotNull JavaResolveResult candidate,
@NotNull PsiElement context) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -28,6 +28,7 @@ import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
@@ -107,8 +108,10 @@ public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction
}
}
public static void registerFixes(@NotNull final CandidateInfo[] candidates, @NotNull final PsiMethodCallExpression methodCall,
@NotNull final HighlightInfo info) {
public static void registerFixes(@NotNull final CandidateInfo[] candidates,
@NotNull final PsiMethodCallExpression methodCall,
@Nullable final HighlightInfo info) {
if (info == null) return;
final Set<PsiLiteralExpression> literals = new HashSet<PsiLiteralExpression>();
boolean exactMatch = false;
for (CandidateInfo candidate : candidates) {
@@ -122,8 +125,9 @@ public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction
}
}
private static void processLiterals(@NotNull final Set<PsiLiteralExpression> literals, @NotNull final PsiCall call,
@NotNull final HighlightInfo info) {
private static void processLiterals(@NotNull final Set<PsiLiteralExpression> literals,
@NotNull final PsiCall call,
@NotNull final HighlightInfo info) {
for (PsiLiteralExpression literal : literals) {
final ChangeStringLiteralToCharInMethodCallFix fix = new ChangeStringLiteralToCharInMethodCallFix(literal, call);
QuickFixAction.registerQuickFixAction(info, fix);
@@ -37,6 +37,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ChangeTypeArgumentsFix implements IntentionAction, HighPriorityAction {
private final PsiMethod myTargetMethod;
@@ -135,7 +136,7 @@ public class ChangeTypeArgumentsFix implements IntentionAction, HighPriorityActi
public static void registerIntentions(@NotNull JavaResolveResult[] candidates,
@NotNull PsiExpressionList list,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
PsiClass psiClass) {
if (candidates.length == 0) return;
PsiExpression[] expressions = list.getExpressions();
@@ -145,13 +146,12 @@ public class ChangeTypeArgumentsFix implements IntentionAction, HighPriorityActi
}
private static void registerIntention(@NotNull PsiExpression[] expressions,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
PsiClass psiClass,
@NotNull JavaResolveResult candidate,
@NotNull PsiElement context) {
if (!candidate.isStaticsScopeCorrect()) return;
PsiMethod method = (PsiMethod)candidate.getElement();
PsiSubstitutor substitutor = candidate.getSubstitutor();
if (method != null && context.getManager().isInProject(method)) {
final ChangeTypeArgumentsFix fix = new ChangeTypeArgumentsFix(method, psiClass, expressions, context);
QuickFixAction.registerQuickFixAction(highlightInfo, null, fix);
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: anna
@@ -82,7 +83,7 @@ public class ConvertDoubleToFloatFix implements IntentionAction {
public static void registerIntentions(@NotNull JavaResolveResult[] candidates,
@NotNull PsiExpressionList list,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange) {
if (candidates.length == 0) return;
PsiExpression[] expressions = list.getExpressions();
@@ -92,7 +93,7 @@ public class ConvertDoubleToFloatFix implements IntentionAction {
}
private static void registerIntention(@NotNull PsiExpression[] expressions,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange,
@NotNull JavaResolveResult candidate,
@NotNull PsiElement context) {
@@ -110,7 +110,7 @@ public class RemoveRedundantArgumentsFix implements IntentionAction {
public static void registerIntentions(@NotNull JavaResolveResult[] candidates,
@NotNull PsiExpressionList arguments,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange) {
for (JavaResolveResult candidate : candidates) {
registerIntention(arguments, highlightInfo, fixRange, candidate, arguments);
@@ -118,7 +118,7 @@ public class RemoveRedundantArgumentsFix implements IntentionAction {
}
private static void registerIntention(@NotNull PsiExpressionList arguments,
@NotNull HighlightInfo highlightInfo,
@Nullable HighlightInfo highlightInfo,
TextRange fixRange,
@NotNull JavaResolveResult candidate,
@NotNull PsiElement context) {