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

void org::codehaus::janino::UnitCompiler::addFields ( Java.FieldDeclaration  fd,
ClassFile  cf 
) throws CompileException [inline, private]

Create ClassFile.FieldInfos for all fields declared by the given Java.FieldDeclaration.

Definition at line 438 of file UnitCompiler.java.

References org::codehaus::janino::util::ClassFile::addConstantUtf8Info(), org::codehaus::janino::util::ClassFile::addFieldInfo(), getConstantValue(), and org::codehaus::janino::IClass::getDescriptor().

                                                                                           {
        for (int j = 0; j < fd.variableDeclarators.length; ++j) {
            Java.VariableDeclarator vd = fd.variableDeclarators[j];
            Java.Type type = fd.type;
            for (int k = 0; k < vd.brackets; ++k) type = new Java.ArrayType(type);

            Object ocv = null;
            if (
                (fd.modifiers & Mod.FINAL) != 0 &&
                vd.optionalInitializer != null
            ) {
                if (vd.optionalInitializer instanceof Java.Rvalue) ocv = this.getConstantValue((Java.Rvalue) vd.optionalInitializer);
                if (ocv == Java.Rvalue.CONSTANT_VALUE_NULL) ocv = null;
            }

            ClassFile.FieldInfo fi;
            if (Mod.isPrivateAccess(fd.modifiers)) {

                // To make the private field accessible for enclosing types, enclosed types and types
                // enclosed by the same type, it is modified as follows:
                //  + Access is changed from PRIVATE to PACKAGE
                fi = cf.addFieldInfo(
                    Mod.changeAccess(fd.modifiers, Mod.PACKAGE), // modifiers
                    vd.name,                                     // fieldName
                    this.getType(type).getDescriptor(),          // fieldTypeFD
                    ocv                                          // optionalConstantValue
                );
            } else
            {
                fi = cf.addFieldInfo(
                    fd.modifiers,                       // modifiers
                    vd.name,                            // fieldName
                    this.getType(type).getDescriptor(), // fieldTypeFD
                    ocv                                 // optionalConstantValue
                );
            }

            // Add "Deprecated" attribute (JVMS 4.7.10)
            if (fd.hasDeprecatedDocTag()) {
                fi.addAttribute(new ClassFile.DeprecatedAttribute(cf.addConstantUtf8Info("Deprecated")));
            }
        }
    }


Generated by  Doxygen 1.6.0   Back to index