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);
}
}
}
}
}
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);
}
});
}
Aggregations