In PlantUML, how to put a label when using the class X extends Y syntax? - plantuml

I have a class diagram using this PlantUML syntax:
#startuml
class A
class B extends A
#enduml
How do I add a label for the arrow? My only constraint is that I cannot use the <|-- syntax due to some other reasons. So I need to keep using this extends syntax...

You can try this
#startuml
class A
class B extends A
class C
A -> C : label1
B -> C : label2
B --> A : label3
#enduml
Or just use note
#startuml
class A
class B extends A
class C
A -> C
B -> C
note left of A : Note
#enduml

Related

mypy TypeVar include bound class as well as subclasses

class Super:
#classmethod
def instantiate(cls) -> What goes here?:
return cls()
class Sub(Super):
pass
class Sub2(Super):
pass
When writing typehints, what's the canonical way to say a method should return an instance of the super class or any of its subclasses. Closest I could find is TypeVar("Super", bound="Super") but this still raises an error for the Super class in mypy
here you can use typing.Type to type-hint cls like this:
from typing import TypeVar, Type
C = TypeVar("C")
class Super:
#classmethod
def instantiate(cls: Type[C]) -> C:
return cls()
class Sub(Super):
pass
class Sub2(Super):
pass
reveal_type(Sub.instantiate()) # note: Revealed type is 'tmp.Sub*'
reveal_type(Sub2.instantiate()) # note: Revealed type is 'tmp.Sub2*'

Scala Array Generics vs Vector Generics

So I have been working on a refactor in my project to convert Vector's in my code to Array's. The reason being that my application needs to be very performant, and using while-iterations on Array's is significantly faster than for comprehensions and iterations on Vector's. (see this blog post for details)
However I have run into an issue I can't seem to easily find an answer for. I have tweaked my code to hide implementation details, and just boil down to the code needed to highlight the issue.
The following class structure, when using Vector, compiles totally fine:
sealed abstract class BaseClass {
def element: Int
}
sealed abstract class TypeA extends BaseClass {
def element = 2
def children: Vector[BaseClass]
}
case class TypeB(element: Int = 2) extends BaseClass
case class TypeAA(children: Vector[TypeA]) extends TypeA
case class TypeAB(children: Vector[TypeB]) extends TypeA
Now, when switching from using Vector to using Array, it no longer compiles:
sealed abstract class BaseClass {
def element: Int
}
sealed abstract class TypeA extends BaseClass {
def element = 2
def children: Array[BaseClass]
}
case class TypeB(element: Int = 2) extends BaseClass
case class TypeAA(children: Array[TypeA]) extends TypeA
case class TypeAB(children: Array[TypeB]) extends TypeA
I get the error: overriding method children in class TypeA of type => Array[BaseClass]; value children has incompatible type for both TypeAA and TypeAB classes.
I have a feeling I need to do an implicit conversion somewhere, but I am relatively new to Scala (only a couple months) and am not sure exactly how to use it.
Sorry if this has been asked elsewhere, I had trouble finding the correct search terms for the issue i am having.
I think you need to use _ <: BaseClass instead of using the generic type itself:
sealed abstract class TypeA extends BaseClass {
def element = 2
def children: Array[_ <: BaseClass]
}
This happens because the generic type parameter in Array is invariant, while in Vector it is covariant:
final class Array[T]
final class Vector[+A]
Hope that helps you.
This comes from the fact Vector[+A] is covariant in its type parameter A while Array[A] is not, meaning invariant in A
You can work around that fact using F-Bounded Polymorphism:
sealed abstract class TypeA[A :< Type[A]] extends BaseClass {
def children: Array[A]
}
case class TypeAA(children: Array[TypeA]) extends TypeA[TypeA]
case class TypeAB(children: Array[TypeB]) extends TypeA[TypeB]

systemverilog static class member cannot be accessed via the class scope resolution operator

In my t1 extended uvm_test class I'd like to use the xxx_write method from a sequence class xxx_io in xxx_pkg.
I've imported * the package into my t1 class, and I've made the method static but I still receive the same error from compiler:
ncvlog: *E,ILLCSS (/ddd/test.sv,82|29): A Non static class member cannot be accessed via the class scope resolution operator '::'.
xxx_pkg::xxx_io::xxx_write(12'h000, 32'h11ceb00c);
Since the error message did not change after I added the static key word to xxx_write method it would not surprise me if the error is elsewhere. But my code 'works' if I do not try to call this method from t1 class.
package xxx_pkg
class xxx_io extends uvm_sequence #(xxx_seq_item);
static task xxx_write( bit [11:0] i_addr, integer i_wdata );
// snip other code
endtask
endclass: xxx_io
endpackage: xxx_pkg
class t1 extends uvm_test
import xxx_pkg::*
class test1 extends uvm_sequence #(xxx_seq_item);
task body ;
xxx_pkg::xxx_io::xxx_write(12'h000, 32'h11ceb00c);
// snip other code
endtask
endclass : t1
From Greg: create an instance of the sequence in the test then call the method from that instance

How do I have every test in class automatically tagged with a specific tag

I am using the flatspec trait to create my tests and I would like to create a base class that would automatically tag any tests in that class with a particular tag.
For example, any tests in classes that inherit from the IntegrationTest class would automatically be appropriately tagged. So instead of:
class ExampleSpec extends FlatSpec {
"The Scala language" must "add correctly" taggedAs(IntegrationTest) in {
val sum = 1 + 1
assert(sum === 2)
}
I would like do this and still have the test tagged as an IntegrationTest
class ExampleSpec extends IntegrationSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
Thanks!
If you're willing to use a direct annotation on the test class, rather than a parent class, you can use the example at https://github.com/kciesielski/tags-demo. Adapted somewhat for your example, you need to declare a Java class:
package tags;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
#org.scalatest.TagAnnotation
#Retention(RUNTIME)
#Target({METHOD, TYPE})
public #interface MyAnnotation {
}
Then you use it to annotate the Scala test class:
#tags.MyAnnotation
class ExampleSpec extends FlatSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
You then have to use the actual string tags.MyAnnotation to specify the tag you want run (or ignored).
I tried to annotate a parent class instead, but I can't get it to work. I could imagine it being a significant problem for you or not, depending on what else you're trying to do.
Actually, the online doc for the org.scalatest.Tag class does a fair job of describing all this, although I say it after getting it to work by following the above project on GitHub..
Since ScalaTest 2.2.0 tags can be inherited (http://www.scalatest.org/release_notes/2.2.0).
Add #Inherited to your annotation definition.
package tags;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
**#Inherited**
#org.scalatest.TagAnnotation
#Retention(RUNTIME)
#Target({METHOD, TYPE})
public #interface RequiresIntegrationStuff {
}
Annotate your base spec.
#RequiresIntegrationStuff
class IntegrationSpec extends FlatSpec {}
Just use your base spec as a base class.
class ExampleSpec extends IntegrationSpec {
"The Scala language" must "add correctly" in {
val sum = 1 + 1
assert(sum === 2)
}
After that, ExampleSpec will be tagged as tags.RequiresIntegrationStuff.
You will find working project here: https://github.com/wojda/tags-demo (based on https://github.com/kciesielski/tags-demo from Spiro Michaylov's answer)

Call method from this class to another that just call

I have classA and classB
in class A I call create classB like this:
classB b = new classB();
b.method();
in class B, I want to call back to class A when method done
How can I do that, please help me!!!
What would you like to call back exactly to class A? A simple solution(and maybe not the best) would be to use a global variable because both class A and class B are in class A. You could also instantiate a class A variable in class B and create a method in class A that sends some variable back to Class A once a method in Class B is done such as:
In classB:
classB b = new classB();
classA a = new classA();
b.method();
a.sendResultToClassAMethod(some variable);
In classA:
method sendResultToClassAMethod(some variable){
this.variable = variable;
}
I hope this helps

Resources