net.bytebuddy.implementation.bind.annotation.RuntimeType Java Examples

The following examples show how to use net.bytebuddy.implementation.bind.annotation.RuntimeType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence.");
        case IN:
            return thiz.getGraph().addFramedEdge(newVertex, thiz, label);
        case OUT:
            return thiz.getGraph().addFramedEdge(thiz, newVertex, label);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #2
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Set getEdges(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            return thiz.traverse(input -> input.bothE(label)).toSet(VertexFrame.class);
        case IN:
            return thiz.traverse(input -> input.inE(label)).toSet(VertexFrame.class);
        case OUT:
            return thiz.traverse(input -> input.outE(label)).toSet(VertexFrame.class);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #3
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        case IN:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            break;
        case OUT:
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }

    return newVertex;
}
 
Example #4
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static List getVertexes(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toList(type);
}
 
Example #5
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method) {
    final VertexFrame newVertex = thiz.getGraph().addFramedVertex();
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        case IN:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            break;
        case OUT:
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }

    return newVertex;
}
 
Example #6
Source File: MapInPropertiesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object execute(@This final ElementFrame thisFrame, @Origin final Method method, @RuntimeType @AllArguments final Object[] args)
{
    final MapInProperties ann = ((CachesReflection) thisFrame).getReflectionCache().getAnnotation(method, MapInProperties.class);

    Element thisElement = thisFrame.getElement();
    if (!(thisElement instanceof Vertex))
        throw new WindupException("Element is not of supported type, must be Vertex, but was: " + thisElement.getClass().getCanonicalName());
    Vertex vertex = (Vertex) thisElement;

    String methodName = method.getName();
    if (methodName.startsWith("get"))
        return handleGetter(vertex, method, args, ann);

    if (methodName.startsWith("set"))
        return handleSetter(vertex, method, args, ann);

    if (methodName.startsWith("put"))
        return handleAdder(vertex, method, args, ann);

    if (methodName.startsWith("putAll"))
        return handleAdder(vertex, method, args, ann);

    throw new WindupException("Only get*, set*, and put* method names are supported for @"
                + MapInProperties.class.getSimpleName() + ", found at: " + method.getName());
}
 
Example #7
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object getVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).next(type);
}
 
Example #8
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method) {
    final VertexFrame newVertex = thiz.getGraph().addFramedVertex();
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        case IN:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label);
            break;
        case OUT:
            thiz.getGraph().addFramedEdge(thiz, newVertex, label);
            break;
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }

    return newVertex;
}
 
Example #9
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Set getVertexes(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toSet(type);
}
 
Example #10
Source File: WindupPropertyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static void setProperty(@This final ElementFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Object obj)
{
    assert thiz instanceof CachesReflection;
    final Property annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Property.class);
    final String propertyName = annotation.value();
    final Object propertyValue;
    if ((obj != null) && (obj.getClass().isEnum()))
        propertyValue = ((Enum<?>) obj).name();
    else
        propertyValue = obj;

    if (propertyValue == null)
    {
        RemovePropertyInterceptor.removeProperty(thiz, method);
        return;
    }

    Element element = thiz.getElement();
    if (element instanceof Vertex)
        thiz.getGraph().getRawTraversal().V(element.id()).property(propertyName, propertyValue).iterate();
    else
        thiz.getGraph().getRawTraversal().E(element.id()).property(propertyName, propertyValue).iterate();
}
 
Example #11
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object getVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).next(type);
}
 
Example #12
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static List getEdges(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            return thiz.traverse(input -> input.bothE(label)).toList(VertexFrame.class);
        case IN:
            return thiz.traverse(input -> input.inE(label)).toList(VertexFrame.class);
        case OUT:
            return thiz.traverse(input -> input.outE(label)).toList(VertexFrame.class);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #13
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Iterator getEdges(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            return thiz.traverse(input -> input.bothE(label)).frame(VertexFrame.class);
        case IN:
            return thiz.traverse(input -> input.inE(label)).frame(VertexFrame.class);
        case OUT:
            return thiz.traverse(input -> input.outE(label)).frame(VertexFrame.class);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #14
Source File: ConcordionInterceptor.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args) throws Exception {
	
       final FeatureResolver resolver = FeatureResolver.newFeatureResolver(bean.getClass()).withTestMethod(method)
               .withDefaultCleanupPhase(CleanupPhase.NONE).build();

       Object result = null;
       final TestInvocationImpl invocation = new TestInvocationImpl(bean, method, resolver);
       executor.processBefore(invocation);
       try {
           result = method.invoke(bean, args);
       } catch (final Exception e) {
       	Exception cause = (Exception)e.getCause();
           invocation.setTestException(cause);
           executor.processAfter(invocation);
           throw cause;
       }
       executor.processAfter(invocation);

       return result;
   }
 
Example #15
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object getVertexes(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return input.in(label);
            case OUT:
                return input.out(label);
            case BOTH:
                return input.both(label);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).nextOrDefault(VertexFrame.class, null);
}
 
Example #16
Source File: CucumberInterceptor.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args) throws Exception {
	
       final FeatureResolver resolver = FeatureResolver.newFeatureResolver(bean.getClass()).withTestMethod(method)
               .withDefaultCleanupPhase(CleanupPhase.NONE).build();

       Object result = null;
       final TestInvocationImpl invocation = new TestInvocationImpl(bean, method, resolver);
       executor.processBefore(invocation);
       try {
           result = method.invoke(bean, args);
       } catch (final Exception e) {
       	Exception cause = (Exception)e.getCause();
           invocation.setTestException(cause);
           executor.processAfter(invocation);
           throw cause;
       }
       executor.processAfter(invocation);

       return result;
   }
 
Example #17
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Set getVertexes(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toSet(type);
}
 
Example #18
Source File: MapInAdjacentPropertiesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object execute(@This final ElementFrame thisFrame, @Origin final Method method, @RuntimeType @AllArguments final Object[] args)
{
    final MapInAdjacentProperties ann = ((CachesReflection) thisFrame).getReflectionCache().getAnnotation(method, MapInAdjacentProperties.class);

    Element thisElement = thisFrame.getElement();
    if (!(thisElement instanceof Vertex))
        throw new WindupException("Element is not of supported type, must be Vertex, but was: " + thisElement.getClass().getCanonicalName());
    Vertex vertex = (Vertex) thisElement;

    String methodName = method.getName();
    if (methodName.startsWith("get"))
        return handleGetter(vertex, method, args, ann);

    if (methodName.startsWith("set"))
    {
        handleSetter(vertex, method, args, ann, thisFrame.getGraph());
        return null;
    }

    throw new WindupException("Only get* and set* method names are supported for @" + MapInAdjacentProperties.class.getSimpleName());
}
 
Example #19
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(value = 0) final ClassInitializer vertexType) {
    final Object newNode = thiz.getGraph().addFramedVertex(vertexType);
    assert newNode instanceof VertexFrame;
    final VertexFrame newVertex = ((VertexFrame) newNode);

    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    assert vertexType.getInitializationType().isInstance(newNode);

    switch (direction) {
        case BOTH:
            throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence.");
        case IN:
            return thiz.getGraph().addFramedEdge(newVertex, thiz, label);
        case OUT:
            return thiz.getGraph().addFramedEdge(thiz, newVertex, label);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #20
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object addEdge(@This final VertexFrame thiz, @Origin final Method method) {
    final VertexFrame newVertex = thiz.getGraph().addFramedVertex();
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            throw new IllegalStateException(method.getName() + " is annotated with direction BOTH, this is not allowed for add methods annotated with @Incidence.");
        case IN:
            return thiz.getGraph().addFramedEdge(newVertex, thiz, label);
        case OUT:
            return thiz.getGraph().addFramedEdge(thiz, newVertex, label);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #21
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static List getVertexes(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toList(type);
}
 
Example #22
Source File: ConstructorInterTemplate.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * Intercept the target constructor.
 *
 * @param obj          target class instance.
 * @param allArguments all constructor arguments
 */
@RuntimeType
public static void intercept(@This Object obj, @AllArguments Object[] allArguments) {
    try {
        prepare();

        EnhancedInstance targetObject = (EnhancedInstance) obj;

        if (INTERCEPTOR == null) {
            return;
        }
        INTERCEPTOR.onConstruct(targetObject, allArguments);
    } catch (Throwable t) {
        LOGGER.error("ConstructorInter failure.", t);
    }
}
 
Example #23
Source File: MapInAdjacentVerticesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object execute(@This final ElementFrame thisFrame, @Origin final Method method, @RuntimeType @AllArguments final Object[] args)
{
    final MapInAdjacentVertices ann = ((CachesReflection) thisFrame).getReflectionCache().getAnnotation(method, MapInAdjacentVertices.class);

    Element thisElement = thisFrame.getElement();
    if (!(thisElement instanceof Vertex))
        throw new WindupException("Element is not of supported type, must be Vertex, but was: " + thisElement.getClass().getCanonicalName());
    Vertex vertex = (Vertex) thisElement;

    String methodName = method.getName();
    if (methodName.startsWith("get"))
    {
        return handleGetter(vertex, method, args, ann, thisFrame.getGraph());
    }
    else if (methodName.startsWith("set"))
    {
        handleSetter((VertexFrame)thisFrame, method, args, ann, thisFrame.getGraph());
        return null;
    }

    throw new WindupException("Only get* and set* method names are supported.");
}
 
Example #24
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object getVertexes(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    try {
        return thiz.traverse(input -> {
            switch (direction) {
                case IN:
                    return input.in(label);
                case OUT:
                    return input.out(label);
                case BOTH:
                    return input.both(label);
                default:
                    throw new IllegalStateException("Direction not recognized.");
            }
        }).next(VertexFrame.class);
    } catch (NoSuchElementException e)
    {
        return null;
    }
}
 
Example #25
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Iterator getVertexes(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return resolver.hasType(input.in(label), type);
            case OUT:
                return resolver.hasType(input.out(label), type);
            case BOTH:
                return resolver.hasType(input.both(label), type);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).frame(type);
}
 
Example #26
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex, @RuntimeType @Argument(1) final ClassInitializer edgeType) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType);
            thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType);
            break;
        case IN:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType);
            break;
        case OUT:
            thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType);
            break;
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }

    return newVertex;
}
 
Example #27
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Object addVertex(@This final VertexFrame thiz, @Origin final Method method, @RuntimeType @Argument(0) final VertexFrame newVertex, @RuntimeType @Argument(1) final ClassInitializer edgeType) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    switch (direction) {
        case BOTH:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType);
            thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType);
            break;
        case IN:
            thiz.getGraph().addFramedEdge(newVertex, thiz, label, edgeType);
            break;
        case OUT:
            thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType);
            break;
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }

    return newVertex;
}
 
Example #28
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Iterator getVertexes(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    return thiz.traverse(input -> {
        switch(direction) {
            case IN:
                return input.in(label);
            case OUT:
                return input.out(label);
            case BOTH:
                return input.both(label);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).frame(VertexFrame.class);
}
 
Example #29
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
@RuntimeType
public static Set getVertexes(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    return thiz.traverse(input -> {
        switch (direction) {
            case IN:
                return input.in(label);
            case OUT:
                return input.out(label);
            case BOTH:
                return input.both(label);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toSet(VertexFrame.class);
}
 
Example #30
Source File: AdjacencyMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Set getVertexes(@This final VertexFrame thiz, @Origin final Method method) {
    assert thiz instanceof CachesReflection;
    final Adjacency annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Adjacency.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();

    return thiz.traverse(input -> {
        switch (direction) {
            case IN:
                return input.in(label);
            case OUT:
                return input.out(label);
            case BOTH:
                return input.both(label);
            default:
                throw new IllegalStateException("Direction not recognized.");
        }
    }).toSet(VertexFrame.class);
}