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

项目:consulo-java    文件:ClsFileImpl.java   
@Override
public PsiPackageStatement getPackageStatement()
{
    ClsPackageStatementImpl statement = myPackageStatement;
    if(statement == null)
    {
        statement = ClsPackageStatementImpl.NULL_PACKAGE;
        PsiClassHolderFileStub<?> stub = getStub();
        if(!(stub instanceof PsiJavaFileStub) || stub.findChildStubByType(JavaStubElementTypes.MODULE) == null)
        {
            String packageName = findPackageName(stub);
            if(packageName != null)
            {
                statement = new ClsPackageStatementImpl(this, packageName);
            }
        }
        myPackageStatement = statement;
    }
    return statement != ClsPackageStatementImpl.NULL_PACKAGE ? statement : null;
}
项目:consulo-java    文件:PsiJavaFileImpl.java   
@RequiredReadAction
@Nullable
@Override
public PsiJavaModule getModuleDeclaration()
{
    PsiJavaFileStub stub = (PsiJavaFileStub) getGreenStub();
    if(stub != null)
    {
        return stub.getModule();
    }

    PsiElement element = getFirstChild();
    if(element instanceof PsiWhiteSpace || element instanceof PsiComment)
    {
        element = PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class, PsiComment.class);
    }
    return element instanceof PsiJavaModule ? (PsiJavaModule) element : null;
}
项目:consulo-java    文件:PsiJavaFileBaseImpl.java   
@Override
@NotNull
public String getPackageName()
{
    PsiJavaFileStub stub = (PsiJavaFileStub) getStub();
    if(stub != null)
    {
        return stub.getPackageName();
    }

    String name = myPackageName;
    if(name == null)
    {
        PsiPackageStatement statement = getPackageStatement();
        myPackageName = name = statement == null ? "" : statement.getPackageName();
    }
    return name;
}
项目:intellij-ce-playground    文件:PsiJavaFileBaseImpl.java   
@Override
@NotNull
public String getPackageName() {
  PsiJavaFileStub stub = (PsiJavaFileStub)getStub();
  if (stub != null) {
    return stub.getPackageName();
  }

  String name = myPackageName;
  if (name == null) {
    PsiPackageStatement statement = getPackageStatement();
    myPackageName = name = statement == null ? "" : statement.getPackageName();
  }
  return name;
}
项目:intellij-ce-playground    文件:JavaFileElementType.java   
@NotNull
@Override
public PsiJavaFileStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
  boolean compiled = dataStream.readBoolean();
  StringRef packName = dataStream.readName();
  return new PsiJavaFileStubImpl(null, packName, compiled);
}
项目:tools-idea    文件:PsiJavaFileBaseImpl.java   
@Override
@NotNull
public String getPackageName() {
  PsiJavaFileStub stub = (PsiJavaFileStub)getStub();
  if (stub != null) {
    return stub.getPackageName();
  }

  String name = myPackageName;
  if (name == null) {
    PsiPackageStatement statement = getPackageStatement();
    myPackageName = name = statement == null ? "" : statement.getPackageName();
  }
  return name;
}
项目:tools-idea    文件:JavaFileElementType.java   
@NotNull
@Override
public PsiJavaFileStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException {
  boolean compiled = dataStream.readBoolean();
  StringRef packName = dataStream.readName();
  return new PsiJavaFileStubImpl(null, packName, compiled);
}
项目:consulo-javaee    文件:JspJavaFileElementType.java   
@Override
public void serialize(@NotNull PsiJavaFileStub stub, @NotNull StubOutputStream dataStream) throws IOException
{
    LanguageLevel level = stub.getLanguageLevel();
    dataStream.writeByte(level != null ? level.ordinal() : -1);
    dataStream.writeName(stub.getPackageName());
}
项目:consulo-javaee    文件:JspJavaFileElementType.java   
@NotNull
@Override
public PsiJavaFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException
{
    int level = dataStream.readByte();
    StringRef packageName = dataStream.readName();
    return new JspJavaFileStub(null, StringRef.toString(packageName), level >= 0 ? LanguageLevel.values()[level] : null);
}
项目:consulo-java    文件:PsiClassStubImpl.java   
@Override
public LanguageLevel getLanguageLevel()
{
    StubElement parent = getParentStub();
    if(parent instanceof PsiJavaFileStub)
    {
        LanguageLevel level = ((PsiJavaFileStub) parent).getLanguageLevel();
        if(level != null)
        {
            return level;
        }
    }
    return LanguageLevel.HIGHEST;
}
项目:consulo-java    文件:ClsFileImpl.java   
private static String findPackageName(PsiClassHolderFileStub<?> stub)
{
    String packageName = null;

    if(stub instanceof PsiJavaFileStub)
    {
        packageName = ((PsiJavaFileStub) stub).getPackageName();
    }
    else
    {
        PsiClass[] psiClasses = stub.getClasses();
        if(psiClasses.length > 0)
        {
            String className = psiClasses[0].getQualifiedName();
            if(className != null)
            {
                int index = className.lastIndexOf('.');
                if(index >= 0)
                {
                    packageName = className.substring(0, index);
                }
            }
        }
    }

    return !StringUtil.isEmpty(packageName) ? packageName : null;
}
项目:consulo-java    文件:ClsFileImpl.java   
@Override
@NotNull
public LanguageLevel getLanguageLevel()
{
    PsiClassHolderFileStub<?> stub = getStub();
    if(stub instanceof PsiJavaFileStub)
    {
        LanguageLevel level = ((PsiJavaFileStub) stub).getLanguageLevel();
        if(level != null)
        {
            return level;
        }
    }
    return LanguageLevel.HIGHEST;
}
项目:consulo-java    文件:ClsFileImpl.java   
@Nullable
@Override
public PsiJavaModule getModuleDeclaration()
{
    PsiClassHolderFileStub<?> stub = getStub();
    return stub instanceof PsiJavaFileStub ? ((PsiJavaFileStub) stub).getModule() : null;
}
项目:consulo-java    文件:JavaFileElementType.java   
@Override
public void serialize(@NotNull PsiJavaFileStub stub, @NotNull StubOutputStream dataStream) throws IOException
{
    dataStream.writeBoolean(stub.isCompiled());
    LanguageLevel level = stub.getLanguageLevel();
    dataStream.writeByte(level != null ? level.ordinal() : -1);
    dataStream.writeName(stub.getPackageName());
}
项目:consulo-java    文件:JavaFileElementType.java   
@NotNull
@Override
public PsiJavaFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException
{
    boolean compiled = dataStream.readBoolean();
    int level = dataStream.readByte();
    StringRef packageName = dataStream.readName();
    return new PsiJavaFileStubImpl(null, StringRef.toString(packageName), level >= 0 ? LanguageLevel.values()[level] : null, compiled);
}
项目:intellij-ce-playground    文件:JavaFileElementType.java   
@Override
public void serialize(@NotNull final PsiJavaFileStub stub, @NotNull final StubOutputStream dataStream) throws IOException {
  dataStream.writeBoolean(stub.isCompiled());
  dataStream.writeName(stub.getPackageName());
}
项目:intellij-ce-playground    文件:JavaFileElementType.java   
@Override
public void indexStub(@NotNull final PsiJavaFileStub stub, @NotNull final IndexSink sink) { }
项目:tools-idea    文件:JavaFileElementType.java   
@Override
public void serialize(@NotNull final PsiJavaFileStub stub, @NotNull final StubOutputStream dataStream) throws IOException {
  dataStream.writeBoolean(stub.isCompiled());
  dataStream.writeName(stub.getPackageName());
}
项目:tools-idea    文件:JavaFileElementType.java   
@Override
public void indexStub(@NotNull final PsiJavaFileStub stub, @NotNull final IndexSink sink) { }
项目:consulo-javaee    文件:JspClassStubElementType.java   
@Override
public PsiClassStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub)
{
    String qualifiedName = null;
    String name = null;

    if(parentStub instanceof PsiFileStub)
    {
        PsiElement psi = parentStub.getPsi();
        if(psi instanceof PsiFile)
        {
            name = JspClassImpl.buildName((PsiFile) psi);
        }
    }

    if(name != null)
    {
        if(parentStub instanceof PsiJavaFileStub)
        {
            final String pkg = ((PsiJavaFileStub) parentStub).getPackageName();
            if(!pkg.isEmpty())
            {
                qualifiedName = pkg + '.' + name;
            }
            else
            {
                qualifiedName = name;
            }
        }
        else if(parentStub instanceof PsiClassStub)
        {
            final String parentFqn = ((PsiClassStub) parentStub).getQualifiedName();
            qualifiedName = parentFqn != null ? parentFqn + '.' + name : null;
        }
        else if(parentStub instanceof PsiClassLevelDeclarationStatementStub)
        {
            StubElement parent = parentStub;
            while(parent != null)
            {
                if(parent instanceof PsiClassStub)
                {
                    qualifiedName = ((PsiClassStub) parent).getQualifiedName();
                    break;
                }
                parent = parent.getParentStub();
            }
        }
    }

    return new PsiClassStubImpl(this, parentStub, qualifiedName, name, null, (byte) 0);
}
项目:consulo-java    文件:ModuleStubBuildingVisitor.java   
public ModuleStubBuildingVisitor(PsiJavaFileStub parent)
{
    super(Opcodes.API_VERSION);
    myParent = parent;
}
项目:consulo-java    文件:StubBuildingVisitor.java   
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
{
    myInternalName = name;
    String parentName = myParent instanceof PsiClassStub ? ((PsiClassStub) myParent).getQualifiedName() : myParent instanceof PsiJavaFileStub ? ((PsiJavaFileStub) myParent).getPackageName() :
            null;
    String fqn = getFqn(name, myShortName, parentName);
    String shortName = myShortName != null && name.endsWith(myShortName) ? myShortName : PsiNameHelper.getShortClassName(fqn);

    int flags = myAccess | access;
    boolean isDeprecated = isSet(flags, Opcodes.ACC_DEPRECATED);
    boolean isInterface = isSet(flags, Opcodes.ACC_INTERFACE);
    boolean isEnum = isSet(flags, Opcodes.ACC_ENUM);
    boolean isAnnotationType = isSet(flags, Opcodes.ACC_ANNOTATION);
    byte stubFlags = PsiClassStubImpl.packFlags(isDeprecated, isInterface, isEnum, false, false, isAnnotationType, false, false);
    myResult = new PsiClassStubImpl(JavaStubElementTypes.CLASS, myParent, fqn, shortName, null, stubFlags);

    myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags));

    ClassInfo info = null;
    if(signature != null)
    {
        try
        {
            info = parseClassSignature(signature);
        }
        catch(ClsFormatException e)
        {
            if(LOG.isDebugEnabled())
            {
                LOG.debug("source=" + mySource + " signature=" + signature, e);
            }
        }
    }
    if(info == null)
    {
        info = parseClassDescription(superName, interfaces);
    }

    PsiTypeParameterListStub typeParameterList = new PsiTypeParameterListStubImpl(myResult);
    for(Pair<String, String[]> parameter : info.typeParameters)
    {
        PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(typeParameterList, StringRef.fromString(parameter.first));
        newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, parameter.second);
    }

    if(myResult.isInterface())
    {
        if(info.interfaceNames != null && myResult.isAnnotationType())
        {
            info.interfaceNames.remove(CommonClassNames.JAVA_LANG_ANNOTATION_ANNOTATION);
        }
        newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, ArrayUtil.toStringArray(info.interfaceNames));
        newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.EMPTY_STRING_ARRAY);
    }
    else
    {
        if(info.superName == null || "java/lang/Object".equals(superName) || myResult.isEnum() && "java/lang/Enum".equals(superName))
        {
            newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, ArrayUtil.EMPTY_STRING_ARRAY);
        }
        else
        {
            newReferenceList(JavaStubElementTypes.EXTENDS_LIST, myResult, new String[]{info.superName});
        }
        newReferenceList(JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.toStringArray(info.interfaceNames));
    }
}
项目:consulo-java    文件:JavaFileElementType.java   
@Override
@SuppressWarnings("LambdaUnfriendlyMethodOverload")
public void indexStub(@NotNull PsiJavaFileStub stub, @NotNull IndexSink sink)
{
}