Java 类com.intellij.psi.PsiReferenceBase 实例源码

项目:intellij-ce-playground    文件:MavenCompletionReferenceProvider.java   
@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);
      }
    }
  };
}
项目:intellij-ce-playground    文件:FixedValuesReferenceProvider.java   
@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;
      }
    }
  };
}
项目:tools-idea    文件:MavenCompletionReferenceProvider.java   
@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);
      }
    }
  };
}
项目:ouzo-phpstorm-plugin    文件:RelationClassReferenceProvider.java   
@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};
}
项目:consulo-apache-velocity    文件:VtlBreak.java   
@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;
        }
    };
}
项目:intellij-ce-playground    文件:JavadocHighlightingTest.java   
@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;
}
项目:intellij-ce-playground    文件:RncDefineImpl.java   
@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();
}
项目:intellij-ce-playground    文件:MavenCommonParamReferenceProviders.java   
@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;
}
项目:intellij    文件:GlobReferenceSearcher.java   
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;
    }
  };
}
项目:tools-idea    文件:RncDefineImpl.java   
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();
}
项目:tools-idea    文件:MavenCommonParamReferenceProviders.java   
@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;
}
项目:ouzo-phpstorm-plugin    文件:ControllerActionReferenceProvider.java   
@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};
}
项目:idea-php-symfony2-plugin    文件:PhpStringLiteralExpressionReference.java   
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];
    }
项目:consulo-xml    文件:RncDefineImpl.java   
@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();
}
项目:consulo-java    文件:JavadocCompletionTest.java   
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);
  }
}
项目:intellij-ce-playground    文件:RngReferenceConverter.java   
@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)
    };
  }
项目:intellij-ce-playground    文件:MavenCommonParamReferenceProviders.java   
@Override
protected Object[] getVariants(@NotNull PsiReferenceBase reference) {
  return MavenUtil.getPhaseVariants(MavenProjectsManager.getInstance(reference.getElement().getProject())).toArray();
}
项目:intellij-ce-playground    文件:MavenCommonParamReferenceProviders.java   
@Override
protected Object[] getVariants(@NotNull PsiReferenceBase reference) {
  return MavenProjectsManager.getInstance(reference.getElement().getProject()).getAvailableProfiles().toArray();
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLEndpointNamedTypePsiElement.java   
@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;
}
项目:tools-idea    文件:RngReferenceConverter.java   
@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)
    };
  }
项目:tools-idea    文件:MavenCommonParamReferenceProviders.java   
@Override
protected Object[] getVariants(@NotNull PsiReferenceBase reference) {
  return MavenUtil.getPhaseVariants(MavenProjectsManager.getInstance(reference.getElement().getProject())).toArray();
}
项目:tools-idea    文件:MavenCommonParamReferenceProviders.java   
@Override
protected Object[] getVariants(@NotNull PsiReferenceBase reference) {
  return MavenProjectsManager.getInstance(reference.getElement().getProject()).getAvailableProfiles().toArray();
}
项目:consulo-xml    文件:RngReferenceConverter.java   
@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)
    };
  }
项目:intellij-ce-playground    文件:MavenCompletionReferenceProvider.java   
protected abstract Object[] getVariants(@NotNull PsiReferenceBase reference);
项目:tools-idea    文件:MavenCompletionReferenceProvider.java   
protected abstract Object[] getVariants(@NotNull PsiReferenceBase reference);