com.intellij.psi.PsiReference Java Examples

The following examples show how to use com.intellij.psi.PsiReference. 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: CypherVariableElement.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@Override
default CypherType getType() {
    return Optional.ofNullable(getReferences())
            .filter(reference -> reference.length > 0)
            .map(reference -> reference[0])
            .map(PsiReference::resolve)
            .map(PsiElement::getParent)
            .map(node -> {
                if (node instanceof CypherNodePattern) {
                    return NODE;
                } else if (node instanceof CypherPatternPart) {
                    return PATH;
                } else if (node instanceof CypherRelationshipDetail) {
                    return resolveRelationshipType((CypherRelationshipDetail) node);
                }

                return null;
            })
            .orElse(ANY);
}
 
Example #2
Source File: GrammarElementRefTest.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private PsiElement resolveRefAtCaret() {
	PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

	if (elementAtCaret != null) {
		PsiReference ref = elementAtCaret.getReference();

		if (ref != null) {
			return ref.resolve();
		} else {
			fail("No reference at caret");
		}
	} else {
		fail("No element at caret");
	}

	return null;
}
 
Example #3
Source File: ConfigEntityTypeAnnotation.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiReference[] getPropertyReferences(AnnotationPropertyParameter parameter, PhpAnnotationReferenceProviderParameter phpAnnotationReferenceProviderParameter) {
    if(!isSupported(parameter)) {
        return new PsiReference[0];
    }

    String propertyName = parameter.getPropertyName();

    if("admin_permission".equalsIgnoreCase(propertyName)) {
        String contents = getContents(parameter.getElement());
        if(StringUtils.isBlank(contents)) {
            return new PsiReference[0];
        }

        return new PsiReference[] {new ContentEntityTypeAnnotation.MyPermissionPsiPolyVariantReferenceBase(parameter.getElement(), contents)};
    }

    return new PsiReference[0];
}
 
Example #4
Source File: SQFVariable.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferences() {
	SQFFile sqfFile = (SQFFile) getContainingFile();
	if (sqfFile == null) {
		return PsiReference.EMPTY_ARRAY;
	}
	List<SQFVariable> vars = new ArrayList<>();
	PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
		PsiElement nodeAsElement = astNode.getPsi();
		if (nodeAsElement instanceof SQFVariable) {
			SQFVariable var = (SQFVariable) nodeAsElement;
			if (var.isLocal()) {
				return false;
			}
			if (SQFVariableName.nameEquals(var.getVarName(), getVarName())) {
				vars.add(var);
			}
		}
		return false;
	});
	if (vars.isEmpty()) {
		return PsiReference.EMPTY_ARRAY;
	}
	return new PsiReference[]{new SQFVariableReference.IdentifierReference(this, vars)};
}
 
Example #5
Source File: SingleTargetRequestResultProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean processTextOccurrence(@Nonnull PsiElement element, int offsetInElement, @Nonnull final Processor<? super PsiReference> consumer) {
  if (!myTarget.isValid()) {
    return false;
  }

  final List<PsiReference> references = ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myTarget, offsetInElement));
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < references.size(); i++) {
    PsiReference ref = references.get(i);
    ProgressManager.checkCanceled();
    if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) {
      return false;
    }
  }
  return true;
}
 
Example #6
Source File: IdentifierMixin.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@Override
public PsiReference[] getReferences() {
  PsiElement element = getNode().getPsi();
  String maybeEmbeddedExpression = this.getText();
  if (!maybeEmbeddedExpression.startsWith("\"")) {
    PsiReference singleReference = getReference();
    return singleReference == null
        ? PsiReference.EMPTY_ARRAY
        : new PsiReference[]{singleReference};
  }

  Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher(maybeEmbeddedExpression);
  List<PsiReference> variableReferenceList = new ArrayList<>();
  while (identifierMatcher.find()) {
    variableReferenceList.add(
        new VariableDefinitionReference(
            element,
            maybeEmbeddedExpression.substring(
                identifierMatcher.start() + 1, identifierMatcher.end()),
            new TextRange(
                element.getTextRange().getStartOffset() + identifierMatcher.start(),
                element.getTextRange().getStartOffset() + identifierMatcher.end()),
            new TextRange(identifierMatcher.start(), identifierMatcher.end())));
  }
  return variableReferenceList.toArray(new PsiReference[variableReferenceList.size()]);
}
 
Example #7
Source File: JSGraphQLEndpointErrorAnnotator.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
private JSGraphQLEndpointFieldDefinition getOverriddenField(JSGraphQLEndpointFieldDefinition override) {
	final String propertyName = override.getProperty().getIdentifier().getText();
	final JSGraphQLEndpointObjectTypeDefinition typeDefinition = PsiTreeUtil.getParentOfType(override, JSGraphQLEndpointObjectTypeDefinition.class);
	if (typeDefinition != null) {
		final JSGraphQLEndpointImplementsInterfaces implementsInterfaces = PsiTreeUtil.findChildOfType(typeDefinition, JSGraphQLEndpointImplementsInterfaces.class);
		if (implementsInterfaces != null) {
			for (JSGraphQLEndpointNamedType namedType : implementsInterfaces.getNamedTypeList()) {
				final PsiReference reference = namedType.getReference();
				if (reference != null) {
					final PsiElement interfaceTypeName = reference.resolve();
					if (interfaceTypeName != null) {
						final JSGraphQLEndpointInterfaceTypeDefinition interfaceTypeDefinition = PsiTreeUtil.getParentOfType(interfaceTypeName, JSGraphQLEndpointInterfaceTypeDefinition.class);
						if (interfaceTypeDefinition != null) {
							for (JSGraphQLEndpointProperty property : PsiTreeUtil.findChildrenOfType(interfaceTypeDefinition, JSGraphQLEndpointProperty.class)) {
								if (property.getIdentifier().getText().equals(propertyName)) {
									return PsiTreeUtil.getParentOfType(property, JSGraphQLEndpointFieldDefinition.class);
								}
							}
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example #8
Source File: BlazePackageFindUsagesTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testLabelFragmentReferenceFound() {
  BuildFile foo =
      createBuildFile(
          new WorkspacePath("java/com/google/foo/BUILD"), "java_library(name = \"lib\")");

  BuildFile bar =
      createBuildFile(
          new WorkspacePath("java/com/google/bar/BUILD"),
          "java_library(name = \"lib2\", exports = [\"//java/com/google/foo:lib\"])");

  PsiReference[] references = FindUsages.findAllReferences(foo);
  assertThat(references).hasLength(1);

  PsiElement ref = references[0].getElement();
  assertThat(ref).isInstanceOf(StringLiteral.class);
  assertThat(ref.getContainingFile()).isEqualTo(bar);
}
 
Example #9
Source File: VarResolveTestCase.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicResolveUnknownGlobalVariable() throws Exception {
    final PsiReference psiReference = configure();

    //must not resolve because the definition is local due to the previous definition
    PsiElement varDef = psiReference.resolve();
    Assert.assertNull("The vardef should not be found, because it is undefined", varDef);

    //the variable must not be a valid reference to the following var def

    final AtomicInteger visited = new AtomicInteger(0);
    psiReference.getElement().getContainingFile().acceptChildren(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof BashVarDef) {
                visited.incrementAndGet();
                Assert.assertFalse("A var def must not be a valid definition for the variable used.",
                        psiReference.isReferenceTo(element));
            }

            super.visitElement(element);
        }
    });
    Assert.assertEquals(1, visited.get());
}
 
Example #10
Source File: HaskellGoToSymbolTest.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2() {
    PsiFile[] psiFiles = myFixture.configureByFiles(
            "QualifiedImport_QualifierResolvesMultipleCons_Cons2/Usage.hs",
            "QualifiedImport_QualifierResolvesMultipleCons_Cons2/Definition.hs"
    );
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("as Def.Lef") + 7;
    PsiElement psiElement = usage
            .findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}
 
Example #11
Source File: GenericInlineHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element,
                                                                      InlineHandler.Settings settings,
                                                                      Collection<? extends PsiReference> allReferences) {
  final Map<Language, InlineHandler.Inliner> inliners = new HashMap<Language, InlineHandler.Inliner>();
  for (PsiReference ref : allReferences) {
    if (ref == null) {
      LOG.error("element: " + element.getClass()+ ", allReferences contains null!");
      continue;
    }
    PsiElement refElement = ref.getElement();
    LOG.assertTrue(refElement != null, ref.getClass().getName());

    final Language language = refElement.getLanguage();
    if (inliners.containsKey(language)) continue;

    final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
    for (InlineHandler handler : handlers) {
      InlineHandler.Inliner inliner = handler.createInliner(element, settings);
      if (inliner != null) {
        inliners.put(language, inliner);
        break;
      }
    }
  }
  return inliners;
}
 
Example #12
Source File: ChangeSignatureAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static PsiElement findTargetMember(@Nullable PsiElement element) {
  if (element == null) return null;
  final ChangeSignatureHandler fileHandler = getChangeSignatureHandler(element.getLanguage());
  if (fileHandler != null) {
    final PsiElement targetMember = fileHandler.findTargetMember(element);
    if (targetMember != null) return targetMember;
  }
  PsiReference reference = element.getReference();
  if (reference == null && element instanceof PsiNameIdentifierOwner) {
    return element;
  }
  if (reference != null) {
    return reference.resolve();
  }
  return null;
}
 
Example #13
Source File: PackageTest.java    From WebStormRequireJsPlugin with MIT License 5 votes vote down vote up
public void testReference10()
{
    myFixture.configureByFile("public/packages/filePackagesResolveTest.js");
    PsiReference reference;

    reference = getReferenceForHumanPosition(11, 35);
    assertReference(reference, "'locationMainPackage'", "location.js");
}
 
Example #14
Source File: HaskellGoToSymbolTest.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
public void testGoToSymbolFunction_CanReferenceOtherFunction(){
    myFixture.configureByFile(getTestName(false)+".hs");
    PsiFile file = myFixture.getFile();
    String textOfFile = file.getText();
    int expectedStartOffset= textOfFile.indexOf("test2 ::");
    PsiElement psiElement = file
            .findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid)reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset,referencedElement.getTextRange().getStartOffset());
}
 
Example #15
Source File: MakefileParsingTest.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public void testCheckRefResolve3() throws Throwable {
  myFixture.testHighlighting(getTestName() + ".mk");
  PsiReference psiReference = myFixture.getFile().findReferenceAt(myFixture.getEditor().getCaretModel().getOffset());
  assertTrue(psiReference instanceof PsiMultiReference);
  ResolveResult[] resolveResults = ((PsiMultiReference) psiReference).multiResolve(false);
  assertEquals(2, resolveResults.length);
  
  assertNotNull(resolveResults[0].getElement());
  assertNotNull(resolveResults[1].getElement());

  // TODO
  //assertEquals(2, ReferencesSearch.search(resolveResults[0].getElement()).findAll().size());
  //assertEquals(2, ReferencesSearch.search(resolveResults[1].getElement()).findAll().size());
}
 
Example #16
Source File: ExclamationMarkTest.java    From WebStormRequireJsPlugin with MIT License 5 votes vote down vote up
public void testReference4()
{
    myFixture.configureByFile("public/blocks/fileForReferenceTestWithExclamationMark.js");
    PsiReference reference;

    // 1
    reference = getReferenceForHumanPosition(5, 42);
    assertReference(reference, "'moduleOne!../fileWithExclamationMarkTest'", "fileWithExclamationMarkTest.js");
}
 
Example #17
Source File: VarDefResolveTestCase.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private BashVarDef assertIsValidVarDef() throws Exception {
    PsiReference ref = configure();
    PsiElement element = ref.resolve();
    Assert.assertNotNull("The definition could not be resolved.", element);
    Assert.assertTrue("The resolved definition is not a BashVarDef: " + element, element instanceof BashVarDef);
    Assert.assertFalse("The variable must not resolve to itself.", ref.equals(element));
    Assert.assertTrue("isReferenceTo is not working properly.", ref.isReferenceTo(element));

    return (BashVarDef) element;
}
 
Example #18
Source File: MapTest.java    From WebStormRequireJsPlugin with MIT License 5 votes vote down vote up
public void testReferenceNewModule() {
    PsiReference reference;

    myFixture.configureByFile("mapPublic/some/newModule.js");
    reference = getReferenceForHumanPosition(2, 26);
    assertReference(reference, "'foo'", "foo1.2.js");

    reference = getReferenceForHumanPosition(3, 26);
    assertReference(reference, "'bar'", "bar2.0r1.js");
}
 
Example #19
Source File: DotEnvReferencesSearcher.java    From idea-php-dotenv-plugin with MIT License 5 votes vote down vote up
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<? super PsiReference> consumer) {
    PsiElement refElement = queryParameters.getElementToSearch();
    if (!(refElement instanceof DotEnvProperty)) return;

    addPropertyUsages((DotEnvProperty)refElement, queryParameters.getEffectiveSearchScope(), queryParameters.getOptimizer());
}
 
Example #20
Source File: FilePathCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Pair<FileReference, Boolean> getReference(final PsiReference original) {
  if (original == null) {
    return null;
  }

  if (original instanceof PsiMultiReference) {
    final PsiMultiReference multiReference = (PsiMultiReference)original;
    for (PsiReference reference : multiReference.getReferences()) {
      if (reference instanceof FileReference) {
        if (((FileReference)reference).getFileReferenceSet().supportsExtendedCompletion()) {
          return Pair.create((FileReference)reference, false);
        }
      }
    }
  }
  else if (original instanceof FileReferenceOwner) {
    final PsiFileReference fileReference = ((FileReferenceOwner)original).getLastFileReference();
    if (fileReference instanceof FileReference) {
      if (((FileReference)fileReference).getFileReferenceSet().supportsExtendedCompletion()) {
        return Pair.create((FileReference)fileReference, true);
      }
    }
  }

  return null;
}
 
Example #21
Source File: PackageReferenceDiagramDataModel.java    From intellij-reference-diagram with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected Collection<PsiReference> resolveOuterReferences(PsiElement psiElement) {
    Collection<PsiReference> result = new ArrayList<>();
    if (!(psiElement instanceof PsiJavaFile)) {
        return result;
    }
    PsiClass[] classes = ((PsiJavaFile) psiElement).getClasses();
    for (PsiClass psiClass : classes) {
        result.addAll(ReferencesSearch.search(psiClass, GlobalSearchScopes.projectProductionScope(getProject())).findAll());
    }
    return result;
}
 
Example #22
Source File: SoyReferenceContributor.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(
    @NotNull PsiElement element,
    @NotNull ProcessingContext context) {
  return element.getReferences();
}
 
Example #23
Source File: FileRenameTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void doRename(boolean expectFileReference, Runnable renameLogic, String... sourceFiles) {
    myFixture.setTestDataPath(getTestDataPath() + getTestName(true));

    List<String> filenames = Lists.newArrayList(sourceFiles);
    filenames.add("target.bash");
    myFixture.configureByFiles(filenames.toArray(new String[filenames.size()]));

    renameLogic.run();

    for (String filename : sourceFiles) {
        myFixture.checkResultByFile(filename, FileUtil.getNameWithoutExtension(filename) + "_after." + FileUtilRt.getExtension(filename), false);
    }

    PsiElement psiElement;
    if (expectFileReference) {
        psiElement = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), BashFileReference.class);
        Assert.assertNotNull("file reference is null. Current: " + myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getText(), psiElement);
        Assert.assertTrue("Filename wasn't changed", psiElement.getText().contains("target_renamed.bash"));
    } else {
        psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
        Assert.assertNotNull("caret element is null", psiElement);

        while (psiElement.getReference() == null) {
            if (psiElement.getParent() == null) {
                break;
            }

            psiElement = psiElement.getParent();
        }
    }


    PsiReference psiReference = psiElement.getReference();
    Assert.assertNotNull("target file reference wasn't found", psiReference);
    Assert.assertTrue("Renamed reference wasn't found in the canonical text", psiReference.getCanonicalText().contains("target_renamed.bash"));

    PsiElement targetFile = psiReference.resolve();
    Assert.assertNotNull("target file resolve result wasn't found", targetFile);
    Assert.assertTrue("target is not a psi file", targetFile instanceof BashFile);
}
 
Example #24
Source File: SpecStepImplTest.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldGetReferenceInGaugeModule() throws Exception {
    ModuleHelper helper = mock(ModuleHelper.class);
    ASTNode node = mock(ASTNode.class);
    SpecStepImpl specStep = new SpecStepImpl(node, helper);
    when(helper.isGaugeModule(specStep)).thenReturn(true);

    PsiReference reference = specStep.getReference();

    assertEquals(reference.getClass(), StepReference.class);
}
 
Example #25
Source File: LoadedSkylarkExtensionTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverridenBuiltInSymbolReference() {
  setBuiltInRuleNames("java_library");
  BuildFile extFile =
      createBuildFile(
          new WorkspacePath("java/com/google/tools/build_defs.bzl"), "java_library = rule()");

  BuildFile buildFile =
      createBuildFile(
          new WorkspacePath("java/com/google/BUILD"),
          "load(",
          "\"//java/com/google/tools:build_defs.bzl\",",
          "\"java_library\"",
          ")",
          "java_library(name = 'name')");

  TargetExpression target =
      PsiUtils.findFirstChildOfClassRecursive(extFile, TargetExpression.class);
  FuncallExpression funcall = buildFile.firstChildOfClass(FuncallExpression.class);
  LoadedSymbol loadElement =
      PsiUtils.findFirstChildOfClassRecursive(buildFile, LoadedSymbol.class);

  assertThat(target).isNotNull();
  assertThat(funcall.getReferencedElement()).isEqualTo(target);
  assertThat(loadElement.getImport().getReferencedElement()).isEqualTo(target);

  assertThat(
          Arrays.stream(FindUsages.findAllReferences(target))
              .map(PsiReference::getElement)
              .collect(Collectors.toList()))
      .containsExactly(funcall, loadElement.getImport());
}
 
Example #26
Source File: ConfigParseTest.java    From WebStormRequireJsPlugin with MIT License 5 votes vote down vote up
public void testConfigWithRelativePathReference()
{
    PsiReference reference;

    initForTestConfigWithRelativePath();

    // 1
    reference = getReferenceForHumanPosition(11, 12);
    assertReference(reference, "'moduleOne'", "kit.js");
}
 
Example #27
Source File: ResourceReferenceContributorTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testResourceReferenceHasVariants() {
    myFixture.addFileToProject("foo/ext_emconf.php", "");
    myFixture.addFileToProject("foo/bar.txt", "");

    myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
            "'EXT:foo/ext_emconf.php<caret>';");

    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();

    ResourceReference target = null;
    PsiReference[] references = elementAtCaret.getReferences();
    for (PsiReference ref : references) {
        if (ref instanceof ResourceReference) {
            target = (ResourceReference) ref;
        }
    }

    if (target != null) {
        for (Object o : target.getVariants()) {
            if (o instanceof ResourceLookupElement && ((ResourceLookupElement) o).getLookupString().contains("EXT:foo/bar.txt")) {
                return;
            }
        }
    }

    fail("No resource reference.");
}
 
Example #28
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
/**
 * Single resolve doesnt work if we have non unique class names in project context,
 * so try a multiResolve
 */
@Nullable
public static Method[] getMultiResolvedMethod(PsiReference psiReference) {

    // class be unique in normal case, so try this first
    PsiElement resolvedReference = psiReference.resolve();
    if (resolvedReference instanceof Method) {
        return new Method[] { (Method) resolvedReference };
    }

    // try multiResolve if class exists twice in project
    if(psiReference instanceof PsiPolyVariantReference) {
        Collection<Method> methods = new HashSet<>();
        for(ResolveResult resolveResult : ((PsiPolyVariantReference) psiReference).multiResolve(false)) {
            PsiElement element = resolveResult.getElement();
            if(element instanceof Method) {
                methods.add((Method) element);
            }
        }

        if(methods.size() > 0) {
            return methods.toArray(new Method[methods.size()]);
        }

    }

    return null;
}
 
Example #29
Source File: RenamePsiFileProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Collection<PsiReference> findReferences(PsiElement element) {
  if (!getSearchForReferences(element)) {
    return Collections.emptyList();
  }
  return super.findReferences(element);
}
 
Example #30
Source File: CustomOptionReferenceTest.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
public void testImportedImportedCustomOptionReference() {
    myFixture.configureByFiles(
            "reference/options/custom/SimpleExtensionField.proto",
            "reference/options/custom/ImportedExtension.proto"
    );
    PsiReference reference = myFixture.getReferenceAtCaretPositionWithAssertion(
            "reference/options/custom/ImportedImportedExtension.proto"
    );
    PsiElement target = reference.resolve();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof FieldNode);
    FieldNode field = (FieldNode) target;
    Assert.assertEquals("bar", field.getFieldName());
    Assert.assertTrue(field.getParent() instanceof ExtendEntryNode);
}