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

项目:intellij-ce-playground    文件:AnchorElementInfoFactory.java   
@Override
@Nullable
public SmartPointerElementInfo createElementInfo(@NotNull PsiElement element, @NotNull PsiFile containingFile) {
  if (element instanceof StubBasedPsiElement && containingFile instanceof PsiFileWithStubSupport) {
    PsiFileWithStubSupport stubFile = (PsiFileWithStubSupport)containingFile;
    StubTree stubTree = stubFile.getStubTree();
    if (stubTree != null) {
      // use stubs when tree is not loaded
      StubBasedPsiElement stubPsi = (StubBasedPsiElement)element;
      int stubId = PsiAnchor.calcStubIndex(stubPsi);
      IStubElementType myStubElementType = stubPsi.getElementType();
      IElementType contentElementType = ((PsiFileImpl)containingFile).getContentElementType();
      if (stubId != -1 && contentElementType instanceof IStubFileElementType) { // TemplateDataElementType is not IStubFileElementType
        return new AnchorElementInfo(element, stubFile, stubId, myStubElementType);
      }
    }
  }

  PsiElement anchor = getAnchor(element);
  if (anchor != null) {
    return new AnchorElementInfo(anchor, containingFile);
  }
  return null;
}
项目:tools-idea    文件: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() {
        PsiAnchor anchor = psiElement.getUserData(PSI_ANCHORIZER_ANCHOR);
        if (!psiElement.isValid()) {
          return anchor != null ? anchor : psiElement;
        }

        if (anchor == null || anchor.retrieve() != psiElement) {
          psiElement.putUserData(PSI_ANCHORIZER_ANCHOR, anchor = PsiAnchor.create(psiElement));
        }
        return anchor;
      }
    });
  }
  return super.createAnchor(element);
}
项目:intellij-ce-playground    文件:SymbolCollectingProcessor.java   
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
  if (element instanceof PsiNamedElement && element.isValid()) {
    PsiNamedElement named = (PsiNamedElement)element;
    String name = named.getName();
    if (name != null) {
      PsiAnchor context = myCurrentContextAnchor;
      if (context == null && myCurrentFileContext != null) {
        myCurrentContextAnchor = context = PsiAnchor.create(myCurrentFileContext);
      }
      myResult.add(name, new ResultWithContext(named, context));
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:SymbolCollectingProcessor.java   
@NotNull
public PsiNamedElement getElement() {
  PsiElement element = myElement.retrieve();
  if (element == null) {
    String message = "Anchor hasn't survived: " + myElement;
    if (myElement instanceof PsiAnchor.StubIndexReference) {
      message += "; diagnostics=" + ((PsiAnchor.StubIndexReference)myElement).diagnoseNull();
    }
    throw new AssertionError(message);
  }

  return (PsiNamedElement)element;
}
项目:intellij-ce-playground    文件:WebReferencesAnnotatorBase.java   
@Override
public MyInfo[] collectInformation(@NotNull PsiFile file) {
  final WebReference[] references = collectWebReferences(file);
  final MyInfo[] infos = new MyInfo[references.length];

  for (int i = 0; i < infos.length; i++) {
    final WebReference reference = references[i];
    infos[i] = new MyInfo(PsiAnchor.create(reference.getElement()), reference.getRangeInElement(), reference.getValue());
  }
  return infos;
}
项目:intellij-ce-playground    文件:PsiFragment.java   
public PsiFragment(PsiElement element, int cost) {
  myElementAnchors = new PsiAnchor[]{createAnchor(element)};
  myDuplicate = false;
  myChecked = false;
  myNested = false;
  myParents = null;
  myCost = cost;
  myLanguage = calcLanguage(element);
}
项目:intellij-ce-playground    文件:PsiFragment.java   
protected PsiAnchor createAnchor(final PsiElement element) {
  return ApplicationManager.getApplication().runReadAction(new Computable<PsiAnchor>() {
    public PsiAnchor compute() {
      return PsiAnchor.create(element);
    }
  });
}
项目:intellij-ce-playground    文件:PsiFragment.java   
public PsiFragment(List<? extends PsiElement> elements, int from, int to) {
  myElementAnchors = new PsiAnchor[to - from + 1];

  for (int i = from; i <= to; i++) {
    myElementAnchors[i - from] = createAnchor(elements.get(i));
  }

  myDuplicate = false;
  myChecked = false;
  myNested = false;
  myParents = null;
  myLanguage = to >= from && from < elements.size()
               ? calcLanguage(elements.get(from))
               : null;
}
项目:intellij-ce-playground    文件:PsiFragment.java   
public String toString() {
  StringBuilder buffer = new StringBuilder();

  for (PsiAnchor psiAnchor : myElementAnchors) {
    final PsiElement element = psiAnchor.retrieve();
    if (element != null) {
      buffer.append(element.getText());
      buffer.append("\n");
    }
  }

  return buffer.toString();
}
项目:intellij-ce-playground    文件:PsiFragment.java   
public int[][] getOffsets() {
  final int[][] result = new int[myElementAnchors.length][2];
  int idx = 0;
  for (PsiAnchor anchor : myElementAnchors) {
    result[idx][0] = anchor.getStartOffset();
    result[idx++][1] = anchor.getEndOffset();
  }
  return result;
}
项目:intellij-ce-playground    文件:IncludedXmlElement.java   
public IncludedXmlElement(@NotNull T original, @Nullable PsiElement parent) {
  super(original.getManager(), original.getLanguage());
  //noinspection unchecked
  T realOriginal = original instanceof IncludedXmlElement ? ((IncludedXmlElement<T>)original).getOriginal() : original;
  myOriginal = PsiAnchor.create(realOriginal);
  myRef = new SoftReference<T>(realOriginal);
  myParent = parent;
}
项目:intellij-ce-playground    文件:CreateNSDeclarationIntentionFix.java   
public CreateNSDeclarationIntentionFix(@NotNull final PsiElement element,
                                       @NotNull String namespacePrefix,
                                       @Nullable final XmlToken token) {
  myNamespacePrefix = namespacePrefix;
  myElement = PsiAnchor.create(element);
  myToken = token == null ? null : PsiAnchor.create(token);
}
项目:epigraph    文件:SchemaTypeParentsSearcher.java   
private static void processParents(@NotNull Processor<SchemaTypeDef> consumer,
                                   @NotNull SchemaTypeDef baseType,
                                   @NotNull SchemaTypeParentsSearch.SearchParameters parameters) {

  final Ref<SchemaTypeDef> currentBase = Ref.create();
  final Queue<PsiAnchor> queue = new Queue<>(10);
  final Set<PsiAnchor> processed = ContainerUtil.newTroveSet();

  final Processor<SchemaTypeDef> processor = new ReadActionProcessor<SchemaTypeDef>() {
    @Override
    public boolean processInReadAction(SchemaTypeDef inheritor) {
      if (!consumer.process(inheritor)) return false;
      if (inheritor == null) return false;
      queue.addLast(PsiAnchor.create(inheritor));
      return true;
    }
  };

  // seed
  ApplicationManager.getApplication().runReadAction(() -> {
    queue.addLast(PsiAnchor.create(baseType));
  });

  // BFS
  while (!queue.isEmpty()) {
    ProgressManager.checkCanceled();

    final PsiAnchor anchor = queue.pullFirst();
    if (!processed.add(anchor)) continue;

    SchemaTypeDef typeDef = ApplicationManager.getApplication().runReadAction(
        (Computable<SchemaTypeDef>) () -> (SchemaTypeDef) anchor.retrieve()
    );
    if (typeDef == null) continue;

    currentBase.set(typeDef);
    if (!SchemaDirectTypeParentsSearch.search(typeDef).forEach(processor))
      return;
  }
}
项目:tools-idea    文件:WebReferencesAnnotatorBase.java   
@Override
public MyInfo[] collectionInformation(@NotNull PsiFile file) {
  final WebReference[] references = collectWebReferences(file);
  final MyInfo[] infos = new MyInfo[references.length];

  for (int i = 0; i < infos.length; i++) {
    final WebReference reference = references[i];
    infos[i] = new MyInfo(PsiAnchor.create(reference.getElement()), reference.getRangeInElement(), reference.getValue());
  }
  return infos;
}
项目:tools-idea    文件:PsiTreeAnchorizer.java   
@Override
@Nullable
public Object retrieveElement(Object pointer) {
  if (pointer instanceof PsiAnchor) {
    PsiElement retrieve = ((PsiAnchor)pointer).retrieve();
    if (retrieve == null) {
      //System.out.println("Null anchor: " + pointer);
    }
    return retrieve;
  }

  return super.retrieveElement(pointer);
}
项目:tools-idea    文件:IncludedXmlElement.java   
public IncludedXmlElement(@NotNull T original, @Nullable PsiElement parent) {
  super(original.getManager(), original.getLanguage());
  //noinspection unchecked
  T realOriginal = original instanceof IncludedXmlElement ? ((IncludedXmlElement<T>)original).getOriginal() : original;
  myOriginal = PsiAnchor.create(realOriginal);
  myRef = new SoftReference<T>(realOriginal);
  myParent = parent;
}
项目:tools-idea    文件:CreateNSDeclarationIntentionFix.java   
public CreateNSDeclarationIntentionFix(@NotNull final PsiElement element,
                                       final String namespacePrefix,
                                       @Nullable final XmlToken token) {
  myNamespacePrefix = namespacePrefix;
  myElement = PsiAnchor.create(element);
  myToken = token == null ? null : PsiAnchor.create(token);
}
项目:consulo    文件:AnchorElementInfo.java   
@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);
  }

  return super.restoreElement();
}
项目:consulo    文件:WebReferencesAnnotatorBase.java   
@Override
public MyInfo[] collectInformation(@Nonnull PsiFile file) {
  final WebReference[] references = collectWebReferences(file);
  final MyInfo[] infos = new MyInfo[references.length];

  for (int i = 0; i < infos.length; i++) {
    final WebReference reference = references[i];
    infos[i] = new MyInfo(PsiAnchor.create(reference.getElement()), reference.getRangeInElement(), reference.getValue());
  }
  return infos;
}
项目:consulo-xml    文件:IncludedXmlElement.java   
public IncludedXmlElement(@NotNull T original, @Nullable PsiElement parent) {
  super(original.getManager(), original.getLanguage());
  //noinspection unchecked
  T realOriginal = original instanceof IncludedXmlElement ? ((IncludedXmlElement<T>)original).getOriginal() : original;
  myOriginal = PsiAnchor.create(realOriginal);
  myRef = new SoftReference<T>(realOriginal);
  myParent = parent;
}
项目:consulo-xml    文件:CreateNSDeclarationIntentionFix.java   
public CreateNSDeclarationIntentionFix(@NotNull final PsiElement element,
                                       final String namespacePrefix,
                                       @Nullable final XmlToken token) {
  myNamespacePrefix = namespacePrefix;
  myElement = PsiAnchor.create(element);
  myToken = token == null ? null : PsiAnchor.create(token);
}
项目:consulo-java    文件:FindSuperElementsHelper.java   
@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();
}
项目:intellij-ce-playground    文件:SymbolCollectingProcessor.java   
public ResultWithContext(@NotNull PsiNamedElement element, @Nullable PsiAnchor fileContext) {
  myElement = PsiAnchor.create(element);
  myFileContext = fileContext;
}
项目:intellij-ce-playground    文件:ClsElementInfo.java   
public ClsElementInfo(@NotNull PsiAnchor.StubIndexReference stubReference) {
  myStubIndexReference = stubReference;
}
项目:intellij-ce-playground    文件:WebReferencesAnnotatorBase.java   
private MyInfo(PsiAnchor anchor, TextRange rangeInElement, String url) {
  myAnchor = anchor;
  myRangeInElement = rangeInElement;
  myUrl = url;
}
项目:intellij-ce-playground    文件:DomAnchorImpl.java   
public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
  DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
  if (handler.getStub() != null) {
    return new StubAnchor<T>(handler);
  }

  if (usePsi) {
    final XmlElement element = t.getXmlElement();
    if (element != null) {
      return new PsiBasedDomAnchor<T>(PsiAnchor.create(element), element.getProject());
    }
  }


  final DomElement parent = t.getParent();
  if (parent == null) {
    LOG.error("Parent null: " + t);
  }

  if (parent instanceof DomFileElementImpl) {
    final DomFileElementImpl fileElement = (DomFileElementImpl)parent;
    //noinspection unchecked
    return new RootAnchor<T>(fileElement.getFile(), fileElement.getRootElementClass());
  }

  final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
  final String name = t.getGenericInfo().getElementName(t);
  final AbstractDomChildrenDescription description = t.getChildDescription();
  final List<? extends DomElement> values = description.getValues(parent);
  if (name != null) {
    int i = 0;
    for (DomElement value : values) {
      if (value.equals(t)) {
        return new NamedAnchor<T>(parentAnchor, description, name, i);
      }
      if (name.equals(value.getGenericInfo().getElementName(value))) {
        i++;
      }
    }
  }

  final int index = values.indexOf(t);
  if (index < 0) {
    diagnoseNegativeIndex2(t, parent, description, values);
  }
  return new IndexedAnchor<T>(parentAnchor, description, index);
}
项目:intellij-ce-playground    文件:DomAnchorImpl.java   
public PsiBasedDomAnchor(PsiAnchor anchor, Project project) {
  myAnchor = anchor;
  myProject = project;
}
项目:intellij-ce-playground    文件:CreatePropertyFix.java   
public CreatePropertyFix(PsiElement element, String key, final List<PropertiesFile> propertiesFiles) {
  myElement = element == null ? null : PsiAnchor.create(element);
  myKey = key;
  myPropertiesFiles = propertiesFiles;
}
项目:epigraph    文件:SchemaTypeInheritorsSearcher.java   
private static void processInheritors(@NotNull Processor<SchemaTypeDef> consumer,
                                        @NotNull SchemaTypeDef baseType,
                                        @NotNull SchemaTypeInheritorsSearch.SearchParameters parameters) {

    // see JavaClassInheritorsSearcher

//    final Project project = PsiUtilCore.getProjectInReadAction(baseType);
    final Ref<SchemaTypeDef> currentBase = Ref.create();
    final Stack<PsiAnchor> stack = new Stack<>();
    final Set<PsiAnchor> processed = ContainerUtil.newTroveSet();

    final Processor<SchemaTypeDef> processor = new ReadActionProcessor<SchemaTypeDef>() {
      @Override
      public boolean processInReadAction(SchemaTypeDef inheritor) {
        if (!consumer.process(inheritor)) return false;
        stack.push(PsiAnchor.create(inheritor));
        return true;
      }
    };

    ApplicationManager.getApplication().runReadAction(() -> {
      stack.push(PsiAnchor.create(baseType));
    });

    // DFS
    while (!stack.isEmpty()) {
      ProgressManager.checkCanceled();

      final PsiAnchor anchor = stack.pop();
      if (!processed.add(anchor)) continue;

      SchemaTypeDef typeDef = ApplicationManager.getApplication().runReadAction(
          (Computable<SchemaTypeDef>) () -> (SchemaTypeDef) anchor.retrieve()
      );
      if (typeDef == null) continue;

      currentBase.set(typeDef);
      if (!SchemaDirectTypeInheritorsSearch.search(typeDef).forEach(processor))
        return;
    }
  }
项目:tools-idea    文件:ClsElementInfo.java   
public ClsElementInfo(@NotNull PsiAnchor.StubIndexReference stubReference) {
  myStubIndexReference = stubReference;
}
项目:tools-idea    文件:WebReferencesAnnotatorBase.java   
private MyInfo(PsiAnchor anchor, TextRange rangeInElement, String url) {
  myAnchor = anchor;
  myRangeInElement = rangeInElement;
  myUrl = url;
}
项目:tools-idea    文件:DomAnchorImpl.java   
public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
  if (usePsi) {
    final XmlElement element = t.getXmlElement();
    if (element != null) {
      return new PsiBasedDomAnchor<T>(PsiAnchor.create(element), element.getProject());
    }
  }

  DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
  if (handler.getStub() != null) {
    return new StubAnchor<T>(handler);
  }

  final DomElement parent = t.getParent();
  if (parent == null) {
    LOG.error("Parent null: " + t);
  }

  if (parent instanceof DomFileElementImpl) {
    final DomFileElementImpl fileElement = (DomFileElementImpl)parent;
    //noinspection unchecked
    return new RootAnchor<T>(fileElement.getFile(), fileElement.getRootElementClass());
  }

  final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
  final String name = t.getGenericInfo().getElementName(t);
  final AbstractDomChildrenDescription description = t.getChildDescription();
  final List<? extends DomElement> values = description.getValues(parent);
  if (name != null) {
    int i = 0;
    for (DomElement value : values) {
      if (value.equals(t)) {
        return new NamedAnchor<T>(parentAnchor, description, name, i);
      }
      if (name.equals(value.getGenericInfo().getElementName(value))) {
        i++;
      }
    }
  }

  final int index = values.indexOf(t);
  if (index < 0) {
    diagnoseNegativeIndex2(t, parent, description, values);
  }
  return new IndexedAnchor<T>(parentAnchor, description, index);
}
项目:tools-idea    文件:DomAnchorImpl.java   
public PsiBasedDomAnchor(PsiAnchor anchor, Project project) {
  myAnchor = anchor;
  myProject = project;
}
项目:tools-idea    文件:CreatePropertyFix.java   
public CreatePropertyFix(PsiElement element, String key, final List<PropertiesFile> propertiesFiles) {
  myElement = element == null ? null : PsiAnchor.create(element);
  myKey = key;
  myPropertiesFiles = propertiesFiles;
}
项目:consulo    文件:ClsElementInfo.java   
public ClsElementInfo(@Nonnull PsiAnchor.StubIndexReference stubReference) {
  myStubIndexReference = stubReference;
}
项目:consulo    文件:WebReferencesAnnotatorBase.java   
private MyInfo(PsiAnchor anchor, TextRange rangeInElement, String url) {
  myAnchor = anchor;
  myRangeInElement = rangeInElement;
  myUrl = url;
}
项目:consulo    文件:PsiCrumb.java   
PsiCrumb(PsiElement element, BreadcrumbsProvider provider) {
  super(provider.getElementIcon(element), provider.getElementInfo(element), provider.getElementTooltip(element));
  anchor = PsiAnchor.create(element);
}
项目:consulo-xml    文件:DomAnchorImpl.java   
public static <T extends DomElement> DomAnchor<T> createAnchor(@NotNull T t, boolean usePsi) {
  if (usePsi) {
    final XmlElement element = t.getXmlElement();
    if (element != null) {
      return new PsiBasedDomAnchor<T>(PsiAnchor.create(element), element.getProject());
    }
  }

  DomInvocationHandler handler = DomManagerImpl.getNotNullHandler(t);
  if (handler.getStub() != null) {
    return new StubAnchor<T>(handler);
  }

  final DomElement parent = t.getParent();
  if (parent == null) {
    LOG.error("Parent null: " + t);
  }

  if (parent instanceof DomFileElementImpl) {
    final DomFileElementImpl fileElement = (DomFileElementImpl)parent;
    //noinspection unchecked
    return new RootAnchor<T>(fileElement.getFile(), fileElement.getRootElementClass());
  }

  final DomAnchor<DomElement> parentAnchor = createAnchor(parent);
  final String name = t.getGenericInfo().getElementName(t);
  final AbstractDomChildrenDescription description = t.getChildDescription();
  final List<? extends DomElement> values = description.getValues(parent);
  if (name != null) {
    int i = 0;
    for (DomElement value : values) {
      if (value.equals(t)) {
        return new NamedAnchor<T>(parentAnchor, description, name, i);
      }
      if (name.equals(value.getGenericInfo().getElementName(value))) {
        i++;
      }
    }
  }

  final int index = values.indexOf(t);
  if (index < 0) {
    diagnoseNegativeIndex2(t, parent, description, values);
  }
  return new IndexedAnchor<T>(parentAnchor, description, index);
}
项目:consulo-xml    文件:DomAnchorImpl.java   
public PsiBasedDomAnchor(PsiAnchor anchor, Project project) {
  myAnchor = anchor;
  myProject = project;
}
项目:consulo-java    文件:FindSuperElementsHelper.java   
SiblingInheritorSearcher(Collection<PsiMethod> methods, PsiClass containingClass)
{
    myContainingClass = containingClass;
    myRemainingMethods = new HashSet<>(methods);
    myCheckedInterfaces.add(PsiAnchor.create(containingClass));
}