@Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull MavenDomConfiguration domCfg, @NotNull ProcessingContext context) { return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, true) { @Override public PsiElement resolve() { return null; } @NotNull @Override public Object[] getVariants() { return MavenCompletionReferenceProvider.this.getVariants(this); } } }; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[]{ new PsiReferenceBase<PsiElement>(element, mySoft) { @Nullable @Override public PsiElement resolve() { return null; } @NotNull @Override public Object[] getVariants() { return myValues; } } }; }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { if (!isApplicable(psiElement)) { return new PsiReference[]{}; } PhpIndex phpIndex = PhpIndex.getInstance(psiElement.getProject()); Collection<PhpClass> phpClasses = phpIndex.getClassesByFQN(OuzoUtils.OUZO_MODEL_NAMESPACE + PsiUtils.getContent(psiElement)); PhpClass phpClass = Iterables.getLast(phpClasses, null); if (phpClass == null) { return new PsiReference[]{}; } PsiReferenceBase.Immediate reference = new PsiReferenceBase.Immediate(psiElement, phpClass); return new PsiReference[]{reference}; }
@Override @Nullable public PsiReference getReference() { final ASTNode foreachNode = findForeachNode(); if (foreachNode == null) { return null; } return new PsiReferenceBase<PsiElement>(this) { public PsiElement resolve() { return foreachNode.getLastChildNode().getPsi(); } public Object[] getVariants() { return EMPTY_ARRAY; } }; }
@NotNull public static List<WebReference> collectWebReferences() { final List<WebReference> refs = new ArrayList<>(); myFile.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { for (PsiReference ref : element.getReferences()) { if (ref instanceof WebReference) refs.add((WebReference)ref); } super.visitElement(element); } }); assertTrue(refs.stream().allMatch(PsiReferenceBase::isSoft)); return refs; }
@Override public PsiReference getReference() { if (getParent() instanceof RncInclude) { final TextRange range = TextRange.from(0, getNameNode().getTextLength()); return new PsiReferenceBase<RncDefine>(this, range, true) { @Override public PsiElement resolve() { return RncDefineImpl.this; } @Override @NotNull public Object[] getVariants() { final RncInclude parent = (RncInclude)getParent(); final RncFile referencedFile = parent.getReferencedFile(); if (referencedFile == null) { return EMPTY_ARRAY; } final RncGrammar grammar = referencedFile.getGrammar(); if (grammar == null) { return EMPTY_ARRAY; } final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { return map.keySet().toArray(); } return EMPTY_ARRAY; } }; } return super.getReference(); }
@Override protected Object[] getVariants(@NotNull PsiReferenceBase reference) { Charset[] charsets = CharsetToolkit.getAvailableCharsets(); LookupElement[] res = new LookupElement[charsets.length]; for (int i = 0; i < charsets.length; i++) { res[i] = LookupElementBuilder.create(charsets[i].name()).withCaseSensitivity(false); } return res; }
private static PsiReference globReference(GlobExpression glob, PsiFileSystemItem file) { return new PsiReferenceBase.Immediate<GlobExpression>( glob, glob.getReferenceTextRange(), file) { @Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException { return glob; } }; }
public PsiReference getReference() { if (getParent() instanceof RncInclude) { final TextRange range = TextRange.from(0, getNameNode().getTextLength()); return new PsiReferenceBase<RncDefine>(this, range, true) { public PsiElement resolve() { return RncDefineImpl.this; } @NotNull public Object[] getVariants() { final RncInclude parent = (RncInclude)getParent(); final RncFile referencedFile = parent.getReferencedFile(); if (referencedFile == null) { return EMPTY_ARRAY; } final RncGrammar grammar = referencedFile.getGrammar(); if (grammar == null) { return EMPTY_ARRAY; } final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { return map.keySet().toArray(); } return EMPTY_ARRAY; } }; } return super.getReference(); }
@NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { if (!isApplicable(psiElement)) { return new PsiReference[]{}; } String controller = extractController(PsiUtils.getContent(psiElement)); String action = extractAction(PsiUtils.getContent(psiElement)); PsiReferenceBase.Immediate reference = new PsiReferenceBase.Immediate(psiElement, OuzoUtils.getControllerAction(psiElement.getProject(), controller, action)); return new PsiReference[]{reference}; }
private PsiReference[] getPsiReferenceBase(PsiElement psiElement) { try { PsiReferenceBase referenceClassInstance = (PsiReferenceBase) this.referenceClass.getDeclaredConstructor(StringLiteralExpression.class).newInstance((StringLiteralExpression) psiElement); return new PsiReference[]{ referenceClassInstance }; } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ignored) { } return new PsiReference[0]; }
public void testCustomReferenceProvider() throws Exception { PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(JavaLanguage.INSTANCE); PsiReferenceProvider provider = new PsiReferenceProvider() { @Override @NotNull public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) { @Override public PsiElement resolve() { return element; } @Override @NotNull public Object[] getVariants() { return new Object[]{"1", "2", "3"}; } }}; } }; try { registrar.registerReferenceProvider(PsiDocTag.class, provider); configureByFile("ReferenceProvider.java"); assertStringItems("1", "2", "3"); } finally { registrar.unregisterReferenceProvider(PsiDocTag.class, provider); } }
@Override @NotNull public PsiReference[] createReferences(GenericDomValue genericDomValue, PsiElement element, ConvertContext context) { final GenericAttributeValue<String> e = (GenericAttributeValue<String>)genericDomValue; if (genericDomValue.getParent() instanceof RngDefine) { final XmlAttributeValue value = e.getXmlAttributeValue(); if (value == null) { return PsiReference.EMPTY_ARRAY; } return new PsiReference[]{ new PsiReferenceBase<XmlAttributeValue>(value, true) { @Override public PsiElement resolve() { // final XmlTag tag = PsiTreeUtil.getParentOfType(value, XmlTag.class); // final XmlTag include = getAncestorTag(tag, "include", ProjectLoader.RNG_NAMESPACE); // final XmlTag grammar = getAncestorTag(tag, "grammar", ProjectLoader.RNG_NAMESPACE); // // if (include != null && (grammar == null || PsiTreeUtil.isAncestor(grammar, include, true))) { // final ResolveResult[] e = new DefinitionReference(getElement(), false).multiResolve(false); // } return myElement.getParent().getParent(); } @Override @NotNull public Object[] getVariants() { final RngInclude include = e.getParentOfType(RngInclude.class, true); final RngGrammar scope = e.getParentOfType(RngGrammar.class, true); if (scope != null && include != null && DomUtil.isAncestor(scope, include, true)) { final XmlFile file = include.getIncludedFile().getValue(); if (file != null) { final DomFileElement<DomElement> fileElement = scope.getManager().getFileElement(file, DomElement.class); if (fileElement == null) { return EMPTY_ARRAY; } final Ref<Object[]> ref = new Ref<Object[]>(ArrayUtil.EMPTY_STRING_ARRAY); fileElement.acceptChildren(new RngDomVisitor(){ @Override public void visit(RngGrammar grammar) { final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { ref.set(map.keySet().toArray()); } } }); return ref.get(); } } return ArrayUtil.EMPTY_STRING_ARRAY; // TODO: look for unresolved refs; } } }; } return new PsiReference[]{ new DefinitionReference(e) }; }
@Override protected Object[] getVariants(@NotNull PsiReferenceBase reference) { return MavenUtil.getPhaseVariants(MavenProjectsManager.getInstance(reference.getElement().getProject())).toArray(); }
@Override protected Object[] getVariants(@NotNull PsiReferenceBase reference) { return MavenProjectsManager.getInstance(reference.getElement().getProject()).getAvailableProfiles().toArray(); }
@Override public PsiReference getReference() { final JSGraphQLEndpointNamedTypePsiElement self = this; final PsiElement nameIdentifier = getNameIdentifier(); if(nameIdentifier != null) { if(JSGraphQLScalars.SCALAR_TYPES.contains(nameIdentifier.getText())) { return new PsiReferenceBase.Immediate<PsiElement>(this, TextRange.allOf(nameIdentifier.getText()), getFirstChild()); } return new PsiReferenceBase<PsiElement>(this, TextRange.from(nameIdentifier.getTextOffset() - self.getTextOffset(), nameIdentifier.getTextLength())) { @Nullable @Override public PsiElement resolve() { final Collection<JSGraphQLEndpointNamedTypeDefinition> definitions = JSGraphQLEndpointPsiUtil.getKnownDefinitions( self.getContainingFile(), JSGraphQLEndpointNamedTypeDefinition.class, false, null ); final JSGraphQLEndpointNamedTypeDefinition resolvedElement = definitions.stream() .filter(d -> d.getNamedTypeDef() != null && d.getNamedTypeDef().getText().equals(nameIdentifier.getText())) .findFirst().orElse(null); if(resolvedElement != null) { return resolvedElement.getNamedTypeDef(); } return null; } @NotNull @Override public Object[] getVariants() { return NO_VARIANTS; } @Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { return self.setName(newElementName); } }; } return null; }
@NotNull public PsiReference[] createReferences(GenericDomValue genericDomValue, PsiElement element, ConvertContext context) { final GenericAttributeValue<String> e = (GenericAttributeValue<String>)genericDomValue; if (genericDomValue.getParent() instanceof RngDefine) { final XmlAttributeValue value = e.getXmlAttributeValue(); if (value == null) { return PsiReference.EMPTY_ARRAY; } return new PsiReference[]{ new PsiReferenceBase<XmlAttributeValue>(value, TextRange.from(1, value.getTextLength() - 2), true) { public PsiElement resolve() { // final XmlTag tag = PsiTreeUtil.getParentOfType(value, XmlTag.class); // final XmlTag include = getAncestorTag(tag, "include", ProjectLoader.RNG_NAMESPACE); // final XmlTag grammar = getAncestorTag(tag, "grammar", ProjectLoader.RNG_NAMESPACE); // // if (include != null && (grammar == null || PsiTreeUtil.isAncestor(grammar, include, true))) { // final ResolveResult[] e = new DefinitionReference(getElement(), false).multiResolve(false); // } return myElement.getParent().getParent(); } @NotNull public Object[] getVariants() { final RngInclude include = e.getParentOfType(RngInclude.class, true); final RngGrammar scope = e.getParentOfType(RngGrammar.class, true); if (scope != null && include != null && DomUtil.isAncestor(scope, include, true)) { final XmlFile file = include.getIncludedFile().getValue(); if (file != null) { final DomFileElement<DomElement> fileElement = scope.getManager().getFileElement(file, DomElement.class); if (fileElement == null) { return EMPTY_ARRAY; } final Ref<Object[]> ref = new Ref<Object[]>(ArrayUtil.EMPTY_STRING_ARRAY); fileElement.acceptChildren(new RngDomVisitor(){ @Override public void visit(RngGrammar grammar) { final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { ref.set(map.keySet().toArray()); } } }); return ref.get(); } } return ArrayUtil.EMPTY_STRING_ARRAY; // TODO: look for unresolved refs; } } }; } return new PsiReference[]{ new DefinitionReference(e) }; }
@Override @NotNull public PsiReference[] createReferences(GenericDomValue genericDomValue, PsiElement element, ConvertContext context) { final GenericAttributeValue<String> e = (GenericAttributeValue<String>)genericDomValue; if (genericDomValue.getParent() instanceof RngDefine) { final XmlAttributeValue value = e.getXmlAttributeValue(); if (value == null) { return PsiReference.EMPTY_ARRAY; } return new PsiReference[]{ new PsiReferenceBase<XmlAttributeValue>(value, true) { @Override public PsiElement resolve() { // final XmlTag tag = PsiTreeUtil.getParentOfType(value, XmlTag.class); // final XmlTag include = getAncestorTag(tag, "include", ProjectLoader.RNG_NAMESPACE); // final XmlTag grammar = getAncestorTag(tag, "grammar", ProjectLoader.RNG_NAMESPACE); // // if (include != null && (grammar == null || PsiTreeUtil.isAncestor(grammar, include, true))) { // final ResolveResult[] e = new DefinitionReference(getElement(), false).multiResolve(false); // } return myElement.getParent().getParent(); } @Override @NotNull public Object[] getVariants() { final RngInclude include = e.getParentOfType(RngInclude.class, true); final RngGrammar scope = e.getParentOfType(RngGrammar.class, true); if (scope != null && include != null && DomUtil.isAncestor(scope, include, true)) { final XmlFile file = include.getIncludedFile().getValue(); if (file != null) { final DomFileElement<DomElement> fileElement = scope.getManager().getFileElement(file, DomElement.class); if (fileElement == null) { return EMPTY_ARRAY; } final Ref<Object[]> ref = new Ref<>(ArrayUtil.EMPTY_STRING_ARRAY); fileElement.acceptChildren(new RngDomVisitor(){ @Override public void visit(RngGrammar grammar) { final Map<String, Set<Define>> map = DefinitionResolver.getAllVariants(grammar); if (map != null) { ref.set(map.keySet().toArray()); } } }); return ref.get(); } } return ArrayUtil.EMPTY_STRING_ARRAY; // TODO: look for unresolved refs; } } }; } return new PsiReference[]{ new DefinitionReference(e) }; }
protected abstract Object[] getVariants(@NotNull PsiReferenceBase reference);