mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
parenthesis processing (IDEA-98421)
This commit is contained in:
+1
-1
@@ -762,7 +762,7 @@ public class HighlightClassUtil {
|
||||
PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
if (PsiKeyword.THIS.equals(methodCallExpression.getMethodExpression().getReferenceName())) continue;
|
||||
PsiReferenceExpression referenceExpression = methodCallExpression.getMethodExpression();
|
||||
PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
|
||||
PsiExpression qualifierExpression = PsiUtil.skipParenthesizedExprDown(referenceExpression.getQualifierExpression());
|
||||
if (!(qualifierExpression instanceof PsiReferenceExpression) && !(qualifierExpression instanceof PsiNewExpression)) return false;
|
||||
PsiType type = qualifierExpression.getType();
|
||||
if (!(type instanceof PsiClassType)) return false;
|
||||
|
||||
+4
-5
@@ -33,7 +33,6 @@ import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.impl.source.resolve.PsiResolveHelperImpl;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.psi.util.*;
|
||||
@@ -99,15 +98,15 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
private PsiType getExpectedType() {
|
||||
final PsiMethodCallExpression methodCall = myMethodCall.getElement();
|
||||
if (methodCall == null) return null;
|
||||
final PsiElement parent = PsiResolveHelperImpl.skipParenthesizedExprUp(methodCall.getParent());
|
||||
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodCall.getParent());
|
||||
|
||||
if (parent instanceof PsiVariable) {
|
||||
if (methodCall.equals(PsiResolveHelperImpl.skipParenthesizedExprDown(((PsiVariable)parent).getInitializer()))) {
|
||||
if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiVariable)parent).getInitializer()))) {
|
||||
return ((PsiVariable)parent).getType();
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiAssignmentExpression) {
|
||||
if (methodCall.equals(PsiResolveHelperImpl.skipParenthesizedExprDown(((PsiAssignmentExpression)parent).getRExpression()))) {
|
||||
if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)parent).getRExpression()))) {
|
||||
return ((PsiAssignmentExpression)parent).getLExpression().getType();
|
||||
}
|
||||
}
|
||||
@@ -131,7 +130,7 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
final PsiMethod psiMethod = (PsiMethod)psiElement;
|
||||
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
|
||||
final int idx = ArrayUtilRt.find(((PsiExpressionList)parent).getExpressions(), PsiResolveHelperImpl.skipParenthesizedExprUp(methodCall));
|
||||
final int idx = ArrayUtilRt.find(((PsiExpressionList)parent).getExpressions(), PsiUtil.skipParenthesizedExprUp(methodCall));
|
||||
if (idx > -1 && parameters.length > 0) {
|
||||
PsiType parameterType = parameters[Math.min(idx, parameters.length - 1)].getType();
|
||||
if (idx >= parameters.length - 1) {
|
||||
|
||||
@@ -970,4 +970,19 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
final PsiMethod[] closes = autoCloseable.findMethodsByName("close", false);
|
||||
return closes.length == 1 ? resourceClass.findMethodBySignature(closes[0], true) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiExpression skipParenthesizedExprDown(PsiExpression initializer) {
|
||||
while (initializer instanceof PsiParenthesizedExpression) {
|
||||
initializer = ((PsiParenthesizedExpression)initializer).getExpression();
|
||||
}
|
||||
return initializer;
|
||||
}
|
||||
|
||||
public static PsiElement skipParenthesizedExprUp(PsiElement parent) {
|
||||
while (parent instanceof PsiParenthesizedExpression) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-19
@@ -504,7 +504,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
Pair<PsiType, ConstraintType> substitution = null;
|
||||
if (owner instanceof PsiMethod && parent instanceof PsiCallExpression) {
|
||||
PsiCallExpression methodCall = (PsiCallExpression)parent;
|
||||
substitution = inferMethodTypeParameterFromParent(skipParenthesizedExprUp(methodCall.getParent()), methodCall, typeParameter, substitutor, policy);
|
||||
substitution = inferMethodTypeParameterFromParent(PsiUtil.skipParenthesizedExprUp(methodCall.getParent()), methodCall, typeParameter, substitutor, policy);
|
||||
}
|
||||
return substitution;
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
PsiType lowerBound) {
|
||||
final PsiLambdaExpression lambdaExpression = arg.getExpression();
|
||||
if (PsiUtil.getLanguageLevel(lambdaExpression).isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
final PsiElement parent = skipParenthesizedExprUp(lambdaExpression.getParent());
|
||||
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(lambdaExpression.getParent());
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
final PsiExpressionList expressionList = (PsiExpressionList)parent;
|
||||
final Map<PsiElement, Pair<PsiMethod, PsiSubstitutor>> methodMap = MethodCandidateInfo.CURRENT_CANDIDATE.get();
|
||||
@@ -927,12 +927,12 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
PsiType expectedType = null;
|
||||
|
||||
if (parent instanceof PsiVariable) {
|
||||
if (methodCall.equals(skipParenthesizedExprDown(((PsiVariable)parent).getInitializer()))) {
|
||||
if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiVariable)parent).getInitializer()))) {
|
||||
expectedType = ((PsiVariable)parent).getType();
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiAssignmentExpression) {
|
||||
if (methodCall.equals(skipParenthesizedExprDown(((PsiAssignmentExpression)parent).getRExpression()))) {
|
||||
if (methodCall.equals(PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)parent).getRExpression()))) {
|
||||
expectedType = ((PsiAssignmentExpression)parent).getLExpression().getType();
|
||||
}
|
||||
}
|
||||
@@ -1053,19 +1053,4 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiExpression skipParenthesizedExprDown(PsiExpression initializer) {
|
||||
while (initializer instanceof PsiParenthesizedExpression) {
|
||||
initializer = ((PsiParenthesizedExpression)initializer).getExpression();
|
||||
}
|
||||
return initializer;
|
||||
}
|
||||
|
||||
public static PsiElement skipParenthesizedExprUp(PsiElement parent) {
|
||||
while (parent instanceof PsiParenthesizedExpression) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -4,3 +4,19 @@ class OtherClass {
|
||||
|
||||
class Main<B extends OtherClass.InnerClass> { }
|
||||
class Main1 extends <error descr="No enclosing instance of type 'OtherClass' is in scope">OtherClass.InnerClass</error> { }
|
||||
|
||||
class NonDefaultConstructorContainer {
|
||||
public class Inner {
|
||||
public Inner(String s) {}
|
||||
}
|
||||
}
|
||||
|
||||
class UsageWithParenthesis extends NonDefaultConstructorContainer.Inner {
|
||||
public UsageWithParenthesis() {
|
||||
(new NonDefaultConstructorContainer()).super("");
|
||||
}
|
||||
|
||||
public UsageWithParenthesis(NonDefaultConstructorContainer e) {
|
||||
(e).super("");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user