mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
moved PossibleHeapPollutionVarargsInspection to analysis
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.PsiUtil;
|
||||
|
||||
public class JavaGenericsUtil {
|
||||
public static boolean isReifiableType(PsiType type) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
return isReifiableType(((PsiArrayType)type).getComponentType());
|
||||
}
|
||||
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClassType classType = (PsiClassType)PsiUtil.convertAnonymousToBaseType(type);
|
||||
if (classType.isRaw()) {
|
||||
return true;
|
||||
}
|
||||
PsiType[] parameters = classType.getParameters();
|
||||
|
||||
for (PsiType parameter : parameters) {
|
||||
if (parameter instanceof PsiWildcardType && ((PsiWildcardType)parameter).getBound() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final PsiClass resolved = ((PsiClassType)PsiUtil.convertAnonymousToBaseType(classType)).resolve();
|
||||
if (resolved instanceof PsiTypeParameter) {
|
||||
return false;
|
||||
}
|
||||
if (parameters.length == 0) {
|
||||
if (resolved != null && !resolved.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiClass containingClass = resolved.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final PsiTypeParameter[] containingClassTypeParameters = containingClass.getTypeParameters();
|
||||
if (containingClassTypeParameters.length > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationFix;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationPsiFix;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* User: anna
|
||||
* Date: 1/28/11
|
||||
*/
|
||||
public class PossibleHeapPollutionVarargsInspection extends BaseJavaLocalInspectionTool {
|
||||
public class PossibleHeapPollutionVarargsInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
public static final Logger LOG = Logger.getInstance("#" + PossibleHeapPollutionVarargsInspection.class.getName());
|
||||
@Nls
|
||||
@NotNull
|
||||
@@ -110,7 +110,7 @@ public class PossibleHeapPollutionVarargsInspection extends BaseJavaLocalInspect
|
||||
if (psiElement instanceof PsiIdentifier) {
|
||||
final PsiMethod psiMethod = (PsiMethod)psiElement.getParent();
|
||||
if (psiMethod != null) {
|
||||
new AddAnnotationFix("java.lang.SafeVarargs", psiMethod).applyFix(project, descriptor);
|
||||
new AddAnnotationPsiFix("java.lang.SafeVarargs", psiMethod, PsiNameValuePair.EMPTY_ARRAY).applyFix(project, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,13 +135,12 @@ public class PossibleHeapPollutionVarargsInspection extends BaseJavaLocalInspect
|
||||
if (psiElement instanceof PsiIdentifier) {
|
||||
final PsiMethod psiMethod = (PsiMethod)psiElement.getParent();
|
||||
psiMethod.getModifierList().setModifierProperty(PsiModifier.FINAL, true);
|
||||
new AddAnnotationFix("java.lang.SafeVarargs", psiMethod).applyFix(project, descriptor);
|
||||
new AddAnnotationPsiFix("java.lang.SafeVarargs", psiMethod, PsiNameValuePair.EMPTY_ARRAY).applyFix(project, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class HeapPollutionVisitor extends JavaElementVisitor {
|
||||
|
||||
public abstract static class HeapPollutionVisitor extends JavaElementVisitor {
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
super.visitMethod(method);
|
||||
@@ -151,7 +150,7 @@ public class PossibleHeapPollutionVarargsInspection extends BaseJavaLocalInspect
|
||||
|
||||
final PsiParameter psiParameter = method.getParameterList().getParameters()[method.getParameterList().getParametersCount() - 1];
|
||||
final PsiType componentType = ((PsiEllipsisType)psiParameter.getType()).getComponentType();
|
||||
if (GenericsHighlightUtil.isReifiableType(componentType)) {
|
||||
if (JavaGenericsUtil.isReifiableType(componentType)) {
|
||||
return;
|
||||
}
|
||||
for (PsiReference reference : ReferencesSearch.search(psiParameter)) {
|
||||
@@ -952,7 +952,7 @@ public class GenericsHighlightUtil {
|
||||
@Nullable
|
||||
public static HighlightInfo checkGenericArrayCreation(PsiElement element, PsiType type) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
if (!isReifiableType(((PsiArrayType)type).getComponentType())) {
|
||||
if (!JavaGenericsUtil.isReifiableType(((PsiArrayType)type).getComponentType())) {
|
||||
String description = JavaErrorMessages.message("generic.array.creation");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(description).create();
|
||||
}
|
||||
@@ -1180,7 +1180,7 @@ public class GenericsHighlightUtil {
|
||||
LOG.assertTrue(varParameter.isVarArgs());
|
||||
final PsiEllipsisType ellipsisType = (PsiEllipsisType)varParameter.getType();
|
||||
final PsiType componentType = ellipsisType.getComponentType();
|
||||
if (isReifiableType(componentType)) {
|
||||
if (JavaGenericsUtil.isReifiableType(componentType)) {
|
||||
PsiElement element = varParameter.getTypeElement();
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.WARNING).range(element).descriptionAndTooltip(
|
||||
"@SafeVarargs is not applicable for reifiable types").create();
|
||||
@@ -1205,7 +1205,7 @@ public class GenericsHighlightUtil {
|
||||
final PsiParameter varargParameter =
|
||||
psiMethod.getParameterList().getParameters()[parametersCount - 1];
|
||||
final PsiType componentType = ((PsiEllipsisType)varargParameter.getType()).getComponentType();
|
||||
if (!isReifiableType(resolveResult.getSubstitutor().substitute(componentType))) {
|
||||
if (!JavaGenericsUtil.isReifiableType(resolveResult.getSubstitutor().substitute(componentType))) {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiCall) {
|
||||
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
|
||||
@@ -1228,7 +1228,7 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
for (int i = parametersCount - 1; i < args.length; i++) {
|
||||
if (!isReifiableType(resolveResult.getSubstitutor().substitute(args[i].getType()))) {
|
||||
if (!JavaGenericsUtil.isReifiableType(resolveResult.getSubstitutor().substitute(args[i].getType()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1242,52 +1242,6 @@ public class GenericsHighlightUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isReifiableType(PsiType type) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
return isReifiableType(((PsiArrayType)type).getComponentType());
|
||||
}
|
||||
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClassType classType = (PsiClassType)PsiUtil.convertAnonymousToBaseType(type);
|
||||
if (classType.isRaw()) {
|
||||
return true;
|
||||
}
|
||||
PsiType[] parameters = classType.getParameters();
|
||||
|
||||
for (PsiType parameter : parameters) {
|
||||
if (parameter instanceof PsiWildcardType && ((PsiWildcardType)parameter).getBound() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final PsiClass resolved = ((PsiClassType)PsiUtil.convertAnonymousToBaseType(classType)).resolve();
|
||||
if (resolved instanceof PsiTypeParameter) {
|
||||
return false;
|
||||
}
|
||||
if (parameters.length == 0) {
|
||||
if (resolved != null && !resolved.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiClass containingClass = resolved.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final PsiTypeParameter[] containingClassTypeParameters = containingClass.getTypeParameters();
|
||||
if (containingClassTypeParameters.length > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void checkEnumConstantForConstructorProblems(PsiEnumConstant enumConstant, final HighlightInfoHolder holder) {
|
||||
PsiClass containingClass = enumConstant.getContainingClass();
|
||||
if (enumConstant.getInitializingClass() == null) {
|
||||
|
||||
@@ -118,8 +118,9 @@ public class AccessStaticViaInstanceFix extends LocalQuickFixAndIntentionActionO
|
||||
if (hasSideEffects && !ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
|
||||
final Editor editor = PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext());
|
||||
if (editor == null)
|
||||
if (editor == null) {
|
||||
return false;
|
||||
}
|
||||
HighlightManager.getInstance(project).addOccurrenceHighlights(editor, PsiUtilCore.toPsiElementArray(sideEffects), attributes, true,
|
||||
null);
|
||||
try {
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
<orderEntry type="module" module-name="java-psi-impl" exported="" />
|
||||
<orderEntry type="module" module-name="indexing-api" exported="" />
|
||||
<orderEntry type="module" module-name="indexing-impl" exported="" />
|
||||
<orderEntry type="module" module-name="projectModel-api" />
|
||||
<orderEntry type="module" module-name="projectModel-api" exported="" />
|
||||
<orderEntry type="module" module-name="projectModel-impl" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user