use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkStaticMethodDeclarationInInnerClass.
@Nullable
private static HighlightInfo checkStaticMethodDeclarationInInnerClass(PsiKeyword keyword) {
if (getEnclosingStaticClass(keyword, PsiMethod.class) == null) {
return null;
}
PsiMethod method = (PsiMethod) keyword.getParent().getParent();
if (PsiUtilCore.hasErrorElementChild(method))
return null;
String message = JavaErrorMessages.message("static.declaration.in.inner.class");
HighlightInfo result = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(keyword).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(result, QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, false, false));
registerMakeInnerClassStatic(result, (PsiClass) keyword.getParent().getParent().getParent());
return result;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkBaseClassDefaultConstructorProblem.
static HighlightInfo checkBaseClassDefaultConstructorProblem(@NotNull PsiClass aClass, RefCountHolder refCountHolder, @NotNull PsiResolveHelper resolveHelper, @NotNull TextRange range, @NotNull PsiClassType[] handledExceptions) {
if (aClass instanceof PsiAnonymousClass)
return null;
PsiClass baseClass = aClass.getSuperClass();
if (baseClass == null)
return null;
PsiMethod[] constructors = baseClass.getConstructors();
if (constructors.length == 0)
return null;
PsiElement resolved = JavaResolveUtil.resolveImaginarySuperCallInThisPlace(aClass, aClass.getProject(), baseClass);
List<PsiMethod> constructorCandidates = (resolved != null ? Collections.singletonList((PsiMethod) resolved) : Arrays.asList(constructors)).stream().filter(constructor -> {
PsiParameter[] parameters = constructor.getParameterList().getParameters();
return (parameters.length == 0 || parameters.length == 1 && parameters[0].isVarArgs()) && resolveHelper.isAccessible(constructor, aClass, null);
}).limit(2).collect(Collectors.toList());
if (constructorCandidates.size() >= 2) {
// two ambiguous var-args-only constructors
final String m1 = PsiFormatUtil.formatMethod(constructorCandidates.get(0), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
final String m2 = PsiFormatUtil.formatMethod(constructorCandidates.get(1), PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(JavaErrorMessages.message("ambiguous.method.call", m1, m2)).create();
}
if (!constructorCandidates.isEmpty()) {
PsiMethod constructor = constructorCandidates.get(0);
String description = checkDefaultConstructorThrowsException(constructor, handledExceptions);
if (description != null) {
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createCreateConstructorMatchingSuperFix(aClass));
return info;
}
if (refCountHolder != null) {
refCountHolder.registerLocallyReferenced(constructor);
}
return null;
}
String description = JavaErrorMessages.message("no.default.constructor.available", HighlightUtil.formatClass(baseClass));
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createCreateConstructorMatchingSuperFix(aClass));
return info;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightControlFlowUtil method checkWriteToFinalInsideLambda.
private static HighlightInfo checkWriteToFinalInsideLambda(@NotNull PsiVariable variable, @NotNull PsiJavaCodeReferenceElement context) {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
if (lambdaExpression != null && !PsiTreeUtil.isAncestor(lambdaExpression, variable, true)) {
final PsiElement parent = variable.getParent();
if (parent instanceof PsiParameterList && parent.getParent() == lambdaExpression) {
return null;
}
if (!isEffectivelyFinal(variable, lambdaExpression, context)) {
String text = JavaErrorMessages.message("lambda.variable.must.be.final");
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(context).descriptionAndTooltip(text).create();
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createVariableAccessFromInnerClassFix(variable, lambdaExpression));
return highlightInfo;
}
}
return null;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightControlFlowUtil method checkFinalVariableInitializedInLoop.
@Nullable
static HighlightInfo checkFinalVariableInitializedInLoop(@NotNull PsiReferenceExpression expression, @NotNull PsiElement resolved) {
if (ControlFlowUtil.isVariableAssignedInLoop(expression, resolved)) {
String description = JavaErrorMessages.message("variable.assigned.in.loop", ((PsiVariable) resolved).getName());
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createModifierListFix((PsiVariable) resolved, PsiModifier.FINAL, false, false));
return highlightInfo;
}
return null;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightControlFlowUtil method checkVariableMustBeFinal.
@Nullable
static HighlightInfo checkVariableMustBeFinal(@NotNull PsiVariable variable, @NotNull PsiJavaCodeReferenceElement context, @NotNull LanguageLevel languageLevel) {
if (variable.hasModifierProperty(PsiModifier.FINAL))
return null;
final PsiElement innerClass = getInnerClassVariableReferencedFrom(variable, context);
if (innerClass instanceof PsiClass) {
if (variable instanceof PsiParameter) {
final PsiElement parent = variable.getParent();
if (parent instanceof PsiParameterList && parent.getParent() instanceof PsiLambdaExpression && notAccessedForWriting(variable, new LocalSearchScope(((PsiParameter) variable).getDeclarationScope()))) {
return null;
}
}
final boolean isToBeEffectivelyFinal = languageLevel.isAtLeast(LanguageLevel.JDK_1_8);
if (isToBeEffectivelyFinal && isEffectivelyFinal(variable, innerClass, context)) {
return null;
}
final String description = JavaErrorMessages.message(isToBeEffectivelyFinal ? "variable.must.be.final.or.effectively.final" : "variable.must.be.final", context.getText());
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(context).descriptionAndTooltip(description).create();
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createVariableAccessFromInnerClassFix(variable, innerClass));
return highlightInfo;
}
return checkWriteToFinalInsideLambda(variable, context);
}
Aggregations