Skip to content

Commit

Permalink
DirectClassTest Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
plagarrigue committed Oct 4, 2016
1 parent e9a010e commit 6a8f631
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
27 changes: 9 additions & 18 deletions gs-common/src/main/java/org/genericsystem/common/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,20 @@ protected Generic build(Vertex vertex) {

protected Class<?> adaptClass(Class<?> clazz, Generic meta) {
InstanceClass metaAnnotation = meta == null ? null : getAnnotedClass(meta).getAnnotation(InstanceClass.class);
if (clazz == null) {
if (metaAnnotation == null)
return getTClass();
else
return metaAnnotation.value();
}
if (clazz == null)
return metaAnnotation == null ? getTClass() : metaAnnotation.value();

DirectClass directClass = clazz.getAnnotation(DirectClass.class);
if (directClass != null)
if (metaAnnotation == null) {
if (metaAnnotation == null)
return clazz;
} else {
if (metaAnnotation.value().isAssignableFrom(clazz))
return clazz;
else
getCurrentCache().discardWithException(new IllegalStateException(clazz + " must extend " + metaAnnotation.value()));
}

if (metaAnnotation == null) {
if (getTClass().isAssignableFrom(clazz))
else if (metaAnnotation.value().isAssignableFrom(clazz))
return clazz;
else
return getTClass();
}
getCurrentCache().discardWithException(new IllegalStateException(clazz + " must extend " + metaAnnotation.value()));
if (metaAnnotation == null)
return getTClass().isAssignableFrom(clazz) ? clazz : getTClass();

if (metaAnnotation.value().isAssignableFrom(clazz))
return clazz;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,33 @@ public void test004() {
}

public void test005() {
Engine engine = new Engine(Vehicle5.class);
assert !(engine.find(Vehicle5.class) instanceof Vehicle5);
}

public void test006() {
Engine engine = new Engine(Vehicle6.class);
assert engine.find(Vehicle6.class) instanceof Vehicle6;
assert engine.find(Vehicle6.class) instanceof Generic;
}

public void test007() {
Engine engine = new Engine(Car.class, CarStandard.class, MyAudi.class, MyBmw.class);
assert engine.find(MyBmw.class) instanceof CarStandard;
assert engine.find(MyAudi.class) instanceof MyAudi;
}

public void test006() {
public void test008() {
Engine engine = new Engine(CarStandard.class);
System.out.println(engine.find(CarStandard.class).getClass().getName());
CarStandard cs = engine.find(CarStandard.class);
}

public void test007() {
public void test009() {
catchAndCheckCause(() -> new Engine(MyBmw2.class), IllegalStateException.class);
catchAndCheckCause(() -> new Engine(MyBmw3.class), IllegalStateException.class);
}

public void test008() {
Engine engine = new Engine(Vehicle5.class);
assert !(engine.find(Vehicle5.class) instanceof Vehicle5);
}

@SystemGeneric
public static interface Vehicle1 extends Generic {

Expand All @@ -77,6 +83,12 @@ public static class Vehicle5 {

}

@DirectClass
@SystemGeneric
public static class Vehicle6 implements Generic {

}

@SystemGeneric
@Meta(Car.class)
public static class Bmw implements Generic {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.genericsystem.reactor.annotations.Select;
import org.genericsystem.reactor.annotations.Select.SelectModel;
import org.genericsystem.reactor.annotations.SetStringExtractor;
import org.genericsystem.reactor.annotations.StyleClass;
import org.genericsystem.reactor.annotations.Styles.AlignItems;
import org.genericsystem.reactor.annotations.Styles.BackgroundColor;
import org.genericsystem.reactor.annotations.Styles.Color;
Expand Down

0 comments on commit 6a8f631

Please sign in to comment.