XText using type information from an external EMF Model - flash-builder

I'm looking into using XText to make an extenstion DSL to a language that I use daily and has some obvious shortcomings (AS3, through FlashBuilder).
I have a grammar and code generation system working, where the below declaration generates a value class, with constructor, class level vars and getters etc.
class Person (name: String, age: int)
This is fine, but I would like the have the types defined in the flash player library and also the types that I define in users projects available in my extension DSL. In the code above both String and int come from the native flash library.
I presume that Flash Builder uses the EMF core internally to represent both any included libs (swcs) and any types I define in my projects. If this is the case, my question is:
How can I access the EMF model of FLash Builder?
If there is no EMF model then I presume I would have to parse the library.swc myself and the source code of my projects.
Is the Xtend language intended to preform these sort of native filesystem tasks?
Thanks

Let us asume the Flash Builder comes with an EMF based metamodel. then the "thing" you have to do is to implement a IResourceServiceProvider. I have blogged on doing the very same stuff for uml models: http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/
and no: xtend is a modern style programming language that compiles to Java and has nice Templating support.

Related

Why does Kotlin documentation for ArrayList mention JavaScript?

In the documentation for ArrayList it says:
Provides a MutableList implementation, which uses a resizable array as its backing storage.
This implementation doesn't provide a way to manage capacity, as backing JS array is resizeable itself. There is no speed advantage to pre-allocating array sizes in JavaScript, so this implementation does not include any of the capacity and "growth increment" concepts.
Link here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-array-list/
Why does the documentation reference JavaScript here? My understanding is Kotlin is based on the JVM and Java. Interested to know what role JS plays here.
Kotlin is a multi-platform language. While it was primarily designed for compatibility with the JVM, it can compile to native code or JavaScript. These different targets have differences in their standard libraries.
At the top of their documentation pages, you can see toggles for the three target platforms which you can use to hide documentation for platforms you aren't interested in.
You'll notice there's an orange dot next to the documentation for the ArrayList class you mentioned. That is because this ArrayList class is only in the JavaScript standard library. On JVM, there's only a typealias to the JVM implementation of ArrayList, so there's a green dot next to that.
Kotlin can currently be compiled to JVM byte code, JS, and native machine code. The website shows details for all three targets. The part you are quoting is exclusively about the JS target.

Nim-lang: OOP features supported?

While learning basics of Nim-lang,
I have read that the OOP is minimalistic in Nim;
But I would like to know what features are exactly supported?
Like:
Over-ride.
Over-load (not supported by PHP yet, 2022).
Multi-inheritance (except C++, not supported by any language?).
Generics.
Classes.
Namespaces.
Import-as/from-namespace (or Include-file-content like C/C++).
Custom type-defs (name aliases).
Custom operator implementation(s).
Traits (saw only in PHP, if this is even OOP?).
BTW, most of the items on this list aren't OOP specific or even related to the OOP paradigm
However, Nim does support:
Over-ride.
Over-load.
Generics.
Import-as/from-namespace (or Include-file-content like C/C++).
Custom type-defs (name aliases).
Custom operator implementation(s).
Nim does not have:
Multi-inheritance.
Traits.
Nim weakly supports:
Classes.
Where Polymorphism only really works on ref types.
Namespaces.
This should be in not-supported list,
but you can force it to use an empty type as the first argument,
or store everything in a variable and don't export anything.

What does "Symbol" mean in KSP

Currently I am studying on KSP(Kotlin Symbol Processing), and I am curious about what does "Symbol" mean in KSP.
When it comes to comparing with KAPT, it says "To run Java annotation processors unmodified, KAPT compiles Kotlin code into Java stubs that retain information that Java annotation processors care about. To create these stubs, KAPT needs to resolve all symbols in the Kotlin program."
I don't know what does "all symbols in the Kotlin program" exactly mean?
I understand "symbols" as declarations of interfaces, classes, functions, properties, etc. It doesn't include the body or the code itself, only the API, items that are visible to others.
This term is not specific to Kotlin. I can't find any definition of "symbols" on Wikipedia, but for example native libraries also contain symbol tables.
In this specific context it means that KAPT has to create a full list of all such symbols in Kotlin code and generate their equivalents in Java, so annotation processors could work on them. This is pretty wasteful as we recreate Kotlin code structure in Java just to throw it away seconds later and replace with true compiled code.

modify a Kotlin class

I'd like to write a plugin for Intellij IDEA that should modify a Java and Kotlin code.
I use the method
PsiClass.getMethods()
in order to get all methods of Java and Kotlin classes. So far so good, so then I use methods like
PsiClass.add(), PsiClass.addAfter(), PsiClass.addBefore()
that all work fine once they are called on Java files, but start to throw an exception
IncorrectOperationException
once I called them on a Kotlin class.
I'd appreciate any hint on how I can modify Kotlin and Java classes (preferably using the same approach).
When you search for a Kotlin class via the JavaPsiFacade, it returns the light class which is a shallow representation that is just based on the information in the class file. In order to add PSI elements, you have to call navigationElement on it. Then, IJ will parse the source and build a full PSI tree that can be modified.
However, if the class is a Kotlin class, navigationElement will return a KtClass which is not derived from PsiClass. You will have to use the facilities in the Kotlin hierarchy to modify it. Method instances in Kotlin are also not instances of PsiMethod, but instances of KtMethod.
For analyzing Java and Kotlin sources in a common fashion there is a different syntax tree called "UAST", but for modifications you need a language-specific approach.

Using Objective-C Metadata to Generate Class Dependency Graph

This guy came up with a pretty neat tool to generate a class dependency graph - however, it relies on parsing your source code and looking for #import directives.
http://seriot.ch/blog.php?article=20110124
https://github.com/nst/objc_dep/blob/master/objc-dep.py
This is neat, but I have a number of problems with this. Not least of which is it doesn't take into account imports of imports nor prefix headers nor whether-or-not the class(es) in the file referenced by the import are actually being used.
I'd like to do something more akin to class-dump and examine the Objective-C metadata stored in the Mach-O file to generate an in-memory representation of the class dependencies.
I'd rather not do this from scratch, so I'm wondering:
Has it already been done?
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
What roadblocks will I need to overcome?
Has it already been done?
Not that I know of.
Is there an open-source library which would provide me with the
foundational tools I need to extract this information?
At the core of class-dump is libMachObjC which does exatly what you want, i.e. parse all classes/methods/ivars and more. The API is very clean, it should be very easy to use.
If you have experience in this sort of thing, is what I'm trying to
accomplish feasible?
Unfortunately, no because some classes don't declare the real class but use id instead. For example, here is the information that can be extracted from a class-dump of UIKit:
#interface UITableView : UIScrollView <NSCoding>
{
int _style;
id <UITableViewDataSource> _dataSource;
id _rowData;
...
The _rowData ivar type information is id but if you check at runtime you will see that _rowData is an instance of the UITableViewRowData class. This information is not present in the Mach-O binary so you have no way to find the relation between UITableView and UITableViewRowData. The same applies for method parameters.
Here's a solution that relies on information in mach.o files, and generates graph dependency based on that information: https://github.com/PaulTaykalo/objc-dependency-visualizer
Has it already been done?
yes - but i can't recommend a good public implementation
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
most use cases would benefit by using the objc runtime facilities objc/... rather than examining the binary.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
yes. i've done something similar using the objc runtime.
What roadblocks will I need to overcome?
that depends largely on the level of detail you want... implementation time if you find no such implementation, but i figure you will find a few options if you google the more esoteric functions in the objc runtime; perhaps you would find one in an (open) language binding or bridge?
if you do end up writing one yourself, you can get registered objc classes using objc_getClassList, then access the properties/information you want from there.