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

Scala example source code file (CustomModifier.java)

This example Scala source code file (CustomModifier.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

custommodifier, custommodifier, string, string, type, type, volatilemarker, volatilemarker

The Scala CustomModifier.java source code

package ch.epfl.lamp.compiler.msil;

/**
 * Quoting from  the CIL spec, Partition II, Sec. 7.1.1: 
 * 
 * Custom modifiers, defined using `modreq` (required modifier) and `modopt` (optional modifier), are
 * similar to custom attributes (Sec. 21) except that modifiers are part of a signature rather than being attached to a
 * declaration. Each modifer associates a type reference with an item in the signature. 
 * 
 */
public class CustomModifier {
    
    public boolean isReqd;
    public Type    marker;
    
    public CustomModifier(boolean isReqd, Type marker) {
        this.isReqd = isReqd;
        this.marker = marker;
    }
    
    public String toString() {
        String res = (isReqd ? "modreq( " : "modopt( ") + marker.toString() + " )";
        return res;
    }
    
    public static Type[] helperCustomMods(boolean isReqd, CustomModifier[] cmods) {
        if(cmods == null) return null;
        int count = 0;
        for (int idx = 0; idx < cmods.length; idx++) {
            if(cmods[idx].isReqd == isReqd) count++;
        }
        Type[] res = new Type[count];
        int residx = 0;
        for (int idx = 0; idx < cmods.length; idx++) {
            res[residx] = cmods[idx].marker;
            residx++;
        }
        return res;
    }
    
    public static Type VolatileMarker() {
        return Type.GetType("System.Runtime.CompilerServices.IsVolatile");
    }

}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala CustomModifier.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.