Search in sources :

Example 6 with GrBindingVariable

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable in project intellij-community by JetBrains.

the class GrAssignmentExpressionImpl method processLValue.

private static boolean processLValue(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place, @NotNull GroovyFileImpl file, @NotNull GrExpression lValue) {
    if (!(lValue instanceof GrReferenceExpression))
        return true;
    final GrReferenceExpression lReference = (GrReferenceExpression) lValue;
    if (lReference.isQualified())
        return true;
    final String name = lReference.getReferenceName();
    if (name == null)
        return true;
    String hintName = ResolveUtil.getNameHint(processor);
    if (hintName != null && !name.equals(hintName))
        return true;
    if (lReference != place && lReference.resolve() != null && !(lReference.resolve() instanceof GrBindingVariable))
        return true;
    final ConcurrentMap<String, GrBindingVariable> bindings = file.getBindings();
    GrBindingVariable variable = bindings.get(name);
    if (variable == null) {
        variable = ConcurrencyUtil.cacheOrGet(bindings, name, new GrBindingVariable(file, name, true));
    }
    if (!variable.hasWriteAccess())
        return true;
    return processor.execute(variable, state);
}
Also used : GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable)

Example 7 with GrBindingVariable

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable in project intellij-community by JetBrains.

the class PropertyResolverProcessor method getCandidates.

@NotNull
@Override
public GroovyResolveResult[] getCandidates() {
    //do not have more than one correct result. And if it exists it is the last
    final List<GroovyResolveResult> candidates = getCandidatesInternal();
    final int size = candidates.size();
    if (size == 0)
        return GroovyResolveResult.EMPTY_ARRAY;
    GroovyResolveResult last = candidates.get(size - 1);
    if (last.getElement() instanceof GrBindingVariable && size > 1) {
        last = candidates.get(size - 2);
    }
    if (isCorrectLocalVarOrParam(last)) {
        return new GroovyResolveResult[] { last };
    }
    for (GroovyResolveResult candidate : candidates) {
        if (candidate.isStaticsOK()) {
            return new GroovyResolveResult[] { candidate };
        }
    }
    return candidates.toArray(new GroovyResolveResult[candidates.size()]);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GrBindingVariable

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable in project intellij-community by JetBrains.

the class GroovyResolverProcessorImpl method getCandidates.

@NotNull
public List<GroovyResolveResult> getCandidates() {
    List<GroovyResolveResult> candidates;
    // return package if whole ref text is valid class name
    if (myAcceptableKinds.contains(GroovyResolveKind.PACKAGE) && myIsPartOfFqn) {
        candidates = getCandidates(GroovyResolveKind.PACKAGE);
        if (!candidates.isEmpty()) {
            final GroovyResolveResult candidate = candidates.get(0);
            final PsiElement element = candidate.getElement();
            assert element instanceof PsiPackage;
            final GrReferenceExpressionImpl topRef = getContextReferenceExpression(myRef);
            if (topRef != null) {
                final String fqn = topRef.getTextSkipWhiteSpaceAndComments();
                if (JavaPsiFacade.getInstance(myRef.getProject()).findClass(fqn, myRef.getResolveScope()) != null) {
                    return candidates;
                }
            }
        }
    }
    candidates = getCandidates(GroovyResolveKind.VARIABLE);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.METHOD);
    if (!candidates.isEmpty()) {
        final List<GroovyResolveResult> results = filterMethodCandidates(candidates);
        return myRef.hasMemberPointer() ? collapseReflectedMethods(results) : results;
    }
    candidates = getCandidates(GroovyResolveKind.ENUM_CONST);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.FIELD);
    if (!candidates.isEmpty()) {
        assert candidates.size() == 1;
        final GroovyResolveResult candidate = candidates.get(0);
        final PsiElement element = candidate.getElement();
        if (element instanceof PsiField) {
            final PsiClass containingClass = ((PsiField) element).getContainingClass();
            if (containingClass != null && PsiUtil.getContextClass(myRef) == containingClass)
                return candidates;
        } else if (!(element instanceof GrBindingVariable)) {
            return candidates;
        }
    }
    if (myIsPartOfFqn) {
        candidates = getCandidates(GroovyResolveKind.PACKAGE, GroovyResolveKind.CLASS);
        if (!candidates.isEmpty()) {
            return candidates;
        }
    }
    candidates = getCandidates(GroovyResolveKind.PROPERTY);
    if (!candidates.isEmpty()) {
        return candidates.size() <= 1 ? candidates : ContainerUtil.newSmartList(candidates.get(0));
    }
    candidates = getCandidates(GroovyResolveKind.FIELD);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.PACKAGE, GroovyResolveKind.CLASS);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.PROPERTY);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    candidates = getCandidates(GroovyResolveKind.BINDING);
    if (!candidates.isEmpty()) {
        return candidates;
    }
    for (GroovyResolveKind kind : myAcceptableKinds) {
        Collection<GroovyResolveResult> results = myInapplicableCandidates.get(kind);
        if (!results.isEmpty()) {
            return ContainerUtil.newArrayList(ResolveUtil.filterSameSignatureCandidates(filterCorrectParameterCount(results)));
        }
    }
    return Collections.emptyList();
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) GrReferenceExpressionImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrReferenceExpressionImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrBindingVariable (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable)8 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)4 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)3 IElementType (com.intellij.psi.tree.IElementType)2 NotNull (org.jetbrains.annotations.NotNull)2 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 GrIndexProperty (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty)2 ClosureSyntheticParameter (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticParameter)2 LightElement (com.intellij.psi.impl.light.LightElement)1 THashMap (gnu.trove.THashMap)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)1 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1