Search in sources :

Example 1 with CompletionResult

use of com.intellij.codeInsight.completion.CompletionResult in project android by JetBrains.

the class AndroidJavaCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet resultSet) {
    super.fillCompletionVariants(parameters, resultSet);
    final PsiElement position = parameters.getPosition();
    final AndroidFacet facet = AndroidFacet.getInstance(position);
    if (facet == null) {
        return;
    }
    if (AndroidMavenUtil.isMavenizedModule(facet.getModule())) {
        resultSet.runRemainingContributors(parameters, new Consumer<CompletionResult>() {

            @Override
            public void consume(CompletionResult result) {
                final Object obj = result.getLookupElement().getObject();
                if (obj instanceof PsiClass) {
                    final String qName = ((PsiClass) obj).getQualifiedName();
                    if (qName != null && !isAllowedInAndroid(qName)) {
                        return;
                    }
                }
                resultSet.passResult(result);
            }
        });
    }
    // Filter out private resources when completing R.type.name expressions, if any
    if (position.getParent() instanceof PsiReferenceExpression) {
        PsiReferenceExpression ref = (PsiReferenceExpression) position.getParent();
        if (ref.getQualifierExpression() != null && ref.getQualifierExpression() instanceof PsiReferenceExpression) {
            PsiReferenceExpression ref2 = (PsiReferenceExpression) ref.getQualifierExpression();
            if (ref2.getQualifierExpression() instanceof PsiReferenceExpression) {
                PsiReferenceExpression ref3 = (PsiReferenceExpression) ref2.getQualifierExpression();
                if (ref3.getQualifierExpression() == null && R_CLASS.equals(ref3.getReferenceName())) {
                    filterPrivateResources(parameters, resultSet, facet);
                }
            }
        }
    }
}
Also used : CompletionResult(com.intellij.codeInsight.completion.CompletionResult) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 2 with CompletionResult

use of com.intellij.codeInsight.completion.CompletionResult in project android by JetBrains.

the class AndroidJavaCompletionContributor method filterPrivateResources.

public void filterPrivateResources(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet resultSet, AndroidFacet facet) {
    final ResourceVisibilityLookup lookup = AppResourceRepository.getAppResources(facet, true).getResourceVisibility(facet);
    if (lookup.isEmpty()) {
        return;
    }
    resultSet.runRemainingContributors(parameters, new Consumer<CompletionResult>() {

        @Override
        public void consume(CompletionResult result) {
            final Object obj = result.getLookupElement().getObject();
            if (obj instanceof PsiField) {
                PsiField field = (PsiField) obj;
                PsiClass containingClass = field.getContainingClass();
                if (containingClass != null) {
                    PsiClass rClass = containingClass.getContainingClass();
                    if (rClass != null && rClass.getName().equals(R_CLASS)) {
                        ResourceType type = ResourceType.getEnum(containingClass.getName());
                        if (type != null && lookup.isPrivate(type, field.getName())) {
                            return;
                        }
                    }
                }
            }
            resultSet.passResult(result);
        }
    });
}
Also used : CompletionResult(com.intellij.codeInsight.completion.CompletionResult) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) ResourceType(com.android.resources.ResourceType) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup)

Aggregations

CompletionResult (com.intellij.codeInsight.completion.CompletionResult)2 PsiClass (com.intellij.psi.PsiClass)2 ResourceVisibilityLookup (com.android.ide.common.repository.ResourceVisibilityLookup)1 ResourceType (com.android.resources.ResourceType)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1