mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-09 08:09:39 +07:00
[java] IDEA-345355 Refactor HighlightingFeature (in progress)
JavaFeature.isAvailable moved to PsiUtil, as we cannot get PsiElement language level inside frontback-api module GitOrigin-RevId: 8092b1f55f0d90af5bc570f2fb49cdf9ef94485a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cd071eaae4
commit
340c4d40ba
@@ -46,7 +46,7 @@ class CallBuilder(private val context: PsiElement) {
|
||||
PsiUtil.setModifierProperty(declaredVariable, PsiModifier.FINAL, declareFinal)
|
||||
|
||||
val isInferredVar = outputVariable?.typeElement?.isInferredType == true
|
||||
if (isInferredVar || JavaFeature.LVTI.isAvailable(context) && settings.INTRODUCE_LOCAL_CREATE_VAR_TYPE == true) {
|
||||
if (isInferredVar || PsiUtil.isAvailable(JavaFeature.LVTI, context) && settings.INTRODUCE_LOCAL_CREATE_VAR_TYPE == true) {
|
||||
IntroduceVariableUtil.expandDiamondsAndReplaceExplicitTypeWithVar(declaredVariable.typeElement, declaredVariable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ object ParameterObjectUtils {
|
||||
val factory = PsiElementFactory.getInstance(introducedClass.project)
|
||||
val typeParameters = introducedClass.typeParameters.map(factory::createType).toTypedArray()
|
||||
val type = factory.createType(introducedClass, *typeParameters)
|
||||
val typeElement = if (JavaFeature.DIAMOND_TYPES.isAvailable(introducedClass) && typeParameters.isNotEmpty()) {
|
||||
val typeElement = if (PsiUtil.isAvailable(JavaFeature.DIAMOND_TYPES, introducedClass) && typeParameters.isNotEmpty()) {
|
||||
"${type.name}<>"
|
||||
} else {
|
||||
type.canonicalText
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.pom.java.JavaFeature
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.PsiUtil
|
||||
import com.intellij.refactoring.extractMethod.ExtractMethodHandler
|
||||
import com.intellij.refactoring.extractMethod.newImpl.ExtractMultipleVariablesException
|
||||
import com.intellij.refactoring.extractMethod.newImpl.MethodExtractor
|
||||
@@ -43,7 +44,7 @@ object ResultObjectExtractor {
|
||||
InplaceExtractUtils.showExtractErrorHint(editor, ExtractMultipleVariablesException(variables, scope))
|
||||
return
|
||||
}
|
||||
val shouldInsertRecord = JavaFeature.RECORDS.isAvailable(variables.first())
|
||||
val shouldInsertRecord = PsiUtil.isAvailable(JavaFeature.RECORDS, variables.first())
|
||||
val objectBuilder = if (shouldInsertRecord) {
|
||||
RecordResultObjectBuilder.create(variables)
|
||||
} else {
|
||||
|
||||
@@ -932,7 +932,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
public static @DialogMessage String checkUnableToInsertCodeBlock(PsiCodeBlock methodBody, PsiElement element) {
|
||||
if (!JavaFeature.STATEMENTS_BEFORE_SUPER.isAvailable(element) &&
|
||||
if (!PsiUtil.isAvailable(JavaFeature.STATEMENTS_BEFORE_SUPER, element) &&
|
||||
checkUnableToInsertCodeBlock(methodBody, element,
|
||||
expr -> JavaPsiConstructorUtil.isConstructorCall(expr) && expr.getMethodExpression() != element)) {
|
||||
return JavaRefactoringBundle.message("inline.method.multiline.method.in.ctor.call");
|
||||
|
||||
@@ -122,7 +122,7 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler implemen
|
||||
declareStatic = isInSuperOrThis = isInSuperOrThis(occurrences[i]);
|
||||
}
|
||||
}
|
||||
if (isInSuperOrThis && JavaFeature.STATIC_INTERFACE_CALLS.isAvailable(expr != null ? expr : anchorElement)) {
|
||||
if (isInSuperOrThis && PsiUtil.isAvailable(JavaFeature.STATIC_INTERFACE_CALLS, expr != null ? expr : anchorElement)) {
|
||||
isInSuperOrThis = false;
|
||||
}
|
||||
int occurrencesNumber = occurrences.length;
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class LocalToFieldHandler {
|
||||
* @return true, if adding a non-compile-time constants static field to the specified class is allowed. False otherwise.
|
||||
*/
|
||||
public static boolean isStaticFieldAllowed(@NotNull PsiClass aClass) {
|
||||
if (JavaFeature.INNER_STATICS.isAvailable(aClass)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.INNER_STATICS, aClass)) {
|
||||
return true;
|
||||
}
|
||||
return aClass.hasModifierProperty(PsiModifier.STATIC) || aClass.getParent() instanceof PsiJavaFile;
|
||||
|
||||
@@ -563,7 +563,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
}
|
||||
|
||||
public static boolean canBeExtractedWithoutExplicitType(PsiExpression expr) {
|
||||
if (JavaFeature.LVTI.isAvailable(expr)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.LVTI, expr)) {
|
||||
PsiType type = getNormalizedType(expr);
|
||||
if (type != null && !PsiTypes.nullType().equals(type) && PsiTypesUtil.isDenotableType(type, expr)) {
|
||||
PsiExpression copy =
|
||||
@@ -832,7 +832,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
}
|
||||
|
||||
private boolean checkAnchorBeforeThisOrSuper(Project project, Editor editor, PsiElement tempAnchorElement) {
|
||||
if (JavaFeature.STATEMENTS_BEFORE_SUPER.isAvailable(tempAnchorElement)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.STATEMENTS_BEFORE_SUPER, tempAnchorElement)) {
|
||||
return false;
|
||||
}
|
||||
if (tempAnchorElement instanceof PsiExpressionStatement) {
|
||||
|
||||
@@ -336,7 +336,7 @@ final class VariableExtractor {
|
||||
}
|
||||
Set<PsiExpression> allOccurrences = StreamEx.of(occurrences).filter(PsiElement::isPhysical).append(expr).toSet();
|
||||
PsiExpression firstOccurrence = Collections.min(allOccurrences, Comparator.comparing(e -> e.getTextRange().getStartOffset()));
|
||||
if (JavaFeature.PATTERNS.isAvailable(anchor)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.PATTERNS, anchor)) {
|
||||
PsiTypeCastExpression cast = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(firstOccurrence), PsiTypeCastExpression.class);
|
||||
if (cast != null) {
|
||||
PsiType castType = cast.getType();
|
||||
|
||||
@@ -139,7 +139,7 @@ public class JavaIntroduceParameterObjectClassDescriptor extends IntroduceParame
|
||||
if (bean != null && bean.getField() != null) {
|
||||
getter = GenerateMembersUtil.suggestGetterName(bean.getField());
|
||||
}
|
||||
else if (bean == null && access == ReadWriteAccessDetector.Access.Read && JavaFeature.RECORDS.isAvailable(context)) {
|
||||
else if (bean == null && access == ReadWriteAccessDetector.Access.Read && PsiUtil.isAvailable(JavaFeature.RECORDS, context)) {
|
||||
getter = paramInfo.getName();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -76,7 +77,7 @@ class ParameterObjectBuilder {
|
||||
}
|
||||
|
||||
public String buildBeanClass() {
|
||||
boolean recordsAvailable = JavaFeature.RECORDS.isAvailable(myFile) &&
|
||||
boolean recordsAvailable = PsiUtil.isAvailable(JavaFeature.RECORDS, myFile) &&
|
||||
!ContainerUtil.exists(fields, ParameterSpec::isSetterRequired);
|
||||
@NonNls final StringBuilder out = new StringBuilder(1024);
|
||||
if (packageName.length() > 0) out.append("package ").append(packageName).append(';');
|
||||
|
||||
@@ -138,7 +138,7 @@ public class MakeStaticHandler implements RefactoringActionHandler, ContextAware
|
||||
return RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("cannot.make.abstract.method.static"));
|
||||
}
|
||||
|
||||
if(PsiUtil.isLocalOrAnonymousClass(containingClass) && !JavaFeature.INNER_STATICS.isAvailable(member) ||
|
||||
if(PsiUtil.isLocalOrAnonymousClass(containingClass) && !PsiUtil.isAvailable(JavaFeature.INNER_STATICS, member) ||
|
||||
containingClass.getContainingClass() != null && !containingClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("inner.classes.cannot.have.static.members"));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
@@ -217,7 +218,7 @@ public class PushDownConflicts {
|
||||
if (movedMember.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!targetClass.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!(targetClass.getParent() instanceof PsiFile) &&
|
||||
!JavaFeature.INNER_STATICS.isAvailable(targetClass)) {
|
||||
!PsiUtil.isAvailable(JavaFeature.INNER_STATICS, targetClass)) {
|
||||
myConflicts.putValue(movedMember, JavaBundle.message("push.down.static.nonstatic.conflict",
|
||||
RefactoringUIUtil.getDescription(movedMember, false),
|
||||
RefactoringUIUtil.getDescription(targetClass, false)));
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaModuleGraphUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.MoveDestination;
|
||||
import com.intellij.refactoring.safeDelete.ModuleInfoSafeDeleteUsageDetector;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
@@ -54,7 +55,7 @@ public abstract class ModuleInfoUsageDetector {
|
||||
@NotNull
|
||||
private static MultiMap<PsiDirectory, PsiClass> groupClassesByDir(PsiElement @NotNull [] elementsToMove) {
|
||||
PsiElement firstElement = ArrayUtil.getFirstElement(elementsToMove);
|
||||
if (firstElement == null || !JavaFeature.MODULES.isAvailable(firstElement)) return MultiMap.empty();
|
||||
if (firstElement == null || !PsiUtil.isAvailable(JavaFeature.MODULES, firstElement)) return MultiMap.empty();
|
||||
MultiMap<PsiDirectory, PsiClass> result = new MultiMap<>();
|
||||
for (PsiElement element : elementsToMove) {
|
||||
PsiClass psiClass = ObjectUtils.tryCast(element, PsiClass.class);
|
||||
|
||||
@@ -23,10 +23,7 @@ import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationLabeler;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationProcessor;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationRules;
|
||||
@@ -143,10 +140,10 @@ public abstract class TypeMigrationDialog extends RefactoringDialog {
|
||||
final String text = rootType != null ? rootType.getCanonicalText(true) : "";
|
||||
int flags = 0;
|
||||
PsiElement root = roots[0];
|
||||
if (JavaFeature.VARARGS.isAvailable(root)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.VARARGS, root)) {
|
||||
flags |= JavaCodeFragmentFactory.ALLOW_ELLIPSIS;
|
||||
}
|
||||
if (JavaFeature.MULTI_CATCH.isAvailable(root)) {
|
||||
if (PsiUtil.isAvailable(JavaFeature.MULTI_CATCH, root)) {
|
||||
flags |= JavaCodeFragmentFactory.ALLOW_DISJUNCTION;
|
||||
}
|
||||
flags |= JavaCodeFragmentFactory.ALLOW_VOID;
|
||||
|
||||
Reference in New Issue
Block a user