use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GdkMethodUtil method isCategoryMethod.
public static boolean isCategoryMethod(@NotNull PsiMethod method, @Nullable PsiType qualifierType, @Nullable PsiElement place, @Nullable PsiSubstitutor substitutor) {
if (!method.hasModifierProperty(PsiModifier.STATIC))
return false;
if (!method.hasModifierProperty(PsiModifier.PUBLIC))
return false;
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 0)
return false;
if (qualifierType == null)
return true;
PsiType selfType = parameters[0].getType();
if (selfType instanceof PsiPrimitiveType)
return false;
if (substitutor != null) {
selfType = substitutor.substitute(selfType);
}
if (selfType instanceof PsiClassType && ((PsiClassType) selfType).rawType().equalsToText(CommonClassNames.JAVA_LANG_CLASS) && place instanceof GrReferenceExpression && ((GrReferenceExpression) place).resolve() instanceof PsiClass) {
// ClassType.categoryMethod() where categoryMethod(Class<> cl, ...)
final GlobalSearchScope scope = method.getResolveScope();
final Project project = method.getProject();
return TypesUtil.isAssignableByMethodCallConversion(selfType, TypesUtil.createJavaLangClassType(qualifierType, project, scope), method);
}
return TypesUtil.isAssignableByMethodCallConversion(selfType, qualifierType, method);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GdkMethodUtil method getMixinTypes.
/**
* @return (type[1] in which methods mixed, reference to type[1], type[2] to mixin)
*/
@Nullable
private static Trinity<PsiClassType, GrReferenceExpression, PsiClass> getMixinTypes(final GrStatement statement) {
if (!(statement instanceof GrMethodCall))
return null;
return CachedValuesManager.getCachedValue(statement, () -> {
GrMethodCall call = (GrMethodCall) statement;
Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(call);
if (original == null)
return CachedValueProvider.Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
PsiClass mix = getTypeToMix(call);
if (mix == null)
return CachedValueProvider.Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
return CachedValueProvider.Result.create(new Trinity<>(original.first, original.second, mix), PsiModificationTracker.MODIFICATION_COUNT);
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GdkMethodUtil method checkMethodCall.
@Nullable
private static GrMethodCall checkMethodCall(GrClosableBlock place, String methodName) {
final PsiElement context = place.getContext();
GrMethodCall call = null;
if (context instanceof GrMethodCall) {
call = (GrMethodCall) context;
} else if (context instanceof GrArgumentList) {
final PsiElement ccontext = context.getContext();
if (ccontext instanceof GrMethodCall) {
call = (GrMethodCall) ccontext;
}
}
if (call == null)
return null;
final GrExpression invoked = call.getInvokedExpression();
if (!(invoked instanceof GrReferenceExpression) || !methodName.equals(((GrReferenceExpression) invoked).getReferenceName())) {
return null;
}
return call;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrStaticChecker method isInStaticContext.
public static boolean isInStaticContext(@NotNull PsiElement place, @Nullable PsiClass targetClass) {
if (place instanceof GrReferenceExpression) {
GrQualifiedReference reference = (GrQualifiedReference) place;
PsiElement qualifier = reference.getQualifier();
if (qualifier != null && !PsiUtil.isThisOrSuperRef(reference)) {
if (PsiUtil.isInstanceThisRef(qualifier) || PsiUtil.isSuperReference(qualifier)) {
return false;
} else if (PsiUtil.isThisReference(qualifier)) {
//instance 'this' already is processed. So it static 'this'
return true;
}
return qualifier instanceof GrQualifiedReference && ResolveUtil.resolvesToClass(qualifier);
}
if (PsiUtil.isSuperReference(reference))
return false;
//this reference should be checked as all other refs
}
PsiElement run = place;
while (run != null && run != targetClass) {
if (targetClass == null && run instanceof PsiClass)
return false;
if (run instanceof GrClosableBlock)
return false;
if (run instanceof PsiModifierListOwner && ((PsiModifierListOwner) run).hasModifierProperty(PsiModifier.STATIC))
return true;
run = run.getParent();
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class GrStringUtil method checkGStringInjectionForUnnecessaryBraces.
public static boolean checkGStringInjectionForUnnecessaryBraces(GrStringInjection injection) {
final GrClosableBlock block = injection.getClosableBlock();
if (block == null)
return false;
final GrStatement[] statements = block.getStatements();
if (statements.length != 1)
return false;
if (!(statements[0] instanceof GrReferenceExpression))
return false;
return checkBraceIsUnnecessary(statements[0], injection.getNextSibling());
}
Aggregations