mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-149950 Bad typo in "Declaration access can be weaker" inspection
This commit is contained in:
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -40,6 +40,7 @@ import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.util.RefactoringChangeUtil;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xml.util.XmlStringUtil;
|
||||
@@ -100,9 +101,9 @@ public class HighlightMethodUtil {
|
||||
int superAccessLevel = PsiUtil.getAccessLevel(superMethod.getModifierList());
|
||||
if (accessLevel < superAccessLevel) {
|
||||
String description = JavaErrorMessages.message("weaker.privileges",
|
||||
createClashMethodMessage(method, superMethod, true),
|
||||
accessModifier,
|
||||
PsiUtil.getAccessModifier(superAccessLevel));
|
||||
createClashMethodMessage(method, superMethod, true),
|
||||
VisibilityUtil.toPresentableText(accessModifier),
|
||||
PsiUtil.getAccessModifier(superAccessLevel));
|
||||
TextRange textRange;
|
||||
if (includeRealPositionInfo) {
|
||||
if (modifierList.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
|
||||
|
||||
+6
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -32,6 +32,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.fixes.ChangeModifierFix;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
@@ -185,12 +186,14 @@ class AccessCanBeTightenedInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
log(member.getName() + " unused; ignore");
|
||||
return; // do not propose private for unused method
|
||||
}
|
||||
|
||||
int max = maxLevel.get();
|
||||
if (max == PsiUtil.ACCESS_LEVEL_PRIVATE && memberClass == null) {
|
||||
max = suggestPackageLocal(member);
|
||||
}
|
||||
|
||||
log(member.getName()+": effective level is '" + PsiUtil.getAccessModifier(max) + "'");
|
||||
String maxModifier = PsiUtil.getAccessModifier(max);
|
||||
log(member.getName() + ": effective level is '" + maxModifier + "'");
|
||||
|
||||
if (max < currentLevel) {
|
||||
if (max == PsiUtil.ACCESS_LEVEL_PACKAGE_LOCAL && member instanceof PsiClass && childMembersAreUsedOutsideMyPackage.contains(member)) {
|
||||
@@ -205,7 +208,7 @@ class AccessCanBeTightenedInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
}
|
||||
});
|
||||
assert toHighlight != null : member +" ; " + ((PsiNameIdentifierOwner)member).getNameIdentifier() + "; "+ memberModifierList.getText();
|
||||
myHolder.registerProblem(toHighlight, "Access can be "+PsiUtil.getAccessModifier(max), new ChangeModifierFix(PsiUtil.getAccessModifier(max)));
|
||||
myHolder.registerProblem(toHighlight, "Access can be " + VisibilityUtil.toPresentableText(maxModifier), new ChangeModifierFix(maxModifier));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -353,10 +353,11 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
}
|
||||
|
||||
@PsiModifier.ModifierConstant
|
||||
@Nullable
|
||||
@NotNull
|
||||
public static String getAccessModifier(@AccessLevel int accessLevel) {
|
||||
assert accessLevel > 0 && accessLevel <= accessModifiers.length : accessLevel;
|
||||
@SuppressWarnings("UnnecessaryLocalVariable") @PsiModifier.ModifierConstant
|
||||
final String modifier = accessLevel > accessModifiers.length ? null : accessModifiers[accessLevel - 1];
|
||||
final String modifier = accessModifiers[accessLevel - 1];
|
||||
return modifier;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -31,6 +31,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class VisibilityUtil {
|
||||
@@ -107,7 +108,8 @@ public class VisibilityUtil {
|
||||
}
|
||||
|
||||
@Nls
|
||||
public static String getVisibilityStringToDisplay(PsiMember member) {
|
||||
@NotNull
|
||||
public static String getVisibilityStringToDisplay(@NotNull PsiMember member) {
|
||||
if (member.hasModifierProperty(PsiModifier.PUBLIC)) {
|
||||
return toPresentableText(PsiModifier.PUBLIC);
|
||||
}
|
||||
@@ -120,7 +122,8 @@ public class VisibilityUtil {
|
||||
return toPresentableText(PsiModifier.PACKAGE_LOCAL);
|
||||
}
|
||||
|
||||
public static String toPresentableText(@PsiModifier.ModifierConstant String modifier) {
|
||||
@NotNull
|
||||
public static String toPresentableText(@PsiModifier.ModifierConstant @NotNull String modifier) {
|
||||
return PsiBundle.visibilityPresentation(modifier);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ interface i {
|
||||
}
|
||||
|
||||
public class a implements i {
|
||||
void <error descr="'ff()' in 'a' clashes with 'ff()' in 'i'; attempting to assign weaker access privileges ('packageLocal'); was 'public'">ff</error>() {}
|
||||
void <error descr="'ff()' in 'a' clashes with 'ff()' in 'i'; attempting to assign weaker access privileges ('package local'); was 'public'">ff</error>() {}
|
||||
}
|
||||
class ai implements i {
|
||||
public <error descr="'ff()' in 'ai' clashes with 'ff()' in 'i'; attempting to use incompatible return type">int</error> ff() { return 0;}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ interface i2 {
|
||||
class weak {
|
||||
void f1() {}
|
||||
}
|
||||
<error descr="'f1()' in 'weak' clashes with 'f1()' in 'i'; attempting to assign weaker access privileges ('packageLocal'); was 'public'">class a2 extends weak implements i</error> {
|
||||
<error descr="'f1()' in 'weak' clashes with 'f1()' in 'i'; attempting to assign weaker access privileges ('package local'); was 'public'">class a2 extends weak implements i</error> {
|
||||
}
|
||||
|
||||
class a3 {
|
||||
|
||||
+2
-2
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -40,8 +41,7 @@ public class ChangeModifierFix extends InspectionGadgetsFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionGadgetsBundle.message("change.modifier.quickfix",
|
||||
modifierText);
|
||||
return InspectionGadgetsBundle.message("change.modifier.quickfix", VisibilityUtil.toPresentableText(modifierText));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -27,7 +27,7 @@ public class AccessCanBeTightenedInspectionTest extends LightInspectionTestCase
|
||||
"class C {\n" +
|
||||
" final int /*Access can be private*/fd/**/ = 0;\n" +
|
||||
" /*Access can be private*/public/**/ int fd2;\n" +
|
||||
" /*Access can be packageLocal*/public/**/ int forSubClass;\n" +
|
||||
" /*Access can be package local*/public/**/ int forSubClass;\n" +
|
||||
" @Override\n" +
|
||||
" public int hashCode() {\n" +
|
||||
" return fd + fd2;\n" + // use field
|
||||
@@ -58,7 +58,7 @@ public class AccessCanBeTightenedInspectionTest extends LightInspectionTestCase
|
||||
"@interface Ann{ String value(); }\n" +
|
||||
"@Ann(value = C.VAL\n)" +
|
||||
"class C {\n" +
|
||||
" /*Access can be packageLocal*/public/**/ static final String VAL = \"xx\";\n" +
|
||||
" /*Access can be package local*/public/**/ static final String VAL = \"xx\";\n" +
|
||||
"}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user