Eclipse modeling tool, define a class as a type for an attribut - eclipse

I try to make a model on eclipse modelling tool and I have in the model a class that use an other class as a type for an attribute.
I have made the class definition but I can't find the way to connect them together.
I have also made the definition for a method with a parameter with the same class type, but there I've no trouble. The class I use as a Type is in the combo box.
How should I do?

If I understand your question correctly, you are trying to create an EMF metamodel, and are using a graphical editor, and try to connect EClasses.
Basically, EMF EClasses can have two kinds of features: EAttributes and EReferences. EAttributes can refer to Java types, like integer or string; while EReferences are used to connect EClasses. In other words, you cannot have an EAttribute refer to another type you added to the diagram; instead you have to create a reference between them.

Related

What is the difference between ::class and ::class.java in Kotlin?

In Java, we write .class (for example: String.class) to get information about the given class. In Kotlin you can write ::class or ::class.java. What is the difference between them?
By using ::class, you get an instance of KClass. It is Kotlin Reflection API, that can handle Kotlin features like properties, data classes, etc.
By using ::class.java, you get an instance of Class. It is Java Reflection API, that interops with any Java reflection code, but can't work with some Kotlin features.
First you need to understand about Reflection. According to the docs:
Reflection is a set of language and library features that allows for introspecting the structure of your own program at runtime.
In simple words, it gives you the ability to get the code you have written i.e., the class name you have defined, the function name you have defined, etc. Everything you have written, you can access all these at runtime using Reflection.
::class and ::class.java are basic features of Reflection.
::class gives you a KClass<T> reference and ::class.java gives you Class<T> reference.
Example,
val a = MyClass::class
can be interpreted as
val a = KClass<MyClass>()
Note: Above code is not syntactically correct, because KClass is an interface and interfaces cannot be instantiated. It is just to give you an idea.
A Class<T> class gives you information about the metadata of the T class like interfaces it is implementing, its functions' names, its package name, etc.
KClass is similar to Class but it gives information about some more properties(Kotlin related properties) than Class. All the information a KClass<T> reference can give you about the T class are listed here https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-class/#properties
According to the Kotlin documentation, when we create an object using any class type as below the reference type will be type of KClass.
val c = MyClass::class // reference type of KClass
Kotlin class reference is not the same as a Java class reference. To get a Java class reference, use the .java property on a KClass instance.
val c = MyClass::class.java // reference type of Class Java

Unity Custom Editor - Add Data Fields Based on Derived Type

Final goal: create a custom editor that will let me select from a list of types and then enter additional parameters specific to that type.
To this end, I have created a pure data type, let's call it BasicData, with a SpecificData parameter of an abstract base type, let's call it ExtraData. The idea is to have the type information in BasicData (enum value), and then populate the SpecificData field in the custom editor code so that when I change selection a new object from a class derived from ExtraData. Then its values can be further edited by additional fields created for that specific type, as shown here.
I started doing the above, but I ran into problems trying to get the actual object being edited in order to set the SpecificData property. My classes are not Unity objects or scripts, and I'd rather not turn them into such just for this. I might be able to use reflection to do this but then changes in the editor won't take effect while it runs, from what I understand.
What is the best way to accomplish this?

Intersystems caché - programmatically create new class

Is it possible to write ObjectScript method, which will create new class in namespace and compile it? I mean programmatically create new class and store it. If so, can I edit this class using ObjectScript later(and recompile)?
Reason: I have class structure defined in string variable and I need to add new class to namespace according this string.
Nothing is impossible. Everything in Caché can be created programmatically. And, Classes is not a execution. There are at least two ways to do it:
simple SQL Query CREATE TABLE, will create a class.
and as you already mentioned ObjectScript Code, which can do this.
All of definition of any classes defined in other classes. Which you can find in package %Dictionary.
The class itself defined in %Dictionary.ClassDefinition. Which have some properties, for defining any parts of classes. So, this is a simple code which create some class, with one property.
set clsDef=##class(%Dictionary.ClassDefinition).%New()
set clsDef.Name="package.classname"
set clsDef.Super="%Persistent"
set propDef=##class(%Dictionary.PropertyDefinition).%New()
set propDef.Name="SomeProperty"
set propDef.Type="%String"
do clsDef.Properties.Insert(propDef)
do clsDef.%Save()
And in latest versions, there is one more way for create/change class. If you have text of class as you can see it in Studio. Then, you can load it in Caché, with class %Compiler.UDL.TextServices
Yes, it is. You likely want to make use of %Dictionary.ClassDefinition and the related %Dictionary.*Definition classes (especially %Dictionary.PropertyDefinition, %Dictionary.MethodDefinition and %Dictionary.IndexDefinition) to create and/or modify your class. Provided your string contains some reasonable representation of the data, you should be able to create the class this way.
The actual class documentation is available at http://docs.intersystems.com/cache20141/csp/documatic/%25CSP.Documatic.cls?CLASSNAME=%25Dictionary.ClassDefinition
You can then compile the class by calling $system.OBJ.Compile("YourPackage.YourClass","ck").
(Note: If your string contains the exported XML definition of the class, you could also write the XML representation to a stream and then call $system.OBJ.LoadStream() to import the XML definition. I would only recommend this if you have an exported class definition to start with.)

How to model Eclipse extension points in a UML class diagram?

for a software design project I have to do, I chose the Eclipse Platform as a framework. Meaning I have lots of extension points to implement.
However, I have trouble specifying these extension points in my UML class diagram. So how do I model the fact that a class belongs to an extension point in my class diagram?
Or is the class diagram the wrong place to do this anyway? If so, where is the best place to specify the extension points I implement?
For reference, I am doing the UML modeling with Papyrus. I already have a working prototype of the application, so it is just about creating the diagram.
Cheers
Speaking of Eclipse plugins I would rather choose a component diagram than a class diagram. You can then model extension points as ports and their contract as interfaces (those lollipops).
If you rather have class diagrams specifying extension points as interfaces with a special stereotype (or keyword) would be fine as well.
Regarding the class implementing an extension point you can either use a dependency on the component or (in the second solution) an interface realization.
An eclipse extension point is like an interface: it declares a set of properties that must be implemented.
For example, the org.eclipse.ui.editors extension point declares that to implement this extension point you have to provide:
id
name
icon
class
file extensions
contributors
There is no EXACT way to say this in UML since an extension point is neither an interface nor an object, but you could model it by adding a stereotype to your model, say <<extension_point>> (you can read more about stereotypes here), and create a class in your diagram (for example org.eclipse.ui.editors) that has all of these attributes, with their required types (in this example all attributes are strings, except class which is of type org.eclipse.ui.IEditorPart).
After this you can create another stereotype, say <<extension_point_implementation>> and a new class that has this stereotype. This class you connect with a realization link from the <<extension_point>> class, and then you set the values of all of the attributes to what you are implementing.
Note that this is not "pure" UML since you are defining a new domain with added semantics, but I think that this would be a good and easy to understand way to model what you want.
In a sense extensions are to extension points what instances are to classes; extension points define the possible attributes of the extensions, and each extension contains the concrete attributes conforming to the extension point.
Just reverse the java code and add a note. It would do the job.

Adding and removing Data Annotation attributes dynamically

I have a little bit of a curve ball for you. Maybe just a design issue...maybe even something as simple as me not understanding Data annotation providers.
Anyway here we go:
I have a class which represents some model data. Let's say it represents a package/box/carton.
It actually represents all of these things so I use the class in several different views. Sometimes I want the attribute of the field Package_Description to be
So that it shows up as Box Number : input box here.
Now if i want it to appear as "Carton Name" my only option would be to sub type it. Or use a separate class to have the annotations for this class. My quandary is that some of the field names are user configurable and therefore I cannot have a static definition!
(By the way i am using third party librarys [Telerik MVC Grid] do display these field names so i cannot change the fact that it's looking at data annotation )
So I just need to know is there a way to add attributes dynamically?
Create an anonymous type on the fly, sub class the original and then add attributes using reflection?
Or what other options are open to me, do I need to somehow implement a different annotation provider?
Attributes are part of the definition of the type. Because of that, you can't modify attributes of existing classes during runtime.
You could create a new type during runtime (not an anonymous type), but I think that's not such a good idea. I'm sure whatever component you're using, it allows you to specify the appearance explicitly.