com.redhat.ceylon.compiler.js.loader.JsonModule Maven / Gradle / Ivy
package com.redhat.ceylon.compiler.js.loader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import com.redhat.ceylon.common.Backend;
import com.redhat.ceylon.common.Backends;
import com.redhat.ceylon.model.typechecker.model.Annotation;
import com.redhat.ceylon.model.typechecker.model.Module;
import com.redhat.ceylon.model.typechecker.model.ModuleImport;
import com.redhat.ceylon.model.typechecker.model.Package;
public class JsonModule extends Module implements NpmAware {
private Map model;
private boolean loaded = false;
private String npmPath;
public void setModel(Map value) {
if (model != null) {
final String modName = (String)model.get("$mod-name");
final String modVers = (String)model.get("$mod-version");
if (!(Objects.equals(modName, value.get("$mod-name"))
&& Objects.equals(modVers, value.get("$mod-version")))) {
throw new IllegalStateException("JsonModule " + modName+"/"+modVers
+ " receives new module " + value.get("$mod-name")+"/"+value.get("$mod-version"));
}
return;
}
model = value;
final String binVersion = (String)model.get("$mod-bin");
final int dotidx = binVersion.indexOf('.');
setJsMajor(Integer.parseInt(binVersion.substring(0,dotidx), 10));
setJsMinor(Integer.parseInt(binVersion.substring(dotidx+1), 10));
if (model.get("$mod-pa") != null) {
int bits = (int)model.get("$mod-pa");
setNativeBackends(JsonPackage.hasAnnotationBit(bits, "native") ? Backend.JavaScript.asSet() : Backends.ANY);
}
@SuppressWarnings("unchecked")
final Object moduleAnns = model.get("$mod-anns");
if (moduleAnns instanceof List) {
JsonPackage.setNewAnnotations(getAnnotations(), (List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy