本文整理汇总了Java中consulo.codeInsight.TargetElementUtil.findReference方法的典型用法代码示例。如果您正苦于以下问题:Java TargetElementUtil.findReference方法的具体用法?Java TargetElementUtil.findReference怎么用?Java TargetElementUtil.findReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类consulo.codeInsight.TargetElementUtil
的用法示例。
在下文中一共展示了TargetElementUtil.findReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: elementToFqn
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
public static String elementToFqn(final PsiElement element, @Nullable Editor editor) {
String result = QualifiedNameProviders.getQualifiedNameFromProviders(element);
if (result != null) return result;
if (editor != null) { //IDEA-70346
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
result = QualifiedNameProviders.getQualifiedNameFromProviders(reference.resolve());
if (result != null) return result;
}
}
String fqn = null;
if (element instanceof PsiFile) {
final PsiFile file = (PsiFile)element;
fqn = FileUtil.toSystemIndependentName(getFileFqn(file));
}
return fqn;
}
示例2: elementToFqn
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
private static String elementToFqn(@Nullable final PsiElement element, @Nullable Editor editor) {
String result = getQualifiedNameFromProviders(element);
if (result != null) return result;
if (editor != null) { //IDEA-70346
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
result = getQualifiedNameFromProviders(reference.resolve());
if (result != null) return result;
}
}
if (element instanceof PsiFile) {
return FileUtil.toSystemIndependentName(getFileFqn((PsiFile)element));
}
if (element instanceof PsiDirectory) {
return FileUtil.toSystemIndependentName(getVirtualFileFqn(((PsiDirectory)element).getVirtualFile(), element.getProject()));
}
return null;
}
示例3: canInlineElementInEditor
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Override
public boolean canInlineElementInEditor(PsiElement element, Editor editor)
{
if(canInlineElement(element))
{
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
if(!InlineMethodHandler.isThisReference(reference))
{
if(element instanceof PsiMethod && reference != null)
{
final PsiElement referenceElement = reference.getElement();
return referenceElement != null && !PsiTreeUtil.isAncestor(((PsiMethod) element).getContainingClass(), referenceElement, false);
}
return true;
}
}
return false;
}
示例4: inlineElement
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public void inlineElement(final Project project, final Editor editor, final PsiElement element) {
PsiClass superClass = (PsiClass) element;
Collection<PsiClass> inheritors = DirectClassInheritorsSearch.search((PsiClass)element).findAll();
if (!superClass.getManager().isInProject(superClass)) {
CommonRefactoringUtil.showErrorHint(project, editor, "Cannot inline non-project class", REFACTORING_NAME, null);
return;
}
for (PsiClass inheritor : inheritors) {
if (PsiTreeUtil.isAncestor(superClass, inheritor, false)) {
CommonRefactoringUtil.showErrorHint(project, editor, "Cannot inline into the inner class. Move \'" + inheritor.getName() + "\' to upper level", REFACTORING_NAME, null);
return;
}
if (inheritor instanceof PsiAnonymousClass) {
CommonRefactoringUtil.showErrorHint(project, editor, "Cannot inline into anonymous class.", REFACTORING_NAME, null);
return;
}
}
PsiClass chosen = null;
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
if (reference != null) {
final PsiElement resolve = reference.resolve();
if (resolve == superClass) {
final PsiElement referenceElement = reference.getElement();
if (referenceElement != null) {
final PsiElement parent = referenceElement.getParent();
if (parent instanceof PsiReferenceList) {
final PsiElement gParent = parent.getParent();
if (gParent instanceof PsiClass && inheritors.contains(gParent)) {
chosen = (PsiClass)gParent;
}
}
}
}
}
new InlineSuperClassRefactoringDialog(project, superClass, chosen, inheritors.toArray(new PsiClass[inheritors.size()])).show();
}
示例5: findTargetElementUnsafe
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
/**
* in case index is not ready will throw IndexNotReadyException
*/
@Nullable
private PsiElement findTargetElementUnsafe(final Editor editor, int offset, @Nullable final PsiFile file, PsiElement contextElement) {
PsiElement element = assertSameProject(getElementFromLookup(editor, file));
if (element == null && file != null) {
final DocumentationProvider documentationProvider = getProviderFromElement(file);
if (documentationProvider instanceof DocumentationProviderEx) {
element = assertSameProject(((DocumentationProviderEx)documentationProvider).getCustomDocumentationElement(editor, file, contextElement));
}
}
if (element == null) {
element = assertSameProject(TargetElementUtil.findTargetElement(editor, TargetElementUtil.getAllAccepted(), offset));
// Allow context doc over xml tag content
if (element != null || contextElement != null) {
final PsiElement adjusted = assertSameProject(TargetElementUtil.adjustElement(editor, TargetElementUtil.getAllAccepted(), element, contextElement));
if (adjusted != null) {
element = adjusted;
}
}
}
if (element == null) {
final PsiReference ref = TargetElementUtil.findReference(editor, offset);
if (ref != null) {
element = assertSameProject(TargetElementUtil.adjustReference(ref));
if (ref instanceof PsiPolyVariantReference) {
element = assertSameProject(ref.getElement());
}
}
}
storeOriginalElement(myProject, contextElement, element);
return element;
}
示例6: getElementFromLookup
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
public PsiElement getElementFromLookup(final Editor editor, @Nullable final PsiFile file) {
final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup();
if (activeLookup != null) {
LookupElement item = activeLookup.getCurrentItem();
if (item != null) {
int offset = editor.getCaretModel().getOffset();
if (offset > 0 && offset == editor.getDocument().getTextLength()) offset--;
PsiReference ref = TargetElementUtil.findReference(editor, offset);
PsiElement contextElement = file == null? null : file.findElementAt(offset);
PsiElement targetElement = ref != null ? ref.getElement() : contextElement;
if (targetElement != null) {
PsiUtilCore.ensureValid(targetElement);
}
DocumentationProvider documentationProvider = getProviderFromElement(file);
PsiManager psiManager = PsiManager.getInstance(myProject);
return documentationProvider.getDocumentationElementForLookupItem(psiManager, item.getObject(), targetElement);
}
}
return null;
}
示例7: getUsageTargets
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
private static UsageTarget[] getUsageTargets(@Nonnull Editor editor, PsiFile file) {
UsageTarget[] usageTargets = UsageTargetUtil.findUsageTargets(editor, file);
if (usageTargets == null) {
PsiElement targetElement = getTargetElement(editor, file);
if (targetElement != null && targetElement != file) {
if (!(targetElement instanceof NavigationItem)) {
targetElement = targetElement.getNavigationElement();
}
if (targetElement instanceof NavigationItem) {
usageTargets = new UsageTarget[]{new PsiElement2UsageTargetAdapter(targetElement)};
}
}
}
if (usageTargets == null) {
PsiReference ref = TargetElementUtil.findReference(editor);
if (ref instanceof PsiPolyVariantReference) {
ResolveResult[] results = ((PsiPolyVariantReference)ref).multiResolve(false);
if (results.length > 0) {
usageTargets = ContainerUtil.mapNotNull(results, result -> {
PsiElement element = result.getElement();
return element == null ? null : new PsiElement2UsageTargetAdapter(element);
}, UsageTarget.EMPTY_ARRAY);
}
}
}
return usageTargets;
}
示例8: getElement
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
private static PsiElement getElement(DataContext dataContext, Editor editor) {
PsiElement element = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
if (element == null && editor != null) {
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
element = reference.getElement();
}
}
return element;
}
示例9: actionPerformed
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@RequiredDispatchThread
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
Project project = dataContext.getData(CommonDataKeys.PROJECT);
List<PsiElement> elements = getElementsToCopy(editor, dataContext);
if (!doCopy(elements, project, editor) && editor != null && project != null) {
Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
if (file != null) {
String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
CopyPasteManager.getInstance().setContents(new StringSelection(toCopy));
setStatusBarText(project, toCopy + " has been copied");
}
return;
}
HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (elements.size() == 1 && editor != null && project != null) {
PsiElement element = elements.get(0);
PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element);
if (nameIdentifier != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{nameIdentifier}, attributes, true, null);
} else {
PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (reference != null) {
highlightManager.addOccurrenceHighlights(editor, new PsiReference[]{reference}, attributes, true, null);
} else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) {
highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{element}, attributes, true, null);
}
}
}
}
示例10: getElementsToCopy
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nonnull
private static List<PsiElement> getElementsToCopy(@Nullable final Editor editor, final DataContext dataContext) {
List<PsiElement> elements = ContainerUtil.newArrayList();
if (editor != null) {
PsiReference reference = TargetElementUtil.findReference(editor);
if (reference != null) {
ContainerUtil.addIfNotNull(elements, reference.getElement());
}
}
if (elements.isEmpty()) {
ContainerUtil.addIfNotNull(elements, dataContext.getData(CommonDataKeys.PSI_ELEMENT));
}
if (elements.isEmpty() && editor == null) {
final Project project = dataContext.getData(CommonDataKeys.PROJECT);
VirtualFile[] files = dataContext.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (project != null && files != null) {
for (VirtualFile file : files) {
ContainerUtil.addIfNotNull(elements, PsiManager.getInstance(project).findFile(file));
}
}
}
return ContainerUtil.mapNotNull(elements, new Function<PsiElement, PsiElement>() {
@Override
public PsiElement fun(PsiElement element) {
return element instanceof PsiFile && !((PsiFile)element).getViewProvider().isPhysical() ? null : adjustElement(element);
}
});
}
示例11: isAvailable
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!(file instanceof PsiJavaFile)) return false;
final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
if (element instanceof PsiIdentifier) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiClass) {
return isEmptyClass(project, (PsiClass)parent) && DirectClassInheritorsSearch.search((PsiClass)parent).findFirst() != null;
}
}
final PsiReference psiReference = TargetElementUtil.findReference(editor);
if (psiReference == null) return false;
final PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(psiReference.getElement(), PsiReferenceList.class);
if (referenceList == null) return false;
final PsiClass psiClass = PsiTreeUtil.getParentOfType(referenceList, PsiClass.class);
if (psiClass == null) return false;
if (psiClass.getExtendsList() != referenceList && psiClass.getImplementsList() != referenceList) return false;
final PsiElement target = psiReference.resolve();
if (target == null || !(target instanceof PsiClass)) return false;
return isEmptyClass(project, (PsiClass)target);
}
示例12: isAvailable
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!(file instanceof PsiJavaFile)) return false;
final PsiReference psiReference = TargetElementUtil.findReference(editor);
if (psiReference == null) return false;
final PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(psiReference.getElement(), PsiReferenceList.class);
if (referenceList == null) return false;
final PsiClass psiClass = PsiTreeUtil.getParentOfType(referenceList, PsiClass.class);
if (psiClass == null) return false;
if (psiClass.getExtendsList() != referenceList && psiClass.getImplementsList() != referenceList) return false;
PsiJavaCodeReferenceElement referenceElement = getTopLevelRef(psiReference, referenceList);
if (referenceElement == null) return false;
final PsiElement target = referenceElement.resolve();
if (target == null || !(target instanceof PsiClass)) return false;
PsiClass targetClass = (PsiClass)target;
if (targetClass.isInterface()) {
myName = "Interface";
}
else {
myName = "Class";
}
return true;
}
示例13: performDefInline
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public static void performDefInline(Project project, Editor editor) {
PsiReference reference = TargetElementUtil.findReference(editor);
assertTrue(reference instanceof PsiReferenceExpression);
final PsiElement local = reference.resolve();
assertTrue(local instanceof PsiLocalVariable);
InlineLocalHandler.invoke(project, editor, (PsiLocalVariable)local, (PsiReferenceExpression)reference);
}
示例14: findCallToInline
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
@Nullable
public static PsiCall findCallToInline(final Editor editor)
{
PsiCall callToInline = null;
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor) : null;
if(reference != null)
{
final PsiElement element = reference.getElement();
if(element instanceof PsiJavaCodeReferenceElement)
{
callToInline = RefactoringUtil.getEnclosingConstructorCall((PsiJavaCodeReferenceElement) element);
}
}
return callToInline;
}
示例15: performForContext
import consulo.codeInsight.TargetElementUtil; //导入方法依赖的package包/类
public void performForContext(@Nonnull DataContext dataContext, boolean invokedByShortcut) {
final Project project = dataContext.getData(CommonDataKeys.PROJECT);
if (project == null) return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
PsiFile file = dataContext.getData(CommonDataKeys.PSI_FILE);
Editor editor = getEditor(dataContext);
PsiElement element = dataContext.getData(CommonDataKeys.PSI_ELEMENT);
boolean isInvokedFromEditor = dataContext.getData(CommonDataKeys.EDITOR) != null;
element = getElement(project, file, editor, element);
if (element == null && file == null) return;
PsiFile containingFile = element != null ? element.getContainingFile() : file;
if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return;
PsiReference ref = null;
if (editor != null) {
ref = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset());
if (element == null && ref != null) {
element = TargetElementUtil.adjustReference(ref);
}
}
//check attached sources if any
if (element instanceof PsiCompiledElement) {
element = element.getNavigationElement();
}
String text = "";
PsiElement[] impls = PsiElement.EMPTY_ARRAY;
if (element != null) {
impls = getSelfAndImplementations(editor, element, createImplementationsSearcher());
text = SymbolPresentationUtil.getSymbolPresentableText(element);
}
if (impls.length == 0 && ref instanceof PsiPolyVariantReference) {
final PsiPolyVariantReference polyReference = (PsiPolyVariantReference)ref;
PsiElement refElement = polyReference.getElement();
TextRange rangeInElement = polyReference.getRangeInElement();
String refElementText = refElement.getText();
LOG.assertTrue(rangeInElement.getEndOffset() <= refElementText.length(),
"Ref:" + polyReference + "; refElement: " + refElement + "; refText:" + refElementText);
text = rangeInElement.substring(refElementText);
final ResolveResult[] results = polyReference.multiResolve(false);
final List<PsiElement> implsList = new ArrayList<>(results.length);
for (ResolveResult result : results) {
final PsiElement resolvedElement = result.getElement();
if (resolvedElement != null && resolvedElement.isPhysical()) {
implsList.add(resolvedElement);
}
}
if (!implsList.isEmpty()) {
impls = implsList.toArray(new PsiElement[implsList.size()]);
}
}
showImplementations(impls, project, text, editor, file, element, isInvokedFromEditor, invokedByShortcut);
}