Java 类com.intellij.psi.impl.java.stubs.PsiClassStub 实例源码

项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public PsiElement getScope() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.getParentStub().getPsi();
  }

  ASTNode treeElement = getNode();
  ASTNode parent = treeElement.getTreeParent();

  while(parent != null) {
    if (parent.getElementType() instanceof IStubElementType){
      return parent.getPsi();
    }
    parent = parent.getTreeParent();
  }

  return getContainingFile();
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public String getQualifiedName() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.getQualifiedName();
  }

  PsiElement parent = getParent();
  if (parent instanceof PsiJavaFile) {
    return StringUtil.getQualifiedName(((PsiJavaFile)parent).getPackageName(), getName());
  }
  if (parent instanceof PsiClass) {
    String parentQName = ((PsiClass)parent).getQualifiedName();
    if (parentQName == null) return null;
    return StringUtil.getQualifiedName(parentQName, getName());
  }

  return null;
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
private static boolean isAnonymousOrLocal(PsiClass aClass) {
  if (aClass instanceof PsiAnonymousClass) return true;

  final PsiClassStub stub = ((PsiClassImpl)aClass).getStub();
  if (stub != null) {
    final StubElement parentStub = stub.getParentStub();
    return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
  }

  PsiElement parent = aClass.getParent();
  while (parent != null) {
    if (parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer) return true;
    if (parent instanceof PsiClass || parent instanceof PsiFile) return false;
    parent = parent.getParent();
  }

  return false;
}
项目:intellij-ce-playground    文件:PsiAnonymousClassImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  if (lastParent instanceof PsiExpressionList) return true;

  final PsiClassStub stub = getStub();
  if (stub != null) {
    // no tree is loaded
    // that means we could not have come from resolving something inside anonymous class, we just resolving the base class reference
    // so skip the (very expensive) getBaseClassReference() call which would load tree
    return true;
  }

  if (lastParent != null/* IMPORTANT: do not call getBaseClassReference() for lastParent == null and lastParent which is not under our node - loads tree!*/
      && lastParent.getParent() == this && lastParent == getBaseClassReference()) {
    return true;
  }
  return super.processDeclarations(processor, state, lastParent, place);
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public PsiElement getScope() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.getParentStub().getPsi();
  }

  ASTNode treeElement = getNode();
  ASTNode parent = treeElement.getTreeParent();

  while(parent != null) {
    if (parent.getElementType() instanceof IStubElementType){
      return parent.getPsi();
    }
    parent = parent.getTreeParent();
  }

  return getContainingFile();
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public String getQualifiedName() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.getQualifiedName();
  }

  PsiElement parent = getParent();
  if (parent instanceof PsiJavaFile) {
    String packageName = ((PsiJavaFile)parent).getPackageName();
    if (packageName.isEmpty()) {
      return getName();
    }
    return packageName + "." + getName();
  }
  if (parent instanceof PsiClass) {
    String parentQName = ((PsiClass)parent).getQualifiedName();
    if (parentQName == null) return null;
    return parentQName + "." + getName();
  }

  return null;
}
项目:tools-idea    文件:PsiClassImpl.java   
private static boolean isAnonymousOrLocal(PsiClass aClass) {
  if (aClass instanceof PsiAnonymousClass) return true;

  final PsiClassStub stub = ((PsiClassImpl)aClass).getStub();
  if (stub != null) {
    final StubElement parentStub = stub.getParentStub();
    return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
  }

  PsiElement parent = aClass.getParent();
  while (parent != null) {
    if (parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer) return true;
    if (parent instanceof PsiClass || parent instanceof PsiFile) return false;
    parent = parent.getParent();
  }

  return false;
}
项目:tools-idea    文件:PsiAnonymousClassImpl.java   
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                   @NotNull ResolveState state,
                                   PsiElement lastParent,
                                   @NotNull PsiElement place) {
  if (lastParent instanceof PsiExpressionList) return true;

  final PsiClassStub stub = getStub();
  if (stub != null) {
    // no tree is loaded
    // that means we could not have come from resolving something inside anonymous class, we just resolving the base class reference
    // so skip the (very expensive) getBaseClassReference() call which would load tree
    return true;
  }

  if (lastParent != null/* IMPORTANT: do not call getBaseClassReference() for lastParent == null and lastParent which is not under our node - loads tree!*/
      && lastParent.getParent() == this && lastParent == getBaseClassReference()) {
    return true;
  }
  return super.processDeclarations(processor, state, lastParent, place);
}
项目:consulo-java    文件:RecordUtil.java   
public static boolean isStaticNonPrivateMember(@NotNull StubElement<?> stub)
{
    StubElement<PsiModifierList> type = stub.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
    if(!(type instanceof PsiModifierListStub))
    {
        return false;
    }

    int mask = ((PsiModifierListStub) type).getModifiersMask();
    if(ModifierFlags.hasModifierProperty(PsiModifier.PRIVATE, mask))
    {
        return false;
    }

    if(ModifierFlags.hasModifierProperty(PsiModifier.STATIC, mask))
    {
        return true;
    }

    return stub instanceof PsiFieldStub && stub.getStubType() == JavaElementType.ENUM_CONSTANT || stub.getParentStub() instanceof PsiClassStub && ((PsiClassStub) stub.getParentStub()).isInterface();
}
项目:consulo-java    文件:PsiClassImpl.java   
private void addTrace(@Nullable PsiClassStub stub)
{
    if(ourTraceStubAstBinding)
    {
        String creationTrace = "Creation thread: " + Thread.currentThread() + "\n" + DebugUtil.currentStackTrace();
        if(stub != null)
        {
            creationTrace += "\nfrom stub " + stub + "@" + System.identityHashCode(stub) + "\n";
            if(stub instanceof UserDataHolder)
            {
                String stubTrace = ((UserDataHolder) stub).getUserData(CREATION_TRACE);
                if(stubTrace != null)
                {
                    creationTrace += stubTrace;
                }
            }
        }
        putUserData(CREATION_TRACE, creationTrace);
    }
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public PsiElement getScope()
{
    final PsiClassStub stub = getStub();
    if(stub != null)
    {
        return stub.getParentStub().getPsi();
    }

    ASTNode treeElement = getNode();
    ASTNode parent = treeElement.getTreeParent();

    while(parent != null)
    {
        if(parent.getElementType() instanceof IStubElementType)
        {
            return parent.getPsi();
        }
        parent = parent.getTreeParent();
    }

    return getContainingFile();
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public String getName()
{
    String name = myCachedName;
    if(name != null)
    {
        return name;
    }
    final PsiClassStub stub = getGreenStub();
    if(stub == null)
    {
        PsiIdentifier identifier = getNameIdentifier();
        name = identifier == null ? null : identifier.getText();
    }
    else
    {
        name = stub.getName();
    }
    myCachedName = name;
    return name;
}
项目:consulo-java    文件:PsiClassImpl.java   
@Nullable
private StubElement getContextStub()
{
    PsiClassStub<?> stub = getStub();
    if(stub == null)
    {
        return null;
    }

    // if AST is not loaded, then we only can need context to resolve supertype references
    // this can be done by stubs unless there are local/anonymous classes referencing other local classes
    StubElement parent = stub.getParentStub();
    if(parent instanceof PsiClassInitializerStub || parent instanceof PsiMethodStub)
    {
        if(parent.getChildrenByType(JavaStubElementTypes.CLASS, PsiElement.ARRAY_FACTORY).length <= 1)
        {
            parent = parent.getParentStub();
        }
    }
    return parent instanceof PsiClassStub ? parent : null;
}
项目:intellij-ce-playground    文件:ClsFileImpl.java   
@Override
@NotNull
public LanguageLevel getLanguageLevel() {
  LanguageLevel level = myLanguageLevel;
  if (level == null) {
    List classes = ApplicationManager.getApplication().runReadAction(new Computable<List>() {
      @Override
      public List compute() {
        return getStub().getChildrenStubs();
      }
    });
    myLanguageLevel = level = !classes.isEmpty() ? ((PsiClassStub<?>)classes.get(0)).getLanguageLevel() : LanguageLevel.HIGHEST;
  }
  return level;
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
private void addTrace(@Nullable PsiClassStub stub) {
  if (ourTraceStubAstBinding) {
    String creationTrace = "Creation thread: " + Thread.currentThread() + "\n" + DebugUtil.currentStackTrace();
    if (stub != null) {
      creationTrace += "\nfrom stub " + stub + "@" + System.identityHashCode(stub) + "\n";
      if (stub instanceof UserDataHolder) {
        String stubTrace = ((UserDataHolder)stub).getUserData(CREATION_TRACE);
        if (stubTrace != null) {
          creationTrace += stubTrace;
        }
      }
    }
    putUserData(CREATION_TRACE, creationTrace);
  }
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@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());
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public String getName() {
  String name = myCachedName;
  if (name != null) return name;
  final PsiClassStub stub = getStub();
  if (stub == null) {
    PsiIdentifier identifier = getNameIdentifier();
    name = identifier == null ? null : identifier.getText();
  }
  else {
    name = stub.getName();
  }
  myCachedName = name;
  return name;
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public boolean isDeprecated() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
  }

  return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public boolean isInterface() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isInterface();
  }

  ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
  return keyword != null && keyword.getElementType() == JavaTokenType.INTERFACE_KEYWORD;
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public boolean isAnnotationType() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isAnnotationType();
  }

  return getNode().findChildByRole(ChildRole.AT) != null;
}
项目:intellij-ce-playground    文件:PsiClassImpl.java   
@Override
public boolean isEnum() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isEnum();
  }

  final ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
  return keyword != null && keyword.getElementType() == JavaTokenType.ENUM_KEYWORD;
}
项目:intellij-ce-playground    文件:PsiAnonymousClassImpl.java   
@Override
public boolean isInQualifiedNew() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isAnonymousInQualifiedNew();
  }

  final PsiElement parent = getParent();
  return parent instanceof PsiNewExpression && ((PsiNewExpression)parent).getQualifier() != null;
}
项目:tools-idea    文件:DefaultClsStubBuilderFactory.java   
private static String getPackageName(final PsiClassStub<PsiClass> result) {
  final String fqn = result.getQualifiedName();
  final String shortName = result.getName();
  if (fqn == null || Comparing.equal(shortName, fqn)) {
    return "";
  }

  return fqn.substring(0, fqn.lastIndexOf('.'));
}
项目:tools-idea    文件:PsiClassImpl.java   
private void addTrace(@Nullable PsiClassStub stub) {
  if (ourTraceStubAstBinding) {
    String creationTrace = "Creation thread: " + Thread.currentThread() + "\n" + DebugUtil.currentStackTrace();
    if (stub != null) {
      creationTrace += "\nfrom stub " + stub + "@" + System.identityHashCode(stub) + "\n";
      if (stub instanceof UserDataHolder) {
        String stubTrace = ((UserDataHolder)stub).getUserData(CREATION_TRACE);
        if (stubTrace != null) {
          creationTrace += stubTrace;
        }
      }
    }
    putUserData(CREATION_TRACE, creationTrace);
  }
}
项目:tools-idea    文件:PsiClassImpl.java   
@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());
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public String getName() {
  String name = myCachedName;
  if (name != null) return name;
  final PsiClassStub stub = getStub();
  if (stub == null) {
    PsiIdentifier identifier = getNameIdentifier();
    name = identifier == null ? null : identifier.getText();
  }
  else {
    name = stub.getName();
  }
  myCachedName = name;
  return name;
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public boolean isDeprecated() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
  }

  return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public boolean isInterface() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isInterface();
  }

  ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
  return keyword != null && keyword.getElementType() == JavaTokenType.INTERFACE_KEYWORD;
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public boolean isAnnotationType() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isAnnotationType();
  }

  return getNode().findChildByRole(ChildRole.AT) != null;
}
项目:tools-idea    文件:PsiClassImpl.java   
@Override
public boolean isEnum() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isEnum();
  }

  final ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
  return keyword != null && keyword.getElementType() == JavaTokenType.ENUM_KEYWORD;
}
项目:tools-idea    文件:PsiAnonymousClassImpl.java   
@Override
public boolean isInQualifiedNew() {
  final PsiClassStub stub = getStub();
  if (stub != null) {
    return stub.isAnonymousInQualifiedNew();
  }

  final PsiElement parent = getParent();
  return parent instanceof PsiNewExpression && ((PsiNewExpression)parent).getQualifier() != null;
}
项目:consulo-javaee    文件:JspClassImpl.java   
@Nullable
@RequiredReadAction
@Override
public String getQualifiedName()
{
    PsiClassStub<JspClass> stub = getGreenStub();
    if(stub != null)
    {
        return stub.getQualifiedName();
    }

    VirtualFile virtualFile = getContainingFile().getVirtualFile();
    if(virtualFile == null)
    {
        return getName();
    }

    VirtualFile parent = virtualFile.getParent();
    if(parent == null)
    {
        return null;
    }

    String packageName = ProjectFileIndex.getInstance(getProject()).getPackageNameByDirectory(parent);
    if(StringUtil.isEmpty(packageName))
    {
        return getName();
    }
    return packageName + "." + getName();
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public boolean isDeprecated()
{
    final PsiClassStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isDeprecated() || stub.hasDeprecatedAnnotation() && PsiImplUtil.isDeprecatedByAnnotation(this);
    }

    return PsiImplUtil.isDeprecatedByDocTag(this) || PsiImplUtil.isDeprecatedByAnnotation(this);
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public boolean isInterface()
{
    final PsiClassStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isInterface();
    }

    ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
    return keyword != null && keyword.getElementType() == JavaTokenType.INTERFACE_KEYWORD;
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public boolean isAnnotationType()
{
    final PsiClassStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isAnnotationType();
    }

    return getNode().findChildByRole(ChildRole.AT) != null;
}
项目:consulo-java    文件:PsiClassImpl.java   
@Override
public boolean isEnum()
{
    final PsiClassStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isEnum();
    }

    final ASTNode keyword = getNode().findChildByRole(ChildRole.CLASS_OR_INTERFACE_KEYWORD);
    return keyword != null && keyword.getElementType() == JavaTokenType.ENUM_KEYWORD;
}
项目:consulo-java    文件:PsiClassImpl.java   
private static boolean isAnonymousOrLocal(PsiClass aClass)
{
    if(aClass instanceof PsiAnonymousClass)
    {
        return true;
    }

    final PsiClassStub stub = ((PsiClassImpl) aClass).getGreenStub();
    if(stub != null)
    {
        final StubElement parentStub = stub.getParentStub();
        return !(parentStub instanceof PsiClassStub || parentStub instanceof PsiFileStub);
    }

    PsiElement parent = aClass.getParent();
    while(parent != null)
    {
        if(parent instanceof PsiMethod || parent instanceof PsiField || parent instanceof PsiClassInitializer)
        {
            return true;
        }
        if(parent instanceof PsiClass || parent instanceof PsiFile)
        {
            return false;
        }
        parent = parent.getParent();
    }

    return false;
}
项目:consulo-java    文件:PsiAnonymousClassImpl.java   
private boolean isDiamond(PsiClassStub stub)
{
    if(PsiUtil.isLanguageLevel9OrHigher(this))
    {
        final String referenceText = stub.getBaseClassReferenceText();
        if(referenceText != null && referenceText.endsWith(">"))
        {
            return StringUtil.trimEnd(referenceText, ">").trim().endsWith("<");
        }
    }
    return false;
}
项目:consulo-java    文件:PsiAnonymousClassImpl.java   
@Override
public boolean isInQualifiedNew()
{
    final PsiClassStub stub = getGreenStub();
    if(stub != null)
    {
        return stub.isAnonymousInQualifiedNew();
    }

    final PsiElement parent = getParent();
    return parent instanceof PsiNewExpression && ((PsiNewExpression) parent).getQualifier() != null;
}
项目:intellij-ce-playground    文件:PsiClassReferenceListStubImpl.java   
@Override
public PsiClassType[] getReferencedTypes() {
  if (myTypes != null) return myTypes;
  if (myNames.length == 0) {
    myTypes = PsiClassType.EMPTY_ARRAY;
    return myTypes;
  }

  PsiClassType[] types = new PsiClassType[myNames.length];

  final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
  if (compiled) {
    for (int i = 0; i < types.length; i++) {
      types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), StringRef.toString(myNames[i])), null);
    }
  }
  else {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();

    int nullCount = 0;
    final PsiReferenceList psi = getPsi();
    for (int i = 0; i < types.length; i++) {
      PsiElement context = psi;
      if (getParentStub() instanceof PsiClassStub) {
        context = ((PsiClassImpl)getParentStub().getPsi()).calcBasesResolveContext(PsiNameHelper.getShortClassName(StringRef.toString(myNames[i])), psi);
      }

      try {
        final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(StringRef.toString(myNames[i]), context);
        ((PsiJavaCodeReferenceElementImpl)ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
        types[i] = factory.createType(ref);
      }
      catch (IncorrectOperationException e) {
        types[i] = null;
        nullCount++;
      }
    }

    if (nullCount > 0) {
      PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
      int cnt = 0;
      for (PsiClassType type : types) {
        if (type != null) newTypes[cnt++] = type;
      }
      types = newTypes;
    }
  }

  myTypes = types;
  return types;
}