当前位置: 首页>>代码示例>>Java>>正文


Java StubElement.getPsi方法代码示例

本文整理汇总了Java中com.intellij.psi.stubs.StubElement.getPsi方法的典型用法代码示例。如果您正苦于以下问题:Java StubElement.getPsi方法的具体用法?Java StubElement.getPsi怎么用?Java StubElement.getPsi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.stubs.StubElement的用法示例。


在下文中一共展示了StubElement.getPsi方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calcStubIndex

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
public static int calcStubIndex(@NotNull StubBasedPsiElement psi) {
  if (psi instanceof PsiFile) {
    return 0;
  }

  final StubElement liveStub = psi.getStub();
  if (liveStub != null) {
    return ((StubBase)liveStub).id;
  }

  PsiFileImpl file = (PsiFileImpl)psi.getContainingFile();
  final StubTree stubTree = file.calcStubTree();
  for (StubElement<?> stb : stubTree.getPlainList()) {
    if (stb.getPsi() == psi) {
      return ((StubBase)stb).id;
    }
  }

  return -1; // it is possible via custom stub builder intentionally not producing stubs for stubbed elements
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PsiAnchor.java

示例2: getContainingFile

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Override
public PsiFile getContainingFile() {
  StubElement p = myStub;
  while (!(p instanceof PsiFileStub)) {
    p = p.getParentStub();
  }
  return (PsiFile)p.getPsi();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ClsRepositoryPsiElement.java

示例3: getParent

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Override
public PsiElement getParent() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    final StubElement parentStub = stub.getParentStub();
    if (parentStub instanceof PsiFileStub || parentStub instanceof PsiClassStub
      ) {
      return parentStub.getPsi();
    }
  }

  return SharedImplUtil.getParent(getNode());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PsiClassImpl.java

示例4: getStubOrPsiParent

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Nullable
@Contract("null -> null")
public static PsiElement getStubOrPsiParent(@Nullable PsiElement element) {
  if (element instanceof StubBasedPsiElement) {
    StubBase stub = (StubBase)((StubBasedPsiElement)element).getStub();
    if (stub != null) {
      //noinspection unchecked
      final StubElement parentStub = stub.getParentStub();
      return parentStub != null ? parentStub.getPsi() : null;
    }
  }
  return element != null ? element.getParent() : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PsiTreeUtil.java

示例5: getContainerByStub

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Nullable
private static PsiElement getContainerByStub(@NotNull StubBasedPsiElement element) {
  final StubElement stub = element.getStub();
  if (stub != null) {
    final StubElement parentStub = stub.getParentStub();
    if (parentStub != null) {
      return parentStub.getPsi();
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:PyContainerProvider.java

示例6: isTopLevel

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
public static boolean isTopLevel(@NotNull PsiElement element) {
  if (element instanceof StubBasedPsiElement) {
    final StubElement stub = ((StubBasedPsiElement)element).getStub();
    if (stub != null) {
      final StubElement parentStub = stub.getParentStub();
      if (parentStub != null) {
        return parentStub.getPsi() instanceof PsiFile;
      }
    }
  }
  return ScopeUtil.getScopeOwner(element) instanceof PsiFile;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PyUtil.java

示例7: getPackageDefinition

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Override
public GrPackageDefinition getPackageDefinition() {
  final StubElement<?> stub = getStub();
  if (stub != null) {
    for (StubElement element : stub.getChildrenStubs()) {
      if (element instanceof GrPackageDefinitionStub) return (GrPackageDefinition)element.getPsi();
    }
    return null;
  }

  ASTNode node = calcTreeElement().findChildByType(GroovyElementTypes.PACKAGE_DEFINITION);
  return node != null ? (GrPackageDefinition)node.getPsi() : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:GroovyFileImpl.java

示例8: getStubsTreeImpl

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
private static void getStubsTreeImpl(StubElement element, StringBuffer buffer, String offset) {
  PsiElement psi = element.getPsi();
  buffer.append(offset).append("[").append(psi.toString()).
          append(element instanceof NamedStub ? " : " + ((NamedStub) element).getName() : "").
          append("]\n");
  for (StubElement stubElement : ((List<StubElement>) element.getChildrenStubs())) {
    getStubsTreeImpl(stubElement, buffer, offset + "  ");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:StubsTest.java

示例9: calcBasesResolveContext

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Nullable
private static PsiElement calcBasesResolveContext(PsiClass aClass,
                                                  String className,
                                                  boolean isInitialClass,
                                                  final PsiElement defaultResolveContext) {
  final PsiClassStub stub = ((PsiClassImpl)aClass).getStub();
  if (stub == null || stub.isAnonymousInQualifiedNew()) {
    return aClass.getParent();
  }

  boolean isAnonOrLocal = isAnonymousOrLocal(aClass);

  if (!isAnonOrLocal) {
    return isInitialClass ? defaultResolveContext : aClass;
  }

  if (!isInitialClass) {
    if (aClass.findInnerClassByName(className, true) != null) return aClass;
  }

  final StubElement parentStub = stub.getParentStub();

  final StubBasedPsiElementBase<?> context = (StubBasedPsiElementBase)parentStub.getPsi();
  @SuppressWarnings("unchecked")
  PsiClass[] classesInScope = (PsiClass[])parentStub.getChildrenByType(Constants.CLASS_BIT_SET, PsiClass.ARRAY_FACTORY);

  boolean needPreciseContext = false;
  if (classesInScope.length > 1) {
    for (PsiClass scopeClass : classesInScope) {
      if (scopeClass == aClass) continue;
      String className1 = scopeClass.getName();
      if (className.equals(className1)) {
        needPreciseContext = true;
        break;
      }
    }
  }
  else {
    if (classesInScope.length != 1) {
      LOG.assertTrue(classesInScope.length == 1, "Parent stub: "+parentStub.getStubType() +"; children: "+parentStub.getChildrenStubs()+"; \ntext:"+context.getText());
    }
    LOG.assertTrue(classesInScope[0] == aClass);
  }

  if (needPreciseContext) {
    return aClass.getParent();
  }
  else {
    if (context instanceof PsiClass) {
      return calcBasesResolveContext((PsiClass)context, className, false, defaultResolveContext);
    }
    else if (context instanceof PsiMember) {
      return calcBasesResolveContext(((PsiMember)context).getContainingClass(), className, false, defaultResolveContext);
    }
    else {
      LOG.assertTrue(false);
      return context;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:61,代码来源:PsiClassImpl.java

示例10: reason

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@NonNls
@NotNull
private static String reason(@NotNull PsiElement root) {
  if (root == PsiUtilCore.NULL_PSI_ELEMENT) return "NULL_PSI_ELEMENT";

  PsiElement element = root instanceof PsiFile ? root : root.getParent();
  if (element == null) {
    String m = "parent is null";
    if (root instanceof StubBasedPsiElement) {
      StubElement stub = ((StubBasedPsiElement)root).getStub();
      while (stub != null) {
        m += "\n  each stub=" + stub;
        if (stub instanceof PsiFileStub) {
          m += "; fileStub.psi=" + stub.getPsi() + "; reason=" + ((PsiFileStub)stub).getInvalidationReason();
        }
        stub = stub.getParentStub();
      }
    }
    return m;
  }

  while (element != null && !(element instanceof PsiFile)) element = element.getParent();
  PsiFile file = (PsiFile)element;
  if (file == null) return "containing file is null";

  FileViewProvider provider = file.getViewProvider();
  VirtualFile vFile = provider.getVirtualFile();
  if (!vFile.isValid()) return vFile + " is invalid";
  if (!provider.isPhysical()) {
    PsiElement context = file.getContext();
    if (context != null && !context.isValid()) {
      return "invalid context: " + reason(context);
    }
  }

  PsiManager manager = file.getManager();
  if (manager.getProject().isDisposed()) return "project is disposed";

  Language language = file.getLanguage();
  if (language != provider.getBaseLanguage()) return "File language:" + language + " != Provider base language:" + provider.getBaseLanguage();

  FileViewProvider p = manager.findViewProvider(vFile);
  if (provider != p) return "different providers: " + provider + "(" + id(provider) + "); " + p + "(" + id(p) + ")";

  if (!provider.isPhysical()) return "non-physical provider: " + provider; // "dummy" file?

  return "psi is outdated";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:PsiInvalidElementAccessException.java

示例11: restoreFromStubIndex

import com.intellij.psi.stubs.StubElement; //导入方法依赖的package包/类
@Nullable
public static PsiElement restoreFromStubIndex(PsiFileWithStubSupport fileImpl,
                                              int index,
                                              @NotNull IStubElementType elementType, boolean throwIfNull) {
  if (fileImpl == null) {
    if (throwIfNull) throw new AssertionError("Null file");
    return null;
  }
  StubTree tree = fileImpl.getStubTree();

  boolean foreign = tree == null;
  if (foreign) {
    if (fileImpl instanceof PsiFileImpl) {
      // Note: as far as this is a realization of StubIndexReference fileImpl#getContentElementType() must be instance of IStubFileElementType
      tree = ((PsiFileImpl)fileImpl).calcStubTree();
    }
    else {
      if (throwIfNull) throw new AssertionError("Not PsiFileImpl: " + fileImpl.getClass());
      return null;
    }
  }

  List<StubElement<?>> list = tree.getPlainList();
  if (index >= list.size()) {
    if (throwIfNull) throw new AssertionError("Too large index: " + index + ">=" + list.size());
    return null;
  }
  StubElement stub = list.get(index);

  if (stub.getStubType() != elementType) {
    if (throwIfNull) throw new AssertionError("Element type mismatch: " + stub.getStubType() + "!=" + elementType);
    return null;
  }

  if (foreign) {
    final PsiElement cachedPsi = ((StubBase)stub).getCachedPsi();
    if (cachedPsi != null) return cachedPsi;

    final ASTNode ast = fileImpl.findTreeForStub(tree, stub);
    if (ast != null) {
      return ast.getPsi();
    }

    if (throwIfNull) throw new AssertionError("No AST for stub");
    return null;
  }
  return stub.getPsi();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:PsiAnchor.java


注:本文中的com.intellij.psi.stubs.StubElement.getPsi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。