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

The following examples show how to use net.bytebuddy.implementation.bind.annotation.This. 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: 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);
}
 
Example #2
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 #3
Source File: BytebuddyInvocationHandler.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public Object byteBuddyInvoke(@This Object proxy, @Origin Method method, @AllArguments @RuntimeType Object[] args)
    throws Throwable {
    String name = method.getName();
    if ("equals".equals(name)) {
        Object another = args[0];
        return proxy == another ||
            (proxy.getClass().isInstance(another) && proxyInvoker.equals(BytebuddyProxy.parseInvoker(another)));
    } else if ("hashCode".equals(name)) {
        return proxyInvoker.hashCode();
    } else if ("toString".equals(name)) {
        return proxyInvoker.toString();
    }

    SofaRequest request = MessageBuilder.buildSofaRequest(method.getDeclaringClass(), method,
        method.getParameterTypes(), args);
    SofaResponse response = proxyInvoker.invoke(request);

    return response.getAppResponse();
}
 
Example #4
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 #5
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 #6
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 #7
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) {
    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.");
        }
    }).toList(VertexFrame.class);
}
 
Example #8
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 #9
Source File: WindupAdjacencyMethodHandler.java    From windup with Eclipse Public License 1.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 #10
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, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    switch (direction) {
        case BOTH:
            return thiz.traverse(input -> resolver.hasType(input.bothE(label), type)).toList(type);
        case IN:
            return thiz.traverse(input -> resolver.hasType(input.inE(label), type)).toList(type);
        case OUT:
            return thiz.traverse(input -> resolver.hasType(input.outE(label), type)).toList(type);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #11
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 #12
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, @RuntimeType @Argument(0) final Class type) {
    assert thiz instanceof CachesReflection;
    final Incidence annotation = ((CachesReflection) thiz).getReflectionCache().getAnnotation(method, Incidence.class);
    final Direction direction = annotation.direction();
    final String label = annotation.label();
    final TypeResolver resolver = thiz.getGraph().getTypeResolver();

    switch (direction) {
        case BOTH:
            return thiz.traverse(input -> resolver.hasType(input.bothE(label), type)).frame(type);
        case IN:
            return thiz.traverse(input -> resolver.hasType(input.inE(label), type)).frame(type);
        case OUT:
            return thiz.traverse(input -> resolver.hasType(input.outE(label), type)).frame(type);
        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 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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #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: 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 #28
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 ClassInitializer vertexType, @RuntimeType @Argument(1) final ClassInitializer edgeType) {
    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, edgeType);
        case OUT:
            return thiz.getGraph().addFramedEdge(thiz, newVertex, label, edgeType);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #29
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 #30
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.");
    }
}