com.intellij.psi.PsiReferenceBase Java Examples

The following examples show how to use com.intellij.psi.PsiReferenceBase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlobReferenceSearcher.java    From intellij with Apache License 2.0 5 votes vote down vote up
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;
    }
  };
}
 
Example #2
Source File: GraphQLDirectiveLocationPsiElement.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public PsiReference getReference() {
    final Ref<PsiReference> reference = new Ref<>();
    final GraphQLDirectiveLocationPsiElement psiElement = this;
    final String locationName = psiElement.getText();
    GraphQLPsiSearchHelper.getService(getProject()).getBuiltInSchema().accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof GraphQLEnumValue && element.getText().equals(locationName)) {
                final GraphQLIdentifier referencedEnumValue = ((GraphQLEnumValue) element).getNameIdentifier();
                reference.set(new PsiReferenceBase<PsiElement>(psiElement, new TextRange(0, psiElement.getTextLength())) {
                    @Nullable
                    @Override
                    public PsiElement resolve() {
                        return referencedEnumValue;
                    }

                    @NotNull
                    @Override
                    public Object[] getVariants() {
                        return PsiReference.EMPTY_ARRAY;
                    }
                });
                return; // done visiting
            }
            super.visitElement(element);
        }
    });
    return reference.get();
}
 
Example #3
Source File: PhpStringLiteralExpressionReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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];
    }
 
Example #4
Source File: JSGraphQLEndpointNamedTypePsiElement.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
@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;
}