mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] JavaFeature.OVERRIDE_INTERFACE; isLanguageLevel6OrHigher usages removed
GitOrigin-RevId: 5d1bedeee34435ecbfc0d4bda6245a50c9ac24d7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e80ef3cc7
commit
92ac3066cb
+3
-9
@@ -1146,15 +1146,9 @@ public final class GenericsHighlightUtil {
|
||||
return builder;
|
||||
}
|
||||
PsiClass superClass = superMethod.getMethod().getContainingClass();
|
||||
if (languageLevel == LanguageLevel.JDK_1_5 &&
|
||||
superClass != null &&
|
||||
superClass.isInterface()) {
|
||||
String description = JavaErrorBundle.message("override.not.allowed.in.interfaces");
|
||||
HighlightInfo.Builder info =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(overrideAnnotation).descriptionAndTooltip(description);
|
||||
IntentionAction action = QuickFixFactory.getInstance().createIncreaseLanguageLevelFix(LanguageLevel.JDK_1_6);
|
||||
info.registerFix(action, null, null, null, null);
|
||||
return info;
|
||||
if (superClass != null && superClass.isInterface()) {
|
||||
return HighlightUtil.checkFeature(overrideAnnotation, JavaFeature.OVERRIDE_INTERFACE, languageLevel,
|
||||
overrideAnnotation.getContainingFile());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -198,7 +199,7 @@ public final class StringEqualsEmptyStringInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiElement context = call.getParent();
|
||||
final boolean useIsEmpty = PsiUtil.isLanguageLevel6OrHigher(call);
|
||||
final boolean useIsEmpty = PsiUtil.getLanguageLevel(call).isAtLeast(LanguageLevel.JDK_1_6);
|
||||
if (!useIsEmpty && context instanceof PsiExpressionStatement) {
|
||||
// cheesy, but necessary, because otherwise the quickfix will
|
||||
// produce uncompilable code (out of merely incorrect code).
|
||||
|
||||
@@ -56,6 +56,7 @@ feature.assertions=Assertions
|
||||
feature.enums=Enums
|
||||
feature.generics=Generics
|
||||
feature.annotations=Annotations
|
||||
feature.override.interface=@Override in interfaces
|
||||
feature.static.imports=Static imports
|
||||
feature.for.each=For-each loops
|
||||
feature.varargs=Variable arity methods
|
||||
|
||||
@@ -20,6 +20,7 @@ public enum JavaFeature {
|
||||
STATIC_IMPORTS(LanguageLevel.JDK_1_5, "feature.static.imports"),
|
||||
FOR_EACH(LanguageLevel.JDK_1_5, "feature.for.each"),
|
||||
VARARGS(LanguageLevel.JDK_1_5, "feature.varargs"),
|
||||
OVERRIDE_INTERFACE(LanguageLevel.JDK_1_6, "feature.override.interface"),
|
||||
HEX_FP_LITERALS(LanguageLevel.JDK_1_5, "feature.hex.fp.literals"),
|
||||
DIAMOND_TYPES(LanguageLevel.JDK_1_7, "feature.diamond.types"),
|
||||
MULTI_CATCH(LanguageLevel.JDK_1_7, "feature.multi.catch", true),
|
||||
@@ -147,16 +148,19 @@ public enum JavaFeature {
|
||||
/**
|
||||
* @return true if the availability of this feature can be additionally filtered using {@link LanguageFeatureProvider}.
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public boolean canBeCustomized() {
|
||||
return myCanBeCustomized;
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public boolean isSufficient(@NotNull LanguageLevel useSiteLevel) {
|
||||
return (useSiteLevel.isAtLeast(myLevel) ||
|
||||
useSiteLevel.isUnsupported() && myObsoletePreviewLevels.contains(useSiteLevel)) &&
|
||||
(!myLevel.isPreview() || useSiteLevel.isPreview());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public boolean isLimited() {
|
||||
return false;
|
||||
}
|
||||
@@ -164,6 +168,7 @@ public enum JavaFeature {
|
||||
/**
|
||||
* Override if feature was preview and then accepted as standard
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public LanguageLevel getStandardLevel() {
|
||||
return myLevel.isPreview() ? null : myLevel;
|
||||
}
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
if (JavaLanguage.INSTANCE == method.getLanguage() &&
|
||||
Objects.requireNonNull(superMethod.getContainingClass()).isInterface()) {
|
||||
return !PsiUtil.isLanguageLevel6OrHigher(method);
|
||||
return !PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, method);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ public class JavaPullUpHelper implements PullUpHelper<MemberInfo> {
|
||||
(PsiMethod)(anchor != null ? myTargetSuperClass.addBefore(methodCopy, anchor) : myTargetSuperClass.add(methodCopy));
|
||||
}
|
||||
OverrideImplementUtil.annotateOnOverrideImplement(method, mySourceClass, movedElement);
|
||||
if (!PsiUtil.isLanguageLevel6OrHigher(mySourceClass) && myIsTargetInterface) {
|
||||
if (!PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, mySourceClass) && myIsTargetInterface) {
|
||||
if (isOriginalMethodAbstract) {
|
||||
for (PsiMethod oMethod : OverridingMethodsSearch.search(method)) {
|
||||
deleteOverrideAnnotationIfFound(oMethod);
|
||||
|
||||
+2
-2
@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Conditions;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
@@ -408,8 +409,7 @@ public class JavaPushDownDelegate extends PushDownDelegate<MemberInfo, PsiMember
|
||||
if (methodBySignature == null) return false;
|
||||
final PsiMethod[] superMethods = methodBySignature.findDeepestSuperMethods();
|
||||
if (superMethods.length == 0) return false;
|
||||
final boolean is15 = !PsiUtil.isLanguageLevel6OrHigher(methodBySignature);
|
||||
if (is15) {
|
||||
if (!PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, methodBySignature)) {
|
||||
for (PsiMethod psiMethod : superMethods) {
|
||||
final PsiClass psiClass = psiMethod.getContainingClass();
|
||||
if (psiClass != null && psiClass.isInterface()) {
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -120,7 +121,7 @@ public final class JavaOverrideImplementMemberChooser extends MemberChooser<PsiM
|
||||
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(aClass);
|
||||
//hide option if implement interface for 1.5 language level
|
||||
final boolean overrideVisible =
|
||||
languageLevel.isAtLeast(LanguageLevel.JDK_1_6) || languageLevel.equals(LanguageLevel.JDK_1_5) && !toImplement;
|
||||
JavaFeature.OVERRIDE_INTERFACE.isSufficient(languageLevel) || JavaFeature.ANNOTATIONS.isSufficient(languageLevel) && !toImplement;
|
||||
|
||||
ClassMember[] selectElements = null;
|
||||
if (toImplement) {
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class OverrideImplementUtil extends OverrideImplementExploreUtil {
|
||||
PsiMethod method = targetClass.findMethodBySignature(superMethod, false);
|
||||
if (method != null && !method.isPhysical()) return false;
|
||||
}
|
||||
if (PsiUtil.isLanguageLevel6OrHigher(targetClass)) return true;
|
||||
if (PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, targetClass)) return true;
|
||||
PsiClass superClass = superMethod.getContainingClass();
|
||||
return superClass != null && !superClass.isInterface();
|
||||
}
|
||||
|
||||
+3
-4
@@ -128,9 +128,9 @@ public class MissingOverrideAnnotationInspection extends BaseInspection implemen
|
||||
|
||||
Project project = method.getProject();
|
||||
final boolean isInterface = Objects.requireNonNull(method.getContainingClass()).isInterface();
|
||||
LanguageLevel minimal = isInterface ? LanguageLevel.JDK_1_6 : LanguageLevel.JDK_1_5;
|
||||
JavaFeature requiredFeature = isInterface ? JavaFeature.OVERRIDE_INTERFACE : JavaFeature.ANNOTATIONS;
|
||||
|
||||
GlobalSearchScope scope = getLanguageLevelScope(minimal, project);
|
||||
GlobalSearchScope scope = getLanguageLevelScope(requiredFeature.getMinimumLevel(), project);
|
||||
if (scope == null) return false;
|
||||
int paramCount = method.getParameterList().getParametersCount();
|
||||
Predicate<PsiMethod> preFilter = m -> m.getParameterList().getParametersCount() == paramCount &&
|
||||
@@ -151,8 +151,7 @@ public class MissingOverrideAnnotationInspection extends BaseInspection implemen
|
||||
if (JavaPsiRecordUtil.getRecordComponentForAccessor(method) != null) {
|
||||
return true;
|
||||
}
|
||||
final boolean useJdk6Rules = level.isAtLeast(LanguageLevel.JDK_1_6);
|
||||
if (useJdk6Rules) {
|
||||
if (JavaFeature.OVERRIDE_INTERFACE.isSufficient(level)) {
|
||||
if (!isJdk6Override(method, methodClass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ package com.siyeh.ig.internationalization;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.intention.AddAnnotationPsiFix;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
@@ -57,7 +58,7 @@ public final class StringToUpperWithoutLocaleInspection extends BaseInspection {
|
||||
final PsiReferenceExpression methodExpression = (PsiReferenceExpression)infos[0];
|
||||
List<LocalQuickFix> fixes = new ArrayList<>(2);
|
||||
final PsiModifierListOwner annotatableQualifier = NonNlsUtils.getAnnotatableQualifier(methodExpression);
|
||||
String constantName = PsiUtil.isLanguageLevel6OrHigher(methodExpression) ? "ROOT" : "ENGLISH";
|
||||
String constantName = PsiUtil.getLanguageLevel(methodExpression).isAtLeast(LanguageLevel.JDK_1_6) ? "ROOT" : "ENGLISH";
|
||||
fixes.add(new AddArgumentFix("java.util.Locale." + constantName, "Locale." + constantName));
|
||||
if (annotatableQualifier != null) {
|
||||
fixes.add(new AddAnnotationPsiFix(AnnotationUtil.NON_NLS, annotatableQualifier));
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -94,7 +95,7 @@ public final class RedundantCollectionOperationInspection extends AbstractBaseJa
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
if (!PsiUtil.isLanguageLevel6OrHigher(holder.getFile())) {
|
||||
if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_1_6)) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
return new JavaElementVisitor() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.siyeh.ipp.adapter;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
@@ -155,8 +156,7 @@ public final class AdapterToListenerIntention extends MCIntention {
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
final Project project = aClass.getProject();
|
||||
final JavaCodeStyleSettings codeStyleSettings = JavaCodeStyleSettings.getInstance(aClass.getContainingFile());
|
||||
if (codeStyleSettings.INSERT_OVERRIDE_ANNOTATION &&
|
||||
PsiUtil.isLanguageLevel6OrHigher(aClass)) {
|
||||
if (codeStyleSettings.INSERT_OVERRIDE_ANNOTATION && PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, aClass)) {
|
||||
modifierList.addAnnotation("java.lang.Override");
|
||||
}
|
||||
final PsiElementFactory factory =
|
||||
|
||||
@@ -1046,6 +1046,10 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
return getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated inline or use {@code PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, element)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isLanguageLevel6OrHigher(@NotNull PsiElement element) {
|
||||
return getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_6);
|
||||
}
|
||||
|
||||
@@ -427,7 +427,6 @@ generic.extend.exception=Generic class may not extend 'java.lang.Throwable'
|
||||
illegal.initializer=Illegal initializer for ''{0}''
|
||||
class.cannot.inherit.from.its.type.parameter=Class cannot inherit from its type parameter
|
||||
cannot.resolve.package=Cannot resolve package {0}
|
||||
override.not.allowed.in.interfaces=@Override is not allowed when implementing interface method
|
||||
declaration.not.allowed=Declaration not allowed here
|
||||
|
||||
underscore.identifier.error=Since Java 9, '_' is a keyword, and may not be used as an identifier
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ public class GrPullUpHelper implements PullUpHelper<MemberInfo> {
|
||||
JavaCodeStyleSettings styleSettings = JavaCodeStyleSettings.getInstance(method.getContainingFile());
|
||||
if (styleSettings.INSERT_OVERRIDE_ANNOTATION) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.ANNOTATIONS, mySourceClass) && !myTargetSuperClass.isInterface() ||
|
||||
PsiUtil.isLanguageLevel6OrHigher(mySourceClass)) {
|
||||
PsiUtil.isAvailable(JavaFeature.OVERRIDE_INTERFACE, mySourceClass)) {
|
||||
new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method)
|
||||
.invoke(method.getProject(), null, mySourceClass.getContainingFile());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user