Skip to content

Add support for casts #710

@codecholeric

Description

@codecholeric

At the moment casts without any further dependencies on the target type are not detected as dependencies. I.e.

SomeClass example(Object rawInput) {
  return (SomeClassImpl) rawInput; // should forbid dependencies on SomeClassImpl
}

Since there are no further dependencies on SomeClassImpl this would be missed. It does likely not cause a maintenance problem later, because the cast could at any time be weakened to (SomeClass) without any further compile or runtime issues, but still it would be nice to detect these things. Also to be able to access all casts that a class or method applies could be useful for other scenarios.

We could add this the following way:

  • extend Set<TypeCast> JavaCodeUnit.getCasts() (compare InstanceofCheck)
  • add the TypeCasts to JavaClass.directDependencies{From/To}Self

(open for discussion: What is the best name for the domain object? TypeCast, Cast, JavaCast, ClassCast, ...?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions