-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port to Moose 11 #16
Comments
@NicolasAnquetil Feel free to add items you think will help here :) |
To gain insights into the changes in Famix (Traits, etc.) for Moose 11, here's a PlantUML class diagram of the Moose 11 version of FamixJava metamodel, generated with the following script in a Playground: FamixUMLDocumentor new
model: FamixJavaModel ;
generate ;
exportWith: (FamixUMLPlantUMLBackend new). |
Here are some examples with Generics: Generic FunctionA generic function can accept parameters of any type and return a value of the same type: function identity<T>(arg: T): T {
return arg;
}
let numberIdentity = identity<number>(42); // numberIdentity is of type number
let stringIdentity = identity<string>("Hello, TypeScript!"); // stringIdentity is of type string
let arrayIdentity = identity<number[]>([1, 2, 3]); // arrayIdentity is of type number[] Generic InterfaceA generic interface can define a structure that works with any type: interface GenericIdentityFn<T> {
(arg: T): T;
}
function identityFn<T>(arg: T): T {
return arg;
}
let myIdentity: GenericIdentityFn<number> = identityFn;
console.log(myIdentity(10)); // Outputs: 10 Generic ClassA generic class can create instances that operate on various types: class GenericNumber<T> {
zeroValue: T;
add: (x: T, y: T) => T;
constructor(zeroValue: T, add: (x: T, y: T) => T) {
this.zeroValue = zeroValue;
this.add = add;
}
}
let myGenericNumber = new GenericNumber<number>(0, (x, y) => x + y);
console.log(myGenericNumber.add(5, 10)); // Outputs: 15
let stringNumeric = new GenericNumber<string>("", (x, y) => x + y);
console.log(stringNumeric.add("Hello, ", "world!")); // Outputs: Hello, world! Generic ConstraintsYou can add constraints to generics to restrict the kinds of types you can use: interface Lengthwise {
length: number;
}
function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length); // Now we know it has a .length property, so no error
return arg;
}
loggingIdentity({ length: 10, value: "Hello" }); // Works because the argument has a length property
// loggingIdentity(3); // Error: Argument of type 'number' is not assignable to parameter of type 'Lengthwise'. Generic Types in Arrow FunctionsYou can also use generics with arrow functions: const identity = <T>(arg: T): T => {
return arg;
};
let output = identity<string>("Hello, TypeScript!"); // output is of type string
console.log(output); // Outputs: Hello, TypeScript! Using Multiple Type VariablesYou can define a function or class with multiple type variables: function map<K, V>(array: K[], fn: (item: K) => V): V[] {
return array.map(fn);
}
let stringToNumber = map<string, number>(["1", "2", "3"], (str) => parseInt(str));
console.log(stringToNumber); // Outputs: [1, 2, 3] |
Currently, ArrowFunction is not in the metamodel. #22 |
See moosetechnology/Famix#773 (comment) as well. |
https://modularmoose.org/moose-wiki/Developers/predefinedEntities#genericity helps with understanding Generics in Java. |
fixed in #18 |
Pharo 12 will soon be finalized, and so Moose 11 should be stable soon as well. This means the FamixTypeScript MM should work in Moose 11.
Currently, here are some of the problems:
TParameterType in Moose 11 doesn't exist, and so the MM can't be generated, for example (in
defineHierarchy
):There are surely hints in the FamixJava metamodel in Moose 11 ;-) So far, I've found:
ParametricClass
,ParameterType
,ParametricInterface
,ParametricMethod
, andParameterConcretization
(perhaps unrelated but seems like it's important).At least one class in Extensions has a dependency on a class that's generated in Entities. When I try to load Extensions, I get the following Warning (Maybe this can be fixed in the Baseline? Maybe this is just a stricter warning in Pharo 11?):
The text was updated successfully, but these errors were encountered: