@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; }
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; }
@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; }
@Nullable @Override public PsiJavaModule getModuleDeclaration() { PsiClassHolderFileStub<?> stub = getStub(); return stub instanceof PsiJavaFileStub ? ((PsiJavaFileStub) stub).getModule() : null; }
@Override @NotNull public PsiClassHolderFileStub<?> getStub() { return (PsiClassHolderFileStub) getStubTree().getRoot(); }