]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/specification/EnvironmentSpecification.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / environment / specification / EnvironmentSpecification.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/specification/EnvironmentSpecification.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/specification/EnvironmentSpecification.java
new file mode 100644 (file)
index 0000000..c6dc8db
--- /dev/null
@@ -0,0 +1,47 @@
+package org.simantics.scl.compiler.environment.specification;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.module.ImportDeclaration;
+
+public class EnvironmentSpecification {
+    public final ArrayList<ImportDeclaration> imports = new ArrayList<ImportDeclaration>();
+    
+    public void importModule(String moduleName, String localName) {
+        imports.add(new ImportDeclaration(moduleName, localName));
+    }
+    
+    public static EnvironmentSpecification of(String ... strings) {
+        if(strings.length % 2 != 0)
+            throw new IllegalArgumentException("Expected even number of parameters.");
+        EnvironmentSpecification spec = new EnvironmentSpecification();
+        for(int i=0;i<strings.length;i+=2)
+            spec.importModule(strings[i], strings[i+1]);
+        return spec;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((imports == null) ? 0 : imports.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        EnvironmentSpecification other = (EnvironmentSpecification) obj;
+        if (imports == null) {
+            if (other.imports != null)
+                return false;
+        } else if (!imports.equals(other.imports))
+            return false;
+        return true;
+    }
+}