@Override
  @Nullable
  public PsiElement restoreElement() {
    long typeAndId = myStubElementTypeAndId;
    int stubId = (int) typeAndId;
    if (stubId != -1) {
      PsiFile file = restoreFile();
      if (!(file instanceof PsiFileWithStubSupport)) return null;
      short index = (short) (typeAndId >> 32);
      IStubElementType stubElementType = (IStubElementType) IElementType.find(index);
      return PsiAnchor.restoreFromStubIndex(
          (PsiFileWithStubSupport) file, stubId, stubElementType, false);
    }

    Segment psiRange = getPsiRange();
    if (psiRange == null) return null;

    PsiFile file = restoreFile();
    if (file == null) return null;
    PsiElement anchor = file.findElementAt(psiRange.getStartOffset());
    if (anchor == null) return null;

    TextRange range = anchor.getTextRange();
    if (range.getStartOffset() != psiRange.getStartOffset()
        || range.getEndOffset() != psiRange.getEndOffset()) return null;

    for (SmartPointerAnchorProvider provider : SmartPointerAnchorProvider.EP_NAME.getExtensions()) {
      final PsiElement element = provider.restoreElement(anchor);
      if (element != null) return element;
    }
    return null;
  }
  @NotNull
  public static PsiAnchor create(@NotNull final PsiElement element) {
    PsiUtilCore.ensureValid(element);

    PsiAnchor anchor = doCreateAnchor(element);
    if (ApplicationManager.getApplication().isUnitTestMode()
        && !element.equals(anchor.retrieve())) {
      LOG.error(
          "Cannot restore element "
              + element
              + " of "
              + element.getClass()
              + " from anchor "
              + anchor);
    }
    return anchor;
  }
Exemple #3
0
  public boolean isReferenced(@NotNull PsiNamedElement element) {
    List<PsiReference> array;
    synchronized (myLocalRefsMap) {
      array = myLocalRefsMap.getKeysByValue(element);
    }
    if (array != null && !array.isEmpty() && !isParameterUsedRecursively(element, array))
      return true;

    Boolean usedStatus = myDclsUsedMap.get(PsiAnchor.create(element));
    return usedStatus == Boolean.TRUE;
  }
 public JavaPsiClassReferenceElement(PsiClass psiClass) {
   super(psiClass.getName(), psiClass.getName());
   myClass =
       psiClass.getContainingFile().getVirtualFile() == null
           ? psiClass
           : PsiAnchor.create(psiClass);
   myQualifiedName = psiClass.getQualifiedName();
   JavaCompletionUtil.setShowFQN(this);
   setInsertHandler(AllClassesGetter.TRY_SHORTENING);
   setTailType(TailType.NONE);
 }
Exemple #5
0
 @Override
 public boolean process(PsiClass inheritor) {
   ProgressManager.checkCanceled();
   for (PsiClassType interfaceType : inheritor.getImplementsListTypes()) {
     ProgressManager.checkCanceled();
     PsiClass anInterface = interfaceType.resolveGenerics().getElement();
     if (anInterface != null && myCheckedInterfaces.add(PsiAnchor.create(anInterface))) {
       processInterface(inheritor, anInterface);
     }
   }
   return !myRemainingMethods.isEmpty();
 }
Exemple #6
0
 SiblingInheritorSearcher(Collection<PsiMethod> methods, PsiClass containingClass) {
   myContainingClass = containingClass;
   myRemainingMethods = new HashSet<>(methods);
   myCheckedInterfaces.add(PsiAnchor.create(containingClass));
 }
 public void invoke(
     @NotNull final Project project, @Nullable Editor editor, @NotNull PsiFile file) {
   invokeAction(project, file, myElement.retrieve(), myKey, myPropertiesFiles);
 }
 public boolean isAvailable(
     @NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) {
   return myElement != null && myElement.retrieve() != null;
 }
 public CreatePropertyFix(
     PsiElement element, String key, final List<PropertiesFile> propertiesFiles) {
   myElement = element == null ? null : PsiAnchor.create(element);
   myKey = key;
   myPropertiesFiles = propertiesFiles;
 }
Exemple #10
0
 private static void removeInvalidFrom(@NotNull Collection<? extends PsiAnchor> collection) {
   for (Iterator<? extends PsiAnchor> it = collection.iterator(); it.hasNext(); ) {
     PsiAnchor element = it.next();
     if (element.retrieve() == null) it.remove();
   }
 }
Exemple #11
0
 public void registerLocallyReferenced(@NotNull PsiNamedElement result) {
   myDclsUsedMap.put(PsiAnchor.create(result), Boolean.TRUE);
 }