Skip to content

Commit 514db4c

Browse files
committed
Implement Ignore on supertype
1 parent 0e7481d commit 514db4c

File tree

23 files changed

+202
-149
lines changed

23 files changed

+202
-149
lines changed

annotation/src/main/java/org/sharedtype/annotation/SharedType.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
/**
4747
* <p>
4848
* The name of the emitted type. If not specified, the simple name of the annotated type will be used.
49-
* This may be used to help avoid conflicting names in target output.
49+
* This may be used to help avoid conflicting names in target code.
5050
* </p>
5151
* <br>
5252
* <p>
@@ -59,36 +59,35 @@
5959
String name() default "";
6060

6161
/**
62-
* Includes fields, record components, accessors, or constants in a type.
6362
* <p>
64-
* To exclude a particular component, use {@link Ignore}.
63+
* Configure whether to include fields, record components, accessors, or constants in a type.
64+
* All included by default.
6565
* </p>
6666
* <p>
67-
* Fields and accessors duplicates resolution:
68-
* <ul>
69-
* <li>In classes, fields and accessors effectively with the same name will be merged.</li>
70-
* <li>Same for record.</li>
71-
* </ul>
67+
* To exclude a particular component, use {@link Ignore}.
68+
* Fields and accessors effectively with the same name will be merged.
7269
* </p>
7370
*
7471
* @see ComponentType#FIELDS
7572
* @see ComponentType#ACCESSORS
7673
* @see ComponentType#CONSTANTS
7774
*/
78-
ComponentType[] includes() default {ComponentType.FIELDS, ComponentType.ACCESSORS};
75+
ComponentType[] includes() default {ComponentType.FIELDS, ComponentType.ACCESSORS, ComponentType.CONSTANTS};
7976

8077
/**
81-
* Mark a method as an accessor regardless of its name. This annotation will be ignored if {@link #includes()} does not include {@link ComponentType#ACCESSORS}.
78+
* Mark a method as an accessor regardless of its name.
79+
* Getter prefixes are configured in global properties.
80+
* This annotation will be ignored if {@link #includes()} does not include {@link ComponentType#ACCESSORS}.
8281
*/
8382
@Target({ElementType.METHOD})
8483
@Retention(RetentionPolicy.SOURCE)
8584
@interface Accessor {
8685
}
8786

8887
/**
89-
* Exclude fields, record components, accessors in a type. Or ignore a dependent type, e.g. a supertype.
88+
* Exclude fields, record components, accessors in a type, or a dependency type, e.g. a supertype.
9089
* <p>
91-
* <b>When placed on type:</b> a subtype of this type will not include inherited members from this type.
90+
* <b>When placed on a type:</b> a subtype of this type will not extend this type in target code.
9291
* But if this type is referenced directly as type of a field or return type of an accessor, an error will be reported,
9392
* unless the field or accessor is also ignored.
9493
* </p>

internal/src/main/java/org/sharedtype/domain/TypeVariableInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
import lombok.Builder;
44
import lombok.EqualsAndHashCode;
5-
import lombok.Getter;
65

76
/**
87
* Represents a generic type variable.
98
*
109
* @author Cause Chung
1110
*/
12-
@Getter
1311
@EqualsAndHashCode
1412
@Builder
1513
public final class TypeVariableInfo implements TypeInfo {
1614
private final String name;
1715
// TODO: support generic bounds
1816

17+
public String name() {
18+
return name;
19+
}
20+
1921
@Override
2022
public boolean resolved() {
2123
return true;

it/java17/src/main/java/org/sharedtype/it/java17/JavaRecord.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ String getDuplicateAccessor() {
6363
String shouldNotBeIncluded() {
6464
return null;
6565
}
66+
67+
@Override
68+
public T getValue() {
69+
return null;
70+
}
6671
}

it/java17/src/test/java/org/sharedtype/it/JavaRecordIntegrationTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.sharedtype.domain.ArrayTypeInfo;
66
import org.sharedtype.domain.ClassDef;
77
import org.sharedtype.domain.ConcreteTypeInfo;
8+
import org.sharedtype.domain.TypeVariableInfo;
89

910
import static org.assertj.core.api.Assertions.assertThat;
1011
import static org.sharedtype.it.TypeDefDeserializer.deserializeTypeDef;
@@ -18,8 +19,8 @@ void typeVariables() {
1819
var typeParameters = classDef.typeVariables();
1920
assertThat(typeParameters).hasSize(2);
2021

21-
assertThat(typeParameters.get(0).getName()).isEqualTo("T");
22-
assertThat(typeParameters.get(1).getName()).isEqualTo("K");
22+
assertThat(typeParameters.get(0).name()).isEqualTo("T");
23+
assertThat(typeParameters.get(1).name()).isEqualTo("K");
2324
}
2425

2526
@Test
@@ -289,8 +290,16 @@ void duplicateAccessorField() {
289290
assertThat(typeInfo.qualifiedName()).isEqualTo("java.lang.String");
290291
}
291292

293+
@Test
294+
void implementedMethodGetValueFromInterface() {
295+
var method = classDef.components().get(31);
296+
assertThat(method.name()).isEqualTo("value");
297+
var typeInfo = (TypeVariableInfo)method.type();
298+
assertThat(typeInfo.name()).isEqualTo("T");
299+
}
300+
292301
@Test
293302
void fieldsSize() {
294-
assertThat(classDef.components().size()).isEqualTo(31);
303+
assertThat(classDef.components().size()).isEqualTo(32);
295304
}
296305
}

it/java17/src/test/java/org/sharedtype/it/TypeDefIntegrationTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ void container() {
2121
softly.assertThat(container.components()).hasSize(1);
2222
val component1 = container.components().get(0);
2323
val field1Type = (TypeVariableInfo) component1.type();
24-
softly.assertThat(field1Type.getName()).isEqualTo("T");
24+
softly.assertThat(field1Type.name()).isEqualTo("T");
2525
softly.assertThat(component1.name()).isEqualTo("t");
2626

2727
softly.assertThat(container.resolved()).isTrue();
2828
softly.assertThat(container.typeVariables()).hasSize(1);
2929
val typeVariable1 = container.typeVariables().get(0);
30-
softly.assertThat(typeVariable1.getName()).isEqualTo("T");
30+
softly.assertThat(typeVariable1.name()).isEqualTo("T");
3131
});
3232
}
3333

@@ -115,13 +115,7 @@ void interfaceA() {
115115
@Test
116116
void superClassA() {
117117
ClassDef superClassA = (ClassDef) deserializeTypeDef("org.sharedtype.it.java8.SuperClassA.ser");
118-
SoftAssertions.assertSoftly(softly -> {
119-
softly.assertThat(superClassA.simpleName()).isEqualTo("SuperClassA");
120-
softly.assertThat(superClassA.components()).hasSize(1);
121-
val component1 = superClassA.components().get(0);
122-
softly.assertThat(component1.name()).isEqualTo("a");
123-
val component1type = (ConcreteTypeInfo) component1.type();
124-
softly.assertThat(component1type.qualifiedName()).isEqualTo("int");
125-
});
118+
assertThat(superClassA.simpleName()).isEqualTo("SuperClassA");
119+
assertThat(superClassA.qualifiedName()).isEqualTo("org.sharedtype.it.java8.SuperClassA");
126120
}
127121
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.sharedtype.it.java8;
2+
3+
import org.sharedtype.annotation.SharedType;
4+
5+
@SharedType.Ignore
6+
interface IgnoredInterfaceB {
7+
default boolean getBooleanValue() {
8+
return false;
9+
}
10+
11+
// TODO: add method, and check implemented method in subtype is not ignored
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.sharedtype.it.java8;
2+
3+
import org.sharedtype.annotation.SharedType;
4+
5+
@SharedType.Ignore
6+
abstract class IgnoredSuperClassB {
7+
int field;
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package org.sharedtype.it.java8;
22

33
public interface InterfaceA<T> {
4+
T getValue();
45
}

it/java8/src/main/java/org/sharedtype/it/java8/JavaClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.sharedtype.annotation.SharedType;
44

55
@SharedType
6-
class JavaClass {
6+
class JavaClass extends SuperClassA {
77
private String string;
88
private EnumSize size;
99

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.sharedtype.it.java8;
22

3-
public abstract class SuperClassA {
3+
public abstract class SuperClassA extends IgnoredSuperClassB implements InterfaceA<Integer>, IgnoredInterfaceB {
44
private int a;
5+
6+
@Override
7+
public Integer getValue() {
8+
return a;
9+
}
510
}

0 commit comments

Comments
 (0)