-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default values using annotation + isDecompiled is transformed to isWi…
…ndupGenerated
- Loading branch information
Showing
16 changed files
with
224 additions
and
23 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
graph/api/src/main/java/org/jboss/windup/graph/frames/FrameBooleanDefaultValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.jboss.windup.graph.frames; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A windup-specific annotation that is used within | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface FrameBooleanDefaultValue { | ||
|
||
public boolean value(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
graph/impl/src/main/java/org/jboss/windup/graph/DefaultValueInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.jboss.windup.graph; | ||
|
||
import com.tinkerpop.blueprints.Element; | ||
import com.tinkerpop.frames.FrameInitializer; | ||
import com.tinkerpop.frames.FramedGraph; | ||
import com.tinkerpop.frames.Property; | ||
import org.jboss.windup.graph.frames.FrameBooleanDefaultValue; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.Map; | ||
|
||
/** | ||
* A tinkerpop frame initializer that makes it possible to specify default values for the elements | ||
* | ||
* @author <a href="mailto:mbriskar@gmail.com">Matej Briskar</a> | ||
*/ | ||
public class DefaultValueInitializer implements FrameInitializer | ||
{ | ||
private Map<Class<?>, LinkedList<PropertyDefaultValue>> cachedValues = new HashMap<>(); | ||
|
||
public void initElement(final Class<?> kind, final FramedGraph<?> framedGraph, final Element element) | ||
{ | ||
if (!cachedValues.containsKey(kind)) | ||
{ | ||
cacheFrameInterface(kind); | ||
} | ||
setupDefaults(element, cachedValues.get(kind)); | ||
} | ||
|
||
private void cacheFrameInterface(Class<?> kind) { | ||
LinkedList<PropertyDefaultValue> values = new LinkedList<>(); | ||
for (Method m : kind.getMethods()) | ||
{ | ||
Annotation[] annotations = m.getAnnotations(); | ||
for (Annotation annotation : m.getAnnotations()) | ||
{ | ||
if (annotation instanceof FrameBooleanDefaultValue) | ||
{ | ||
PropertyDefaultValue pDefault = new PropertyDefaultValue(); | ||
pDefault.value = ((FrameBooleanDefaultValue) annotation).value(); | ||
pDefault.key = m.getAnnotation(Property.class).value(); | ||
values.add(pDefault); | ||
} | ||
} | ||
} | ||
cachedValues.put(kind, values); | ||
} | ||
|
||
private void setupDefaults(Element element, LinkedList<PropertyDefaultValue> values) | ||
{ | ||
for (PropertyDefaultValue pValue : values) | ||
{ | ||
element.setProperty(pValue.key, pValue.value); | ||
} | ||
} | ||
|
||
private class PropertyDefaultValue | ||
{ | ||
private String key; | ||
private Object value; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
graph/tests/src/test/java/org/jboss/windup/graph/test/DefaultValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jboss.windup.graph.test; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.AddonDependencies; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.archive.AddonArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.GraphContextFactory; | ||
import org.jboss.windup.graph.typedgraph.DefaultValueTestModel; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.inject.Inject; | ||
|
||
@RunWith(Arquillian.class) | ||
public class DefaultValueTest | ||
{ | ||
@Deployment | ||
@AddonDependencies({ | ||
@AddonDependency(name = "org.jboss.windup.graph:windup-graph"), | ||
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi") | ||
}) | ||
public static AddonArchive getDeployment() | ||
{ | ||
AddonArchive archive = ShrinkWrap.create(AddonArchive.class) | ||
.addBeansXML() | ||
.addClasses(DefaultValueTestModel.class); | ||
return archive; | ||
} | ||
|
||
@Inject | ||
private GraphContextFactory factory; | ||
|
||
@Test | ||
public void testDefaultValue() throws Exception | ||
{ | ||
try (GraphContext context = factory.create()) | ||
{ | ||
Assert.assertNotNull(context); | ||
DefaultValueTestModel initialModelType = context.getFramed().addVertex(null, DefaultValueTestModel.class); | ||
Assert.assertFalse(initialModelType.getDefaultFalseValue()); | ||
Assert.assertTrue(initialModelType.getDefaultTrueValue()); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
graph/tests/src/test/java/org/jboss/windup/graph/typedgraph/DefaultValueTestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.windup.graph.typedgraph; | ||
|
||
import com.tinkerpop.frames.Property; | ||
import com.tinkerpop.frames.modules.typedgraph.TypeValue; | ||
import org.jboss.windup.graph.frames.FrameBooleanDefaultValue; | ||
import org.jboss.windup.graph.model.WindupVertexFrame; | ||
import org.jboss.windup.graph.model.resource.ResourceModel; | ||
|
||
/** | ||
* A vertex used to test default value settings | ||
* @author <a href="mailto:mbriskar@redhat.com">Matej Briskar</a> | ||
*/ | ||
@TypeValue("DefaultValueTestModel") | ||
public interface DefaultValueTestModel extends WindupVertexFrame | ||
{ | ||
|
||
@Property("defaultFalse") | ||
@FrameBooleanDefaultValue(false) | ||
public void setDefaultFalseValue(Boolean prop); | ||
|
||
@Property("defaultFalse") | ||
public Boolean getDefaultFalseValue(); | ||
|
||
@Property("defaultTrue") | ||
@FrameBooleanDefaultValue(true) | ||
public void setDefaultTrueValue(Boolean prop); | ||
|
||
@Property("defaultTrue") | ||
public Boolean getDefaultTrueValue(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.