com.intellij.psi.PsiQualifiedNamedElement Java Examples

The following examples show how to use com.intellij.psi.PsiQualifiedNamedElement. 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: InspectionResultsViewComparator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int compareEntity(final RefEntity entity, final PsiElement element) {
  if (entity instanceof RefElement) {
    final PsiElement psiElement = ((RefElement)entity).getElement();
    if (psiElement != null && element != null) {
      return PsiUtilCore.compareElementsByPosition(psiElement, element);
    }
    if (element == null) return psiElement == null ? 0 : 1;
  }
  if (element instanceof PsiQualifiedNamedElement) {
    return StringUtil.compare(entity.getQualifiedName(), ((PsiQualifiedNamedElement)element).getQualifiedName(), true);
  }
  if (element instanceof PsiNamedElement) {
    return StringUtil.compare(entity.getName(), ((PsiNamedElement)element).getName(), true);
  }
  return -1;
}
 
Example #2
Source File: RefactoringScopeElementListenerProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public RefactoringElementListener getListener(PsiElement element) {
  final PsiFile containingFile = element.getContainingFile();
  if (!(element instanceof PsiQualifiedNamedElement)) return null;
  final String oldName = ((PsiQualifiedNamedElement)element).getQualifiedName();
  RefactoringElementListenerComposite composite = null;
  for (final NamedScopesHolder holder : NamedScopeManager.getAllNamedScopeHolders(element.getProject())) {
    final NamedScope[] scopes = holder.getEditableScopes();
    for (int i = 0; i < scopes.length; i++) {
      final NamedScope scope = scopes[i];
      final PackageSet packageSet = scope.getValue();
      if (packageSet != null && (containingFile == null || packageSet.contains(containingFile, holder))) {
        composite = traverse(new OldScopeDescriptor(oldName, scope, i, holder), composite, packageSet);
      }
    }
  }
  return composite;
}
 
Example #3
Source File: RunConfigurationContext.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Convert a {@link #getSourceElement()} into an uniquely identifiable string. */
default String getSourceElementString() {
  if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
    return ReadAction.compute(this::getSourceElementString);
  }
  PsiElement element = getSourceElement();
  if (element instanceof PsiFile) {
    return Optional.of((PsiFile) element)
        .map(PsiFile::getVirtualFile)
        .map(VirtualFile::getPath)
        .orElse(element.toString());
  }
  String path =
      Optional.of(element)
              .map(PsiElement::getContainingFile)
              .map(PsiFile::getVirtualFile)
              .map(VirtualFile::getPath)
              .orElse("")
          + '#';
  if (element instanceof PsiQualifiedNamedElement) {
    return path + ((PsiQualifiedNamedElement) element).getQualifiedName();
  } else if (element instanceof PsiNamedElement) {
    return path + ((PsiNamedElement) element).getName();
  } else {
    return path + element.toString();
  }
}
 
Example #4
Source File: QuickDocUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Contract("_, _, _, null -> null")
public static String inferLinkFromFullDocumentation(@Nonnull DocumentationProvider provider, PsiElement element, PsiElement originalElement, @Nullable String navigationInfo) {
  if (navigationInfo != null) {
    String fqn = element instanceof PsiQualifiedNamedElement ? ((PsiQualifiedNamedElement)element).getQualifiedName() : null;
    String fullText = provider.generateDoc(element, originalElement);
    return HintUtil.prepareHintText(DocPreviewUtil.buildPreview(navigationInfo, fqn, fullText), HintUtil.getInformationHint());
  }
  return null;
}