summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-03-13 16:44:23 (EDT)
committer ahaase2008-03-13 16:44:23 (EDT)
commit43af73b41314b1155f37e66d37978a946443bfac (patch)
tree54bc8a1270c4d6e577bbe2aba9eaf4593101cbb7
parenta67692fefd7015ee21be752116e07c7fe3c4dc4f (diff)
downloadorg.eclipse.xpand-43af73b41314b1155f37e66d37978a946443bfac.zip
org.eclipse.xpand-43af73b41314b1155f37e66d37978a946443bfac.tar.gz
org.eclipse.xpand-43af73b41314b1155f37e66d37978a946443bfac.tar.bz2
added "find type by unique string representation" and added some tests
-rw-r--r--plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/UmlTypesystem.java4
-rw-r--r--plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/EnumType.java3
-rw-r--r--plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/MultipleStereotypeType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/StereotypeType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendTypesystem.java5
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractType.java11
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java34
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BooleanType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/CollectionType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/DoubleType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/FunctionType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ListType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/LongType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/MapType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ObjectType.java4
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/PropertyType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/SetType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StaticPropertyType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/VoidType.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EObjectType.java (renamed from plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EObjectType.java)5
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EmfTypesystem.java36
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EClassType.java3
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EDataTypeType.java3
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EEnumType.java3
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java15
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java4
-rw-r--r--plugins/org.eclipse.xtend.middleend.xtend/src/org/eclipse/xtend/middleend/xtend/internal/TypeToBackendType.java2
-rw-r--r--tests/org.eclipse.xtend.backend.test/META-INF/MANIFEST.MF1
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/BuiltinTypesTest.java60
-rw-r--r--tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java14
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/GeneralTest.java135
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/Person.java (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/Person.java)2
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/WithFileOutput.xpt (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/WithFileOutput.xpt)0
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/aTemplate.xpt (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/aTemplate.xpt)4
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first.ext (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/first.ext)4
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java83
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/imported.ext4
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/reexported.ext5
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/imported.ext4
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/otherTemplate.xpt (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/otherTemplate.xpt)0
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/reexported.ext5
-rw-r--r--tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/sub/templateInOtherPackage.xpt (renamed from tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/sub/templateInOtherPackage.xpt)0
45 files changed, 362 insertions, 123 deletions
diff --git a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/UmlTypesystem.java b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/UmlTypesystem.java
index 5a23e99..8a3fc50 100644
--- a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/UmlTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/UmlTypesystem.java
@@ -196,4 +196,8 @@ public final class UmlTypesystem implements BackendTypesystem {
_emfTypesystem.setRootTypesystem (ts);
_rootTs = ts;
}
+
+ public BackendType findType (String uniqueRepresentation) {
+ throw new UnsupportedOperationException ("TODO"); //TODO implement findByUniqueRepresentation
+ }
}
diff --git a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/EnumType.java b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/EnumType.java
index f7a9a25..9cc4213 100644
--- a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/EnumType.java
+++ b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/EnumType.java
@@ -19,6 +19,7 @@ import org.eclipse.xtend.backend.common.StaticProperty;
import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.types.AbstractType;
import org.eclipse.xtend.backend.types.builtin.StringType;
+import org.eclipse.xtend.backend.types.emf.EObjectType;
/**
@@ -30,7 +31,7 @@ public final class EnumType extends AbstractType {
private final Enumeration _enumeration;
public EnumType (String name, Enumeration en) {
- super (name);
+ super (name, name, EObjectType.INSTANCE); //TODO uniqueRepresentation
_enumeration = en;
for (final EnumerationLiteral el: en.getOwnedLiterals())
diff --git a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/MultipleStereotypeType.java b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/MultipleStereotypeType.java
index 815020c..2a754a4 100644
--- a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/MultipleStereotypeType.java
+++ b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/MultipleStereotypeType.java
@@ -27,7 +27,7 @@ public final class MultipleStereotypeType extends AbstractType {
private final List<BackendType> _stereotypeTypes;
public MultipleStereotypeType (List<BackendType> stereoTypeTypes) {
- super (computeName (stereoTypeTypes), stereoTypeTypes.toArray (new BackendType[0]));
+ super (computeName (stereoTypeTypes), computeName(stereoTypeTypes), stereoTypeTypes.toArray (new BackendType[0])); //TODO uniqueRepresentation
_stereotypeTypes = stereoTypeTypes;
}
diff --git a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/StereotypeType.java b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/StereotypeType.java
index 4469b44..e818b98 100644
--- a/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/StereotypeType.java
+++ b/plugins/org.eclipse.xtend.backend.uml2types/src/org/eclipse/xtend/backend/types/uml2/internal/StereotypeType.java
@@ -45,7 +45,7 @@ public final class StereotypeType extends AbstractType {
private final Stereotype _stereoType;
public StereotypeType (String name, Stereotype stereoType, UmlTypesystem umlTs) {
- super (name, superTypes (umlTs, stereoType).toArray (new BackendType[0]));
+ super (name, name, superTypes (umlTs, stereoType).toArray (new BackendType[0])); //TODO uniqueRepresentation
_stereoType = stereoType;
for (StereotypeProperty stp: getProperties(this, stereoType, umlTs))
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendType.java
index 5074ed9..fae346d 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendType.java
@@ -33,4 +33,6 @@ public interface BackendType {
Collection<? extends BackendType> getSuperTypes ();
Map<String, ? extends Property> getProperties ();
Map<String, ? extends StaticProperty> getStaticProperties ();
+
+ String getUniqueRepresentation ();
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendTypesystem.java
index 809c406..d0f2e70 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/BackendTypesystem.java
@@ -26,6 +26,11 @@ public interface BackendTypesystem {
*/
BackendType findType (Class<?> cls);
+ /**
+ * returns the type corresponding with the unique representation. It is up to typesystem implementations to
+ * provide - and document - their respective naming schemes
+ */
+ BackendType findType (String uniqueRepresentation);
void setRootTypesystem (BackendTypesystem ts);
BackendTypesystem getRootTypesystem ();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractType.java
index b32e3ca..31466da 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/AbstractType.java
@@ -38,6 +38,7 @@ import org.eclipse.xtend.backend.util.StringHelper;
*/
public abstract class AbstractType implements BackendType {
private final String _name;
+ private final String _uniqueRepresentation;
private final List<BackendType> _superTypes;
private final Map<String, Property> _properties = new HashMap<String, Property> ();
@@ -45,8 +46,9 @@ public abstract class AbstractType implements BackendType {
private final Collection<NamedFunction> _builtinOperations = new HashSet<NamedFunction> ();
- public AbstractType(String name, BackendType... superTypes) {
+ public AbstractType(String name, String uniqueRepresentation, BackendType... superTypes) {
_name = name;
+ _uniqueRepresentation = uniqueRepresentation;
if (superTypes.length == 0)
_superTypes = Collections.singletonList((BackendType) ObjectType.INSTANCE);
@@ -60,8 +62,9 @@ public abstract class AbstractType implements BackendType {
}
}
- public AbstractType(String name, Collection<? extends BackendType> superTypes) {
+ public AbstractType(String name, String uniqueRepresentation, Collection<? extends BackendType> superTypes) {
_name = name;
+ _uniqueRepresentation = uniqueRepresentation;
_superTypes = new ArrayList<BackendType> (superTypes);
}
@@ -130,6 +133,10 @@ public abstract class AbstractType implements BackendType {
return _staticProperties;
}
+ public String getUniqueRepresentation () {
+ return _uniqueRepresentation;
+ }
+
public boolean isAssignableFrom (BackendType other) {
if (other == VoidType.INSTANCE)
return true;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
index 39f0263..3756ed8 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/CompositeTypesystem.java
@@ -12,6 +12,7 @@ package org.eclipse.xtend.backend.types;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -50,6 +51,25 @@ public final class CompositeTypesystem implements BackendTypesystem {
private BackendTypesystem _rootTypesystem = this;
private final List<BackendTypesystem> _inner = new ArrayList<BackendTypesystem>();
+ private static final Map<String, BackendType> _typeByUniqueRepresentation = new HashMap<String, BackendType> ();
+
+ static {
+ _typeByUniqueRepresentation.put ("{builtin}Boolean", BooleanType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Collection", CollectionType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Double", DoubleType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Function", FunctionType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}List", ListType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Long", LongType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Map", MapType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Object", ObjectType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Property", PropertyType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Set", SetType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}StaticProperty", StaticPropertyType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}String", StringType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Type", TypeType.INSTANCE);
+ _typeByUniqueRepresentation.put ("{builtin}Void", VoidType.INSTANCE);
+ }
+
private final BackendTypesystem _javaBeansTypesystem = new GlobalJavaBeansTypesystem ();
{
_javaBeansTypesystem.setRootTypesystem (_rootTypesystem);
@@ -130,6 +150,20 @@ public final class CompositeTypesystem implements BackendTypesystem {
return _typeByClassCache.get (cls);
}
+ public BackendType findType (String uniqueRepresentation) {
+ final BackendType asBuiltin = _typeByUniqueRepresentation.get (uniqueRepresentation);
+ if (asBuiltin != null)
+ return asBuiltin;
+
+ for (BackendTypesystem ts: _inner) {
+ final BackendType t = ts.findType (uniqueRepresentation);
+ if (t != null)
+ return t;
+ }
+
+ return _javaBeansTypesystem.findType (uniqueRepresentation);
+ }
+
public BackendTypesystem getRootTypesystem () {
return _rootTypesystem;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BooleanType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BooleanType.java
index 4902db9..cacc528 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BooleanType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/BooleanType.java
@@ -21,7 +21,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
public final class BooleanType extends AbstractType {
public static final BooleanType INSTANCE = new BooleanType ();
- private BooleanType () {super ("boolean");}
+ private BooleanType () {super ("boolean", "{builtin}Boolean");}
@Override
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/CollectionType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/CollectionType.java
index 4274aad..cf8c7d6 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/CollectionType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/CollectionType.java
@@ -24,7 +24,7 @@ public final class CollectionType extends AbstractType {
public static final CollectionType INSTANCE = new CollectionType();
private CollectionType() {
- super ("Collection");
+ super ("Collection", "{builtin}Collection");
register (new BuiltinProperty (this, LongType.INSTANCE, "size", ReflectionHelper.getKnownMethod(Collection.class, "size"), null));
register (new BuiltinProperty (this, BooleanType.INSTANCE, "isEmpty", ReflectionHelper.getKnownMethod(Collection.class, "isEmpty"), null));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/DoubleType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/DoubleType.java
index 8378214..05455c4 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/DoubleType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/DoubleType.java
@@ -21,7 +21,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
public final class DoubleType extends AbstractType {
public static final DoubleType INSTANCE = new DoubleType();
- private DoubleType () {super ("Double"); }
+ private DoubleType () {super ("Double", "{builtin}Double"); }
@Override
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/FunctionType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/FunctionType.java
index 9778938..feccb87 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/FunctionType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/FunctionType.java
@@ -29,7 +29,7 @@ public final class FunctionType extends AbstractType {
public static final FunctionType INSTANCE = new FunctionType ();
private FunctionType () {
- super ("Function");
+ super ("Function", "{builtin}Function");
register ("invoke", new Function () {
public List<BackendType> getParameterTypes() {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ListType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ListType.java
index d862beb..96980df 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ListType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ListType.java
@@ -20,7 +20,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
* @author Arno Haase (http://www.haase-consulting.com)
*/
public final class ListType extends AbstractType {
- private ListType () {super ("List", CollectionType.INSTANCE); }
+ private ListType () {super ("List", "{builtin}List", CollectionType.INSTANCE); }
public static final ListType INSTANCE = new ListType ();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/LongType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/LongType.java
index a20702b..7ea7459 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/LongType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/LongType.java
@@ -21,7 +21,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
public final class LongType extends AbstractType {
public static final LongType INSTANCE = new LongType();
- private LongType () {super ("Long"); }
+ private LongType () {super ("Long", "{builtin}Long"); }
@Override
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/MapType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/MapType.java
index e778139..8b319a2 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/MapType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/MapType.java
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.util.ReflectionHelper;
*/
public final class MapType extends AbstractType {
private MapType () {
- super ("Map");
+ super ("Map", "{builtin}Map");
register (new BuiltinProperty (CollectionType.INSTANCE, LongType.INSTANCE, "size", ReflectionHelper.getKnownMethod(Collection.class, "size"), null));
register (new BuiltinProperty (CollectionType.INSTANCE, BooleanType.INSTANCE, "isEmpty", ReflectionHelper.getKnownMethod(Collection.class, "isEmpty"), null));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ObjectType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ObjectType.java
index 06925e2..e62be49 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ObjectType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/ObjectType.java
@@ -45,6 +45,10 @@ public final class ObjectType implements BackendType {
public String getName () {
return "Object";
}
+
+ public String getUniqueRepresentation () {
+ return "{builtin}Object";
+ }
public Map<String, ? extends Property> getProperties () {
return Collections.emptyMap();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/PropertyType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/PropertyType.java
index 289adbd..c105304 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/PropertyType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/PropertyType.java
@@ -24,7 +24,7 @@ public final class PropertyType extends AbstractType {
public static final PropertyType INSTANCE = new PropertyType ();
private PropertyType () {
- super ("Property");
+ super ("Property", "{builtin}Property");
register (new BuiltinProperty (this, StringType.INSTANCE, "name", ReflectionHelper.getKnownMethod(Property.class, "getName"), null));
register (new BuiltinProperty (this, TypeType.INSTANCE, "returnType", ReflectionHelper.getKnownMethod(Property.class, "getType"), null));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/SetType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/SetType.java
index 6465b2e..ac34096 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/SetType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/SetType.java
@@ -21,7 +21,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
*/
public final class SetType extends AbstractType {
private SetType () {
- super ("Set", CollectionType.INSTANCE);
+ super ("Set", "{builtin}Set", CollectionType.INSTANCE);
}
public static final SetType INSTANCE = new SetType ();
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StaticPropertyType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StaticPropertyType.java
index 9c6a91e..790efbf 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StaticPropertyType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StaticPropertyType.java
@@ -24,7 +24,7 @@ public final class StaticPropertyType extends AbstractType {
public static final StaticPropertyType INSTANCE = new StaticPropertyType ();
private StaticPropertyType () {
- super ("Property");
+ super ("StaticProperty", "{builtin}StaticProperty");
register (new BuiltinProperty (this, StringType.INSTANCE, "name", ReflectionHelper.getKnownMethod(Property.class, "getName"), null));
register (new BuiltinProperty (this, TypeType.INSTANCE, "returnType", ReflectionHelper.getKnownMethod(Property.class, "getType"), null));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
index c2469d1..07575bd 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/StringType.java
@@ -29,7 +29,7 @@ public final class StringType extends AbstractType {
public static final StringType INSTANCE = new StringType();
private StringType () {
- super ("String");
+ super ("String", "{builtin}String");
register (new BuiltinProperty (this, this, "length", ReflectionHelper.getKnownMethod (CharSequence.class, "length"), null));
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
index 1eb2f0b..773fd06 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/TypeType.java
@@ -33,7 +33,7 @@ public final class TypeType extends AbstractType {
public static final TypeType INSTANCE = new TypeType ();
private TypeType () {
- super ("Type");
+ super ("Type", "{builtin}Type");
register (new BuiltinProperty (this, StringType.INSTANCE, "name", ReflectionHelper.getKnownMethod (BackendType.class, "getName"), null));
register (new BuiltinProperty (this, ListType.INSTANCE, "superTypes", ReflectionHelper.getKnownMethod (BackendType.class, "getSuperTypes"), null));
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/VoidType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/VoidType.java
index 82ffc8e..6dc4412 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/VoidType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/builtin/VoidType.java
@@ -23,7 +23,7 @@ import org.eclipse.xtend.backend.types.AbstractType;
public final class VoidType extends AbstractType {
public static final VoidType INSTANCE = new VoidType();
- private VoidType () {super ("Void"); }
+ private VoidType () {super ("Void", "{builtin}Void"); }
@Override
public boolean isAssignableFrom (BackendType other) {
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EObjectType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EObjectType.java
index 29ffb96..f237735 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EObjectType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EObjectType.java
@@ -8,13 +8,14 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors:
Arno Haase - initial API and implementation
*/
-package org.eclipse.xtend.backend.types.emf.internal;
+package org.eclipse.xtend.backend.types.emf;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
@@ -33,7 +34,7 @@ public final class EObjectType extends AbstractType {
public static final EObjectType INSTANCE = new EObjectType ();
private EObjectType () {
- super ("emf::EObject");
+ super ("emf::EObject", EmfTypesystem.getUniqueIdentifier (EcorePackage.eINSTANCE.getEObject()));
register (new AbstractProperty (INSTANCE, INSTANCE, EObject.class, "eContainer", false) {
@Override
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EmfTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EmfTypesystem.java
index 34dd792..6f4d51a 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EmfTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/EmfTypesystem.java
@@ -13,6 +13,7 @@ package org.eclipse.xtend.backend.types.emf;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EDataType;
@@ -20,6 +21,7 @@ import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.xtend.backend.common.BackendType;
@@ -34,7 +36,6 @@ import org.eclipse.xtend.backend.types.builtin.StringType;
import org.eclipse.xtend.backend.types.emf.internal.EClassType;
import org.eclipse.xtend.backend.types.emf.internal.EDataTypeType;
import org.eclipse.xtend.backend.types.emf.internal.EEnumType;
-import org.eclipse.xtend.backend.types.emf.internal.EObjectType;
/**
@@ -43,6 +44,9 @@ import org.eclipse.xtend.backend.types.emf.internal.EObjectType;
*/
public final class EmfTypesystem implements BackendTypesystem {
private BackendTypesystem _rootTypesystem;
+
+ public static final String UNIQUE_REPRESENTATION_PREFIX = "{emf}";
+
private final Map<EClassifier, BackendType> _cache = new HashMap<EClassifier, BackendType>();
@@ -75,6 +79,36 @@ public final class EmfTypesystem implements BackendTypesystem {
_ecorePrimitives.put (EcorePackage.eINSTANCE.getEJavaObject(), ObjectType.INSTANCE);
}
+
+ public static String getUniqueIdentifier (EClassifier cls) {
+ return UNIQUE_REPRESENTATION_PREFIX + "{" + cls.getEPackage().getNsURI() + "}" + cls.getName();
+ }
+
+ public BackendType findType (String uniqueRepresentation) {
+ if (! uniqueRepresentation.startsWith (UNIQUE_REPRESENTATION_PREFIX))
+ return null;
+
+ uniqueRepresentation = uniqueRepresentation.substring (UNIQUE_REPRESENTATION_PREFIX.length());
+
+ final String nsUri = uniqueRepresentation.substring (1, uniqueRepresentation.indexOf('}'));
+ final String name = uniqueRepresentation.substring (uniqueRepresentation.indexOf('}') + 1);
+
+ final EPackage pkg = EPackage.Registry.INSTANCE.getEPackage (nsUri);
+
+ for (final TreeIterator<EObject> iter = pkg.eAllContents(); iter.hasNext(); ) {
+ final EObject eo = iter.next();
+ if (! (eo instanceof EClassifier))
+ continue;
+
+ final EClassifier cls = (EClassifier) eo;
+ if (name.equals(cls.getName()))
+ return getTypeForEClassifier (cls);
+ }
+
+ return null;
+ }
+
+
/**
* This method serves as the single point of access to the internal cache of types; all other methods that
* look up a type should go through this method.
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EClassType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EClassType.java
index f64266a..8a337e8 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EClassType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EClassType.java
@@ -29,6 +29,7 @@ import org.eclipse.xtend.backend.common.Function;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.types.AbstractProperty;
import org.eclipse.xtend.backend.types.AbstractType;
+import org.eclipse.xtend.backend.types.emf.EObjectType;
import org.eclipse.xtend.backend.types.emf.EmfTypesystem;
import org.eclipse.xtend.backend.util.CollectionHelper;
import org.eclipse.xtend.backend.util.ErrorHandler;
@@ -42,7 +43,7 @@ public final class EClassType extends AbstractType {
private final EClass _cls;
public EClassType (EClass cls, EmfTypesystem ts) {
- super (EmfTypesystem.getFullyQualifiedName(cls), superTypes(cls, ts));
+ super (EmfTypesystem.getFullyQualifiedName(cls), EmfTypesystem.getUniqueIdentifier(cls), superTypes(cls, ts));
_cls = cls;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EDataTypeType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EDataTypeType.java
index e6f906b..d1a0288 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EDataTypeType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EDataTypeType.java
@@ -12,6 +12,7 @@ package org.eclipse.xtend.backend.types.emf.internal;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.xtend.backend.types.AbstractType;
+import org.eclipse.xtend.backend.types.emf.EObjectType;
import org.eclipse.xtend.backend.types.emf.EmfTypesystem;
@@ -23,7 +24,7 @@ public final class EDataTypeType extends AbstractType {
private final EDataType _dt;
public EDataTypeType (EDataType dt) {
- super (EmfTypesystem.getFullyQualifiedName(dt));
+ super (EmfTypesystem.getFullyQualifiedName(dt), EmfTypesystem.getUniqueIdentifier(dt), EObjectType.INSTANCE);
_dt = dt;
}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EEnumType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EEnumType.java
index 63208bc..c0148c7 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EEnumType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/emf/internal/EEnumType.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.StaticProperty;
import org.eclipse.xtend.backend.types.AbstractType;
+import org.eclipse.xtend.backend.types.emf.EObjectType;
import org.eclipse.xtend.backend.types.emf.EmfTypesystem;
@@ -26,7 +27,7 @@ public final class EEnumType extends AbstractType {
private final EEnum _enum;
public EEnumType (EEnum e) {
- super (EmfTypesystem.getFullyQualifiedName(e), EObjectType.INSTANCE);
+ super (EmfTypesystem.getFullyQualifiedName(e), EmfTypesystem.getUniqueIdentifier(e), EObjectType.INSTANCE);
_enum = e;
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java
index 892b461..a96717c 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/AbstractJavaBeansTypesystem.java
@@ -28,6 +28,9 @@ public abstract class AbstractJavaBeansTypesystem implements BackendTypesystem {
private BackendTypesystem _rootTypesystem = null;
private Map<Class<?>, JavaBeansType> _cache = new HashMap<Class<?>, JavaBeansType>(); // this is necessary to avoid endless recursion!
+ public static final String UNIQUE_REPRESENTATION_PREFIX = "{javabean}";
+
+
public BackendType findType (Class<?> cls) {
if (cls == Object.class)
return null;
@@ -61,6 +64,18 @@ public abstract class AbstractJavaBeansTypesystem implements BackendTypesystem {
return findType (o.getClass());
}
+ public BackendType findType (String uniqueRepresentation) {
+ if (! uniqueRepresentation.startsWith(UNIQUE_REPRESENTATION_PREFIX))
+ return null;
+
+ try {
+ return findType (Class.forName (uniqueRepresentation.substring (UNIQUE_REPRESENTATION_PREFIX.length())));
+ } catch (ClassNotFoundException e) {
+ ErrorHandler.handle (e);
+ return null; //just to make the compiler happy
+ }
+ }
+
/**
* This operation allows support for type system instances that are selective, e.g. by package, as
* to which classes they feel responsible for.
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
index e1dfdb4..94b678a 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/types/java/internal/JavaBeansType.java
@@ -151,6 +151,10 @@ public final class JavaBeansType implements BackendType {
return _javaClass.getCanonicalName().replace(".", "::");
}
+ public String getUniqueRepresentation () {
+ return AbstractJavaBeansTypesystem.UNIQUE_REPRESENTATION_PREFIX + _javaClass.getName();
+ }
+
public Map<String, ? extends Property> getProperties () {
return _properties;
}
diff --git a/plugins/org.eclipse.xtend.middleend.xtend/src/org/eclipse/xtend/middleend/xtend/internal/TypeToBackendType.java b/plugins/org.eclipse.xtend.middleend.xtend/src/org/eclipse/xtend/middleend/xtend/internal/TypeToBackendType.java
index 17cb1d6..0af60e5 100644
--- a/plugins/org.eclipse.xtend.middleend.xtend/src/org/eclipse/xtend/middleend/xtend/internal/TypeToBackendType.java
+++ b/plugins/org.eclipse.xtend.middleend.xtend/src/org/eclipse/xtend/middleend/xtend/internal/TypeToBackendType.java
@@ -112,7 +112,7 @@ public final class TypeToBackendType {
if (t instanceof EEnumType)
return convertEEnumType (t);
if (t instanceof EObjectType)
- return org.eclipse.xtend.backend.types.emf.internal.EObjectType.INSTANCE;
+ return org.eclipse.xtend.backend.types.emf.EObjectType.INSTANCE;
if (t instanceof JavaTypeImpl)
return convertJavaType (t);
diff --git a/tests/org.eclipse.xtend.backend.test/META-INF/MANIFEST.MF b/tests/org.eclipse.xtend.backend.test/META-INF/MANIFEST.MF
index ff7c111..bfe3ece 100644
--- a/tests/org.eclipse.xtend.backend.test/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.xtend.backend.test/META-INF/MANIFEST.MF
@@ -3,5 +3,6 @@ Bundle-ManifestVersion: 2
Bundle-Name: Test Plug-in
Bundle-SymbolicName: org.eclipse.xtend.backend.test
Bundle-Version: 1.0.0
+Fragment-Host: org.eclipse.xtend.backend;bundle-version="0.7.0"
Require-Bundle: org.eclipse.xtend.backend,
org.junit4
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/BuiltinTypesTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/BuiltinTypesTest.java
new file mode 100644
index 0000000..0643fa7
--- /dev/null
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/BuiltinTypesTest.java
@@ -0,0 +1,60 @@
+/*
+Copyright (c) 2008 Arno Haase.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+ Arno Haase - initial API and implementation
+ */
+package org.eclipse.xtend.backend.types;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.BackendTypesystem;
+import org.eclipse.xtend.backend.types.builtin.BooleanType;
+import org.eclipse.xtend.backend.types.builtin.CollectionType;
+import org.eclipse.xtend.backend.types.builtin.DoubleType;
+import org.eclipse.xtend.backend.types.builtin.FunctionType;
+import org.eclipse.xtend.backend.types.builtin.ListType;
+import org.eclipse.xtend.backend.types.builtin.LongType;
+import org.eclipse.xtend.backend.types.builtin.MapType;
+import org.eclipse.xtend.backend.types.builtin.ObjectType;
+import org.eclipse.xtend.backend.types.builtin.PropertyType;
+import org.eclipse.xtend.backend.types.builtin.SetType;
+import org.eclipse.xtend.backend.types.builtin.StaticPropertyType;
+import org.eclipse.xtend.backend.types.builtin.StringType;
+import org.eclipse.xtend.backend.types.builtin.TypeType;
+import org.eclipse.xtend.backend.types.builtin.VoidType;
+import org.junit.Test;
+
+/**
+ *
+ * @author Arno Haase (http://www.haase-consulting.com)
+ */
+public class BuiltinTypesTest {
+ @Test public void testUniqueIdentifier () {
+ check ("{builtin}Boolean", BooleanType.INSTANCE);
+ check ("{builtin}Collection", CollectionType.INSTANCE);
+ check ("{builtin}Double", DoubleType.INSTANCE);
+ check ("{builtin}Function", FunctionType.INSTANCE);
+ check ("{builtin}List", ListType.INSTANCE);
+ check ("{builtin}Long", LongType.INSTANCE);
+ check ("{builtin}Map", MapType.INSTANCE);
+ check ("{builtin}Object", ObjectType.INSTANCE);
+ check ("{builtin}Property", PropertyType.INSTANCE);
+ check ("{builtin}Set", SetType.INSTANCE);
+ check ("{builtin}StaticProperty", StaticPropertyType.INSTANCE);
+ check ("{builtin}String", StringType.INSTANCE);
+ check ("{builtin}Type", TypeType.INSTANCE);
+ check ("{builtin}Void", VoidType.INSTANCE);
+ }
+
+ private void check (String representation, BackendType type) {
+ final BackendTypesystem ts = new CompositeTypesystem ();
+ assertSame (ts.findType (representation), type);
+ assertEquals (representation, type.getUniqueRepresentation());
+ }
+}
diff --git a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java
index 7078414..9927863 100644
--- a/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java
+++ b/tests/org.eclipse.xtend.backend.test/src/org/eclipse/xtend/backend/types/JavaBeansTypeTest.java
@@ -11,10 +11,12 @@ Contributors:
package org.eclipse.xtend.backend.types;
import static org.eclipse.xtend.backend.testhelpers.BackendTestHelper.createEmptyExecutionContext;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.util.Arrays;
+import org.eclipse.xtend.backend.common.BackendType;
+import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.testhelpers.BeanWithSizeProperty;
import org.junit.Test;
@@ -29,4 +31,14 @@ public class JavaBeansTypeTest {
assertEquals ("asdfabc7 - 2", ctx.getFunctionDefContext().invoke (ctx, "myFunction", Arrays.asList(new BeanWithSizeProperty(7), "abc", 5L)));
}
+
+ @Test public void testUniqueIdentifier () {
+ final BackendTypesystem ts = new CompositeTypesystem ();
+
+ final BackendType byClass = ts.findType (BeanWithSizeProperty.class);
+ final BackendType byIdentifier = ts.findType ("{javabean}" + BeanWithSizeProperty.class.getName());
+ assertSame (byClass, byIdentifier);
+
+ assertEquals ("{javabean}" + BeanWithSizeProperty.class.getName(), byClass.getUniqueRepresentation());
+ }
}
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/GeneralTest.java b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/GeneralTest.java
new file mode 100644
index 0000000..e3a14c4
--- /dev/null
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/GeneralTest.java
@@ -0,0 +1,135 @@
+/*
+Copyright (c) 2008 Arno Haase.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
+ Arno Haase - initial API and implementation
+ */
+package org.eclipse.xtend.middleend.old;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.emf.mwe.core.WorkflowContext;
+import org.eclipse.emf.mwe.core.issues.IssuesImpl;
+import org.eclipse.emf.mwe.internal.core.WorkflowContextDefaultImpl;
+import org.eclipse.internal.xtend.type.impl.java.JavaBeansMetaModel;
+import org.eclipse.xpand2.output.Outlet;
+import org.eclipse.xtend.backend.BackendFacade;
+import org.eclipse.xtend.backend.common.ExecutionContext;
+import org.eclipse.xtend.backend.types.CompositeTypesystem;
+import org.eclipse.xtend.middleend.xpand.XpandBackendFacade;
+import org.eclipse.xtend.middleend.xpand.XpandComponent;
+import org.eclipse.xtend.middleend.xtend.XtendBackendFacade;
+import org.eclipse.xtend.typesystem.MetaModel;
+import org.junit.Test;
+
+
+public class GeneralTest {
+ @Test
+ public void testXpandFacade () throws Exception {
+ final List<MetaModel> mms = new ArrayList<MetaModel> ();
+ mms.add (new JavaBeansMetaModel ());
+
+ final CompositeTypesystem ts = new CompositeTypesystem ();
+
+ final XpandBackendFacade xp = XpandBackendFacade.createForFile ("org::eclipse::xtend::middleend::old::aTemplate", "iso-8859-1", mms, new ArrayList<Outlet>());
+ final ExecutionContext ctx = BackendFacade.createExecutionContext (xp.getFunctionDefContext(), ts, true);
+
+ assertEquals ("\n" +
+ "Hello, Arno: Hallo, Arno: 27 - imported 99!\n" +
+ "\n" +
+ " Name: Arno \n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ " ... output from otherTemplate.xpt...\n" +
+ "\n" +
+ "\n" +
+ " This is a message from another package!\n" +
+ "\n" +
+ "\n" +
+ " This is a message from another package!\n" +
+ "\n" +
+ "\n" +
+ " This is a message from another package!\n" +
+ "\n" +
+ "\n" +
+ "", BackendFacade.invoke (ctx, "org/eclipse/xtend/middleend/old/aTemplate/greeting", Arrays.asList("Arno")).toString());
+ }
+
+ @Test
+ public void testXpandComponentWithFile() throws Exception {
+ final File genFile = new File ("src-gen/dummy.txt");
+ genFile.delete();
+
+ final List<MetaModel> mms = new ArrayList<MetaModel> ();
+ mms.add (new JavaBeansMetaModel ());
+
+ final CompositeTypesystem ts = new CompositeTypesystem ();
+
+ final XpandComponent xwc = new XpandComponent ();
+ xwc.setExpand ("org::eclipse::xtend::middleend::old::WithFileOutput::WithFileOutput FOR toBeGreeted");
+ xwc.addOutlet (new Outlet (false, "iso-8859-1", null, true, "src-gen"));
+ xwc.setFileEncoding ("iso-8859-1");
+
+ final WorkflowContext wfContext = new WorkflowContextDefaultImpl ();
+ wfContext.set ("toBeGreeted", "Arno");
+ xwc.invoke (wfContext, null, new IssuesImpl ());
+
+ final Reader r = new BufferedReader (new InputStreamReader (new FileInputStream (genFile), "iso-8859-1"));
+ final StringBuilder sb = new StringBuilder ();
+ int i;
+ while ((i=r.read()) != -1)
+ sb.append ((char) i);
+
+ assertEquals ("\n" +
+ "\tHello Arno: 4!\n" +
+ "\t", sb.toString());
+
+ genFile.delete();
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testXtendFacade() throws Exception {
+ final List<MetaModel> mms = new ArrayList<MetaModel> ();
+ mms.add (new JavaBeansMetaModel ());
+
+ final CompositeTypesystem ts = new CompositeTypesystem ();
+
+ final XtendBackendFacade bc = XtendBackendFacade.createForFile ("org::eclipse::xtend::middleend::old::first", "iso-8859-1", mms);
+ final ExecutionContext ctx = BackendFacade.createExecutionContext (bc.getFunctionDefContext(), ts, true);
+
+ assertEquals ("Hallo, Arno: 27 - imported 99!", BackendFacade.invoke (ctx, "test", Arrays.asList ("Arno")).toString());
+ assertEquals ("[a Hallo b]", BackendFacade.invoke (ctx, "testColl", Arrays.asList (Arrays.asList (1L, "Hallo"))).toString());
+ assertEquals (10L, BackendFacade.invoke (ctx, "reexp", Arrays.asList (2L)));
+
+ final Person p = new Person ();
+ p.setFirstName ("Testa");
+ p.setName ("Testarossa");
+
+ assertEquals ("[Testa Testarossa] - Testa Testarossa - Testa Testarossa - Testa", BackendFacade.invoke (ctx, "testPerson", Arrays.asList(p)).toString());
+ }
+
+ @Test
+ public void testEvaluateExpression() throws Exception {
+ final List<MetaModel> mms = new ArrayList<MetaModel> ();
+ mms.add (new JavaBeansMetaModel ());
+
+ assertEquals ("Hallo, Arno: 27 - imported 99!", XtendBackendFacade.invokeXtendFunction ("org::eclipse::xtend::middleend::old::first", null, mms, "test", "Arno").toString());
+ assertEquals (7L, XtendBackendFacade.evaluateExpression ("1 + 2 + \"asdf\".length", null, null));
+ assertEquals (33L, XtendBackendFacade.evaluateExpression ("1 + 2 + test(\"Arno\").length", "org::eclipse::xtend::middleend::old::first", null, mms, null));
+ }
+}
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/Person.java b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/Person.java
index 37453a3..21ddf5c 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/Person.java
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/Person.java
@@ -1,4 +1,4 @@
-package org.eclipse.xtend.middleend.old.first;
+package org.eclipse.xtend.middleend.old;
public class Person {
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/WithFileOutput.xpt b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/WithFileOutput.xpt
index c9b4514..c9b4514 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/WithFileOutput.xpt
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/WithFileOutput.xpt
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/aTemplate.xpt b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/aTemplate.xpt
index bceb21a..d1f3c35 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/aTemplate.xpt
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/aTemplate.xpt
@@ -1,4 +1,4 @@
-«EXTENSION org::eclipse::xtend::middleend::old::first::first»
+«EXTENSION org::eclipse::xtend::middleend::old::first»
«DEFINE greeting FOR String»
Hello, «this»: «test(this)»
@@ -7,7 +7,7 @@ Hello, «this»: «test(this)»
«EXPAND otherTemplate::ot FOR this»
«EXPAND sub::templateInOtherPackage::other FOR this»
«EXPAND sub::templateInOtherPackage::other»
-«EXPAND org::eclipse::xtend::middleend::old::first::sub::templateInOtherPackage::other»
+«EXPAND org::eclipse::xtend::middleend::old::sub::templateInOtherPackage::other»
«ENDDEFINE»
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/first.ext b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first.ext
index b2938bc..3ed8d17 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/first.ext
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first.ext
@@ -1,6 +1,6 @@
-import org::eclipse::xtend::middleend::old::first;
+import org::eclipse::xtend::middleend::old;
-extension org::eclipse::xtend::middleend::old::first::imported reexport;
+extension org::eclipse::xtend::middleend::old::imported reexport;
test (Object s): test2 (s);
test2 (Object s): "Hallo, " + s + ": " + 3*(4+5) + " - " + other (99);
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java
deleted file mode 100644
index 0b13bff..0000000
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/FirstAttempt.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-Copyright (c) 2008 Arno Haase.
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
-
-Contributors:
- Arno Haase - initial API and implementation
- */
-package org.eclipse.xtend.middleend.old.first;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.emf.mwe.core.WorkflowContext;
-import org.eclipse.emf.mwe.core.issues.IssuesImpl;
-import org.eclipse.emf.mwe.internal.core.WorkflowContextDefaultImpl;
-import org.eclipse.internal.xtend.type.impl.java.JavaBeansMetaModel;
-import org.eclipse.xpand2.output.Outlet;
-import org.eclipse.xtend.backend.BackendFacade;
-import org.eclipse.xtend.backend.common.ExecutionContext;
-import org.eclipse.xtend.backend.types.CompositeTypesystem;
-import org.eclipse.xtend.middleend.xpand.XpandBackendFacade;
-import org.eclipse.xtend.middleend.xpand.XpandComponent;
-import org.eclipse.xtend.middleend.xtend.XtendBackendFacade;
-import org.eclipse.xtend.typesystem.MetaModel;
-import org.junit.Test;
-
-
-public class FirstAttempt {
- @Test
- public void main() throws Exception {
- final List<MetaModel> mms = new ArrayList<MetaModel> ();
- mms.add (new JavaBeansMetaModel ());
-
- final CompositeTypesystem ts = new CompositeTypesystem ();
-// ts.register (new EmfTypesystem ());
-
- {
- final XpandBackendFacade xp = XpandBackendFacade.createForFile ("org::eclipse::xtend::middleend::old::first::aTemplate", "iso-8859-1", mms, new ArrayList<Outlet>());
- final ExecutionContext ctx = BackendFacade.createExecutionContext (xp.getFunctionDefContext(), ts, true);
-
- System.err.println (BackendFacade.invoke (ctx, "org/eclipse/xtend/middleend/old/first/aTemplate/greeting", Arrays.asList("Arno")));
- }
-
- {
- final XpandComponent xwc = new XpandComponent ();
- xwc.setExpand ("org::eclipse::xtend::middleend::old::first::WithFileOutput::WithFileOutput FOR toBeGreeted");
- xwc.addOutlet (new Outlet (false, "iso-8859-1", null, true, "src-gen"));
- xwc.setFileEncoding ("iso-8859-1");
-
- final WorkflowContext wfContext = new WorkflowContextDefaultImpl ();
- wfContext.set ("toBeGreeted", "Arno");
- xwc.invoke (wfContext, null, new IssuesImpl ());
- }
-
- {
- System.out.println ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-
- final XtendBackendFacade bc = XtendBackendFacade.createForFile ("org::eclipse::xtend::middleend::old::first::first", "iso-8859-1", mms);
- final ExecutionContext ctx = BackendFacade.createExecutionContext (bc.getFunctionDefContext(), ts, true);
-
- System.err.println (BackendFacade.invoke (ctx, "test", Arrays.asList ("Arno")));
- System.err.println (BackendFacade.invoke (ctx, "testColl", Arrays.asList (Arrays.asList (1L, "Hallo"))));
- System.err.println (BackendFacade.invoke (ctx, "reexp", Arrays.asList (2L)));
-
- final Person p = new Person ();
- p.setFirstName ("Testa");
- p.setName ("Testarossa");
-
- System.err.println (BackendFacade.invoke (ctx, "testPerson", Arrays.asList(p)));
- }
-
- {
- System.err.println ("--");
- System.err.println (XtendBackendFacade.invokeXtendFunction ("org::eclipse::xtend::middleend::old::first::first", null, mms, "test", "Arno"));
- System.err.println (XtendBackendFacade.evaluateExpression ("1 + 2 + \"asdf\".length", null, null));
- System.err.println (XtendBackendFacade.evaluateExpression ("1 + 2 + test(\"Arno\").length", "org::eclipse::xtend::middleend::old::first::first", null, mms, null));
- }
- }
-}
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/imported.ext b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/imported.ext
deleted file mode 100644
index f8b011d..0000000
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/imported.ext
+++ /dev/null
@@ -1,4 +0,0 @@
-
-extension org::eclipse::xtend::middleend::old::first::reexported reexport;
-
-other(Object o): "imported " + o + "!";
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/reexported.ext b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/reexported.ext
deleted file mode 100644
index fb453be..0000000
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/reexported.ext
+++ /dev/null
@@ -1,5 +0,0 @@
-
-extension org::eclipse::xtend::middleend::old::first::imported reexport;
-extension org::eclipse::xtend::middleend::old::first::first reexport;
-
-reexp(Integer i): 3*i+4; \ No newline at end of file
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/imported.ext b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/imported.ext
new file mode 100644
index 0000000..541fca5
--- /dev/null
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/imported.ext
@@ -0,0 +1,4 @@
+
+extension org::eclipse::xtend::middleend::old::reexported reexport;
+
+other(Object o): "imported " + o + "!";
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/otherTemplate.xpt b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/otherTemplate.xpt
index 1040463..1040463 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/otherTemplate.xpt
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/otherTemplate.xpt
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/reexported.ext b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/reexported.ext
new file mode 100644
index 0000000..29abc0d
--- /dev/null
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/reexported.ext
@@ -0,0 +1,5 @@
+
+extension org::eclipse::xtend::middleend::old::imported reexport;
+extension org::eclipse::xtend::middleend::old::first reexport;
+
+reexp(Integer i): 3*i+4; \ No newline at end of file
diff --git a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/sub/templateInOtherPackage.xpt b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/sub/templateInOtherPackage.xpt
index 3e7ae2c..3e7ae2c 100644
--- a/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/first/sub/templateInOtherPackage.xpt
+++ b/tests/org.eclipse.xtend.middleend.old.test/src/org/eclipse/xtend/middleend/old/sub/templateInOtherPackage.xpt