Skip to content

Referenced classes from class diagrams in the same package cannot be resolved in generated Java code #120

Description

@schmalzing

Classes from class diagrams in the same package cannot be resolved in generated Java code

Issue description

The class-diagram generator creates an individual Java package for each class diagram. Therefore, classes declared in different class diagrams cannot reference each other, even if both class diagrams are located in the same package.

Reproduction

Example CDs:

package test;

classdiagram CD1 {
  public class A {
  }
}
package test;

classdiagram CD2 {
  public class B extends A {
  }
}

Actual behavior

The generator creates separate Java packages for the class diagrams. In this example, A is generated in package test.CD1, while B is generated in package test.CD2.

The generated class B contains code equivalent to:

package test.CD2;

public class B extends A {
}

Since A is located in test.CD1, it cannot be resolved from test.CD2. This produces a Java compiler error:

ERROR in ...\test\CD2\B.java (at line 29)
public class B extends A {
                       ^
A cannot be resolved to a type

Expected behavior

Classes declared in class diagrams that share the same package should be accessible from each other in the generated Java code.

For the example above, A and B should be generated into the same Java package, for example:

package test;

Alternatively, the generator must emit the required imports so that B can resolve and extend A.

Impact

Any CD that references classes from another class diagram in the same CD package can generate Java code that does not compile. This prevents splitting related models across multiple class diagrams while retaining package-level visibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions