alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (PropertyInfo.java)

This example Scala source code file (PropertyInfo.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

attributes, canread, canwrite, getaccessors, getgetmethod, getgetmethod, getsetmethod, getsetmethod, methodinfo, methodinfo, propertyinfo, propertyinfo, propertytype, type

The Scala PropertyInfo.java source code

/*
 * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
 */


package ch.epfl.lamp.compiler.msil;

/**
 * Discovers the attributes of a property
 * and provides access to property metadata.
 *
 * @author Nikolay Mihaylov
 * @version 1.0
 */
public class PropertyInfo extends MemberInfo {

    //##########################################################################

    public final int MemberType() { return MemberTypes.Property; }

    public final short Attributes;

    public final boolean CanRead;

    public final boolean CanWrite;

    public final Type PropertyType;

    /** Returns an array of the public get and set accessors for this property.
     */
    public MethodInfo[] GetAccessors() {
	return GetAccessors(false);
    }

    /** Returns an array of the public or non-public <b>get
     *  and <b>set accessors for this property.
     */
    public MethodInfo[] GetAccessors(boolean nonPublic) {
	MethodInfo getter = GetGetMethod(nonPublic);
	MethodInfo setter = GetSetMethod(nonPublic);
	if (getter == null)
	    if (setter == null) return MethodInfo.EMPTY_ARRAY;
	    else return new MethodInfo[]{setter};
	else if (setter == null) return new MethodInfo[] {getter};
	else return new MethodInfo[] {getter, setter};
    }

    /** Returns the public <b>get accessor for this property.
     */
    public MethodInfo GetGetMethod() {
	return GetGetMethod(false);
    }

    /** Returns the public or non-public <b>get accessor for this property.
     */
    public MethodInfo GetGetMethod(boolean nonPublic) {
	return nonPublic ? getter
	    : getter == null || getter.IsPublic() ? getter : null;
    }

    /** Returns the public <b>set accessor for this property.
     */
    public MethodInfo GetSetMethod() {
	return GetSetMethod(false);
    }

    /** Returns the public or non-public <b>set accessor for this property.
     */
    public MethodInfo GetSetMethod(boolean nonPublic) {
	return nonPublic ? setter
	    : setter == null || setter.IsPublic() ? setter : null;
    }

    public String toString() {
	MethodInfo m = getter != null ? getter : setter;
	return MethodAttributes.accessFlagsToString
	    ((getter != null ? getter : setter).Attributes)
	    +  " " + PropertyAttributes.toString(Attributes)
	    + DeclaringType + "::" + Name;
    }

    //##########################################################################
    // protected members

    protected static final PropertyInfo[] EMPTY_ARRAY = new PropertyInfo[0];

    protected MethodInfo getter;
    protected MethodInfo setter;

    protected PropertyInfo(String name, Type declType, short attr,
			   Type propType, MethodInfo getter, MethodInfo setter)
    {
	super(name, declType);
	Attributes = attr;
	PropertyType = propType;
	this.getter = getter;
	this.setter = setter;
	CanRead = getter != null;
	CanWrite = setter != null;
    }

    //##########################################################################

} // class PropertyInfo

Other Scala examples (source code examples)

Here is a short list of links related to this Scala PropertyInfo.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.