Search in sources :

Example 1 with PsiReferenceRegistrarImpl

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

the class WordCompletionTest method testNoWordCompletionForNonSoftReference.

public void testNoWordCompletionForNonSoftReference() throws Throwable {
    final PsiReferenceProvider softProvider = new PsiReferenceProvider() {

        @Override
        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, true) {

                @Override
                public PsiElement resolve() {
                    return null;
                }

                @Override
                @NotNull
                public Object[] getVariants() {
                    return new Object[] { "MySoftVariant" };
                }
            } };
        }
    };
    final PsiReferenceProvider hardProvider = new PsiReferenceProvider() {

        @Override
        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, false) {

                @Override
                public PsiElement resolve() {
                    return null;
                }

                @Override
                @NotNull
                public Object[] getVariants() {
                    return new Object[] { "MyHardVariant" };
                }
            } };
        }
    };
    PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
    try {
        registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider);
        registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider);
        configureByFile(BASE_PATH + "3.java");
        checkResultByFile(BASE_PATH + "3_after.java");
    } finally {
        registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider);
        registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider);
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) NotNull(org.jetbrains.annotations.NotNull) PsiReferenceRegistrarImpl(com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl)

Aggregations

PsiReferenceRegistrarImpl (com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl)1 ProcessingContext (com.intellij.util.ProcessingContext)1 NotNull (org.jetbrains.annotations.NotNull)1