mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved RedundantThrowsDeclaration, SillyAssignment to analysis
This commit is contained in:
+3
-1
@@ -23,6 +23,7 @@ package com.intellij.debugger.engine.evaluation.expression;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.debugger.DebuggerBundle;
|
||||
import com.intellij.debugger.SourcePosition;
|
||||
import com.intellij.debugger.engine.ContextUtil;
|
||||
@@ -1029,7 +1030,8 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder {
|
||||
|
||||
if (castType != null && operandType != null && !TypeConversionUtil.areTypesConvertible(operandType, castType)) {
|
||||
throw new EvaluateRuntimeException(
|
||||
new EvaluateException(JavaErrorMessages.message("inconvertible.type.cast", HighlightUtil.formatType(operandType), HighlightUtil.formatType(castType)))
|
||||
new EvaluateException(JavaErrorMessages.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil
|
||||
.formatType(castType)))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<orderEntry type="module" module-name="java-psi-impl" exported="" />
|
||||
<orderEntry type="module" module-name="projectModel-impl" exported="" />
|
||||
<orderEntry type="module" module-name="java-analysis-api" exported="" />
|
||||
<orderEntry type="module" module-name="resources-en" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JavaHighlightUtil {
|
||||
public static boolean isSerializable(@NotNull PsiClass aClass) {
|
||||
PsiManager manager = aClass.getManager();
|
||||
PsiClass serializableClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.io.Serializable", aClass.getResolveScope());
|
||||
return serializableClass != null && aClass.isInheritor(serializableClass, true);
|
||||
}
|
||||
|
||||
public static boolean isSerializationRelatedMethod(PsiMethod method, PsiClass containingClass) {
|
||||
if (containingClass == null || method.isConstructor()) return false;
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
@NonNls String name = method.getName();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiType returnType = method.getReturnType();
|
||||
if ("readObjectNoData".equals(name)) {
|
||||
return parameters.length == 0 && TypeConversionUtil.isVoidType(returnType) && isSerializable(containingClass);
|
||||
}
|
||||
if ("readObject".equals(name)) {
|
||||
return parameters.length == 1
|
||||
&& parameters[0].getType().equalsToText("java.io.ObjectInputStream")
|
||||
&& TypeConversionUtil.isVoidType(returnType) && method.hasModifierProperty(PsiModifier.PRIVATE)
|
||||
&& isSerializable(containingClass);
|
||||
}
|
||||
if ("readResolve".equals(name)) {
|
||||
return parameters.length == 0
|
||||
&& returnType != null
|
||||
&& returnType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)
|
||||
&& (containingClass.hasModifierProperty(PsiModifier.ABSTRACT) || isSerializable(containingClass));
|
||||
}
|
||||
if ("writeReplace".equals(name)) {
|
||||
return parameters.length == 0
|
||||
&& returnType != null
|
||||
&& returnType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)
|
||||
&& (containingClass.hasModifierProperty(PsiModifier.ABSTRACT) || isSerializable(containingClass));
|
||||
}
|
||||
if ("writeObject".equals(name)) {
|
||||
return parameters.length == 1
|
||||
&& TypeConversionUtil.isVoidType(returnType)
|
||||
&& parameters[0].getType().equalsToText("java.io.ObjectOutputStream")
|
||||
&& method.hasModifierProperty(PsiModifier.PRIVATE)
|
||||
&& isSerializable(containingClass);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatType(@Nullable PsiType type) {
|
||||
if (type == null) return PsiKeyword.NULL;
|
||||
String text = type.getInternalCanonicalText();
|
||||
return text == null ? PsiKeyword.NULL : text;
|
||||
}
|
||||
}
|
||||
+5
-10
@@ -17,10 +17,9 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.openapi.command.undo.UndoUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -28,9 +27,8 @@ import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MethodThrowsFix extends LocalQuickFixAndIntentionActionOnPsiElement {
|
||||
public class MethodThrowsFix extends LocalQuickFixOnPsiElement {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.MethodThrowsFix");
|
||||
|
||||
private final String myThrowsCanonicalText;
|
||||
@@ -73,11 +71,7 @@ public class MethodThrowsFix extends LocalQuickFixAndIntentionActionOnPsiElement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable("is null when called from inspection") Editor editor,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
|
||||
final PsiMethod myMethod = (PsiMethod)startElement;
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(myMethod.getContainingFile())) return;
|
||||
PsiJavaCodeReferenceElement[] referenceElements = myMethod.getThrowsList().getReferenceElements();
|
||||
@@ -100,7 +94,8 @@ public class MethodThrowsFix extends LocalQuickFixAndIntentionActionOnPsiElement
|
||||
myMethod.getThrowsList().add(ref);
|
||||
}
|
||||
UndoUtil.markPsiFileForUndo(file);
|
||||
} catch (IncorrectOperationException e) {
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -51,8 +51,8 @@ public class DeleteThrowsFix implements LocalQuickFix {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
if (element == null) return;
|
||||
final PsiFile psiFile = element.getContainingFile();
|
||||
if (myQuickFix.isAvailable(project, null, psiFile)) {
|
||||
myQuickFix.invoke(project, null, psiFile);
|
||||
if (myQuickFix.isAvailable(project, psiFile, element, element)) {
|
||||
myQuickFix.invoke(project, psiFile, element, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.sillyAssignment;
|
||||
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -31,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* User: anna
|
||||
* Date: 15-Nov-2005
|
||||
*/
|
||||
public class SillyAssignmentInspection extends BaseJavaLocalInspectionTool {
|
||||
public class SillyAssignmentInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getGroupDisplayName() {
|
||||
@@ -164,7 +161,8 @@ public class SillyAssignmentInspection extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
}
|
||||
return thisQualifier;
|
||||
} else if (qualifier != null) {
|
||||
}
|
||||
if (qualifier != null) {
|
||||
return ((PsiSuperExpression)qualifier).getQualifier();
|
||||
}
|
||||
return null;
|
||||
@@ -22,10 +22,7 @@ import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMessageUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.*;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInsight.intention.EmptyIntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -497,7 +494,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
myUnusedSymbolInspection.REPORT_PARAMETER_FOR_PUBLIC_METHODS &&
|
||||
!isOverriddenOrOverrides(method)) &&
|
||||
!method.hasModifierProperty(PsiModifier.NATIVE) &&
|
||||
!HighlightMethodUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
!JavaHighlightUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
!PsiClassImplUtil.isMainOrPremainMethod(method)) {
|
||||
if (UnusedSymbolLocalInspection.isInjected(method)) return null;
|
||||
HighlightInfo highlightInfo = checkUnusedParameter(parameter, identifier, progress);
|
||||
@@ -581,7 +578,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
|
||||
|
||||
boolean aPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
if (HighlightMethodUtil.isSerializationRelatedMethod(method, containingClass)) return true;
|
||||
if (JavaHighlightUtil.isSerializationRelatedMethod(method, containingClass)) return true;
|
||||
if (aPrivate) {
|
||||
if (isIntentionalPrivateConstructor(method, containingClass)) {
|
||||
return true;
|
||||
|
||||
+5
-4
@@ -133,12 +133,12 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
String description = JavaErrorMessages.message("annotation.incompatible.types",
|
||||
formatReference(nameRef), HighlightUtil.formatType(expectedType));
|
||||
formatReference(nameRef), JavaHighlightUtil.formatType(expectedType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
|
||||
}
|
||||
if (value instanceof PsiArrayInitializerMemberValue) {
|
||||
if (expectedType instanceof PsiArrayType) return null;
|
||||
String description = JavaErrorMessages.message("annotation.illegal.array.initializer", HighlightUtil.formatType(expectedType));
|
||||
String description = JavaErrorMessages.message("annotation.illegal.array.initializer", JavaHighlightUtil.formatType(expectedType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
|
||||
}
|
||||
if (value instanceof PsiExpression) {
|
||||
@@ -151,7 +151,7 @@ public class AnnotationsHighlightUtil {
|
||||
}
|
||||
|
||||
String description = JavaErrorMessages.message("annotation.incompatible.types",
|
||||
HighlightUtil.formatType(type), HighlightUtil.formatType(expectedType));
|
||||
JavaHighlightUtil.formatType(type), JavaHighlightUtil.formatType(expectedType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(value).descriptionAndTooltip(description).create();
|
||||
}
|
||||
|
||||
@@ -599,7 +599,8 @@ public class AnnotationsHighlightUtil {
|
||||
if (methods.length == 1) {
|
||||
PsiType expected = new PsiImmediateClassType((PsiClass)target, PsiSubstitutor.EMPTY).createArrayType();
|
||||
if (!expected.equals(methods[0].getReturnType())) {
|
||||
return JavaErrorMessages.message("annotation.container.bad.type", container.getQualifiedName(), HighlightUtil.formatType(expected));
|
||||
return JavaErrorMessages.message("annotation.container.bad.type", container.getQualifiedName(), JavaHighlightUtil
|
||||
.formatType(expected));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-17
@@ -96,8 +96,8 @@ public class GenericsHighlightUtil {
|
||||
String description = JavaErrorMessages.message(
|
||||
messageKey,
|
||||
HighlightUtil.formatClass(typeParameter),
|
||||
HighlightUtil.formatType(extendsType),
|
||||
HighlightUtil.formatType(substituted)
|
||||
JavaHighlightUtil.formatType(extendsType),
|
||||
JavaHighlightUtil.formatType(substituted)
|
||||
);
|
||||
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(call).descriptionAndTooltip(description).create();
|
||||
@@ -273,7 +273,7 @@ public class GenericsHighlightUtil {
|
||||
|
||||
String description = JavaErrorMessages.message(messageKey,
|
||||
referenceClass != null ? HighlightUtil.formatClass(referenceClass) : type.getPresentableText(),
|
||||
HighlightUtil.formatType(bound));
|
||||
JavaHighlightUtil.formatType(bound));
|
||||
|
||||
final HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement2Highlight).descriptionAndTooltip(description).create();
|
||||
@@ -447,8 +447,8 @@ public class GenericsHighlightUtil {
|
||||
if (!Comparing.equal(type1, type2)) {
|
||||
String description = JavaErrorMessages.message("generics.cannot.be.inherited.with.different.type.arguments",
|
||||
HighlightUtil.formatClass(superClass),
|
||||
HighlightUtil.formatType(type1),
|
||||
HighlightUtil.formatType(type2));
|
||||
JavaHighlightUtil.formatType(type1),
|
||||
JavaHighlightUtil.formatType(type2));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
}
|
||||
}
|
||||
@@ -532,9 +532,9 @@ public class GenericsHighlightUtil {
|
||||
MethodSignatureBackedByPsiMethod sameErasure = sameErasureMethods.get(signatureToErase);
|
||||
HighlightInfo info;
|
||||
if (sameErasure != null) {
|
||||
if (aClass instanceof PsiTypeParameter ||
|
||||
if (aClass instanceof PsiTypeParameter ||
|
||||
MethodSignatureUtil.findMethodBySuperMethod(aClass, sameErasure.getMethod(), false) != null ||
|
||||
!(InheritanceUtil.isInheritorOrSelf(sameErasure.getMethod().getContainingClass(), method.getContainingClass(), true) ||
|
||||
!(InheritanceUtil.isInheritorOrSelf(sameErasure.getMethod().getContainingClass(), method.getContainingClass(), true) ||
|
||||
InheritanceUtil.isInheritorOrSelf(method.getContainingClass(), sameErasure.getMethod().getContainingClass(), true))) {
|
||||
info = checkSameErasureNotSubSignatureOrSameClass(sameErasure, signature, aClass, method);
|
||||
if (info != null) return info;
|
||||
@@ -659,7 +659,7 @@ public class GenericsHighlightUtil {
|
||||
if (refParent instanceof PsiNewExpression) {
|
||||
PsiNewExpression newExpression = (PsiNewExpression)refParent;
|
||||
if (!(newExpression.getType() instanceof PsiArrayType)) {
|
||||
String description = JavaErrorMessages.message("wildcard.type.cannot.be.instantiated", HighlightUtil.formatType(type));
|
||||
String description = JavaErrorMessages.message("wildcard.type.cannot.be.instantiated", JavaHighlightUtil.formatType(type));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
|
||||
}
|
||||
}
|
||||
@@ -700,7 +700,7 @@ public class GenericsHighlightUtil {
|
||||
if (toConvert instanceof PsiPrimitiveType) {
|
||||
final PsiClassType boxedType = ((PsiPrimitiveType)toConvert).getBoxedType(typeElement);
|
||||
if (boxedType != null) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo,
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo,
|
||||
new ReplacePrimitiveWithBoxedTypeAction(typeElement, toConvert.getPresentableText(), ((PsiPrimitiveType)toConvert).getBoxedTypeName()));
|
||||
}
|
||||
}
|
||||
@@ -835,7 +835,7 @@ public class GenericsHighlightUtil {
|
||||
final PsiType itemType = getCollectionItemType(expression);
|
||||
if (itemType == null) {
|
||||
String description = JavaErrorMessages.message("foreach.not.applicable",
|
||||
HighlightUtil.formatType(expression.getType()));
|
||||
JavaHighlightUtil.formatType(expression.getType()));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
|
||||
}
|
||||
final int start = parameter.getTextRange().getStartOffset();
|
||||
@@ -1058,10 +1058,10 @@ public class GenericsHighlightUtil {
|
||||
|
||||
if (resolved instanceof PsiClass) {
|
||||
final PsiClass containingClass = ((PsiClass)resolved).getContainingClass();
|
||||
if (containingClass != null &&
|
||||
ref.getQualifier() == null &&
|
||||
containingClass.getTypeParameters().length > 0 &&
|
||||
!((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC) &&
|
||||
if (containingClass != null &&
|
||||
ref.getQualifier() == null &&
|
||||
containingClass.getTypeParameters().length > 0 &&
|
||||
!((PsiClass)resolved).hasModifierProperty(PsiModifier.STATIC) &&
|
||||
((PsiClass)resolved).getTypeParameters().length == 0) {
|
||||
String description = JavaErrorMessages.message("illegal.generic.type.for.instanceof");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
|
||||
@@ -1407,7 +1407,7 @@ public class GenericsHighlightUtil {
|
||||
if ((parent instanceof PsiCallExpression || parent instanceof PsiMethodReferenceExpression) && PsiUtil.isLanguageLevel7OrHigher(parent)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (element instanceof PsiMethod) {
|
||||
if (((PsiMethod)element).findSuperMethods().length > 0) return null;
|
||||
if (qualifier instanceof PsiReferenceExpression){
|
||||
@@ -1520,8 +1520,8 @@ public class GenericsHighlightUtil {
|
||||
if (qualifier instanceof PsiJavaCodeReferenceElement) {
|
||||
if (((PsiJavaCodeReferenceElement)qualifier).getTypeParameters().length > 0) {
|
||||
final PsiElement resolve = ((PsiJavaCodeReferenceElement)parent).resolve();
|
||||
if (resolve instanceof PsiTypeParameterListOwner
|
||||
&& ((PsiTypeParameterListOwner)resolve).hasTypeParameters()
|
||||
if (resolve instanceof PsiTypeParameterListOwner
|
||||
&& ((PsiTypeParameterListOwner)resolve).hasTypeParameters()
|
||||
&& !((PsiTypeParameterListOwner)resolve).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parent).descriptionAndTooltip(
|
||||
"Improper formed type; some type parameters are missing").create();
|
||||
|
||||
+10
-46
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.daemon.impl.RefCountHolder;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.*;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElementAsIntentionAdapter;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -265,7 +266,7 @@ public class HighlightMethodUtil {
|
||||
PsiClassType exception = checkedExceptions.get(index);
|
||||
String description = JavaErrorMessages.message("overridden.method.does.not.throw",
|
||||
createClashMethodMessage(method, superMethod, true),
|
||||
HighlightUtil.formatType(exception));
|
||||
JavaHighlightUtil.formatType(exception));
|
||||
TextRange textRange;
|
||||
if (includeRealPositionInfo) {
|
||||
PsiElement exceptionContext = exceptionContexts.get(index);
|
||||
@@ -275,8 +276,8 @@ public class HighlightMethodUtil {
|
||||
textRange = TextRange.EMPTY_RANGE;
|
||||
}
|
||||
HighlightInfo errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, false, false));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, QUICK_FIX_FACTORY.createMethodThrowsFix(superMethod, exception, true, true));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new LocalQuickFixOnPsiElementAsIntentionAdapter(QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, false, false)));
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new LocalQuickFixOnPsiElementAsIntentionAdapter(QUICK_FIX_FACTORY.createMethodThrowsFix(superMethod, exception, true, true)));
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
@@ -683,7 +684,7 @@ public class HighlightMethodUtil {
|
||||
if (parameter != null) {
|
||||
PsiType type = substitutor.substitute(parameter.getType());
|
||||
s += "<font " + (mismatchColor == null ? "" : "color=" + mismatchColor) + ">" +
|
||||
esctrim(showShort ? type.getPresentableText() : HighlightUtil.formatType(type))
|
||||
esctrim(showShort ? type.getPresentableText() : JavaHighlightUtil.formatType(type))
|
||||
+ "</font>"
|
||||
;
|
||||
}
|
||||
@@ -694,7 +695,7 @@ public class HighlightMethodUtil {
|
||||
PsiType type = expression.getType();
|
||||
s += "<font " + (mismatchColor == null ? "" : "color='" + mismatchColor + "'") + ">" +
|
||||
esctrim(expression.getText()) + " "+
|
||||
(mismatchColor == null || type == null || type == PsiType.NULL ? "" : "("+esctrim(HighlightUtil.formatType(type))+")")
|
||||
(mismatchColor == null || type == null || type == PsiType.NULL ? "" : "("+esctrim(JavaHighlightUtil.formatType(type))+")")
|
||||
+ "</font>"
|
||||
;
|
||||
|
||||
@@ -722,7 +723,7 @@ public class HighlightMethodUtil {
|
||||
@NonNls String mismatchColor = showShort ? null : UIUtil.isUnderDarcula() ? "ff6464" : "red";
|
||||
ms += "<td> " + "<b><nobr>" + (i == 0 ? "(" : "")
|
||||
+ "<font " + (showShort ? "" : "color=" + mismatchColor) + ">" +
|
||||
XmlStringUtil.escapeString(showShort ? type.getPresentableText() : HighlightUtil.formatType(type))
|
||||
XmlStringUtil.escapeString(showShort ? type.getPresentableText() : JavaHighlightUtil.formatType(type))
|
||||
+ "</font>"
|
||||
+ (i == expressions.length - 1 ? ")" : ",") + "</nobr></b></td>";
|
||||
}
|
||||
@@ -744,7 +745,7 @@ public class HighlightMethodUtil {
|
||||
ms += "<td><b><nobr>" + (i == 0 ? "(" : "") +
|
||||
XmlStringUtil.escapeString(showShortType(i, parameters, expressions, substitutor)
|
||||
? type.getPresentableText()
|
||||
: HighlightUtil.formatType(type))
|
||||
: JavaHighlightUtil.formatType(type))
|
||||
+ (i == parameters.length - 1 ? ")" : ",") + "</nobr></b></td>";
|
||||
}
|
||||
return ms;
|
||||
@@ -1177,7 +1178,7 @@ public class HighlightMethodUtil {
|
||||
TextRange textRange = HighlightNamesUtil.getMethodDeclarationTextRange(method);
|
||||
HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
|
||||
for (PsiClassType exception : unhandled) {
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, true, false));
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new LocalQuickFixOnPsiElementAsIntentionAdapter(QUICK_FIX_FACTORY.createMethodThrowsFix(method, exception, true, false)));
|
||||
}
|
||||
return highlightInfo;
|
||||
}
|
||||
@@ -1380,43 +1381,6 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSerializationRelatedMethod(PsiMethod method, PsiClass containingClass) {
|
||||
if (containingClass == null || method.isConstructor()) return false;
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
@NonNls String name = method.getName();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiType returnType = method.getReturnType();
|
||||
if ("readObjectNoData".equals(name)) {
|
||||
return parameters.length == 0 && TypeConversionUtil.isVoidType(returnType) && HighlightUtil.isSerializable(containingClass);
|
||||
}
|
||||
if ("readObject".equals(name)) {
|
||||
return parameters.length == 1
|
||||
&& parameters[0].getType().equalsToText("java.io.ObjectInputStream")
|
||||
&& TypeConversionUtil.isVoidType(returnType) && method.hasModifierProperty(PsiModifier.PRIVATE)
|
||||
&& HighlightUtil.isSerializable(containingClass);
|
||||
}
|
||||
if ("readResolve".equals(name)) {
|
||||
return parameters.length == 0
|
||||
&& returnType != null
|
||||
&& returnType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)
|
||||
&& (containingClass.hasModifierProperty(PsiModifier.ABSTRACT) || HighlightUtil.isSerializable(containingClass));
|
||||
}
|
||||
if ("writeReplace".equals(name)) {
|
||||
return parameters.length == 0
|
||||
&& returnType != null
|
||||
&& returnType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)
|
||||
&& (containingClass.hasModifierProperty(PsiModifier.ABSTRACT) || HighlightUtil.isSerializable(containingClass));
|
||||
}
|
||||
if ("writeObject".equals(name)) {
|
||||
return parameters.length == 1
|
||||
&& TypeConversionUtil.isVoidType(returnType)
|
||||
&& parameters[0].getType().equalsToText("java.io.ObjectOutputStream")
|
||||
&& method.hasModifierProperty(PsiModifier.PRIVATE)
|
||||
&& HighlightUtil.isSerializable(containingClass);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String buildArgTypesList(PsiExpressionList list) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("(");
|
||||
@@ -1426,7 +1390,7 @@ public class HighlightMethodUtil {
|
||||
builder.append(", ");
|
||||
}
|
||||
PsiType argType = args[i].getType();
|
||||
builder.append(argType != null ? HighlightUtil.formatType(argType) : "?");
|
||||
builder.append(argType != null ? JavaHighlightUtil.formatType(argType) : "?");
|
||||
}
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
|
||||
+19
-29
@@ -280,7 +280,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (TypeConversionUtil.isPrimitiveAndNotNull(operandType)
|
||||
|| TypeConversionUtil.isPrimitiveAndNotNull(checkType)
|
||||
|| !TypeConversionUtil.areTypesConvertible(operandType, checkType)) {
|
||||
String message = JavaErrorMessages.message("inconvertible.type.cast", formatType(operandType), formatType(checkType));
|
||||
String message = JavaErrorMessages.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil
|
||||
.formatType(checkType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
|
||||
}
|
||||
return null;
|
||||
@@ -300,7 +301,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (operandType != null &&
|
||||
!TypeConversionUtil.areTypesConvertible(operandType, castType) &&
|
||||
!RedundantCastUtil.isInPolymorphicCall(expression)) {
|
||||
String message = JavaErrorMessages.message("inconvertible.type.cast", formatType(operandType), formatType(castType));
|
||||
String message = JavaErrorMessages.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil
|
||||
.formatType(castType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
|
||||
}
|
||||
|
||||
@@ -347,8 +349,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
PsiType.getJavaLangObject(assignment.getManager(), assignment.getResolveScope()).equals(lType)) {
|
||||
String operatorText = operationSign.getText().substring(0, operationSign.getText().length() - 1);
|
||||
String message = JavaErrorMessages.message("binary.operator.not.applicable", operatorText,
|
||||
formatType(lType),
|
||||
formatType(rType));
|
||||
JavaHighlightUtil.formatType(lType),
|
||||
JavaHighlightUtil.formatType(rType));
|
||||
|
||||
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(assignment).descriptionAndTooltip(message).create();
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new ChangeToAppendFix(eqOpSign, lType, assignment));
|
||||
@@ -547,7 +549,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public String fun(PsiClassType type) {
|
||||
return formatType(type);
|
||||
return JavaHighlightUtil.formatType(type);
|
||||
}
|
||||
}, ", ");
|
||||
}
|
||||
@@ -640,14 +642,6 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return PsiFormatUtil.formatVariable(field, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatType(@Nullable PsiType type) {
|
||||
if (type == null) return PsiKeyword.NULL;
|
||||
String text = type.getInternalCanonicalText();
|
||||
return text == null ? PsiKeyword.NULL : text;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static HighlightInfo checkUnhandledExceptions(@NotNull final PsiElement element, @Nullable TextRange textRange) {
|
||||
final List<PsiClassType> unhandledExceptions = ExceptionUtil.getUnhandledExceptions(element);
|
||||
@@ -1148,7 +1142,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (exceptionType.isAssignableFrom(caughtType) || caughtType.isAssignableFrom(exceptionType)) return null;
|
||||
}
|
||||
|
||||
final String description = JavaErrorMessages.message("exception.never.thrown.try", formatType(caughtType));
|
||||
final String description = JavaErrorMessages.message("exception.never.thrown.try", JavaHighlightUtil.formatType(caughtType));
|
||||
final HighlightInfo errorResult =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parameter).descriptionAndTooltip(description).create();
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new DeleteCatchFix(parameter));
|
||||
@@ -1173,7 +1167,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
}
|
||||
if (!used) {
|
||||
final String description = JavaErrorMessages.message("exception.never.thrown.try", formatType(catchType));
|
||||
final String description = JavaErrorMessages.message("exception.never.thrown.try", JavaHighlightUtil.formatType(catchType));
|
||||
final HighlightInfo highlight =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
|
||||
QuickFixAction.registerQuickFixAction(highlight, new DeleteMultiCatchFix(typeElement));
|
||||
@@ -1267,7 +1261,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (type != null) {
|
||||
if (!isValidTypeForSwitchSelector(type, PsiUtil.isLanguageLevel7OrHigher(expression))) {
|
||||
String message =
|
||||
JavaErrorMessages.message("incompatible.types", JavaErrorMessages.message("valid.switch.selector.types"), formatType(type));
|
||||
JavaErrorMessages.message("incompatible.types", JavaErrorMessages.message("valid.switch.selector.types"), JavaHighlightUtil
|
||||
.formatType(type));
|
||||
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
|
||||
QuickFixAction.registerQuickFixAction(errorResult, new ConvertSwitchToIfIntention(statement));
|
||||
if (PsiType.LONG.equals(type) || PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type)) {
|
||||
@@ -1312,8 +1307,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (!TypeConversionUtil.isBinaryOperatorApplicable(operationSign, lType, rType, false)) {
|
||||
PsiJavaToken token = expression.getTokenBeforeOperand(operand);
|
||||
String message = JavaErrorMessages.message("binary.operator.not.applicable", token.getText(),
|
||||
formatType(lType),
|
||||
formatType(rType));
|
||||
JavaHighlightUtil.formatType(lType),
|
||||
JavaHighlightUtil.formatType(rType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
|
||||
}
|
||||
lType = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, operationSign, true);
|
||||
@@ -1328,7 +1323,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
if (token != null && expression != null && !TypeConversionUtil.isUnaryOperatorApplicable(token, expression)) {
|
||||
PsiType type = expression.getType();
|
||||
if (type == null) return null;
|
||||
String message = JavaErrorMessages.message("unary.operator.not.applicable", token.getText(), formatType(type));
|
||||
String message = JavaErrorMessages.message("unary.operator.not.applicable", token.getText(), JavaHighlightUtil.formatType(type));
|
||||
|
||||
PsiElement parentExpr = token.getParent();
|
||||
HighlightInfo highlightInfo =
|
||||
@@ -1510,7 +1505,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
final PsiType arrayExpressionType = arrayExpression.getType();
|
||||
|
||||
if (arrayExpressionType != null && !(arrayExpressionType instanceof PsiArrayType)) {
|
||||
final String description = JavaErrorMessages.message("array.type.expected", formatType(arrayExpressionType));
|
||||
final String description = JavaErrorMessages.message("array.type.expected", JavaHighlightUtil.formatType(arrayExpressionType));
|
||||
final HighlightInfo info =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(arrayExpression).descriptionAndTooltip(description).create();
|
||||
QuickFixAction.registerQuickFixAction(info, new ReplaceWithListAccessFix(arrayAccessExpression));
|
||||
@@ -1606,7 +1601,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
private static HighlightInfo checkArrayInitializerCompatibleTypes(@NotNull PsiExpression initializer, final PsiType componentType) {
|
||||
PsiType initializerType = initializer.getType();
|
||||
if (initializerType == null) {
|
||||
String description = JavaErrorMessages.message("illegal.initializer", formatType(componentType));
|
||||
String description = JavaErrorMessages.message("illegal.initializer", JavaHighlightUtil.formatType(componentType));
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(initializer).descriptionAndTooltip(description).create();
|
||||
}
|
||||
PsiExpression expression = initializer instanceof PsiArrayInitializerExpression ? null : initializer;
|
||||
@@ -2333,7 +2328,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
redIfNotMatch(lRawType, assignable), requiredRow,
|
||||
redIfNotMatch(rRawType, assignable), foundRow);
|
||||
|
||||
String description = JavaErrorMessages.message("incompatible.types", formatType(lType1), formatType(rType1));
|
||||
String description = JavaErrorMessages.message("incompatible.types", JavaHighlightUtil.formatType(lType1), JavaHighlightUtil
|
||||
.formatType(rType1));
|
||||
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).description(description).escapedToolTip(toolTip).navigationShift(navigationShift).create();
|
||||
}
|
||||
@@ -2575,18 +2571,12 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSerializable(@NotNull PsiClass aClass) {
|
||||
PsiManager manager = aClass.getManager();
|
||||
PsiClass serializableClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.io.Serializable", aClass.getResolveScope());
|
||||
return serializableClass != null && aClass.isInheritor(serializableClass, true);
|
||||
}
|
||||
|
||||
public static boolean isSerializationImplicitlyUsedField(@NotNull PsiField field) {
|
||||
final String name = field.getName();
|
||||
if (!SERIAL_VERSION_UID_FIELD_NAME.equals(name) && !SERIAL_PERSISTENT_FIELDS_FIELD_NAME.equals(name)) return false;
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
PsiClass aClass = field.getContainingClass();
|
||||
return aClass == null || isSerializable(aClass);
|
||||
return aClass == null || JavaHighlightUtil.isSerializable(aClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -38,10 +38,10 @@ public class CastMethodArgumentFix extends MethodArgumentFix {
|
||||
@NotNull
|
||||
public String getText() {
|
||||
if (myArgList.getExpressions().length == 1) {
|
||||
return QuickFixBundle.message("cast.single.parameter.text", HighlightUtil.formatType(myToType));
|
||||
return QuickFixBundle.message("cast.single.parameter.text", JavaHighlightUtil.formatType(myToType));
|
||||
}
|
||||
|
||||
return QuickFixBundle.message("cast.parameter.text", myIndex + 1, HighlightUtil.formatType(myToType));
|
||||
return QuickFixBundle.message("cast.parameter.text", myIndex + 1, JavaHighlightUtil.formatType(myToType));
|
||||
}
|
||||
|
||||
private static class MyFixerActionFactory extends ArgumentFixerActionFactory {
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -34,7 +34,7 @@ public class DeleteCatchFix implements IntentionAction {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return QuickFixBundle.message("delete.catch.text", HighlightUtil.formatType(myCatchParameter.getType()));
|
||||
return QuickFixBundle.message("delete.catch.text", JavaHighlightUtil.formatType(myCatchParameter.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -39,7 +39,7 @@ public class DeleteMultiCatchFix implements IntentionAction {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return QuickFixBundle.message("delete.catch.text", HighlightUtil.formatType(myTypeElement.getType()));
|
||||
return QuickFixBundle.message("delete.catch.text", JavaHighlightUtil.formatType(myTypeElement.getType()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -41,8 +41,8 @@ public class GeneralizeCatchFix implements IntentionAction {
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return QuickFixBundle.message("generalize.catch.text",
|
||||
HighlightUtil.formatType(myCatchParameter == null ? null : myCatchParameter.getType()),
|
||||
HighlightUtil.formatType(myUnhandledException));
|
||||
JavaHighlightUtil.formatType(myCatchParameter == null ? null : myCatchParameter.getType()),
|
||||
JavaHighlightUtil.formatType(myUnhandledException));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -44,8 +44,8 @@ public class MoveCatchUpFix implements IntentionAction {
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return QuickFixBundle.message("move.catch.up.text",
|
||||
HighlightUtil.formatType(myCatchSection.getCatchType()),
|
||||
HighlightUtil.formatType(myMoveBeforeSection.getCatchType()));
|
||||
JavaHighlightUtil.formatType(myCatchSection.getCatchType()),
|
||||
JavaHighlightUtil.formatType(myMoveBeforeSection.getCatchType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -52,7 +52,7 @@ public class SuperMethodReturnFix implements IntentionAction {
|
||||
);
|
||||
return QuickFixBundle.message("fix.super.method.return.type.text",
|
||||
name,
|
||||
HighlightUtil.formatType(mySuperMethodType));
|
||||
JavaHighlightUtil.formatType(mySuperMethodType));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.daemon.quickFix.CreateFieldOrPropertyFix;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PropertyMemberType;
|
||||
import com.intellij.psi.util.ClassKind;
|
||||
@@ -77,7 +78,7 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalQuickFixAndIntentionActionOnPsiElement createMethodThrowsFix(@NotNull PsiMethod method,
|
||||
public LocalQuickFixOnPsiElement createMethodThrowsFix(@NotNull PsiMethod method,
|
||||
@NotNull PsiClassType exceptionClass,
|
||||
boolean shouldThrow,
|
||||
boolean showContainingClass) {
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ package com.intellij.codeInspection.accessStaticViaInstance;
|
||||
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMessageUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.AccessStaticViaInstanceFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.RemoveUnusedVariableFix;
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
@@ -93,7 +93,7 @@ public class AccessStaticViaInstance extends BaseJavaLocalInspectionTool {
|
||||
if (!((PsiMember)resolved).hasModifierProperty(PsiModifier.STATIC)) return;
|
||||
|
||||
String description = JavaErrorMessages.message("static.member.accessed.via.instance.reference",
|
||||
HighlightUtil.formatType(qualifierExpression.getType()),
|
||||
JavaHighlightUtil.formatType(qualifierExpression.getType()),
|
||||
HighlightMessageUtil.getSymbolName(resolved, result.getSubstitutor()));
|
||||
if (!onTheFly) {
|
||||
if (RemoveUnusedVariableFix.checkSideEffects(qualifierExpression, null, new ArrayList<PsiElement>())) {
|
||||
|
||||
+10
-8
@@ -19,6 +19,7 @@ package com.intellij.codeInspection.uncheckedWarnings;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.GenerifyFileFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.VariableArrayTypeFix;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -225,7 +226,8 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
|
||||
if (!TypeConversionUtil.areTypesConvertible(exprType, castType)) return;
|
||||
if (GenericsHighlightUtil.isUncheckedCast(castType, exprType)) {
|
||||
final String description =
|
||||
JavaErrorMessages.message("generics.unchecked.cast", HighlightUtil.formatType(exprType), HighlightUtil.formatType(castType));
|
||||
JavaErrorMessages.message("generics.unchecked.cast", JavaHighlightUtil.formatType(exprType), JavaHighlightUtil
|
||||
.formatType(castType));
|
||||
registerProblem(description, expression, myGenerifyFixes);
|
||||
}
|
||||
}
|
||||
@@ -337,8 +339,8 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
|
||||
if (!TypeConversionUtil.isAssignable(componentType, itemType)) continue;
|
||||
if (GenericsHighlightUtil.isRawToGeneric(componentType, itemType)) {
|
||||
String description = JavaErrorMessages.message("generics.unchecked.assignment",
|
||||
HighlightUtil.formatType(itemType),
|
||||
HighlightUtil.formatType(componentType));
|
||||
JavaHighlightUtil.formatType(itemType),
|
||||
JavaHighlightUtil.formatType(componentType));
|
||||
if (!arrayTypeFixChecked) {
|
||||
final PsiType checkResult = HighlightUtil.sameType(initializers);
|
||||
fix = checkResult != null ? new VariableArrayTypeFix(arrayInitializer, checkResult) : null;
|
||||
@@ -361,8 +363,8 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
|
||||
if (checkAssignability && !TypeConversionUtil.isAssignable(parameterType, itemType)) return;
|
||||
if (GenericsHighlightUtil.isRawToGeneric(parameterType, itemType)) {
|
||||
String description = JavaErrorMessages.message("generics.unchecked.assignment",
|
||||
HighlightUtil.formatType(itemType),
|
||||
HighlightUtil.formatType(parameterType));
|
||||
JavaHighlightUtil.formatType(itemType),
|
||||
JavaHighlightUtil.formatType(parameterType));
|
||||
registerProblem(description, parameter, quickFixes);
|
||||
}
|
||||
}
|
||||
@@ -386,8 +388,8 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
|
||||
if (baseReturnType == null || overriderReturnType == null) return;
|
||||
if (GenericsHighlightUtil.isRawToGeneric(baseReturnType, overriderReturnType)) {
|
||||
final String message = JavaErrorMessages.message("unchecked.overriding.incompatible.return.type",
|
||||
HighlightUtil.formatType(overriderReturnType),
|
||||
HighlightUtil.formatType(baseReturnType));
|
||||
JavaHighlightUtil.formatType(overriderReturnType),
|
||||
JavaHighlightUtil.formatType(baseReturnType));
|
||||
|
||||
final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
|
||||
LOG.assertTrue(returnTypeElement != null);
|
||||
@@ -471,7 +473,7 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
|
||||
PsiType type = elementFactory.createType(method.getContainingClass(), substitutor);
|
||||
return JavaErrorMessages.message("generics.unchecked.call.to.member.of.raw.type",
|
||||
HighlightUtil.formatMethod(method),
|
||||
HighlightUtil.formatType(type));
|
||||
JavaHighlightUtil.formatType(type));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+3
-4
@@ -18,8 +18,7 @@ package com.intellij.codeInspection.unneededThrows;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -118,9 +117,9 @@ public class RedundantThrowsDeclaration extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
if (HighlightMethodUtil.isSerializationRelatedMethod(method, containingClass)) return null;
|
||||
if (JavaHighlightUtil.isSerializationRelatedMethod(method, containingClass)) return null;
|
||||
|
||||
String description = JavaErrorMessages.message("exception.is.never.thrown", HighlightUtil.formatType(exceptionType));
|
||||
String description = JavaErrorMessages.message("exception.is.never.thrown", JavaHighlightUtil.formatType(exceptionType));
|
||||
LocalQuickFix quickFixes = new DeleteThrowsFix(method, exceptionType);
|
||||
return inspectionManager.createProblemDescriptor(referenceElement, description, quickFixes, ProblemHighlightType.LIKE_UNUSED_SYMBOL, onTheFly);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.codeInsight.intention;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PropertyMemberType;
|
||||
@@ -48,7 +49,7 @@ public abstract class QuickFixFactory {
|
||||
*/
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement createImplementMethodsFix(@NotNull PsiElement psiElement);
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement createImplementMethodsFix(@NotNull PsiClass psiElement);
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement createMethodThrowsFix(@NotNull PsiMethod method, @NotNull PsiClassType exceptionClass, boolean shouldThrow, boolean showContainingClass);
|
||||
public abstract LocalQuickFixOnPsiElement createMethodThrowsFix(@NotNull PsiMethod method, @NotNull PsiClassType exceptionClass, boolean shouldThrow, boolean showContainingClass);
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddDefaultConstructorFix(@NotNull PsiClass aClass);
|
||||
@Nullable
|
||||
public abstract LocalQuickFixAndIntentionActionOnPsiElement createAddConstructorFix(@NotNull PsiClass aClass, @PsiModifier.ModifierConstant String modifier);
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LocalQuickFixOnPsiElementAsIntentionAdapter implements IntentionAction {
|
||||
private final LocalQuickFixOnPsiElement myFix;
|
||||
|
||||
public LocalQuickFixOnPsiElementAsIntentionAdapter(@NotNull LocalQuickFixOnPsiElement fix) {
|
||||
myFix = fix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return myFix.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return myFix.getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return myFix.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
myFix.applyFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.*;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightMethodUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.SafeDeleteFix;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -212,7 +212,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
|
||||
method.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
!method.hasModifierProperty(PsiModifier.ABSTRACT) && !isOverriddenOrOverrides(method)) &&
|
||||
!method.hasModifierProperty(PsiModifier.NATIVE) &&
|
||||
!HighlightMethodUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
!JavaHighlightUtil.isSerializationRelatedMethod(method, method.getContainingClass()) &&
|
||||
!PsiClassImplUtil.isMainOrPremainMethod(method);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user