mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PsiExpressionList: added getExpressionCount() and isEmpty()
Optimized implementations in PsiExpressionListImpl, usages replaced where possible
This commit is contained in:
+3
-3
@@ -642,7 +642,7 @@ public class HighlightMethodUtil {
|
||||
boolean isThisOrSuper = referenceToMethod.getReferenceNameElement() instanceof PsiKeyword;
|
||||
if (isThisOrSuper) {
|
||||
// super(..) or this(..)
|
||||
if (list.getExpressions().length == 0) { // implicit ctr call
|
||||
if (list.isEmpty()) { // implicit ctr call
|
||||
CandidateInfo[] candidates = resolveHelper.getReferencedMethodCandidates(methodCall, true);
|
||||
if (candidates.length == 1 && !candidates[0].getElement().isPhysical()) {
|
||||
isDummy = true;// dummy constructor
|
||||
@@ -990,7 +990,7 @@ public class HighlightMethodUtil {
|
||||
String methodName,
|
||||
PsiSubstitutor substitutor,
|
||||
PsiClass aClass) {
|
||||
return Math.max(parameters.length, list.getExpressions().length) <= 2
|
||||
return Math.max(parameters.length, list.getExpressionCount()) <= 2
|
||||
? createShortMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass)
|
||||
: createLongMismatchedArgumentsHtmlTooltip(list, info, parameters, methodName, substitutor, aClass);
|
||||
}
|
||||
@@ -1640,7 +1640,7 @@ public class HighlightMethodUtil {
|
||||
PsiMethod[] constructors = aClass.getConstructors();
|
||||
|
||||
if (constructors.length == 0) {
|
||||
if (list.getExpressions().length != 0) {
|
||||
if (!list.isEmpty()) {
|
||||
String constructorName = aClass.getName();
|
||||
String argTypes = buildArgTypesList(list);
|
||||
String description = JavaErrorMessages.message("wrong.constructor.arguments", constructorName+"()", argTypes);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
if (myArgList.getExpressions().length == 1) {
|
||||
if (myArgList.getExpressionCount() == 1) {
|
||||
return QuickFixBundle.message("add.type.arguments.single.argument.text");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ public class AdjustFunctionContextFix extends LocalQuickFixAndIntentionActionOnP
|
||||
PsiFunctionalExpression fn = PsiTreeUtil.getParentOfType(context, PsiFunctionalExpression.class, false);
|
||||
if (fn == null) return null;
|
||||
PsiExpressionList expressionList = ObjectUtils.tryCast(fn.getParent(), PsiExpressionList.class);
|
||||
if (expressionList == null || expressionList.getExpressions().length != 1) return null;
|
||||
if (expressionList == null || expressionList.getExpressionCount() != 1) return null;
|
||||
PsiMethodCallExpression call = ObjectUtils.tryCast(expressionList.getParent(), PsiMethodCallExpression.class);
|
||||
Function<PsiType, String> remapper = METHOD_NAME_ADJUSTER.mapFirst(call);
|
||||
if (remapper == null) return null;
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class CastMethodArgumentFix extends MethodArgumentFix implements HighPrio
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
if (myArgList.getExpressions().length == 1) {
|
||||
if (myArgList.getExpressionCount() == 1) {
|
||||
return QuickFixBundle.message("cast.single.parameter.text", JavaHighlightUtil.formatType(myToType));
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -43,12 +43,11 @@ public abstract class MethodArgumentFix implements IntentionAction {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return
|
||||
myToType != null &&
|
||||
myToType.isValid() &&
|
||||
myArgList.getExpressions().length > myIndex &&
|
||||
myArgList.getExpressions()[myIndex] != null &&
|
||||
myArgList.getExpressions()[myIndex].isValid();
|
||||
if (myToType != null && myToType.isValid()) {
|
||||
PsiExpression[] args = myArgList.getExpressions();
|
||||
return args.length > myIndex && args[myIndex] != null && args[myIndex].isValid();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class WrapObjectWithOptionalOfNullableFix extends MethodArgumentFix imple
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
if (myArgList.getExpressions().length == 1) {
|
||||
if (myArgList.getExpressionCount() == 1) {
|
||||
return QuickFixBundle.message("wrap.with.optional.single.parameter.text");
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -215,7 +215,7 @@ public class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentionActio
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return myArgList.getExpressions().length == 1
|
||||
return myArgList.getExpressionCount() == 1
|
||||
? QuickFixBundle.message("wrap.with.adapter.parameter.single.text", myArgumentFixerActionFactory)
|
||||
: QuickFixBundle.message("wrap.with.adapter.parameter.multiple.text", myIndex + 1, myArgumentFixerActionFactory);
|
||||
}
|
||||
|
||||
+1
-1
@@ -269,7 +269,7 @@ public class GuessManagerImpl extends GuessManager {
|
||||
PsiMethodCallExpression callExpr = (PsiMethodCallExpression)expr;
|
||||
PsiReferenceExpression methodExpr = callExpr.getMethodExpression();
|
||||
String methodName = methodExpr.getReferenceName();
|
||||
MethodPattern pattern = myMethodPatternMap.findPattern(methodName, callExpr.getArgumentList().getExpressions().length);
|
||||
MethodPattern pattern = myMethodPatternMap.findPattern(methodName, callExpr.getArgumentList().getExpressionCount());
|
||||
if (pattern != null && pattern.parameterIndex < 0/* return value */){
|
||||
PsiExpression qualifier = methodExpr.getQualifierExpression();
|
||||
if (qualifier != null) {
|
||||
|
||||
+1
-2
@@ -53,8 +53,7 @@ public class AnonymousHasLambdaAlternativeInspection extends AbstractBaseJavaLoc
|
||||
super.visitAnonymousClass(aClass);
|
||||
PsiExpressionList argumentList = aClass.getArgumentList();
|
||||
if (AnonymousCanBeLambdaInspection.isLambdaForm(aClass, Collections.emptySet()) &&
|
||||
argumentList != null &&
|
||||
argumentList.getExpressions().length == 0) {
|
||||
argumentList != null && argumentList.isEmpty()) {
|
||||
PsiMethod method = aClass.getMethods()[0];
|
||||
PsiClassType type = aClass.getBaseClassType();
|
||||
AnonymousLambdaAlternative alternative = getAlternative(type.resolve(), method);
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ public class FieldAccessNotGuardedInspection extends AbstractBaseJavaLocalInspec
|
||||
else if (guardExpression instanceof PsiMethodCallExpression && lockExpression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCallExpression1 = (PsiMethodCallExpression)guardExpression;
|
||||
final PsiMethodCallExpression methodCallExpression2 = (PsiMethodCallExpression)lockExpression;
|
||||
if (methodCallExpression2.getArgumentList().getExpressions().length == 0) {
|
||||
if (methodCallExpression2.getArgumentList().isEmpty()) {
|
||||
final PsiMethod method1 = methodCallExpression1.resolveMethod();
|
||||
final PsiMethod method2 = methodCallExpression2.resolveMethod();
|
||||
if (method1 == null || method1.equals(method2)) {
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ public class UnknownGuardInspection extends AbstractBaseJavaLocalInspectionTool
|
||||
else if (expression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final JavaResolveResult result = methodCallExpression.resolveMethodGenerics();
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class ReplaceWithObjectsEqualsFix implements LocalQuickFix {
|
||||
public static ReplaceWithObjectsEqualsFix createFix(@NotNull PsiMethodCallExpression call,
|
||||
@NotNull PsiReferenceExpression methodExpression) {
|
||||
if (!"equals".equals(methodExpression.getReferenceName()) ||
|
||||
call.getArgumentList().getExpressions().length != 1 ||
|
||||
call.getArgumentList().getExpressionCount() != 1 ||
|
||||
!PsiUtil.getLanguageLevel(call).isAtLeast(LanguageLevel.JDK_1_7)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -74,13 +74,13 @@ public class CollectionFactoryInliner implements CallInliner {
|
||||
if (info != null) return info;
|
||||
if (JDK9_FACTORIES.test(call)) {
|
||||
int size =
|
||||
JDK9_ARRAY_FACTORIES.test(call) && !MethodCallUtils.isVarArgCall(call) ? -1 : call.getArgumentList().getExpressions().length;
|
||||
JDK9_ARRAY_FACTORIES.test(call) && !MethodCallUtils.isVarArgCall(call) ? -1 : call.getArgumentList().getExpressionCount();
|
||||
return new FactoryInfo(size, COLLECTION_SIZE, true);
|
||||
}
|
||||
if (JDK9_MAP_FACTORIES.test(call)) {
|
||||
boolean ofEntries = "ofEntries".equals(call.getMethodExpression().getReferenceName());
|
||||
int size =
|
||||
ofEntries && !MethodCallUtils.isVarArgCall(call) ? -1 : call.getArgumentList().getExpressions().length / (ofEntries ? 1 : 2);
|
||||
ofEntries && !MethodCallUtils.isVarArgCall(call) ? -1 : call.getArgumentList().getExpressionCount() / (ofEntries ? 1 : 2);
|
||||
return new FactoryInfo(size, MAP_SIZE, true);
|
||||
}
|
||||
return null;
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ abstract class DeprecationInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
if (hasDefaultDeprecatedConstructor(superClass, myForRemoval)) {
|
||||
if (superClass instanceof PsiAnonymousClass) {
|
||||
final PsiExpressionList argumentList = ((PsiAnonymousClass)superClass).getArgumentList();
|
||||
if (argumentList != null && argumentList.getExpressions().length > 0) return;
|
||||
if (argumentList != null && !argumentList.isEmpty()) return;
|
||||
}
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if (body != null) {
|
||||
@@ -175,7 +175,7 @@ abstract class DeprecationInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
final boolean isAnonymous = aClass instanceof PsiAnonymousClass;
|
||||
if (isAnonymous) {
|
||||
final PsiExpressionList argumentList = ((PsiAnonymousClass)aClass).getArgumentList();
|
||||
if (argumentList != null && argumentList.getExpressions().length > 0) return;
|
||||
if (argumentList != null && !argumentList.isEmpty()) return;
|
||||
}
|
||||
registerDefaultConstructorProblem(superClass,
|
||||
isAnonymous ? ((PsiAnonymousClass)aClass).getBaseClassReference() : aClass.getNameIdentifier(),
|
||||
|
||||
+5
-2
@@ -2,7 +2,10 @@
|
||||
package com.intellij.codeInspection.java18api;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -27,7 +30,7 @@ public class Java8ListSortInspection extends AbstractBaseJavaLocalInspectionTool
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
PsiElement nameElement = expression.getMethodExpression().getReferenceNameElement();
|
||||
if(nameElement != null && expression.getArgumentList().getExpressions().length == 2 &&
|
||||
if(nameElement != null && expression.getArgumentList().getExpressionCount() == 2 &&
|
||||
"sort".equals(nameElement.getText())) {
|
||||
PsiMethod method = expression.resolveMethod();
|
||||
if(method != null) {
|
||||
|
||||
+1
-1
@@ -265,7 +265,7 @@ public class RefJavaUtilImpl extends RefJavaUtil{
|
||||
}
|
||||
|
||||
PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (argumentList.getExpressions().length > 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
refMethod.updateParameterValues(argumentList.getExpressions());
|
||||
}
|
||||
|
||||
|
||||
+8
-7
@@ -24,10 +24,9 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
import java.util.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -118,7 +117,7 @@ public class ExtractMethodUtil {
|
||||
final PsiParameter[] oldParameters = oldTarget.getParameterList().getParameters();
|
||||
if (oldParameters.length > 0) {
|
||||
final PsiMethodCallExpression copy = (PsiMethodCallExpression)call.copy();
|
||||
final PsiExpression[] args = copy.getArgumentList().getExpressions();
|
||||
PsiExpression[] args = copy.getArgumentList().getExpressions();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
PsiExpression arg = args[i];
|
||||
PsiType paramType = i < oldParameters.length ? oldParameters[i].getType() : oldParameters[oldParameters.length - 1].getType();
|
||||
@@ -132,11 +131,13 @@ public class ExtractMethodUtil {
|
||||
arg.replace(cast);
|
||||
}
|
||||
|
||||
for (int i = 0; i < copy.getArgumentList().getExpressions().length; i++) {
|
||||
PsiExpression oldarg = call.getArgumentList().getExpressions()[i];
|
||||
PsiTypeCastExpression cast = (PsiTypeCastExpression)copy.getArgumentList().getExpressions()[i];
|
||||
args = copy.getArgumentList().getExpressions();
|
||||
PsiExpression[] oldArgs = call.getArgumentList().getExpressions();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
PsiExpression oldArg = oldArgs[i];
|
||||
PsiTypeCastExpression cast = (PsiTypeCastExpression)args[i];
|
||||
if (!RedundantCastUtil.isCastRedundant(cast)) {
|
||||
oldarg.replace(cast);
|
||||
oldArg.replace(cast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.intellij.lang.regexp.RegExpModifierProvider;
|
||||
@@ -30,11 +27,14 @@ public class JavaRegExpModifierProvider implements RegExpModifierProvider {
|
||||
@Override
|
||||
public int getFlags(PsiElement elementInHost, PsiFile regexp) {
|
||||
final PsiExpressionList list = PsiTreeUtil.getParentOfType(elementInHost, PsiExpressionList.class);
|
||||
if (list != null && list.getExpressions().length == 2 && PsiType.INT.equals(list.getExpressionTypes()[1])) {
|
||||
final Object result = JavaConstantExpressionEvaluator.computeConstantExpression(list.getExpressions()[1], false);
|
||||
if (result instanceof Integer) {
|
||||
//noinspection MagicConstant
|
||||
return ((Integer)result).intValue();
|
||||
if (list != null) {
|
||||
PsiExpression[] expressions = list.getExpressions();
|
||||
if (expressions.length == 2 && PsiType.INT.equals(expressions[1].getType())) {
|
||||
final Object result = JavaConstantExpressionEvaluator.computeConstantExpression(expressions[1], false);
|
||||
if (result instanceof Integer) {
|
||||
//noinspection MagicConstant
|
||||
return ((Integer)result).intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -258,7 +258,7 @@ public class JavaMethodCallElement extends LookupItem<PsiMethod> implements Type
|
||||
context.commitDocument();
|
||||
PsiCall call = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiCall.class, false);
|
||||
PsiExpressionList argList = call == null ? null : call.getArgumentList();
|
||||
if (argList == null || argList.getExpressions().length > 0) {
|
||||
if (argList == null || !argList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public class CreateClassFromNewFix extends CreateFromUsageBaseFix {
|
||||
|
||||
PsiExpressionList argList = newExpression.getArgumentList();
|
||||
final Project project = aClass.getProject();
|
||||
if (argList != null && argList.getExpressions().length > 0) {
|
||||
if (argList != null && !argList.isEmpty()) {
|
||||
PsiMethod constructor = elementFactory.createConstructor();
|
||||
constructor = (PsiMethod)aClass.add(constructor);
|
||||
|
||||
|
||||
+2
-2
@@ -116,7 +116,7 @@ public class CreateFromUsageUtils {
|
||||
if (argList == null) return false;
|
||||
if (candidate == null) {
|
||||
return targetClass != null && !targetClass.isInterface() && !(targetClass instanceof PsiTypeParameter) &&
|
||||
!(argList.getExpressions().length == 0 && targetClass.getConstructors().length == 0);
|
||||
!(argList.isEmpty() && targetClass.getConstructors().length == 0);
|
||||
}
|
||||
else {
|
||||
return !PsiUtil.isApplicable(candidate, PsiSubstitutor.EMPTY, argList);
|
||||
@@ -601,7 +601,7 @@ public class CreateFromUsageUtils {
|
||||
if (someExpectedTypes.length > 0) {
|
||||
Comparator<ExpectedTypeInfo> comparator = expectedTypesComparator;
|
||||
if (expressionList != null) {
|
||||
int argCount = expressionList.getExpressions().length;
|
||||
int argCount = expressionList.getExpressionCount();
|
||||
Comparator<ExpectedTypeInfo> mostSuitableMethodComparator =
|
||||
Comparator.comparingInt(typeInfo -> typeInfo.getCalledMethod().getParameterList().getParametersCount() == argCount ? 0 : 1);
|
||||
comparator = mostSuitableMethodComparator.thenComparing(comparator);
|
||||
|
||||
+2
-2
@@ -88,11 +88,11 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix implement
|
||||
|
||||
String getterOrSetter = null;
|
||||
if (methodName.startsWith(GET_PREFIX) || methodName.startsWith(IS_PREFIX)) {
|
||||
if (myMethodCall.getArgumentList().getExpressions().length != 0) return false;
|
||||
if (!myMethodCall.getArgumentList().isEmpty()) return false;
|
||||
getterOrSetter = QuickFixBundle.message("create.getter");
|
||||
}
|
||||
else if (methodName.startsWith(SET_PREFIX)) {
|
||||
if (myMethodCall.getArgumentList().getExpressions().length != 1) return false;
|
||||
if (myMethodCall.getArgumentList().getExpressionCount() != 1) return false;
|
||||
getterOrSetter = QuickFixBundle.message("create.setter");
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class JavaVarArgNextParameterHandler extends EditorActionHandler {
|
||||
CharSequence text = editor.getDocument().getImmutableCharSequence();
|
||||
int next = CharArrayUtil.shiftForward(text, offset, " \t");
|
||||
PsiExpressionList list = (PsiExpressionList)exprList;
|
||||
int actualParameterCount = list.getExpressions().length;
|
||||
int actualParameterCount = list.getExpressionCount();
|
||||
int lastParamStart = actualParameterCount == 0 ? list.getTextOffset() + 1 : list.getExpressions()[actualParameterCount - 1].getTextOffset();
|
||||
if (next >= lastParamStart) {
|
||||
int prev = CharArrayUtil.shiftBackward(text, lastParamStart - 1, " \t");
|
||||
|
||||
+3
-3
@@ -145,7 +145,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
}
|
||||
if (currentMethodReference == null || originalMethodName.equals(currentMethodReference.getReferenceName())) {
|
||||
|
||||
int currentNumberOfParameters = expressionList.getExpressions().length;
|
||||
int currentNumberOfParameters = expressionList.getExpressionCount();
|
||||
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(context.getProject());
|
||||
Document document = psiDocumentManager.getCachedDocument(context.getFile());
|
||||
if (parent instanceof PsiCallExpression && JavaMethodCallElement.isCompletionMode((PsiCall)parent)) {
|
||||
@@ -187,7 +187,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
for (PsiElement element : owner.getChildren()) {
|
||||
if (element instanceof PsiErrorElement) return false;
|
||||
}
|
||||
if (owner instanceof PsiExpressionList && ((PsiExpressionList)owner).getExpressions().length == 0) {
|
||||
if (owner instanceof PsiExpressionList && ((PsiExpressionList)owner).isEmpty()) {
|
||||
PsiElement parent = owner.getParent();
|
||||
if (parent instanceof PsiCall) {
|
||||
PsiMethod chosenMethod = CompletionMemory.getChosenMethod((PsiCall)parent);
|
||||
@@ -358,7 +358,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
Inlay currentHint = null;
|
||||
List<Inlay> highlightedHints = null;
|
||||
if (expressionList != null && expressionList.isValid()) {
|
||||
int expressionCount = expressionList.getExpressions().length;
|
||||
int expressionCount = expressionList.getExpressionCount();
|
||||
if (currentHintIndex == 0 || currentHintIndex > 0 && currentHintIndex < expressionCount) {
|
||||
highlightedHints = new ArrayList<>(expressionCount);
|
||||
ParameterHintsPass.syncUpdate(expressionList.getParent(), editor);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class ComposeFunctionChainAction extends PsiElementBaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(call.getParent());
|
||||
if (!(parent instanceof PsiExpressionList) || ((PsiExpressionList)parent).getExpressions().length != 1) return false;
|
||||
if (!(parent instanceof PsiExpressionList) || ((PsiExpressionList)parent).getExpressionCount() != 1) return false;
|
||||
|
||||
PsiElement gParent = parent.getParent();
|
||||
if (!(gParent instanceof PsiMethodCallExpression)) return false;
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class InlineStreamMapAction extends PsiElementBaseIntentionAction {
|
||||
if (!isMapCall(curCall)) return false;
|
||||
PsiMethodCallExpression nextCall = getNextExpressionToMerge(curCall);
|
||||
if(nextCall == null) return false;
|
||||
String key = curCall.getArgumentList().getExpressions().length == 0 || nextCall.getArgumentList().getExpressions().length == 0 ?
|
||||
String key = curCall.getArgumentList().isEmpty() || nextCall.getArgumentList().isEmpty() ?
|
||||
"intention.inline.map.merge.text" : "intention.inline.map.inline.text";
|
||||
setText(CodeInsightBundle.message(key, element.getText(), nextCall.getMethodExpression().getReferenceName()));
|
||||
return true;
|
||||
|
||||
+2
-2
@@ -59,14 +59,14 @@ public class JavaMethodParameterUnwrapper extends JavaUnwrapper {
|
||||
}
|
||||
if (e instanceof PsiReferenceExpression && parent instanceof PsiCallExpression) {
|
||||
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
|
||||
if (argumentList != null && argumentList.getExpressions().length == 1) {
|
||||
if (argumentList != null && argumentList.getExpressionCount() == 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (e instanceof PsiJavaCodeReferenceElement) {
|
||||
if (parent instanceof PsiCall) {
|
||||
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
|
||||
if (argumentList != null && argumentList.getExpressions().length == 1) {
|
||||
if (argumentList != null && argumentList.getExpressionCount() == 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ public class CollectionAddAllCanBeReplacedWithConstructorInspection extends
|
||||
return false;
|
||||
}
|
||||
final PsiExpressionList argumentList = newExpression.getArgumentList();
|
||||
return argumentList != null && argumentList.getExpressions().length == 0;
|
||||
return argumentList != null && argumentList.isEmpty();
|
||||
}
|
||||
|
||||
private static boolean hasProperConstructor(PsiClass psiClass) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class OptionalIsPresentInspection extends AbstractBaseJavaLocalInspection
|
||||
static PsiReferenceExpression extractOptionalFromIfPresentCheck(PsiExpression expression) {
|
||||
if (!(expression instanceof PsiMethodCallExpression)) return null;
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
|
||||
if (call.getArgumentList().getExpressions().length != 0) return null;
|
||||
if (!call.getArgumentList().isEmpty()) return null;
|
||||
if (!"isPresent".equals(call.getMethodExpression().getReferenceName())) return null;
|
||||
PsiMethod method = call.resolveMethod();
|
||||
if (method == null) return null;
|
||||
@@ -159,7 +159,7 @@ public class OptionalIsPresentInspection extends AbstractBaseJavaLocalInspection
|
||||
static boolean isOptionalGetCall(PsiElement element, @NotNull PsiReferenceExpression optionalRef) {
|
||||
if (!(element instanceof PsiMethodCallExpression)) return false;
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)element;
|
||||
if (call.getArgumentList().getExpressions().length != 0) return false;
|
||||
if (!call.getArgumentList().isEmpty()) return false;
|
||||
PsiReferenceExpression methodExpression = call.getMethodExpression();
|
||||
return "get".equals(methodExpression.getReferenceName()) &&
|
||||
areElementsEquivalent(ExpressionUtils.getQualifierOrThis(methodExpression), optionalRef);
|
||||
|
||||
+3
-3
@@ -112,7 +112,7 @@ public class RedundantStreamOptionalCallInspection extends AbstractBaseJavaLocal
|
||||
if (args.length == 0) {
|
||||
PsiMethodCallExpression furtherCall =
|
||||
findSubsequentCall(call, Predicate.isEqual("distinct"), CALLS_KEEPING_ELEMENTS_DISTINCT::contains);
|
||||
if (furtherCall != null && furtherCall.getArgumentList().getExpressions().length == 0) {
|
||||
if (furtherCall != null && furtherCall.getArgumentList().isEmpty()) {
|
||||
register(furtherCall, InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.distinct"));
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class RedundantStreamOptionalCallInspection extends AbstractBaseJavaLocal
|
||||
if (args.length == 0) {
|
||||
PsiMethodCallExpression furtherCall =
|
||||
findSubsequentCall(call, Predicate.isEqual("unordered"), n -> !n.equals("sorted"));
|
||||
if (furtherCall != null && furtherCall.getArgumentList().getExpressions().length == 0) {
|
||||
if (furtherCall != null && furtherCall.getArgumentList().isEmpty()) {
|
||||
register(furtherCall, InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.unordered"));
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class RedundantStreamOptionalCallInspection extends AbstractBaseJavaLocal
|
||||
case "parallel":
|
||||
if (args.length == 0) {
|
||||
PsiMethodCallExpression furtherCall = findSubsequentCall(call, CALLS_AFFECTING_PARALLELIZATION::contains, n -> true);
|
||||
if (furtherCall != null && furtherCall.getArgumentList().getExpressions().length == 0) {
|
||||
if (furtherCall != null && furtherCall.getArgumentList().isEmpty()) {
|
||||
register(call, InspectionsBundle.message("inspection.redundant.stream.optional.call.explanation.parallel",
|
||||
furtherCall.getMethodExpression().getReferenceName()));
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SimplifyCollectorInspection extends AbstractBaseJavaLocalInspection
|
||||
return;
|
||||
}
|
||||
if (isCollectorMethod(downstream, "maxBy", "minBy", "reducing") &&
|
||||
downstream.getArgumentList().getExpressions().length == 1) {
|
||||
downstream.getArgumentList().getExpressionCount() == 1) {
|
||||
String replacement = nameElement.getText().equals("groupingBy") ? "toMap" : "toConcurrentMap";
|
||||
holder.registerProblem(nameElement, InspectionsBundle.message("inspection.simplify.collector.message", replacement),
|
||||
new SimplifyCollectorFix(replacement));
|
||||
@@ -65,7 +65,7 @@ public class SimplifyCollectorInspection extends AbstractBaseJavaLocalInspection
|
||||
if (method != null && method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
return aClass != null && CommonClassNames.JAVA_UTIL_STREAM_COLLECTORS.equals(aClass.getQualifiedName())
|
||||
&& method.getParameterList().getParametersCount() == call.getArgumentList().getExpressions().length;
|
||||
&& method.getParameterList().getParametersCount() == call.getArgumentList().getExpressionCount();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -96,7 +96,7 @@ public class StreamFilterNotNullFix implements LocalQuickFix, HighPriorityAction
|
||||
PsiFunctionalExpression fn = findFunction(reference);
|
||||
if (fn == null) return null;
|
||||
PsiExpressionList args = tryCast(PsiUtil.skipParenthesizedExprUp(fn.getParent()), PsiExpressionList.class);
|
||||
if (args == null || args.getExpressions().length != 1) return null;
|
||||
if (args == null || args.getExpressionCount() != 1) return null;
|
||||
PsiMethodCallExpression call = tryCast(args.getParent(), PsiMethodCallExpression.class);
|
||||
if (call == null) return null;
|
||||
PsiExpression qualifier = call.getMethodExpression().getQualifierExpression();
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@ public class Java9CollectionFactoryInspection extends BaseLocalInspectionTool {
|
||||
if (mapDefinition instanceof PsiNewExpression) {
|
||||
PsiAnonymousClass anonymousClass = ((PsiNewExpression)mapDefinition).getAnonymousClass();
|
||||
PsiExpressionList argumentList = ((PsiNewExpression)mapDefinition).getArgumentList();
|
||||
if (anonymousClass != null && argumentList != null && argumentList.getExpressions().length == 0) {
|
||||
if (anonymousClass != null && argumentList != null && argumentList.isEmpty()) {
|
||||
PsiJavaCodeReferenceElement baseClassReference = anonymousClass.getBaseClassReference();
|
||||
if (CommonClassNames.JAVA_UTIL_HASH_MAP.equals(baseClassReference.getQualifiedName())) {
|
||||
return fromInitializer(anonymousClass, "Map", MAP_PUT);
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class FuseStreamOperationsInspection extends AbstractBaseJavaLocalInspect
|
||||
PsiExpression body = LambdaUtil.extractSingleExpressionFromBody(((PsiLambdaExpression)function).getBody());
|
||||
PsiNewExpression newExpression = tryCast(PsiUtil.skipParenthesizedExprDown(body), PsiNewExpression.class);
|
||||
if (newExpression != null && newExpression.getAnonymousClass() == null && newExpression.getQualifier() == null &&
|
||||
newExpression.getArgumentList() != null && newExpression.getArgumentList().getExpressions().length == 0) {
|
||||
newExpression.getArgumentList() != null && newExpression.getArgumentList().isEmpty()) {
|
||||
PsiJavaCodeReferenceElement classReference = newExpression.getClassReference();
|
||||
if (classReference != null) {
|
||||
return tryCast(classReference.resolve(), PsiClass.class);
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ public class SimplifyForEachInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
PsiElement lambdaBody = lambda.getBody();
|
||||
if (lambdaBody == null) return null;
|
||||
PsiExpressionList parameters = tryCast(PsiUtil.skipParenthesizedExprUp(lambda.getParent()), PsiExpressionList.class);
|
||||
if (parameters == null || parameters.getExpressions().length != 1) return null;
|
||||
if (parameters == null || parameters.getExpressionCount() != 1) return null;
|
||||
PsiMethodCallExpression call = tryCast(parameters.getParent(), PsiMethodCallExpression.class);
|
||||
SimplifyForEachContext simplifyForEachContext = SimplifyForEachContext.from(call);
|
||||
if (simplifyForEachContext == null || simplifyForEachContext.myMigration instanceof ForEachMigration) return null;
|
||||
|
||||
+1
-1
@@ -257,7 +257,7 @@ public class StreamApiMigrationInspection extends AbstractBaseJavaLocalInspectio
|
||||
if (!ArrayUtil.contains(name, methodNames)) return false;
|
||||
PsiMethod maybeMapMethod = call.resolveMethod();
|
||||
if (maybeMapMethod == null ||
|
||||
maybeMapMethod.getParameterList().getParametersCount() != call.getArgumentList().getExpressions().length) {
|
||||
maybeMapMethod.getParameterList().getParametersCount() != call.getArgumentList().getExpressionCount()) {
|
||||
return false;
|
||||
}
|
||||
PsiClass containingClass = maybeMapMethod.getContainingClass();
|
||||
|
||||
@@ -332,8 +332,7 @@ class TerminalBlock {
|
||||
PsiNewExpression initializer = tryCast(var.getInitializer(), PsiNewExpression.class);
|
||||
if (initializer == null) return null;
|
||||
PsiExpressionList argumentList = initializer.getArgumentList();
|
||||
if (argumentList == null ||
|
||||
argumentList.getExpressions().length != 0 ||
|
||||
if (argumentList == null || !argumentList.isEmpty() ||
|
||||
ControlFlowUtils.getInitializerUsageStatus(var, getStreamSourceStatement()) == ControlFlowUtils.InitializerUsageStatus.UNKNOWN) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class IteratorDeclaration {
|
||||
public boolean isIteratorMethodCall(PsiElement candidate, String method) {
|
||||
if (!(candidate instanceof PsiMethodCallExpression)) return false;
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)candidate;
|
||||
if (call.getArgumentList().getExpressions().length != 0) return false;
|
||||
if (!call.getArgumentList().isEmpty()) return false;
|
||||
PsiReferenceExpression expression = call.getMethodExpression();
|
||||
return method.equals(expression.getReferenceName()) && ExpressionUtils.isReferenceTo(expression.getQualifierExpression(), myIterator);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class IteratorDeclaration {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (!(initializer instanceof PsiMethodCallExpression)) return null;
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)initializer;
|
||||
if (call.getArgumentList().getExpressions().length != 0) return null;
|
||||
if (!call.getArgumentList().isEmpty()) return null;
|
||||
PsiReferenceExpression methodExpression = call.getMethodExpression();
|
||||
boolean listIterator = "listIterator".equals(methodExpression.getReferenceName());
|
||||
if (!"iterator".equals(methodExpression.getReferenceName()) && !listIterator) return null;
|
||||
|
||||
@@ -1212,7 +1212,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
}
|
||||
else if (myRole2 == ChildRole.RPARENTH) {
|
||||
boolean space = myRole1 == ChildRole.COMMA || mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
|
||||
if (mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE && list.getExpressions().length > 1) {
|
||||
if (mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE && list.getExpressionCount() > 1) {
|
||||
createSpaceWithLinefeedIfListWrapped(list, space);
|
||||
return;
|
||||
}
|
||||
@@ -1220,7 +1220,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
}
|
||||
else if (myRole1 == ChildRole.LPARENTH) {
|
||||
boolean space = mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
|
||||
if (mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE && list.getExpressions().length > 1) {
|
||||
if (mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE && list.getExpressionCount() > 1) {
|
||||
createSpaceWithLinefeedIfListWrapped(list, space);
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-2
@@ -30,7 +30,10 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
@@ -126,7 +129,7 @@ public class JavaReflectionReferenceUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (GET_CLASS.equals(methodReferenceName) && methodCall.getArgumentList().getExpressions().length == 0) {
|
||||
else if (GET_CLASS.equals(methodReferenceName) && methodCall.getArgumentList().isEmpty()) {
|
||||
final PsiMethod method = methodCall.resolveMethod();
|
||||
if (method != null && isJavaLangObject(method.getContainingClass())) {
|
||||
final PsiExpression qualifier = ParenthesesUtils.stripParentheses(methodCall.getMethodExpression().getQualifierExpression());
|
||||
|
||||
@@ -96,7 +96,7 @@ public interface ChainCallExtractor {
|
||||
PsiParameterList parameters = lambda.getParameterList();
|
||||
if (parameters.getParametersCount() != 1) return null;
|
||||
PsiExpressionList args = tryCast(lambda.getParent(), PsiExpressionList.class);
|
||||
if (args == null || args.getExpressions().length != 1) return null;
|
||||
if (args == null || args.getExpressionCount() != 1) return null;
|
||||
PsiParameter parameter = parameters.getParameters()[0];
|
||||
if (ExpressionUtils.isReferenceTo(expression, parameter) && parameter.getType().equals(targetType)) {
|
||||
// No-op extraction is useless
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ class JavaChangeSignatureUsageSearcher {
|
||||
if (!isToCatchExceptions) {
|
||||
if (RefactoringUtil.isMethodUsage(element)) {
|
||||
PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(element);
|
||||
if (list == null || !method.isVarArgs() && list.getExpressions().length != parameterCount) continue;
|
||||
if (list == null || !method.isVarArgs() && list.getExpressionCount() != parameterCount) continue;
|
||||
}
|
||||
}
|
||||
if (RefactoringUtil.isMethodUsage(element)) {
|
||||
|
||||
+2
-3
@@ -489,9 +489,8 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (staticqualifier != null) {
|
||||
newReplacement = argumentList.getExpressions().length > 0
|
||||
? "new " + staticqualifier + inferredTypeArguments + argumentList.getText() + "."
|
||||
: staticqualifier + ".";
|
||||
newReplacement = argumentList.isEmpty() ? staticqualifier + "." :
|
||||
"new " + staticqualifier + inferredTypeArguments + argumentList.getText() + ".";
|
||||
} else {
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
final String qualifier = qualifierExpression != null ? qualifierExpression.getText() + "." : "";
|
||||
|
||||
+1
-1
@@ -334,7 +334,7 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
if (constructors.length == 0) {
|
||||
PsiExpressionList newArgumentList = newExpression.getArgumentList();
|
||||
if (newArgumentList != null && newArgumentList.getExpressions().length > 0) {
|
||||
if (newArgumentList != null && !newArgumentList.isEmpty()) {
|
||||
return "Class cannot be inlined because a call to its constructor is unresolved";
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -189,7 +189,7 @@ public class JavaIntroduceParameterMethodUsagesProcessor implements IntroducePar
|
||||
final PsiCall call = RefactoringUtil.getCallExpressionByMethodReference(element);
|
||||
final PsiExpressionList argList = call.getArgumentList();
|
||||
if (argList != null) {
|
||||
final int actualParamLength = argList.getExpressions().length;
|
||||
final int actualParamLength = argList.getExpressionCount();
|
||||
if ((method.isVarArgs() && actualParamLength + 1 < parametersCount) ||
|
||||
(!method.isVarArgs() && actualParamLength < parametersCount)) {
|
||||
conflicts.putValue(call, "Incomplete call(" + call.getText() +"): " + parametersCount + " parameters expected but only " + actualParamLength + " found");
|
||||
|
||||
+1
-3
@@ -30,7 +30,6 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.psi.util.PropertyUtilBase;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
@@ -45,7 +44,6 @@ import com.intellij.refactoring.wrapreturnvalue.usageInfo.UnwrapCall;
|
||||
import com.intellij.refactoring.wrapreturnvalue.usageInfo.WrapReturnValue;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -359,7 +357,7 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
if (myUseExistingClass && returnValue instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)returnValue;
|
||||
if (callExpression.getArgumentList().getExpressions().length == 0) {
|
||||
if (callExpression.getArgumentList().isEmpty()) {
|
||||
final PsiReferenceExpression callMethodExpression = callExpression.getMethodExpression();
|
||||
final String methodName = callMethodExpression.getReferenceName();
|
||||
if (Comparing.strEqual(myUnwrapMethodName, methodName)) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ApproximateResolver {
|
||||
|
||||
Set<PsiClass> qualifierType = getPossibleTypes(qualifier, maxDepth - 1);
|
||||
String refName = ref.getReferenceName();
|
||||
int argCount = ((PsiMethodCallExpression)expression).getArgumentList().getExpressions().length;
|
||||
int argCount = ((PsiMethodCallExpression)expression).getArgumentList().getExpressionCount();
|
||||
List<PsiMethod> methods = refName == null || qualifierType == null ? null : getPossibleMethods(qualifierType, refName, argCount);
|
||||
return methods == null ? null : getDefiniteSymbolTypes(methods);
|
||||
}
|
||||
|
||||
@@ -32,4 +32,20 @@ public interface PsiExpressionList extends PsiElement {
|
||||
@NotNull PsiExpression[] getExpressions();
|
||||
|
||||
@NotNull PsiType[] getExpressionTypes();
|
||||
|
||||
/**
|
||||
* @return number of expressions in the expression list
|
||||
* @since 2018.1
|
||||
*/
|
||||
default int getExpressionCount() {
|
||||
return getExpressions().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if expression list contains no expressions
|
||||
* @since 2018.1
|
||||
*/
|
||||
default boolean isEmpty() {
|
||||
return getExpressionCount() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ class ClosureFolding {
|
||||
|
||||
private static boolean hasNoArguments(PsiNewExpression expression) {
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
return argumentList != null && argumentList.getExpressions().length == 0;
|
||||
return argumentList != null && argumentList.isEmpty();
|
||||
}
|
||||
|
||||
private static boolean hasOnlyOneLambdaMethod(@NotNull PsiAnonymousClass anonymousClass, boolean checkResolve) {
|
||||
|
||||
+10
@@ -37,6 +37,16 @@ public class PsiExpressionListImpl extends CompositePsiElement implements PsiExp
|
||||
return getChildrenAsPsiElements(ElementType.EXPRESSION_BIT_SET, PsiExpression.ARRAY_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExpressionCount() {
|
||||
return countChildren(ElementType.EXPRESSION_BIT_SET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return findChildByType(ElementType.EXPRESSION_BIT_SET) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PsiType[] getExpressionTypes() {
|
||||
|
||||
+1
-1
@@ -448,7 +448,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
private int getActualParametersLength() {
|
||||
if (myActualParameterTypes == null) {
|
||||
LOG.assertTrue(myArgumentsList instanceof PsiExpressionList, myArgumentsList);
|
||||
return ((PsiExpressionList)myArgumentsList).getExpressions().length;
|
||||
return ((PsiExpressionList)myArgumentsList).getExpressionCount();
|
||||
}
|
||||
return myActualParameterTypes.length;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class AddNullArgument extends FilePsiMutation {
|
||||
protected void performMutation() {
|
||||
PsiTreeUtil.findChildrenOfType(getFile(), PsiMethodCallExpression.class).stream()
|
||||
.filter(PsiElement::isValid)
|
||||
.filter(call -> call.getArgumentList().getExpressions().length > 1)
|
||||
.filter(call -> call.getArgumentList().getExpressionCount() > 1)
|
||||
.forEach(call -> call.getArgumentList().add(
|
||||
JavaPsiFacade.getElementFactory(getFile().getProject()).createExpressionFromText("null", call)));
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class DeleteSecondArgument extends FilePsiMutation {
|
||||
.filter(PsiElement::isValid)
|
||||
.map(PsiCall::getArgumentList)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(argList -> argList.getExpressions().length > 1)
|
||||
.filter(argList -> argList.getExpressionCount() > 1)
|
||||
.limit(20)
|
||||
.forEach(argList -> {
|
||||
if (!argList.isValid()) return;
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class GuavaOptionalConversionUtil {
|
||||
final PsiElement maybeMethodCall = parent.getParent();
|
||||
if (!(maybeMethodCall instanceof PsiMethodCallExpression)) return false;
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)maybeMethodCall;
|
||||
final int argumentLength = methodCall.getArgumentList().getExpressions().length;
|
||||
final int argumentLength = methodCall.getArgumentList().getExpressionCount();
|
||||
if (argumentLength != 1) return false;
|
||||
final PsiMethod resolvedMethod = methodCall.resolveMethod();
|
||||
if (resolvedMethod == null || !"or".equals(resolvedMethod.getName())) return false;
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class GuavaPredicatesUtil {
|
||||
return new TypeConversionDescriptorWithLocalVariable("equalTo", "$x$ -> java.util.Objects.equals($x$, $v$)");
|
||||
}
|
||||
if (!isConvertablePredicatesMethod(method, (PsiMethodCallExpression)context)) return null;
|
||||
if (((PsiMethodCallExpression)context).getArgumentList().getExpressions().length == 0) {
|
||||
if (((PsiMethodCallExpression)context).getArgumentList().isEmpty()) {
|
||||
return createConstantPredicate(name, name.equals("and"));
|
||||
}
|
||||
if (PREDICATES_AND_OR.contains(name) && canMigrateAndOrOr((PsiMethodCallExpression)context)) {
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class SuspiciousArrayCastInspection extends BaseInspection {
|
||||
}
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 1) {
|
||||
if (argumentList.getExpressionCount() != 1) {
|
||||
return false;
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ public class ConditionalCanBePushedInsideExpressionInspection extends BaseInspec
|
||||
return false;
|
||||
}
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
if (expressionList.getExpressions().length != 1) {
|
||||
if (expressionList.getExpressionCount() != 1) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement grandParent = expressionList.getParent();
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class DateToStringInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (NonNlsUtils.isNonNlsAnnotatedUse(expression)) {
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ public class LoggerInitializedWithForeignClassInspectionBase extends BaseInspect
|
||||
}
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
|
||||
final PsiExpressionList list = methodCallExpression.getArgumentList();
|
||||
if (list.getExpressions().length != 0) {
|
||||
if (!list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
parent = methodCallExpression.getParent();
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class ThreadDumpStackInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final PsiReferenceExpression methodExpression =
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class ThrowablePrintStackTraceInspectionBase extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = expression.resolveMethod();
|
||||
|
||||
+1
-1
@@ -455,7 +455,7 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
|
||||
+4
-4
@@ -90,7 +90,7 @@ public class ConstructionUtils {
|
||||
expression = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
PsiExpressionList argumentList = ((PsiNewExpression)expression).getArgumentList();
|
||||
if (argumentList != null && argumentList.getExpressions().length == 0) {
|
||||
if (argumentList != null && argumentList.isEmpty()) {
|
||||
PsiType type = expression.getType();
|
||||
return com.intellij.psi.util.InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_COLLECTION) ||
|
||||
com.intellij.psi.util.InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP);
|
||||
@@ -100,7 +100,7 @@ public class ConstructionUtils {
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
|
||||
String name = call.getMethodExpression().getReferenceName();
|
||||
PsiExpressionList argumentList = call.getArgumentList();
|
||||
if(name != null && name.startsWith("new") && argumentList.getExpressions().length == 0) {
|
||||
if(name != null && name.startsWith("new") && argumentList.isEmpty()) {
|
||||
PsiMethod method = call.resolveMethod();
|
||||
if(method != null && method.getParameterList().getParametersCount() == 0) {
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
@@ -127,7 +127,7 @@ public class ConstructionUtils {
|
||||
expression = PsiUtil.skipParenthesizedExprDown(expression);
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
PsiExpressionList argumentList = ((PsiNewExpression)expression).getArgumentList();
|
||||
if (argumentList == null || argumentList.getExpressions().length == 0) return false;
|
||||
if (argumentList == null || argumentList.isEmpty()) return false;
|
||||
PsiMethod constructor = ((PsiNewExpression)expression).resolveConstructor();
|
||||
if (constructor == null) return false;
|
||||
PsiClass aClass = constructor.getContainingClass();
|
||||
@@ -145,7 +145,7 @@ public class ConstructionUtils {
|
||||
if (ENUM_SET_NONE_OF.test(call)) return true;
|
||||
String name = call.getMethodExpression().getReferenceName();
|
||||
PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (name != null && name.startsWith("new") && argumentList.getExpressions().length > 0) {
|
||||
if (name != null && name.startsWith("new") && !argumentList.isEmpty()) {
|
||||
PsiMethod method = call.resolveMethod();
|
||||
if (method != null && method.getParameterList().getParametersCount() > 0) {
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class StreamApiUtil {
|
||||
if (!(expression instanceof PsiMethodCallExpression)) return false;
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
|
||||
String name = call.getMethodExpression().getReferenceName();
|
||||
if ((!"empty".equals(name) && !"of".equals(name)) || !(call.getArgumentList().getExpressions().length == 0)) {
|
||||
if ((!"empty".equals(name) && !"of".equals(name)) || !call.getArgumentList().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
PsiMethod method = call.resolveMethod();
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class UnnecessaryConstructorInspection extends BaseInspection {
|
||||
}
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ public class ConditionSignalInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod method = expression.resolveMethod();
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class NakedNotifyInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpressionList argumentList =
|
||||
methodCallExpression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(methodCallExpression);
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class ObjectNotifyInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList.getExpressions().length != 0) {
|
||||
if (!argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression);
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class TrivialFunctionalExpressionUsageInspection extends AbstractBaseJava
|
||||
boolean suitableMethod = method != null &&
|
||||
referenceNameElement != null &&
|
||||
!method.isVarArgs() &&
|
||||
call.getArgumentList().getExpressions().length == method.getParameterList().getParametersCount() &&
|
||||
call.getArgumentList().getExpressionCount() == method.getParameterList().getParametersCount() &&
|
||||
elementContainerPredicate.test(call);
|
||||
if (!suitableMethod) return;
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(interfaceType);
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ public class IfCanBeAssertionInspection extends BaseInspection {
|
||||
GUAVA_PRECONDITIONS,
|
||||
null,
|
||||
GUAVA_CHECK_NON_NULL,
|
||||
(PsiType[])null) && expression.getArgumentList().getExpressions().length <= 2) { // for parametrized messages we don't suggest anything
|
||||
(PsiType[])null) && expression.getArgumentList().getExpressionCount() <= 2) { // for parametrized messages we don't suggest anything
|
||||
registerMethodCallError(expression, PsiUtil.isLanguageLevel7OrHigher(expression), false);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ public class CollectionsMustHaveInitialCapacityInspection
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
if (argumentList == null || argumentList.getExpressions().length != 0) {
|
||||
if (argumentList == null || !argumentList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
registerNewExpressionError(expression);
|
||||
|
||||
@@ -29,7 +29,7 @@ class AssertLiteralPredicate implements PsiElementPredicate {
|
||||
final PsiMethodCallExpression expression =
|
||||
(PsiMethodCallExpression)element;
|
||||
final PsiExpressionList args = expression.getArgumentList();
|
||||
final int numExpressions = args.getExpressions().length;
|
||||
final int numExpressions = args.getExpressionCount();
|
||||
if (numExpressions < 1 || numExpressions > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class AssertTrueOrFalsePredicate implements PsiElementPredicate {
|
||||
final PsiMethodCallExpression expression =
|
||||
(PsiMethodCallExpression)element;
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
final int numExpressions = argumentList.getExpressions().length;
|
||||
final int numExpressions = argumentList.getExpressionCount();
|
||||
if (numExpressions < 1 || numExpressions > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class UseDPIAwareEmptyBorderInspection extends DevKitInspectionBase {
|
||||
final PsiType parentType = ((PsiNewExpression)parent.getParent()).getType();
|
||||
if (parentType == null || JBEmptyBorder.class.getName().equals(parentType.getCanonicalText())) return null;
|
||||
}
|
||||
if (arguments.getExpressions().length == 4) {
|
||||
if (arguments.getExpressionCount() == 4) {
|
||||
return manager.createProblemDescriptor(expression, "Replace with JBUI.Borders.empty(...)", new ConvertToJBBorderQuickFix(),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class UseDPIAwareInsetsInspection extends DevKitInspectionBase {
|
||||
final PsiType parentType = ((PsiNewExpression)parent.getParent()).getType();
|
||||
if (parentType == null || JBInsets.class.getName().equals(parentType.getCanonicalText())) return null;
|
||||
}
|
||||
if (arguments.getExpressions().length == 4) {
|
||||
if (arguments.getExpressionCount() == 4) {
|
||||
return manager.createProblemDescriptor(expression, "Replace with JBUI.insets(...)", new ConvertToJBInsetsQuickFix(),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConvertToJBBorderQuickFix extends LocalQuickFixBase {
|
||||
final PsiCall newExpression = (PsiCall)descriptor.getPsiElement();
|
||||
PsiExpressionList list = newExpression.getArgumentList();
|
||||
String text;
|
||||
if (list != null && list.getExpressions().length == 4) {
|
||||
if (list != null && list.getExpressionCount() == 4) {
|
||||
String top = list.getExpressions()[0].getText();
|
||||
String left = list.getExpressions()[1].getText();
|
||||
String bottom = list.getExpressions()[2].getText();
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ConvertToJBInsetsQuickFix extends LocalQuickFixBase {
|
||||
final PsiNewExpression newExpression = (PsiNewExpression)descriptor.getPsiElement();
|
||||
PsiExpressionList list = newExpression.getArgumentList();
|
||||
String text = null;
|
||||
if ( list != null && list.getExpressions().length == 4) {
|
||||
if ( list != null && list.getExpressionCount() == 4) {
|
||||
String top = list.getExpressions()[0].getText();
|
||||
String left = list.getExpressions()[1].getText();
|
||||
String bottom = list.getExpressions()[2].getText();
|
||||
|
||||
@@ -70,7 +70,7 @@ public class InlinePropertyHandler extends JavaInlineActionHandler {
|
||||
PsiElement element = psiReference.getElement();
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiMethodCallExpression) {
|
||||
if (((PsiExpressionList)parent).getExpressions().length == 1) {
|
||||
if (((PsiExpressionList)parent).getExpressionCount() == 1) {
|
||||
occurrences.add(parent.getParent());
|
||||
containingFiles.add(element.getContainingFile());
|
||||
return true;
|
||||
|
||||
@@ -13,12 +13,12 @@ import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import java.util.HashMap;
|
||||
import com.theoryinpractice.testng.util.TestNGUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -209,7 +209,7 @@ public class JUnitConvertTool extends AbstractBaseJavaLocalInspectionTool {
|
||||
PsiExpression expression = statement.getExpression();
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expression;
|
||||
if (methodCall.getArgumentList().getExpressions().length == 1) {
|
||||
if (methodCall.getArgumentList().getExpressionCount() == 1) {
|
||||
PsiMethod resolved = methodCall.resolveMethod();
|
||||
if (resolved != null && "junit.framework.TestCase".equals(resolved.getContainingClass().getQualifiedName()) &&
|
||||
"TestCase".equals(resolved.getName())) {
|
||||
|
||||
Reference in New Issue
Block a user