Search in sources :

Example 1 with JavaClassReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.

the class CanonicalPsiTypeConverterImpl method getReferences.

public PsiReference[] getReferences(@Nullable PsiType type, String typeText, int startOffsetInText, @NotNull final PsiElement element) {
    final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
    assert manipulator != null;
    String trimmed = typeText.trim();
    int offset = manipulator.getRangeInElement(element).getStartOffset() + startOffsetInText + typeText.indexOf(trimmed);
    if (trimmed.startsWith(ARRAY_PREFIX)) {
        offset += ARRAY_PREFIX.length();
        if (trimmed.endsWith(";")) {
            trimmed = trimmed.substring(ARRAY_PREFIX.length(), trimmed.length() - 1);
        } else {
            trimmed = trimmed.substring(ARRAY_PREFIX.length());
        }
    }
    if (type != null) {
        type = type.getDeepComponentType();
    }
    final boolean isPrimitiveType = type instanceof PsiPrimitiveType;
    return new JavaClassReferenceSet(trimmed, element, offset, false, CLASS_REFERENCE_PROVIDER) {

        @Override
        @NotNull
        protected JavaClassReference createReference(int refIndex, @NotNull String subRefText, @NotNull TextRange textRange, boolean staticImport) {
            return new JavaClassReference(this, textRange, refIndex, subRefText, staticImport) {

                @Override
                public boolean isSoft() {
                    return true;
                }

                @Override
                @NotNull
                public JavaResolveResult advancedResolve(final boolean incompleteCode) {
                    if (isPrimitiveType) {
                        return new CandidateInfo(element, PsiSubstitutor.EMPTY, false, false, element);
                    }
                    return super.advancedResolve(incompleteCode);
                }

                @Override
                public void processVariants(@NotNull final PsiScopeProcessor processor) {
                    if (processor instanceof JavaCompletionProcessor) {
                        ((JavaCompletionProcessor) processor).setCompletionElements(getVariants());
                    } else {
                        super.processVariants(processor);
                    }
                }

                @Override
                @NotNull
                public Object[] getVariants() {
                    final Object[] variants = super.getVariants();
                    if (myIndex == 0) {
                        return ArrayUtil.mergeArrays(variants, PRIMITIVES, ArrayUtil.OBJECT_ARRAY_FACTORY);
                    }
                    return variants;
                }
            };
        }
    }.getAllReferences();
}
Also used : JavaClassReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) CandidateInfo(com.intellij.psi.infos.CandidateInfo) TextRange(com.intellij.openapi.util.TextRange) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) NotNull(org.jetbrains.annotations.NotNull) JavaCompletionProcessor(com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)

Example 2 with JavaClassReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-plugins by JetBrains.

the class OgnlFqnTypeExpressionBase method getReferences.

@NotNull
@Override
public PsiReference[] getReferences() {
    JavaClassReferenceProvider referenceProvider = new JavaClassReferenceProvider();
    referenceProvider.setOption(JavaClassReferenceProvider.DEFAULT_PACKAGE, CommonClassNames.DEFAULT_PACKAGE);
    OgnlPsiUtil.customizeFqnTypeExpressionReferences(this, referenceProvider);
    final JavaClassReferenceSet classReferenceSet = new JavaClassReferenceSet(getText(), this, 0, false, referenceProvider);
    return classReferenceSet.getReferences();
}
Also used : JavaClassReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet) JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JavaClassReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.

the class JavaClassReferenceCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
    if (reference == null) {
        return;
    }
    String[] extendClassNames = reference.getExtendClassNames();
    PsiElement context = reference.getCompletionContext();
    if (extendClassNames != null && context instanceof PsiPackage) {
        if (parameters.getCompletionType() == CompletionType.SMART) {
            JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
            int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
            String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
            reference.processSubclassVariants((PsiPackage) context, extendClassNames, result.withPrefixMatcher(fullPrefix));
            return;
        }
        result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " + StringUtil.join(extendClassNames, ", "));
    }
    if (parameters.getCompletionType() == CompletionType.SMART) {
        return;
    }
    if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
        JavaClassNameCompletionContributor.addAllClasses(parameters, result);
    } else {
        LegacyCompletionContributor.completeReference(parameters, result);
    }
    result.stopHere();
}
Also used : JavaClassReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement)

Example 4 with JavaClassReferenceSet

use of com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet in project intellij-community by JetBrains.

the class JavaClassReferenceCompletionContributor method duringCompletion.

@Override
public void duringCompletion(@NotNull CompletionInitializationContext context) {
    JavaClassReference reference = findJavaClassReference(context.getFile(), context.getStartOffset());
    if (reference != null && reference.getExtendClassNames() != null) {
        JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
        context.setReplacementOffset(set.getRangeInElement().getEndOffset() + set.getElement().getTextRange().getStartOffset());
    }
}
Also used : JavaClassReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference)

Aggregations

JavaClassReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet)4 JavaClassReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference)3 NotNull (org.jetbrains.annotations.NotNull)2 JavaCompletionProcessor (com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PsiPackage (com.intellij.psi.PsiPackage)1 JavaClassReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)1