Beispiel #1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public FieldBuilder(FieldDefinition javaField, TypeBuilder declaringTypeBuilder)
 {
     if (javaField == null)
         throw new ArgumentNullException("javaField");
     if (declaringTypeBuilder == null)
         throw new ArgumentNullException("declaringTypeBuilder");
     this.javaField = javaField;
     this.declaringTypeBuilder = declaringTypeBuilder;
 }
 /// <summary>
 /// Gets the name of the given field
 /// </summary>
 public override string GetFieldName(FieldDefinition field)
 {
     switch (field.Name)
     {
         case "MAX_VALUE":
             return "MaxValue";
         case "MIN_VALUE":
             return "MinValue";
         default:
             return field.Name;
     }
 }
        /// <summary>
        /// Gets the name of the given field
        /// </summary>
        public override string GetFieldName(FieldDefinition field)
        {
            switch (field.Name)
            {
                case "MIN_VALUE":
                    return "Epsilon";

                case "NEGATIVE_INFINITY":
                    return "NegativeInfinity";

                case "POSITIVE_INFINITY":
                    return "PositiveInfinity";

                default:
                    return base.GetFieldName(field);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create type attributes
        /// </summary>
        private static FieldAttributes GetAttributes(FieldDefinition javaField, bool isValueType)
        {
            var result = (FieldAttributes)0;
            var isStatic = javaField.IsStatic;

            if (javaField.IsPublic) result |= FieldAttributes.Public;
            else if (javaField.IsPrivate) result |= FieldAttributes.Private;
            else if (javaField.IsProtected) result |= FieldAttributes.FamORAssem;
            else if (javaField.IsPackagePrivate) result |= FieldAttributes.Assembly;

            if (isStatic) result |= FieldAttributes.Static;
            if (javaField.IsFinal)
            {
                if (isValueType && isStatic)
                    result |= FieldAttributes.Literal;
                else
                    result |= FieldAttributes.InitOnly;
            }
            //if ((accessFlags & FieldAccessFlags.Transient) != 0) result |= MemberAttributes..NotSerialized;

            return result;
        }
 /// <summary>
 /// Should the given field be implemented?
 /// </summary>
 protected internal override bool ShouldImplement(FieldDefinition field, TargetFramework target)
 {
     if (cf.IsInterface)
         return false;
     return base.ShouldImplement(field, target);
 }
 /// <summary>
 /// Gets the name of the given field
 /// </summary>
 public override string GetFieldName(FieldDefinition field)
 {
     return FixFieldName(base.GetFieldName(field), field, typeDef);
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public JavaFieldDefinitionNode(FieldDefinition fieldDef)
 {
     this.fieldDef = fieldDef;
     Text = fieldDef.Name;
     ImageIndex = 4;
 }
Beispiel #8
0
        /// <summary>
        /// Read the header
        /// </summary>
        internal void ReadHeader(ClassFile cf)
        {
            var magic = stream.ReadU4();
            if (magic != ClassFile.Magic)
                throw new Dot42Exception("Invalid magic");

            cf.MinorVersion = stream.ReadU2();
            cf.MajorVersion = stream.ReadU2();

            var cpCount = stream.ReadU2();
            var cp = new ConstantPool(cpCount, cf.Loader);
            for (var i = 1; i < cpCount; i++)
            {
                var tag = (ConstantPoolTags) stream.ReadU1();
                ConstantPoolEntry entry;
                int tmp;
                switch (tag)
                {
                    case ConstantPoolTags.Class:
                        entry = new ConstantPoolClass(cp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.Fieldref:
                        tmp = stream.ReadU2();
                        entry = new ConstantPoolFieldRef(cp, tmp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.Methodref:
                        tmp = stream.ReadU2();
                        entry = new ConstantPoolMethodRef(cp, tmp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.InterfaceMethodref:
                        tmp = stream.ReadU2();
                        entry = new ConstantPoolInterfaceMethodRef(cp, tmp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.String:
                        entry = new ConstantPoolString(cp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.Integer:
                        entry = new ConstantPoolInteger(cp, stream.ReadS4());
                        break;
                    case ConstantPoolTags.Float:
                        entry = new ConstantPoolFloat(cp, stream.ReadF4());
                        break;
                    case ConstantPoolTags.Long:
                        entry = new ConstantPoolLong(cp, stream.ReadS8());
                        break;
                    case ConstantPoolTags.Double:
                        entry = new ConstantPoolDouble(cp, stream.ReadF8());
                        break;
                    case ConstantPoolTags.NameAndType:
                        tmp = stream.ReadU2();
                        entry = new ConstantPoolNameAndType(cp, tmp, stream.ReadU2());
                        break;
                    case ConstantPoolTags.Utf8:
                        tmp = stream.ReadU2();
                        entry = new ConstantPoolUtf8(cp, stream.ReadUTF8(tmp));
                        break;
                    default:
                        throw new Dot42Exception("Unknown constant pool tag: " + (int)tag);
                }
                cp[i] = entry;
                if ((tag == ConstantPoolTags.Double) || (tag == ConstantPoolTags.Long))
                    i++;
            }

            cf.ClassAccessFlags = (ClassAccessFlags) stream.ReadU2();
            
            var index = stream.ReadU2();
            cf.ClassName = cp.GetEntry<ConstantPoolClass>(index).Name;
            index = stream.ReadU2();
            cf.SuperClass = (index == 0) ? null : new ObjectTypeReference(cp.GetEntry<ConstantPoolClass>(index).Name, null);

            // Interfaces
            var icount = stream.ReadU2();
            var interfaces = new string[icount];
            for (var i = 0; i < icount; i++)
            {
                index = stream.ReadU2();
                interfaces[i] = cp.GetEntry<ConstantPoolClass>(index).Name;
            }
            cf.Interfaces = interfaces.Select(x => new ObjectTypeReference(x, null)).ToArray();

            // Fields
            var fcount = stream.ReadU2();
            for (var i = 0; i < fcount; i++)
            {
                var accessFlags = (FieldAccessFlags) stream.ReadU2();
                var nameIndex = stream.ReadU2();
                var descriptorIndex = stream.ReadU2();
                var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value;
                var descriptor = cp.GetEntry<ConstantPoolUtf8>(descriptorIndex).Value;
                var field = new FieldDefinition(cf, accessFlags, name, descriptor, null);
                ReadAttributes(cp, field);
                cf.Fields.Add(field);
            }

            // Methods
            var mcount = stream.ReadU2();
            for (var i = 0; i < mcount; i++)
            {
                var accessFlags = (MethodAccessFlags)stream.ReadU2();
                var nameIndex = stream.ReadU2();
                var descriptorIndex = stream.ReadU2();
                var name = cp.GetEntry<ConstantPoolUtf8>(nameIndex).Value;
                var descriptor = cp.GetEntry<ConstantPoolUtf8>(descriptorIndex).Value;
                var method = new MethodDefinition(cf, accessFlags, name, descriptor, null);
                ReadAttributes(cp, method);
                cf.Methods.Add(method);
            }

            // Attributes
            ReadAttributes(cp, cf);
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public JavaFieldDefinition(XTypeDefinition declaringType, FieldDefinition field)
     : base(declaringType)
 {
     this.field = field;
 }
Beispiel #10
0
 /// <summary>
 /// Mark all eachable items in argument as such.
 /// </summary>
 private static void Walk(ReachableContext context, FieldDefinition field)
 {
     field.FieldType.MarkReachable(context);
     field.DeclaringClass.MarkReachable(context);
 }
 protected internal override bool ShouldImplement(FieldDefinition field, TargetFramework target)
 {
     return true;
 }
Beispiel #12
0
 /// <summary>
 /// Convert an Java field reference to an XFieldReference.
 /// </summary>
 public static XFieldDefinition AsFieldDefinition(XModule module, FieldDefinition field)
 {
     return AsTypeReference(module, field.DeclaringClass, XTypeUsageFlags.DeclaringType).Resolve().GetByOriginalField(field);
 }
 /// <summary>
 /// Resolve the field into a java field definition.
 /// </summary>
 public JavaFieldDefinition Resolve(ClassFile declaringClass)
 {
     return(resolved ?? (resolved = BuildField(declaringClass)));
 }
Beispiel #14
0
 /// <summary>
 /// Clone this definition for use in a given other class.
 /// </summary>
 public FieldDefinition CloneTo(ClassFile otherClass)
 {
     var clone = new FieldDefinition(otherClass, accessFlags, Name, descriptor, null);
     clone.Signature = Signature;
     return clone;
 }