Skip to content

Commit

Permalink
fix outdated Javadoc on JavaField.getType()
Browse files Browse the repository at this point in the history
The comment on `JavaField.getType()` was a leftover from a previous time before generics support was fully implemented. Meanwhile, the described "possible" future has already become reality. I've noticed that the Javadoc on `JavaType` and `HasType` was a little sparse, so I tried to extend that instead.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Feb 2, 2023
1 parent 9b712d5 commit 5e80b17
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public String getFullName() {
return getOwner().getName() + "." + getName();
}

/**
* Note: This is still work in progress and thus does not support generic types at the moment.
* In the future the result can possibly also be a {@link JavaParameterizedType} or {@link JavaTypeVariable}
*/
@Override
@PublicAPI(usage = ACCESS)
public JavaType getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@
*/
package com.tngtech.archunit.core.domain;

import java.lang.reflect.Type;

import com.tngtech.archunit.PublicAPI;
import com.tngtech.archunit.base.ChainableFunction;
import com.tngtech.archunit.core.domain.properties.HasName;

import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;

/**
* Represents a general Java type. This can e.g. be a class like {@code java.lang.String}, a parameterized type
* like {@code List<String>} or a type variable like {@code T}.<br>
* Besides having a {@link HasName#getName() name} and offering the possibility to being converted to an
* {@link #toErasure() erasure} (which is then always {@link JavaClass a raw class object}) {@link JavaType} doesn't offer
* an extensive API. Instead, users can check a {@link JavaType} for being an instance of a concrete subtype
* (like {@link JavaTypeVariable}) and then cast it to the respective subclass
* (same as with {@link Type} of the Java Reflection API).
*
* @see JavaClass
* @see JavaParameterizedType
* @see JavaTypeVariable
* @see JavaWildcardType
* @see JavaGenericArrayType
*/
@PublicAPI(usage = ACCESS)
public interface JavaType extends HasName {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.tngtech.archunit.base.ChainableFunction;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaParameterizedType;
import com.tngtech.archunit.core.domain.JavaType;

import static com.tngtech.archunit.PublicAPI.Usage.ACCESS;
Expand All @@ -29,9 +30,21 @@
@PublicAPI(usage = ACCESS)
public interface HasType {

/**
* @return The (possibly generic) {@link JavaType} of this object. Refer to the documentation of {@link JavaType}
* for further information.
* @see #getRawType()
*/
@PublicAPI(usage = ACCESS)
JavaType getType();

/**
* @return The raw type of this object. This is effectively the same as calling
* {@link #getType()}.{@link JavaType#toErasure() toErasure()}. E.g. given a {@link JavaParameterizedType}
* {@code java.util.List<String>} the raw type (i.e. type erasure) would be the
* {@link JavaClass} {@code java.util.List}.
* @see #getType()
*/
@PublicAPI(usage = ACCESS)
JavaClass getRawType();

Expand Down

0 comments on commit 5e80b17

Please sign in to comment.