Logo Search packages:      
Sourcecode: janino version File versions  Download package

void org::codehaus::janino::UnitCompiler::checkAccessible ( IClass  type,
Java.BlockStatement  contextBlockStatement 
) throws CompileException [inline, private]

Check whether the given IClass is accessible in the given context, according to JLS2 6.6.1.2 and 6.6.1.4. Issues a compileError(String) if not.

Definition at line 4318 of file UnitCompiler.java.

References org::codehaus::janino::Access::DEFAULT, org::codehaus::janino::IClass::getAccess(), org::codehaus::janino::IClass::getDeclaringIClass(), org::codehaus::janino::IClass::getDescriptor(), and org::codehaus::janino::Access::PUBLIC.

                              {

        // Determine the type declaring the type.
        IClass iClassDeclaringType = type.getDeclaringIClass();

        // Check accessibility of package member type.
        if (iClassDeclaringType == null) {
            if (type.getAccess() == Access.PUBLIC) {
                return;
            } else
            if (type.getAccess() == Access.DEFAULT) {
    
                // Determine the type declaring the context block statement.
                IClass iClassDeclaringContextBlockStatement;
                for (Java.Scope s = contextBlockStatement.getEnclosingScope();; s = s.getEnclosingScope()) {
                    if (s instanceof Java.TypeDeclaration) {
                        iClassDeclaringContextBlockStatement = this.resolve((Java.TypeDeclaration) s);
                        break;
                    }
                }
    
                // Check whether the type is accessed from within the same package.
                String packageDeclaringType = Descriptor.getPackageName(type.getDescriptor());
                String contextPackage = Descriptor.getPackageName(iClassDeclaringContextBlockStatement.getDescriptor());
                if (!(packageDeclaringType == null ? contextPackage == null : packageDeclaringType.equals(contextPackage))) this.compileError("\"" + type + "\" is inaccessible from this package");
                return;
            } else
            {
                throw new RuntimeException("\"" + type + "\" has unexpected access \"" + type.getAccess() + "\"");
            }
        }

        // "type" is a member type at this point.

        this.checkAccessible(iClassDeclaringType, type.getAccess(), contextBlockStatement);
    }


Generated by  Doxygen 1.6.0   Back to index