Java Code Examples for org.spongepowered.asm.mixin.MixinEnvironment#setCompatibilityLevel()

The following examples show how to use org.spongepowered.asm.mixin.MixinEnvironment#setCompatibilityLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MixinPlatformManager.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Set the desired compatibility level as a string, used by agents to set
 * compatibility level from jar manifest
 * 
 * @param level compatibility level as a string
 */
@SuppressWarnings("deprecation")
final void setCompatibilityLevel(String level) {
    try {
        CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase(Locale.ROOT));
        MixinPlatformManager.logger.debug("Setting mixin compatibility level: {}", value);
        MixinEnvironment.setCompatibilityLevel(value);
    } catch (IllegalArgumentException ex) {
        MixinPlatformManager.logger.warn("Invalid compatibility level specified: {}", level);
    }
}
 
Example 2
Source File: MixinConfig.java    From Mixin with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void initCompatibilityLevel() {
    if (this.compatibility == null) {
        return;
    }
    
    CompatibilityLevel level = CompatibilityLevel.valueOf(this.compatibility.trim().toUpperCase(Locale.ROOT));
    CompatibilityLevel current = MixinEnvironment.getCompatibilityLevel();
    
    if (level == current) {
        return;
    }
    
    // Current level is higher than required but too new to support it
    if (current.isAtLeast(level)) {
        if (!current.canSupport(level)) {
            throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is too old");
        }
    }
    
    // Current level is lower than required but current level prohibits elevation
    if (!current.canElevateTo(level)) {
        throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is prohibited by "
                + current);
    }
    
    MixinEnvironment.setCompatibilityLevel(level);
}