use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class GenericsHighlightUtil method checkTypeParametersList.
@Nullable
static HighlightInfo checkTypeParametersList(PsiTypeParameterList list, PsiTypeParameter[] parameters, @NotNull LanguageLevel level) {
final PsiElement parent = list.getParent();
if (parent instanceof PsiClass && ((PsiClass) parent).isEnum()) {
String description = JavaErrorMessages.message("generics.enum.may.not.have.type.parameters");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
}
if (PsiUtil.isAnnotationMethod(parent)) {
String description = JavaErrorMessages.message("generics.annotation.members.may.not.have.type.parameters");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
}
if (parent instanceof PsiClass && ((PsiClass) parent).isAnnotationType()) {
String description = JavaErrorMessages.message("annotation.may.not.have.type.parameters");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(list).descriptionAndTooltip(description).create();
}
for (int i = 0; i < parameters.length; i++) {
final PsiTypeParameter typeParameter1 = parameters[i];
final HighlightInfo cyclicInheritance = HighlightClassUtil.checkCyclicInheritance(typeParameter1);
if (cyclicInheritance != null)
return cyclicInheritance;
String name1 = typeParameter1.getName();
for (int j = i + 1; j < parameters.length; j++) {
final PsiTypeParameter typeParameter2 = parameters[j];
String name2 = typeParameter2.getName();
if (Comparing.strEqual(name1, name2)) {
String message = JavaErrorMessages.message("generics.duplicate.type.parameter", name1);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeParameter2).descriptionAndTooltip(message).create();
}
}
if (!level.isAtLeast(LanguageLevel.JDK_1_7)) {
for (PsiJavaCodeReferenceElement referenceElement : typeParameter1.getExtendsList().getReferenceElements()) {
final PsiElement resolve = referenceElement.resolve();
if (resolve instanceof PsiTypeParameter && ArrayUtilRt.find(parameters, resolve) > i) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(referenceElement.getTextRange()).descriptionAndTooltip("Illegal forward reference").create();
}
}
}
}
return null;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightMethodUtil method checkConstructorName.
static HighlightInfo checkConstructorName(PsiMethod method) {
String methodName = method.getName();
PsiClass aClass = method.getContainingClass();
HighlightInfo errorResult = null;
if (aClass != null) {
String className = aClass instanceof PsiAnonymousClass ? null : aClass.getName();
if (className == null || !Comparing.strEqual(methodName, className)) {
PsiElement element = method.getNameIdentifier();
String description = JavaErrorMessages.message("missing.return.type");
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
if (className != null) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createRenameElementFix(method, className));
}
}
}
return errorResult;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightMethodUtil method checkOverrideEquivalentInheritedMethods.
static HighlightInfo checkOverrideEquivalentInheritedMethods(PsiClass aClass, PsiFile containingFile, @NotNull LanguageLevel languageLevel) {
String description = null;
boolean appendImplementMethodFix = true;
final Collection<HierarchicalMethodSignature> visibleSignatures = aClass.getVisibleSignatures();
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(aClass.getProject()).getResolveHelper();
Ultimate: for (HierarchicalMethodSignature signature : visibleSignatures) {
PsiMethod method = signature.getMethod();
if (!resolveHelper.isAccessible(method, aClass, null))
continue;
List<HierarchicalMethodSignature> superSignatures = signature.getSuperSignatures();
boolean allAbstracts = method.hasModifierProperty(PsiModifier.ABSTRACT);
final PsiClass containingClass = method.getContainingClass();
//to be checked at method level
if (aClass.equals(containingClass))
continue;
if (aClass.isInterface() && !containingClass.isInterface())
continue;
HighlightInfo highlightInfo;
if (allAbstracts) {
superSignatures = new ArrayList<>(superSignatures);
superSignatures.add(0, signature);
highlightInfo = checkInterfaceInheritedMethodsReturnTypes(superSignatures, languageLevel);
} else {
highlightInfo = checkMethodIncompatibleReturnType(signature, superSignatures, false);
}
if (highlightInfo != null)
description = highlightInfo.getDescription();
if (method.hasModifierProperty(PsiModifier.STATIC)) {
for (HierarchicalMethodSignature superSignature : superSignatures) {
PsiMethod superMethod = superSignature.getMethod();
if (!superMethod.hasModifierProperty(PsiModifier.STATIC)) {
description = JavaErrorMessages.message("static.method.cannot.override.instance.method", JavaHighlightUtil.formatMethod(method), HighlightUtil.formatClass(containingClass), JavaHighlightUtil.formatMethod(superMethod), HighlightUtil.formatClass(superMethod.getContainingClass()));
appendImplementMethodFix = false;
break Ultimate;
}
}
continue;
}
if (description == null) {
highlightInfo = checkMethodIncompatibleThrows(signature, superSignatures, false, aClass);
if (highlightInfo != null)
description = highlightInfo.getDescription();
}
if (description == null) {
highlightInfo = checkMethodWeakerPrivileges(signature, superSignatures, false, containingFile);
if (highlightInfo != null)
description = highlightInfo.getDescription();
}
if (description != null)
break;
}
if (description != null) {
// show error info at the class level
TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
if (appendImplementMethodFix) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createImplementMethodsFix(aClass));
}
return highlightInfo;
}
return null;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightMethodUtil method checkMethodCanHaveBody.
@Nullable
static HighlightInfo checkMethodCanHaveBody(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
PsiClass aClass = method.getContainingClass();
boolean hasNoBody = method.getBody() == null;
boolean isInterface = aClass != null && aClass.isInterface();
boolean isExtension = method.hasModifierProperty(PsiModifier.DEFAULT);
boolean isStatic = method.hasModifierProperty(PsiModifier.STATIC);
boolean isPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
final List<IntentionAction> additionalFixes = new ArrayList<>();
String description = null;
if (hasNoBody) {
if (isExtension) {
description = JavaErrorMessages.message("extension.method.should.have.a.body");
additionalFixes.add(QUICK_FIX_FACTORY.createAddMethodBodyFix(method));
} else if (isInterface) {
if (isStatic && languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
description = "Static methods in interfaces should have a body";
} else if (isPrivate && languageLevel.isAtLeast(LanguageLevel.JDK_1_9)) {
description = "Private methods in interfaces should have a body";
}
}
} else if (isInterface) {
if (!isExtension && !isStatic && !isPrivate) {
description = JavaErrorMessages.message("interface.methods.cannot.have.body");
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.DEFAULT, true, false));
additionalFixes.add(QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.STATIC, true, false));
}
}
} else if (isExtension) {
description = JavaErrorMessages.message("extension.method.in.class");
} else if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
description = JavaErrorMessages.message("abstract.methods.cannot.have.a.body");
} else if (method.hasModifierProperty(PsiModifier.NATIVE)) {
description = JavaErrorMessages.message("native.methods.cannot.have.a.body");
}
if (description == null)
return null;
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
if (!hasNoBody) {
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createDeleteMethodBodyFix(method));
}
if (method.hasModifierProperty(PsiModifier.ABSTRACT) && !isInterface) {
QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createModifierListFix(method, PsiModifier.ABSTRACT, false, false));
}
for (IntentionAction intentionAction : additionalFixes) {
QuickFixAction.registerQuickFixAction(info, intentionAction);
}
return info;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.
the class HighlightClassUtil method checkClassWithAbstractMethods.
@Nullable
static HighlightInfo checkClassWithAbstractMethods(PsiClass aClass, PsiElement implementsFixElement, TextRange range) {
PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(aClass);
if (abstractMethod == null) {
return null;
}
final PsiClass superClass = abstractMethod.getContainingClass();
if (superClass == null) {
return null;
}
String baseClassName = HighlightUtil.formatClass(aClass, false);
String methodName = JavaHighlightUtil.formatMethod(abstractMethod);
String message = JavaErrorMessages.message(aClass instanceof PsiEnumConstantInitializer || implementsFixElement instanceof PsiEnumConstant ? "enum.constant.should.implement.method" : "class.must.be.abstract", baseClassName, methodName, HighlightUtil.formatClass(superClass, false));
HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range).descriptionAndTooltip(message).create();
final PsiMethod anyMethodToImplement = ClassUtil.getAnyMethodToImplement(aClass);
if (anyMethodToImplement != null) {
if (!anyMethodToImplement.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || JavaPsiFacade.getInstance(aClass.getProject()).arePackagesTheSame(aClass, superClass)) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createImplementMethodsFix(implementsFixElement));
} else {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(anyMethodToImplement, PsiModifier.PROTECTED, true, true));
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(anyMethodToImplement, PsiModifier.PUBLIC, true, true));
}
}
if (!(aClass instanceof PsiAnonymousClass) && HighlightUtil.getIncompatibleModifier(PsiModifier.ABSTRACT, aClass.getModifierList()) == null) {
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createModifierListFix(aClass, PsiModifier.ABSTRACT, true, false));
}
return errorResult;
}
Aggregations