Java 类com.intellij.psi.SmartPsiElementPointer 实例源码

项目:intellij-ce-playground    文件:LookupElement.java   
@Nullable
public PsiElement getPsiElement() {
  Object o = getObject();
  if (o instanceof PsiElement) {
    return (PsiElement)o;
  }
  if (o instanceof ResolveResult) {
    return ((ResolveResult)o).getElement();
  }
  if (o instanceof PsiElementNavigationItem) {
    return ((PsiElementNavigationItem)o).getTargetElement();
  }
  if (o instanceof SmartPsiElementPointer) {
    return ((SmartPsiElementPointer)o).getElement();
  }
  return null;
}
项目:intellij-ce-playground    文件:DocumentationComponent.java   
public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) {
  myEffectiveExternalUrl = effectiveExternalUrl;
  if (myElement != null) {
    myBackStack.push(saveContext());
    myForwardStack.clear();
  }

  final SmartPsiElementPointer element = _element != null && _element.isValid()
                                         ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element)
                                         : null;

  if (element != null) {
    setElement(element);
  }

  myIsEmpty = false;
  updateControlState();
  setDataInternal(element, text, new Rectangle(0, 0), ref);

  if (clearHistory) clearHistory();
}
项目:intellij-ce-playground    文件:DocumentationComponent.java   
private void setDataInternal(SmartPsiElementPointer element, String text, final Rectangle viewRect, final String ref) {
  setElement(element);

  highlightLink(-1);

  myEditorPane.setText(text);
  applyFontSize();

  if (!myIsShown && myHint != null && !ApplicationManager.getApplication().isUnitTestMode()) {
    myManager.showHint(myHint);
    myIsShown = true;
  }

  myText = text;

  //noinspection SSBasedInspection
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      myEditorPane.scrollRectToVisible(viewRect); // if ref is defined but is not found in document, this provides a default location
      if (ref != null) {
        myEditorPane.scrollToReference(ref);
      }
    }
  });
}
项目:intellij-ce-playground    文件:FavoritesViewTreeBuilder.java   
@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
  for (Object child : getRoot().getChildren()) {
    AbstractTreeNode favorite = (AbstractTreeNode)child;
    Object currentValue = favorite.getValue();
    if (currentValue instanceof SmartPsiElementPointer) {
      currentValue = ((SmartPsiElementPointer)favorite.getValue()).getElement();
    }
     /*else if (currentValue instanceof PsiJavaFile) {
      final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
      if (classes.length > 0) {
        currentValue = classes[0];
      }
    }*/
    if (Comparing.equal(element, currentValue)) {
      final DefaultMutableTreeNode nodeWithObject =
        findFirstLevelNodeWithObject((DefaultMutableTreeNode)getTree().getModel().getRoot(), favorite);
      if (nodeWithObject != null) {
        return nodeWithObject;
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:PsiTreeAnchorizer.java   
@Override
public Object createAnchor(Object element) {
  if (element instanceof PsiElement) {
    final PsiElement psiElement = (PsiElement)element;

    return ApplicationManager.getApplication().runReadAction(new Computable<Object>() {
      @Override
      public Object compute() {
        SmartPointerWrapper pointer = psiElement.getUserData(PSI_ANCHORIZER_POINTER);
        if (!psiElement.isValid()) {
          return pointer != null ? pointer : psiElement;
        }

        if (pointer == null || pointer.myPointer.getElement() != psiElement) {
          Project project = psiElement.getProject();
          SmartPsiElementPointer<PsiElement> psiElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
          pointer = new SmartPointerWrapper(psiElementPointer);
          psiElement.putUserData(PSI_ANCHORIZER_POINTER, pointer);
        }
        return pointer;
      }
    });
  }
  return super.createAnchor(element);
}
项目:intellij-ce-playground    文件:NavigationGutterIconBuilder.java   
private static <T> NotNullLazyValue<List<SmartPsiElementPointer>> createPointersThunk(boolean lazy,
                                                                                      final Project project,
                                                                                      final Factory<Collection<T>> targets,
                                                                                      final NotNullFunction<T, Collection<? extends PsiElement>> converter) {
  if (!lazy) {
    return NotNullLazyValue.createConstantValue(calcPsiTargets(project, targets.create(), converter));
  }

  return new NotNullLazyValue<List<SmartPsiElementPointer>>() {
    @Override
    @NotNull
    public List<SmartPsiElementPointer> compute() {
      return calcPsiTargets(project, targets.create(), converter);
    }
  };
}
项目:intellij-ce-playground    文件:AbstractDomChildDescriptionImpl.java   
@Override
@Nullable
public PsiElement getDeclaration(final Project project) {
  DomElement domDeclaration = getDomDeclaration();
  if (domDeclaration != null) {
    final DomTarget target = DomTarget.getTarget(domDeclaration);
    if (target != null) {
      return PomService.convertToPsi(target);
    }
    return domDeclaration.getXmlElement();
  }
  final DomAnchor anchor = getUserData(DomExtensionImpl.KEY_DOM_DECLARATION);
  if (anchor != null) {
    return anchor.getContainingFile();
  }
  final SmartPsiElementPointer<?> pointer = getUserData(DomExtensionImpl.DECLARING_ELEMENT_KEY);
  if (pointer != null) {
    final PsiElement element = pointer.getElement();
    if (element != null) {
      return element;
    }
  }

  return PomService.convertToPsi(project, this);
}
项目:intellij-ce-playground    文件:GroovyResolveSnapshot.java   
public GroovyResolveSnapshot(final PsiElement scope) {
  myProject = scope.getProject();
  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile());
  final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject);
  final Map<PsiElement, SmartPsiElementPointer> pointers = new HashMap<PsiElement, SmartPsiElementPointer>();
  scope.accept(new GroovyPsiElementVisitor(new GroovyRecursiveElementVisitor() {
    @Override
    public void visitReferenceExpression(GrReferenceExpression refExpr) {
      if (!refExpr.isQualified()) {
        PsiElement resolved = refExpr.resolve();
        if (resolved instanceof GrMember) {
          SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr);
          SmartPsiElementPointer value = pointers.get(resolved);
          if (value == null) {
            value = pointerManager.createSmartPsiElementPointer(resolved);
            pointers.put(resolved, value);
          }
          myReferencesMap.put(key, value);
        }
      }
      super.visitReferenceExpression(refExpr);
    }
  }));
}
项目:dbunit-extractor    文件:QueryToXMLConverter.java   
@Override
public boolean isAvailable(@NotNull final Project project,
                           final Editor editor,
                           @NotNull final PsiElement psiElement) {
    final boolean isDataSetFile;
    if (editor instanceof EditorWindowImpl) {
        isDataSetFile = ((EditorWindowImpl) editor).getDelegate()
                                                   .getDocument()
                                                   .getText()
                                                   .startsWith("<dataset>");
    } else {
        isDataSetFile = editor.getDocument().getText().startsWith("<dataset>");
    }
    SmartPsiElementPointer<SqlSelectStatement> pointer = getNearestPointer(project, psiElement);
    final String selectedText = editor.getSelectionModel().getSelectedText();
    final boolean hasSelectedQuery = editor.getSelectionModel().hasSelection() && selectedText.trim().toUpperCase().startsWith("SELECT");
    return isDataSetFile && (hasSelectedQuery || pointer != null);
}
项目:tools-idea    文件:DocumentationComponent.java   
public void setData(PsiElement _element, String text, final boolean clearHistory) {
  if (myElement != null) {
    myBackStack.push(saveContext());
    myForwardStack.clear();
  }

  final SmartPsiElementPointer element = _element != null && _element.isValid()
                                         ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element)
                                         : null;

  if (element != null) {
    myElement = element;
  }

  myIsEmpty = false;
  updateControlState();
  setDataInternal(element, text, new Rectangle(0, 0));

  if (clearHistory) clearHistory();
}
项目:tools-idea    文件:FavoritesViewTreeBuilder.java   
@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
  for (Object child : getRoot().getChildren()) {
    AbstractTreeNode favorite = (AbstractTreeNode)child;
    Object currentValue = favorite.getValue();
    if (currentValue instanceof SmartPsiElementPointer) {
      currentValue = ((SmartPsiElementPointer)favorite.getValue()).getElement();
    }
     /*else if (currentValue instanceof PsiJavaFile) {
      final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
      if (classes.length > 0) {
        currentValue = classes[0];
      }
    }*/
    if (Comparing.equal(element, currentValue)) {
      final DefaultMutableTreeNode nodeWithObject =
        findFirstLevelNodeWithObject((DefaultMutableTreeNode)getTree().getModel().getRoot(), favorite);
      if (nodeWithObject != null) {
        return nodeWithObject;
      }
    }
  }
  return null;
}
项目:tools-idea    文件:AbstractDomChildDescriptionImpl.java   
@Nullable
public PsiElement getDeclaration(final Project project) {
  DomElement domDeclaration = getDomDeclaration();
  if (domDeclaration != null) {
    final DomTarget target = DomTarget.getTarget(domDeclaration);
    if (target != null) {
      return PomService.convertToPsi(target);
    }
    return domDeclaration.getXmlElement();
  }
  final DomAnchor anchor = getUserData(DomExtensionImpl.KEY_DOM_DECLARATION);
  if (anchor != null) {
    return anchor.getContainingFile();
  }
  final SmartPsiElementPointer<?> pointer = getUserData(DomExtensionImpl.DECLARING_ELEMENT_KEY);
  if (pointer != null) {
    final PsiElement element = pointer.getElement();
    if (element != null) {
      return element;
    }
  }

  return PomService.convertToPsi(project, this);
}
项目:tools-idea    文件:GroovyResolveSnapshot.java   
public GroovyResolveSnapshot(final PsiElement scope) {
  myProject = scope.getProject();
  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(scope.getContainingFile());
  final SmartPointerManager pointerManager = SmartPointerManager.getInstance(myProject);
  final Map<PsiElement, SmartPsiElementPointer> pointers = new HashMap<PsiElement, SmartPsiElementPointer>();
  scope.accept(new GroovyPsiElementVisitor(new GroovyRecursiveElementVisitor() {
    @Override
    public void visitReferenceExpression(GrReferenceExpression refExpr) {
      if (!refExpr.isQualified()) {
        PsiElement resolved = refExpr.resolve();
        if (resolved instanceof GrMember) {
          SmartPsiElementPointer key = pointerManager.createSmartPsiElementPointer(refExpr);
          SmartPsiElementPointer value = pointers.get(resolved);
          if (value == null) {
            value = pointerManager.createSmartPsiElementPointer(resolved);
            pointers.put(resolved, value);
          }
          myReferencesMap.put(key, value);
        }
      }
      super.visitReferenceExpression(refExpr);
    }
  }));
}
项目:consulo    文件:LookupElement.java   
@Nullable
public PsiElement getPsiElement() {
  Object o = getObject();
  if (o instanceof PsiElement) {
    return (PsiElement)o;
  }
  if (o instanceof ResolveResult) {
    return ((ResolveResult)o).getElement();
  }
  if (o instanceof PsiElementNavigationItem) {
    return ((PsiElementNavigationItem)o).getTargetElement();
  }
  if (o instanceof SmartPsiElementPointer) {
    return ((SmartPsiElementPointer)o).getElement();
  }
  return null;
}
项目:consulo    文件:ElementCreator.java   
public PsiElement[] tryCreate(@Nonnull final String inputString) {
  if (inputString.length() == 0) {
    Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return PsiElement.EMPTY_ARRAY;
  }

  Ref<List<SmartPsiElementPointer>> createdElements = Ref.create();
  Exception exception = executeCommand(getActionName(inputString), () -> {
    PsiElement[] psiElements = create(inputString);
    SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
    createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer));
  });
  if (exception != null) {
    handleException(exception);
    return PsiElement.EMPTY_ARRAY;
  }

  return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY);
}
项目:consulo    文件:DocumentationComponent.java   
public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) {
  if (myElement != null) {
    myBackStack.push(saveContext());
    myForwardStack.clear();
  }
  myEffectiveExternalUrl = effectiveExternalUrl;

  final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null;

  if (element != null) {
    setElement(element);
  }

  myIsEmpty = false;
  updateControlState();
  setDataInternal(element, text, new Rectangle(0, 0), ref);

  if (clearHistory) clearHistory();
}
项目:consulo    文件:DocumentationComponent.java   
private void setDataInternal(SmartPsiElementPointer element, String text, final Rectangle viewRect, final String ref) {
  setElement(element);

  highlightLink(-1);

  myEditorPane.setText(text);
  applyFontProps();

  if (!myIsShown && myHint != null && !ApplicationManager.getApplication().isUnitTestMode()) {
    myManager.showHint(myHint);
    myIsShown = true;
  }

  myText = text;

  //noinspection SSBasedInspection
  SwingUtilities.invokeLater(() -> {
    myEditorPane.scrollRectToVisible(viewRect); // if ref is defined but is not found in document, this provides a default location
    if (ref != null) {
      myEditorPane.scrollToReference(ref);
    }
    else if (ScreenReader.isActive()) {
      myEditorPane.setCaretPosition(0);
    }
  });
}
项目:consulo    文件:ShredImpl.java   
ShredImpl(@Nonnull SmartPsiFileRange relevantRangeInHost,
          @Nonnull SmartPsiElementPointer<PsiLanguageInjectionHost> hostElementPointer,
          @Nonnull String prefix,
          @Nonnull String suffix,
          @Nonnull TextRange rangeInDecodedPSI,
          boolean usePsiRange,
          boolean isOneLine) {
  this.hostElementPointer = hostElementPointer;
  this.relevantRangeInHost = relevantRangeInHost;
  this.prefix = prefix;
  this.suffix = suffix;
  this.rangeInDecodedPSI = rangeInDecodedPSI;
  this.usePsiRange = usePsiRange;
  this.isOneLine = isOneLine;

  assertValid();
}
项目:consulo    文件:FavoritesViewTreeBuilder.java   
@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
  for (Object child : getRoot().getChildren()) {
    AbstractTreeNode favorite = (AbstractTreeNode)child;
    Object currentValue = favorite.getValue();
    if (currentValue instanceof SmartPsiElementPointer) {
      currentValue = ((SmartPsiElementPointer)favorite.getValue()).getElement();
    }
     /*else if (currentValue instanceof PsiJavaFile) {
      final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
      if (classes.length > 0) {
        currentValue = classes[0];
      }
    }*/
    if (Comparing.equal(element, currentValue)) {
      final DefaultMutableTreeNode nodeWithObject =
        findFirstLevelNodeWithObject((DefaultMutableTreeNode)getTree().getModel().getRoot(), favorite);
      if (nodeWithObject != null) {
        return nodeWithObject;
      }
    }
  }
  return null;
}
项目:consulo-xml    文件:AbstractDomChildDescriptionImpl.java   
@Nullable
public PsiElement getDeclaration(final Project project) {
  DomElement domDeclaration = getDomDeclaration();
  if (domDeclaration != null) {
    final DomTarget target = DomTarget.getTarget(domDeclaration);
    if (target != null) {
      return PomService.convertToPsi(target);
    }
    return domDeclaration.getXmlElement();
  }
  final DomAnchor anchor = getUserData(DomExtensionImpl.KEY_DOM_DECLARATION);
  if (anchor != null) {
    return anchor.getContainingFile();
  }
  final SmartPsiElementPointer<?> pointer = getUserData(DomExtensionImpl.DECLARING_ELEMENT_KEY);
  if (pointer != null) {
    final PsiElement element = pointer.getElement();
    if (element != null) {
      return element;
    }
  }

  return PomService.convertToPsi(project, this);
}
项目:consulo-xml    文件:XmlEntityCache.java   
public static void cacheParticularEntity(PsiFile file, XmlEntityDecl decl)
{
    synchronized(LOCK)
    {
        final Map<String, CachedValue<XmlEntityDecl>> cachingMap = getCachingMap(file);
        final String name = decl.getName();
        if(cachingMap.containsKey(name))
        {
            return;
        }
        final SmartPsiElementPointer declPointer = SmartPointerManager.getInstance(file.getProject()).createSmartPsiElementPointer(decl);

        cachingMap.put(name, CachedValuesManager.getManager(file.getProject()).createCachedValue(() ->
        {
            PsiElement declElement = declPointer.getElement();
            if(declElement instanceof XmlEntityDecl && declElement.isValid() && name.equals(((XmlEntityDecl) declElement).getName()))
            {
                return new CachedValueProvider.Result<>((XmlEntityDecl) declElement, declElement);
            }
            cachingMap.put(name, null);
            return new CachedValueProvider.Result<>(null, ModificationTracker.NEVER_CHANGED);
        }, false));
    }
}
项目:consulo-xml    文件:XmlUnusedNamespaceInspection.java   
@Nullable
public SmartPsiElementPointer<XmlTag> doFix(Project project, ProblemDescriptor descriptor, boolean reformat) {
  PsiElement element = descriptor.getPsiElement();
  if (element instanceof XmlAttributeValue) {
    element = element.getParent();
  }
  else if (!(element instanceof XmlAttribute)) {
    return null;
  }
  XmlAttribute attribute = (XmlAttribute)element;
  XmlTag parent = attribute.getParent();

  if (!FileModificationService.getInstance().prepareFileForWrite(parent.getContainingFile())) return null;

  SmartPsiElementPointer<XmlTag> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(parent);

  doRemove(project, attribute, parent);

  if (reformat) {
    reformatStartTag(project, pointer);
  }
  return pointer;
}
项目:consulo-java    文件:ClassInheritorsSearch.java   
public static Query<PsiClass> search(@NotNull SearchParameters parameters)
{
    return INSTANCE.createUniqueResultsQuery(parameters, ContainerUtil.<SmartPsiElementPointer<PsiClass>>canonicalStrategy(), new Function<PsiClass, SmartPsiElementPointer<PsiClass>>()
    {
        @Override
        public SmartPsiElementPointer<PsiClass> fun(final PsiClass psiClass)
        {
            return ApplicationManager.getApplication().runReadAction(new Computable<SmartPsiElementPointer<PsiClass>>()
            {
                @Override
                public SmartPsiElementPointer<PsiClass> compute()
                {
                    return SmartPointerManager.getInstance(psiClass.getProject()).createSmartPsiElementPointer(psiClass);
                }
            });
        }
    });
}
项目:manifold-ij    文件:FileUtil.java   
public static VirtualFile toVirtualFile( PsiFile file )
{
  VirtualFile vfile = file.getUserData( IndexingDataKeys.VIRTUAL_FILE );
  if( vfile == null )
  {
    vfile = file.getVirtualFile();
    if( vfile == null )
    {
      vfile = file.getOriginalFile().getVirtualFile();
      if( vfile == null )
      {
        vfile = file.getViewProvider().getVirtualFile();
      }
    }
    else if( vfile instanceof LightVirtualFile )
    {
      PsiFile containingFile = file.getContainingFile();
      if( containingFile != null && containingFile != file )
      {
        PsiFile originalFile = containingFile.getOriginalFile();
        SmartPsiElementPointer owningFile = originalFile.getUserData( FileContextUtil.INJECTED_IN_ELEMENT );
        if( owningFile != null )
        {
          vfile = owningFile.getVirtualFile();
        }
      }
    }
  }
  return vfile;
}
项目:intellij-ce-playground    文件:ClassInheritorsSearch.java   
public static Query<PsiClass> search(@NotNull SearchParameters parameters) {
  return INSTANCE.createUniqueResultsQuery(parameters, ContainerUtil.<SmartPsiElementPointer<PsiClass>>canonicalStrategy(), new Function<PsiClass, SmartPsiElementPointer<PsiClass>>() {
    @Override
    public SmartPsiElementPointer<PsiClass> fun(final PsiClass psiClass) {
      return ApplicationManager.getApplication().runReadAction(new Computable<SmartPsiElementPointer<PsiClass>>() {
        @Override
        public SmartPsiElementPointer<PsiClass> compute() {
          return SmartPointerManager.getInstance(psiClass.getProject()).createSmartPsiElementPointer(psiClass);
        }
      });
    }
  });
}
项目:intellij-ce-playground    文件:UsageInfoToUsageConverter.java   
@NotNull
private static List<SmartPsiElementPointer<PsiElement>> convertToSmartPointers(@NotNull PsiElement[] primaryElements) {
  if (primaryElements.length == 0) return Collections.emptyList();

  final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(primaryElements[0].getProject());
  return ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer<PsiElement>>() {
          @Override
          public SmartPsiElementPointer<PsiElement> fun(final PsiElement s) {
            return smartPointerManager.createSmartPsiElementPointer(s);
          }
        });
}
项目:intellij-ce-playground    文件:UsageInfoToUsageConverter.java   
@NotNull
public List<SmartPsiElementPointer<PsiElement>> getAllElementPointers() {
  List<SmartPsiElementPointer<PsiElement>> result = new ArrayList<SmartPsiElementPointer<PsiElement>>(myPrimarySearchedElements.size() + myAdditionalSearchedElements.size());
  result.addAll(myPrimarySearchedElements);
  result.addAll(myAdditionalSearchedElements);
  return result;
}
项目:intellij-ce-playground    文件:UsageViewImpl.java   
private void disposeSmartPointers() {
  SmartPointerManager pointerManager = SmartPointerManager.getInstance(getProject());
  for (Usage usage : myUsageNodes.keySet()) {
    if (usage instanceof UsageInfo2UsageAdapter) {
      SmartPsiElementPointer<?> pointer = ((UsageInfo2UsageAdapter)usage).getUsageInfo().getSmartPointer();
      pointerManager.removePointer(pointer);
    }
  }
}
项目:intellij-ce-playground    文件:DocumentationComponent.java   
@Nullable
@Override
protected Navigatable[] getNavigatables(DataContext dataContext) {
  SmartPsiElementPointer element = myElement;
  if (element != null) {
    PsiElement psiElement = element.getElement();
    return psiElement instanceof Navigatable ? new Navigatable[] {(Navigatable)psiElement} : null;
  }
  return null;
}
项目:intellij-ce-playground    文件:EditorFoldingInfo.java   
@Nullable
public PsiElement getPsiElement(@NotNull FoldRegion region) {
  final SmartPsiElementPointer<?> pointer = myFoldRegionToSmartPointerMap.get(region);
  if (pointer == null) {
    return null;
  }
  PsiElement element = pointer.getElement();
  return element != null && element.isValid() ? element : null;
}
项目:intellij-ce-playground    文件:FavoritesTreeNodeDescriptor.java   
public static String getLocation(final AbstractTreeNode element, final Project project) {
  Object nodeElement = element.getValue();
  if (nodeElement instanceof SmartPsiElementPointer) {
    nodeElement = ((SmartPsiElementPointer)nodeElement).getElement();
  }
  if (nodeElement instanceof PsiElement) {
    if (nodeElement instanceof PsiDirectory) {
      return ((PsiDirectory)nodeElement).getVirtualFile().getPresentableUrl();
    }
    if (nodeElement instanceof PsiFile) {
      final PsiFile containingFile = (PsiFile)nodeElement;
      final VirtualFile virtualFile = containingFile.getVirtualFile();
      return virtualFile != null ? virtualFile.getPresentableUrl() : "";
    }
  }

  if (nodeElement instanceof LibraryGroupElement) {
    return ((LibraryGroupElement)nodeElement).getModule().getName();
  }
  if (nodeElement instanceof NamedLibraryElement) {
    final NamedLibraryElement namedLibraryElement = ((NamedLibraryElement)nodeElement);
    final Module module = namedLibraryElement.getModule();
    return (module != null ? module.getName() : "") + ":" + namedLibraryElement.getOrderEntry().getPresentableName();
  }

  final FavoriteNodeProvider[] nodeProviders = Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project);
  for (FavoriteNodeProvider provider : nodeProviders) {
    String location = provider.getElementLocation(nodeElement);
    if (location != null) return location;
  }
  return null;
}
项目:intellij-ce-playground    文件:NavigationGutterIconBuilder.java   
private MyNavigationGutterIconRenderer createGutterIconRenderer(@NotNull final Project project) {
  checkBuilt();

  NotNullLazyValue<List<SmartPsiElementPointer>> pointers = createPointersThunk(myLazy, project, evaluateAndForget(myTargets),
                                                                                myConverter);

  final boolean empty = isEmpty();

  if (myTooltipText == null && !myLazy) {
    final SortedSet<String> names = new TreeSet<String>();
    for (T t : myTargets.getValue()) {
      final String text = myNamer.fun(t);
      if (text != null) {
        names.add(MessageFormat.format(PATTERN, text));
      }
    }
    @NonNls StringBuilder sb = new StringBuilder("<html><body>");
    if (myTooltipTitle != null) {
      sb.append(myTooltipTitle).append("<br>");
    }
    for (String name : names) {
      sb.append(name).append("<br>");
    }
    sb.append("</body></html>");
    myTooltipText = sb.toString();
  }

  Computable<PsiElementListCellRenderer> renderer =
    myCellRenderer == null ? new Computable<PsiElementListCellRenderer>() {
      @Override
      public PsiElementListCellRenderer compute() {
        return new DefaultPsiElementCellRenderer();
      }
    } : myCellRenderer;
  return new MyNavigationGutterIconRenderer(this, myAlignment, myIcon, myTooltipText, pointers, renderer, empty);
}
项目:intellij-ce-playground    文件:NavigationGutterIconBuilder.java   
private static <T> List<SmartPsiElementPointer> calcPsiTargets(Project project, Collection<? extends T> targets,
                                                               NotNullFunction<T, Collection<? extends PsiElement>> converter) {
  SmartPointerManager manager = SmartPointerManager.getInstance(project);
  Set<PsiElement> elements = new THashSet<PsiElement>();
  final List<SmartPsiElementPointer> list = new ArrayList<SmartPsiElementPointer>(targets.size());
  for (final T target : targets) {
    for (final PsiElement psiElement : converter.fun(target)) {
      if (elements.add(psiElement) && psiElement.isValid()) {
        list.add(manager.createSmartPsiElementPointer(psiElement));
      }
    }
  }
  return list;
}
项目:intellij-ce-playground    文件:NavigationGutterIconBuilder.java   
public MyNavigationGutterIconRenderer(@NotNull NavigationGutterIconBuilder builder,
                                      final Alignment alignment,
                                      final Icon icon,
                                      @Nullable final String tooltipText,
                                      @NotNull NotNullLazyValue<List<SmartPsiElementPointer>> pointers,
                                      Computable<PsiElementListCellRenderer> cellRenderer,
                                      boolean empty) {
  super(builder.myPopupTitle, builder.myEmptyText, cellRenderer, pointers);
  myAlignment = alignment;
  myIcon = icon;
  myTooltipText = tooltipText;
  myEmpty = empty;
}
项目:intellij-ce-playground    文件:NavigationGutterIconRenderer.java   
protected NavigationGutterIconRenderer(final String popupTitle, final String emptyText, @NotNull Computable<PsiElementListCellRenderer> cellRenderer,
  @NotNull NotNullLazyValue<List<SmartPsiElementPointer>> pointers) {
  myPopupTitle = popupTitle;
  myEmptyText = emptyText;
  myCellRenderer = cellRenderer;
  myPointers = pointers;
}
项目:intellij-ce-playground    文件:NavigationGutterIconRenderer.java   
public List<PsiElement> getTargetElements() {
  return ContainerUtil.mapNotNull(myPointers.getValue(), new NullableFunction<SmartPsiElementPointer, PsiElement>() {
    @Override
    public PsiElement fun(final SmartPsiElementPointer smartPsiElementPointer) {
      return smartPsiElementPointer.getElement();
    }
  });
}
项目:intellij-ce-playground    文件:ExtensionPointCandidate.java   
public ExtensionPointCandidate(SmartPsiElementPointer pointer,
                               String epName,
                               String attributeName,
                               String tagName,
                               String beanClassName) {
  this.pointer = pointer;
  this.epName = epName;
  this.attributeName = attributeName;
  this.tagName = tagName;
  this.beanClassName = beanClassName;
}
项目:intellij-ce-playground    文件:ExtensionPointCandidate.java   
public ExtensionPointCandidate(SmartPsiElementPointer pointer,
                               String epName) {
  this.pointer = pointer;
  this.epName = epName;
  this.attributeName = "implementation";
  this.tagName = null;
  this.beanClassName = null;
}
项目:intellij-ce-playground    文件:GroovyResolveSnapshot.java   
@Override
public void apply(String hidingLocalName) {
  PsiDocumentManager.getInstance(myProject).commitDocument(myDocument);
  for (Map.Entry<SmartPsiElementPointer, SmartPsiElementPointer> entry : myReferencesMap.entrySet()) {
    qualify(entry.getKey().getElement(), entry.getValue().getElement(), hidingLocalName);
  }
}
项目:intellij-ce-playground    文件:CoverageProjectViewClassNodeDecorator.java   
public void decorate(ProjectViewNode node, PresentationData data) {
  final CoverageDataManager coverageDataManager = getCoverageDataManager();
  final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();

  final Project project = node.getProject();
  final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
  // This decorator is applicable only to JavaCoverageAnnotator
  if (javaCovAnnotator == null) {
    return;
  }

  final Object value = node.getValue();
  PsiElement element = null;
  if (value instanceof PsiElement) {
    element = (PsiElement)value;
  }
  else if (value instanceof SmartPsiElementPointer) {
    element = ((SmartPsiElementPointer)value).getElement();
  }
  else if (value instanceof PackageElement) {
    PackageElement packageElement = (PackageElement)value;
    final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(),
                                                                                       packageElement.getModule(),
                                                                                       coverageDataManager);
    data.setLocationString(coverageString);
  }

  if (element instanceof PsiClass) {
    final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
    final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
    if (vFile != null && searchScope.contains(vFile)) {
      final String qName = ((PsiClass)element).getQualifiedName();
      if (qName != null) {
        data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
      }
    }
  }
}