本文整理汇总了Java中com.intellij.psi.PsiReference类的典型用法代码示例。如果您正苦于以下问题:Java PsiReference类的具体用法?Java PsiReference怎么用?Java PsiReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiReference类属于com.intellij.psi包,在下文中一共展示了PsiReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prepareRenaming
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@Override
public void prepareRenaming(PsiElement psiElement, String s, Map<PsiElement, String> map) {
renders.clear();
for (PsiReference reference : findReferences(psiElement)) {
final PsiElement element = reference.getElement();
if (element instanceof StringLiteralExpression) {
String fileName = ((StringLiteralExpression) element).getContents();
if (fileName.contains("/")) {
element.getParent().putUserData(RELATIVE_PATH, fileName.substring(0, fileName.lastIndexOf('/') + 1));
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
}
element.getParent().putUserData(WITH_EXT, fileName.contains("."));
String realFile = ((PsiFile) psiElement).getName();
if (realFile.contains(".")) {
element.getParent().putUserData(OLD_EXT, realFile.substring(realFile.lastIndexOf('.')));
}
renders.add(element.getParent());
}
}
}
示例2: execute
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
String selector;
if (element instanceof AppleScriptHandlerCall) {
AppleScriptHandlerCall handlerCall = (AppleScriptHandlerCall) element;
selector = handlerCall.getHandlerSelector();
if (myHandlerSelector.equals(selector)) {
for (PsiReference ref : element.getReferences()) {
if (ref.isReferenceTo(myHandler)) {
return myConsumer.process(ref);
}
}
}
}
return true;
}
示例3: doExecute
import com.intellij.psi.PsiReference; //导入依赖的package包/类
private Boolean doExecute(ReferencesSearch.SearchParameters queryParameters, final Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch(); //was selector_identifier->redefined in
DictionaryComponent dictionaryComponent = null;
if (element instanceof DictionaryComponent) {
dictionaryComponent = (DictionaryComponent) element;
}
if (dictionaryComponent == null) return true;
final List<String> parts = dictionaryComponent.getNameIdentifiers();
if (parts.isEmpty())
return true;
final String componentName = dictionaryComponent.getName(); //or just getName()...
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
String searchWord = parts.get(0);
return searchWord.isEmpty() || helper.processElementsWithWord(new MyOccurrenceProcessor(dictionaryComponent, componentName, consumer),
queryParameters.getScopeDeterminedByUser(), searchWord, UsageSearchContext.IN_CODE, true);
}
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:21,代码来源:AppleScriptDictionaryComponentReferencesSearch.java
示例4: execute
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
String selector = null;
if (element instanceof AppleScriptCommandHandlerCall) {
AppleScriptCommandHandlerCall handlerCall = (AppleScriptCommandHandlerCall) element;
selector = handlerCall.getCommandName();
}//todo: handle other component types
else if (element instanceof DictionaryCompositeElement) {
DictionaryCompositeElement dictionaryCompositeElement = (DictionaryCompositeElement) element;
selector = dictionaryCompositeElement.getCompositeNameElement().getCompositeName();
}
if (selector != null) {
boolean selectorMatches;
selectorMatches = myComponentName.equals(selector);
if (selectorMatches) {
for (PsiReference ref : element.getReferences()) {
if (ref.isReferenceTo(myDictionaryComponent)) {
return myConsumer.process(ref);
}
}
}
}
return true;
}
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:25,代码来源:AppleScriptDictionaryComponentReferencesSearch.java
示例5: should_process_reference
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@Test
public void should_process_reference() throws Exception {
// given
PsiReference reference1 = mock(PsiReference.class);
PsiReference reference2 = mock(PsiReference.class);
PsiField field = mock(PsiField.class);
ReferencesSearch.SearchParameters searchParameters = mock(ReferencesSearch.SearchParameters.class);
when(searchParameters.getElementToSearch()).thenReturn(field);
when(searchParameters.getEffectiveSearchScope()).thenReturn(mock(GlobalSearchScope.class));
when(scenarioStateReferenceProvider.findReferences(field)).thenReturn(Arrays.asList(reference1, reference2));
when(scenarioStateProvider.isJGivenScenarioState(field)).thenReturn(true);
// when
referenceProvider.processQuery(searchParameters, processor);
// then
verify(processor).process(reference1);
verify(processor).process(reference2);
}
示例6: annotate
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
if (!(psiElement instanceof StringLiteralExpression)) {
return;
}
StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
String value = literalExpression.getContents();
if (value.isEmpty()) {
return;
}
for (PsiReference psiReference : literalExpression.getReferences()) {
if (psiReference instanceof RouteReference) {
annotateRoute(psiElement, annotationHolder, value);
}
}
}
示例7: buildFoldRegions
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
FoldingGroup group = FoldingGroup.newGroup("TYPO3Route");
List<FoldingDescriptor> descriptors = new ArrayList<>();
Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);
for (final StringLiteralExpression literalExpression : literalExpressions) {
for (PsiReference reference : literalExpression.getReferences()) {
if (reference instanceof RouteReference) {
String value = literalExpression.getContents();
FoldingDescriptor descriptor = foldRouteReferenceString(reference, value, group);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
}
}
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
示例8: testReferenceCanResolveDefinition
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testReferenceCanResolveDefinition() {
PsiFile file = myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
"class ActionController {" +
"public function action() {" +
" $this->forward('<caret>baz');" +
"}" +
"}"
);
PsiElement elementAtCaret = file.findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference reference : references) {
if (reference instanceof ControllerActionReference) {
ResolveResult[] resolveResults = ((ControllerActionReference) reference).multiResolve(false);
for (ResolveResult resolveResult : resolveResults) {
assertInstanceOf(resolveResult.getElement(), Method.class);
return;
}
}
}
fail("No TranslationReference found");
}
示例9: testCanCreateTranslationReferencesOnPhpStrings
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testCanCreateTranslationReferencesOnPhpStrings() {
PsiFile file = myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
"class ActionController {" +
"public function action() {" +
" $this->forward('<caret>baz');" +
"}" +
"}"
);
PsiElement elementAtCaret = file.findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference reference : references) {
if (reference instanceof ControllerActionReference) {
return;
}
}
fail("No ControllerActionReference found");
}
示例10: testResourceReferencesAreCreated
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testResourceReferencesAreCreated() {
myFixture.addFileToProject("foo/ext_emconf.php", "");
myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
"'EXT:foo/ext_emconf.php<caret>';");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference ref : references) {
if (ref instanceof ResourceReference) {
return;
}
}
fail("No resource reference.");
}
示例11: testReferenceCanResolveDefinition
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testReferenceCanResolveDefinition() {
PsiFile file = myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
"\"LLL:EXT:foo/sample.xlf:sys_<caret>language.language_isocode.ab\";");
PsiElement elementAtCaret = file.findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference reference : references) {
if (reference instanceof TranslationReference) {
ResolveResult[] resolveResults = ((TranslationReference) reference).multiResolve(false);
for (ResolveResult resolveResult : resolveResults) {
assertInstanceOf(resolveResult.getElement(), XmlTag.class);
return;
}
}
}
fail("No TranslationReference found");
}
示例12: testReferenceCanResolveVariants
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testReferenceCanResolveVariants() {
PsiFile file = myFixture.configureByText(PhpFileType.INSTANCE, "<?php \n" +
"\"LLL:EXT:foo/sample.xlf:sys_<caret>language.language_isocode.ab\";");
PsiElement elementAtCaret = file.findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference reference : references) {
if (reference instanceof TranslationReference) {
Object[] variants = reference.getVariants();
for (Object variant : variants) {
if (variant instanceof LookupElement) {
String lookupString = ((LookupElement) variant).getLookupString();
assertEquals("LLL:EXT:foo/sample.xlf:sys_language.language_isocode.ab", lookupString);
return;
}
}
}
}
fail("No TranslationReference found");
}
示例13: testIconReferenceIsCreatedOnGetIcon
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testIconReferenceIsCreatedOnGetIcon() {
myFixture.addFileToProject("foo/ext_emconf.php", "");
myFixture.configureByFile("IconRegistry9.php");
myFixture.configureByFile("icon_provider_test.php");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference ref : references) {
if (ref instanceof IconReference) {
return;
}
}
fail("No icon reference found");
}
示例14: testIconReferenceIsCreatedOnGetIconFromGeneralUtility
import com.intellij.psi.PsiReference; //导入依赖的package包/类
public void testIconReferenceIsCreatedOnGetIconFromGeneralUtility() {
myFixture.addFileToProject("foo/ext_emconf.php", "");
myFixture.configureByFile("IconRegistry9.php");
myFixture.configureByFile("general_utility_icon_provider_test.php");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();
PsiReference[] references = elementAtCaret.getReferences();
for (PsiReference ref : references) {
if (ref instanceof IconReference) {
return;
}
}
fail("No icon reference found");
}
示例15: getReferencesByElement
import com.intellij.psi.PsiReference; //导入依赖的package包/类
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (!(element instanceof XmlElement)) {
return PsiReference.EMPTY_ARRAY;
}
List<PsiReference> psiReferences = new ArrayList<>();
String methodName = StringUtil.unquoteString(element.getText());
PhpClass phpClass = DiIndex.getPhpClassOfServiceMethod((XmlElement) element);
if (phpClass != null) {
Collection<Method> methods = phpClass.getMethods();
methods.removeIf(m -> !m.getName().equalsIgnoreCase(methodName));
psiReferences.add(new PolyVariantReferenceBase(element, methods));
}
return psiReferences.toArray(new PsiReference[psiReferences.size()]);
}