IDEADEV-619

This commit is contained in:
Alexey Kudravtsev
2005-03-21 19:47:57 +03:00
parent 79f8671bae
commit 2ad1023a50
2 changed files with 43 additions and 62 deletions
@@ -56,10 +56,7 @@ public abstract class GenericsHighlightUtil {
HighlightUtil.formatType(extendsType),
HighlightUtil.formatType(substituted)
});
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
call,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, call, description);
}
}
}
@@ -223,10 +220,7 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("''{0}'' cannot be inherited with different type arguments: ''{1}'' and ''{2}''",
new Object[]{HighlightUtil.formatClass(superClass), HighlightUtil.formatType(type1),
HighlightUtil.formatType(type2)});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
textRange,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, description);
}
}
}
@@ -297,10 +291,7 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("{0}; both methods have same erasure, yet neither overrides the other",
new Object[]{HighlightMethodUtil.createClashMethodMessage(method1, method2, true)});
TextRange textRange = HighlightUtil.getMethodDeclarationTextRange(method);
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
textRange,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, description);
}
}
}
@@ -320,10 +311,7 @@ public abstract class GenericsHighlightUtil {
final PsiTypeParameter typeParameter = (PsiTypeParameter)result.getElement();
String description = MessageFormat.format("Type parameter ''{0}'' cannot be instantiated directly",
new Object[]{HighlightUtil.formatClass(typeParameter)});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
classReference,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, classReference, description);
}
return null;
}
@@ -344,10 +332,7 @@ public abstract class GenericsHighlightUtil {
PsiNewExpression newExpression = (PsiNewExpression)refParent;
if (!(newExpression.getType() instanceof PsiArrayType)) {
String description = MessageFormat.format("Wildcard type ''{0}'' cannot be instantiated directly", new Object[]{HighlightUtil.formatType(type)});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
typeElement,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeElement, description);
}
}
else if (refParent instanceof PsiReferenceList) {
@@ -381,10 +366,7 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("Type argument cannot be of primitive type",
ArrayUtil.EMPTY_OBJECT_ARRAY);
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
typeElement,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, typeElement, description);
}
return null;
@@ -399,7 +381,7 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("Unchecked assignment: ''{0}'' to ''{1}''",
new Object[]{HighlightUtil.formatType(rType), HighlightUtil.formatType(lType)});
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(elementToHighlight.getProject()));
final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(elementToHighlight.getProject());
if (iManager.inspectionResultSuppressed(elementToHighlight, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING,
elementToHighlight,
@@ -417,8 +399,7 @@ public abstract class GenericsHighlightUtil {
if (!(lType instanceof PsiClassType) || !(rType instanceof PsiClassType)) return false;
if (!((PsiClassType)rType).isRaw()) return false;
final PsiClassType lClassType = (PsiClassType)lType;
if (!lClassType.hasNonTrivialParameters()) return false;
return true;
return lClassType.hasNonTrivialParameters();
}
public static HighlightInfo checkUncheckedTypeCast(PsiTypeCastExpression typeCast) {
@@ -434,7 +415,7 @@ public abstract class GenericsHighlightUtil {
String description = MessageFormat.format("Unchecked cast: ''{0}'' to ''{1}''",
new Object[]{HighlightUtil.formatType(exprType), HighlightUtil.formatType(castType)});
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(expression.getProject()));
final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(expression.getProject());
if (iManager.inspectionResultSuppressed(expression, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING,
@@ -550,7 +531,7 @@ public abstract class GenericsHighlightUtil {
new Object[]{HighlightUtil.formatMethod(method), HighlightUtil.formatType(type)});
PsiElement element = call instanceof PsiMethodCallExpression ? (PsiElement)((PsiMethodCallExpression)call).getMethodExpression() : call;
if (DaemonCodeAnalyzerSettings.getInstance().getInspectionProfile().isToolEnabled(HighlightDisplayKey.UNCHECKED_WARNING)){
final InspectionManagerEx iManager = ((InspectionManagerEx)InspectionManager.getInstance(call.getProject()));
final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(call.getProject());
if (iManager.inspectionResultSuppressed(call, HighlightDisplayKey.UNCHECKED_WARNING.toString())) return null;
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.UNCHECKED_WARNING, element, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(element.getContainingFile()));
@@ -632,10 +613,7 @@ public abstract class GenericsHighlightUtil {
new Object[]{
HighlightMessageUtil.getSymbolName(resolved, result.getSubstitutor())
});
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
expr,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expr, description);
}
public static HighlightInfo checkEnumInstantiation(PsiNewExpression expression) {
@@ -644,10 +622,7 @@ public abstract class GenericsHighlightUtil {
final PsiClass aClass = ((PsiClassType)type).resolve();
if (aClass != null && aClass.isEnum()) {
String description = "Enum types cannot be instantiated";
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
expression,
description);
return highlightInfo;
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, description);
}
}
return null;
@@ -780,14 +755,15 @@ public abstract class GenericsHighlightUtil {
return null;
}
static HighlightInfo checkEnumConstantForConstructorProblems(PsiEnumConstant enumConstant,
DaemonCodeAnalyzerSettings settings) {
static HighlightInfo checkEnumConstantForConstructorProblems(PsiEnumConstant enumConstant, DaemonCodeAnalyzerSettings settings) {
PsiClass containingClass = enumConstant.getContainingClass();
PsiClassType type = enumConstant.getManager().getElementFactory().createType(containingClass);
if (enumConstant.getInitializingClass() == null) {
HighlightInfo highlightInfo = HighlightClassUtil.checkInstantiationOfAbstractClass(containingClass, enumConstant.getNameIdentifier());
if (highlightInfo != null) return highlightInfo;
highlightInfo = HighlightClassUtil.checkClassWithAbstractMethods(enumConstant.getContainingClass(), enumConstant.getNameIdentifier());
if (highlightInfo != null) return highlightInfo;
}
PsiClassType type = enumConstant.getManager().getElementFactory().createType(containingClass);
return HighlightMethodUtil.checkConstructorCall(containingClass, enumConstant, type, settings, null);
}
@@ -36,7 +36,7 @@ public class HighlightClassUtil {
public static final String CLASS_EXPECTED = "No interface expected here";
public static final String NO_IMPLEMENTS_ALLOWED = "No implements clause allowed for interface";
private static final String STATIC_DECLARATION_IN_INNER_CLASS = "Inner classes cannot have static declarations";
public static final String CLASS_MUST_BE_ABSTRACT = "Class ''{0}'' is not abstract and does not implement abstract method ''{1}'' in ''{2}''";
private static final String CLASS_MUST_BE_ABSTRACT = "Class ''{0}'' is not abstract and does not implement abstract method ''{1}'' in ''{2}''";
public static final String DUPLICATE_CLASS = "Duplicate class: ''{0}''";
private static final String REFERENCED_FROM_STATIC_CONTEXT = "''{0}'' cannot be referenced from a static context";
@@ -58,29 +58,33 @@ public class HighlightClassUtil {
&& parent.getParent() instanceof PsiNewExpression
&& !PsiUtil.hasErrorElementChild(parent.getParent())) {
PsiAnonymousClass aClass = (PsiAnonymousClass)parent;
final MethodSignatureUtil.MethodSignatureToMethods allMethods = MethodSignatureUtil.getSameSignatureMethods(aClass);
final PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(aClass, allMethods);
if (abstractMethod != null && abstractMethod.getContainingClass() != null) {
String baseClassName = HighlightUtil.formatClass((PsiClass)parent, false);
String methodName = HighlightUtil.formatMethod(abstractMethod);
String message = MessageFormat.format(CLASS_MUST_BE_ABSTRACT,
new Object[]{
baseClassName,
methodName,
HighlightUtil.formatClass(abstractMethod.getContainingClass(), false)
});
highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR,
ref,
message);
if (ClassUtil.getAnyMethodToImplement(aClass, allMethods) != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new ImplementMethodsFix(aClass));
}
}
highlightInfo = checkClassWithAbstractMethods(aClass, ref);
}
return highlightInfo;
}
public static HighlightInfo checkClassWithAbstractMethods(final PsiClass aClass, final PsiElement highlightElement) {
final MethodSignatureUtil.MethodSignatureToMethods allMethods = MethodSignatureUtil.getSameSignatureMethods(aClass);
final PsiMethod abstractMethod = ClassUtil.getAnyAbstractMethod(aClass, allMethods);
if (abstractMethod != null && abstractMethod.getContainingClass() != null) {
String baseClassName = HighlightUtil.formatClass(aClass, false);
String methodName = HighlightUtil.formatMethod(abstractMethod);
String message = MessageFormat.format(CLASS_MUST_BE_ABSTRACT,
new Object[]{
baseClassName,
methodName,
HighlightUtil.formatClass(abstractMethod.getContainingClass(), false)
});
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, highlightElement, message);
if (ClassUtil.getAnyMethodToImplement(aClass, allMethods) != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, new ImplementMethodsFix(aClass));
}
return highlightInfo;
}
return null;
}
//@top
public static HighlightInfo checkInstantiationOfAbstractClass(PsiClass aClass, PsiElement highlighElement) {
HighlightInfo errorResult = null;
@@ -98,8 +102,9 @@ public class HighlightClassUtil {
//@top
static HighlightInfo checkClassMustBeAbstract(PsiClass aClass) {
if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) || aClass.getRBrace() == null ||
(aClass.isEnum() && hasEnumConstants(aClass))) {
if (aClass.hasModifierProperty(PsiModifier.ABSTRACT) || aClass.getRBrace() == null
|| (aClass.isEnum() && hasEnumConstants(aClass))
) {
return null;
}
HighlightInfo errorResult = null;