mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
we don't always have to do findClass("java.lang.Class") to check if groovy resolve result is OK with respect to statics access
This commit is contained in:
+2
-2
@@ -195,7 +195,7 @@ public class ConvertParameterToMapEntryIntention extends Intention {
|
||||
call instanceof GrCallExpression ? ((GrCallExpression)call).getClosureArguments() : GrClosableBlock.EMPTY_ARRAY;
|
||||
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos =
|
||||
GrClosureSignatureUtil.mapParametersToArguments(signature, argumentList, closureArguments, occurrence.getManager(), owner.getResolveScope());
|
||||
GrClosureSignatureUtil.mapParametersToArguments(signature, argumentList, closureArguments, owner.getResolveScope());
|
||||
if (argInfos == null) continue;
|
||||
final GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo = argInfos[index];
|
||||
|
||||
@@ -319,7 +319,7 @@ public class ConvertParameterToMapEntryIntention extends Intention {
|
||||
private static boolean firstOwnerParameterMustBeMap(final GrParametersOwner owner) {
|
||||
final GrParameter first = getFirstParameter(owner);
|
||||
final PsiType type = first.getTypeGroovy();
|
||||
final PsiClassType mapType = PsiUtil.createMapType(owner.getManager(), GlobalSearchScope.allScope(owner.getProject()));
|
||||
final PsiClassType mapType = PsiUtil.createMapType(GlobalSearchScope.allScope(owner.getProject()));
|
||||
// First parameter may be used as map
|
||||
return type == null || type.isConvertibleFrom(mapType);
|
||||
}
|
||||
|
||||
+2
-1
@@ -133,7 +133,8 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx
|
||||
if (classResults.length == 0) return GroovyResolveResult.EMPTY_ARRAY;
|
||||
|
||||
if (getNamedArguments().length > 0 && getArgumentList().getExpressionArguments().length == 0) {
|
||||
GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classResults, new PsiType[]{PsiUtil.createMapType(getManager(), getResolveScope())}); //one Map parameter, actually
|
||||
GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classResults, new PsiType[]{PsiUtil.createMapType(
|
||||
getResolveScope())}); //one Map parameter, actually
|
||||
for (GroovyResolveResult result : constructorResults) {
|
||||
if (result.getElement() instanceof PsiMethod) {
|
||||
PsiMethod constructor = (PsiMethod)result.getElement();
|
||||
|
||||
+7
-9
@@ -301,10 +301,9 @@ public class GrClosureSignatureUtil {
|
||||
*/
|
||||
@Nullable
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrClosureSignature signature,
|
||||
@NotNull GrArgumentList list,
|
||||
PsiManager manager,
|
||||
GlobalSearchScope scope) {
|
||||
return mapParametersToArguments(signature, list, GrClosableBlock.EMPTY_ARRAY, manager, scope);
|
||||
@NotNull GrArgumentList list,
|
||||
GlobalSearchScope scope) {
|
||||
return mapParametersToArguments(signature, list, GrClosableBlock.EMPTY_ARRAY, scope);
|
||||
}
|
||||
|
||||
private static class InnerArg {
|
||||
@@ -319,10 +318,9 @@ public class GrClosureSignatureUtil {
|
||||
|
||||
@Nullable
|
||||
public static ArgInfo<PsiElement>[] mapParametersToArguments(@NotNull GrClosureSignature signature,
|
||||
@NotNull GrArgumentList list,
|
||||
@NotNull GrClosableBlock[] closureArguments,
|
||||
PsiManager manager,
|
||||
GlobalSearchScope scope) {
|
||||
@NotNull GrArgumentList list,
|
||||
@NotNull GrClosableBlock[] closureArguments,
|
||||
GlobalSearchScope scope) {
|
||||
final GrNamedArgument[] namedArgs = list.getNamedArguments();
|
||||
boolean hasNamedArgs = namedArgs.length > 0;
|
||||
GrClosureParameter[] params = signature.getParameters();
|
||||
@@ -333,7 +331,7 @@ public class GrClosureSignatureUtil {
|
||||
if (params.length == 0) return null;
|
||||
PsiType type = params[0].getType();
|
||||
if (InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) {
|
||||
innerArgs.add(new InnerArg(PsiUtil.createMapType(manager, scope), namedArgs));
|
||||
innerArgs.add(new InnerArg(PsiUtil.createMapType(scope), namedArgs));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
||||
@@ -156,7 +156,7 @@ public class PsiUtil {
|
||||
return GrClosureSignatureUtil.isSignatureApplicable(signature, argumentTypes, context);
|
||||
}
|
||||
|
||||
public static PsiClassType createMapType(PsiManager manager, GlobalSearchScope scope) {
|
||||
public static PsiClassType createMapType(GlobalSearchScope scope) {
|
||||
return new GrMapType(scope);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class PsiUtil {
|
||||
|
||||
GrNamedArgument[] namedArgs = call.getNamedArguments();
|
||||
if (namedArgs.length > 0) {
|
||||
result.add(createMapType(place.getManager(), place.getResolveScope()));
|
||||
result.add(createMapType(place.getResolveScope()));
|
||||
}
|
||||
|
||||
GrExpression[] expressions = call.getExpressionArguments();
|
||||
@@ -212,7 +212,7 @@ public class PsiUtil {
|
||||
|
||||
GrNamedArgument[] namedArgs = argList.getNamedArguments();
|
||||
if (namedArgs.length > 0) {
|
||||
result.add(createMapType(place.getManager(), place.getResolveScope()));
|
||||
result.add(createMapType(place.getResolveScope()));
|
||||
}
|
||||
|
||||
GrExpression[] expressions = argList.getExpressionArguments();
|
||||
@@ -234,7 +234,7 @@ public class PsiUtil {
|
||||
GrNamedArgument[] namedArgs = argList != null ? argList.getNamedArguments() : GrNamedArgument.EMPTY_ARRAY;
|
||||
final ArrayList<PsiType> result = new ArrayList<PsiType>();
|
||||
if (namedArgs.length > 0) {
|
||||
result.add(createMapType(place.getManager(), place.getResolveScope()));
|
||||
result.add(createMapType(place.getResolveScope()));
|
||||
}
|
||||
for (GrExpression arg : args) {
|
||||
PsiType argType = arg.getType();
|
||||
@@ -252,7 +252,7 @@ public class PsiUtil {
|
||||
|
||||
List<PsiType> result = new ArrayList<PsiType>();
|
||||
if (argList.getNamedArguments().length > 0) {
|
||||
result.add(createMapType(place.getManager(), place.getResolveScope()));
|
||||
result.add(createMapType(place.getResolveScope()));
|
||||
}
|
||||
|
||||
GrExpression[] expressions = argList.getExpressionArguments();
|
||||
@@ -395,16 +395,33 @@ public class PsiUtil {
|
||||
if (owner instanceof PsiClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//non-physical method, e.g. gdk
|
||||
if (containingClass == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (owner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//members from java.lang.Class can be invoked without ".class"
|
||||
PsiClass javaLangClass =
|
||||
JavaPsiFacade.getInstance(place.getProject()).findClass(CommonClassNames.JAVA_LANG_CLASS, place.getResolveScope());
|
||||
if (javaLangClass != null) {
|
||||
if ((containingClass == null) || //default groovy method
|
||||
InheritanceUtil.isInheritorOrSelf(javaLangClass, containingClass, true)) {
|
||||
final String qname = containingClass.getQualifiedName();
|
||||
if (qname != null && qname.startsWith("java.")) {
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(qname) || CommonClassNames.JAVA_LANG_CLASS.equals(qname)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (containingClass.isInterface()) {
|
||||
PsiClass javaLangClass =
|
||||
JavaPsiFacade.getInstance(place.getProject()).findClass(CommonClassNames.JAVA_LANG_CLASS, place.getResolveScope());
|
||||
if (javaLangClass != null && javaLangClass.isInheritor(containingClass, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return owner.hasModifierProperty(PsiModifier.STATIC);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (qualifier instanceof GrThisReferenceExpression && ((GrThisReferenceExpression)qualifier).getQualifier() == null) {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class GrMethodCallUsageInfo extends UsageInfo implements PossiblyIncorrec
|
||||
}
|
||||
else {
|
||||
myMapToArguments =
|
||||
GrClosureSignatureUtil.mapParametersToArguments(signature, list, element.getManager(), GlobalSearchScope.allScope(getProject()));
|
||||
GrClosureSignatureUtil.mapParametersToArguments(signature, list, GlobalSearchScope.allScope(getProject()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user