void () { final PsiReferenceProvider softProvider = new PsiReferenceProvider() { @Override public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { return new PsiReference[]{new PsiReferenceBase<>(element, true) { @Override public PsiElement resolve() { return null; } @Override public Object @NotNull [] getVariants() { return new Object[]{"MySoftVariant"}; } }}; } }; final PsiReferenceProvider hardProvider = new PsiReferenceProvider() { @Override public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) { return new PsiReference[]{new PsiReferenceBase<>(element, false) { @Override public PsiElement resolve() { return null; } @Override public Object @NotNull [] getVariants() { return new Object[]{"MyHardVariant"}; } }}; } }; PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl)ReferenceProvidersRegistry.getInstance().getRegistrar(JavaLanguage.INSTANCE); try { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), softProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), hardProvider); configureByFile("3.java"); checkResultByFile("3_after.java"); } finally { registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider); registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider); } }