Search in sources :

Example 86 with GrReferenceExpression

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);
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 87 with GrReferenceExpression

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);
    });
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with GrReferenceExpression

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;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with GrReferenceExpression

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;
}
Also used : GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrQualifiedReference(org.jetbrains.plugins.groovy.lang.psi.GrQualifiedReference) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 90 with GrReferenceExpression

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());
}
Also used : GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)177 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)92 PsiElement (com.intellij.psi.PsiElement)56 Nullable (org.jetbrains.annotations.Nullable)28 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)27 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)26 NotNull (org.jetbrains.annotations.NotNull)25 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)22 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)22 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)21 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)17 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)16 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)15 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)14 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)14 PsiType (com.intellij.psi.PsiType)13 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)12 Project (com.intellij.openapi.project.Project)11 ArrayList (java.util.ArrayList)11 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)11