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

The following examples show how to use net.bytebuddy.implementation.bind.annotation.Origin. 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 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 #3
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 #4
Source File: IncidenceMethodHandler.java    From Ferma with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object getEdge(@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)).next(type);
        case IN:
            return thiz.traverse(input -> resolver.hasType(input.inE(label), type)).next(type);
        case OUT:
            return thiz.traverse(input -> resolver.hasType(input.outE(label), type)).next(type);
        default:
            throw new IllegalStateException(method.getName() + " is annotated with a direction other than BOTH, IN, or OUT.");
    }
}
 
Example #5
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 #6
Source File: GenericImmutableProxyForwarder.java    From reflection-util with Apache License 2.0 6 votes vote down vote up
@RuntimeType
public static Object forward(@Origin Method method,
							 @FieldValue(ImmutableProxy.DELEGATE_FIELD_NAME) Object delegate,
							 @AllArguments Object[] args) throws InvocationTargetException, IllegalAccessException {
	Object value = method.invoke(delegate, args);
	if (ImmutableProxy.isImmutable(value)) {
		return value;
	}
	if (!shouldProxyReturnValue(method)) {
		return value;
	}
	if (value instanceof Collection) {
		return createImmutableCollection(value, method);
	} else if (value instanceof Map) {
		return createImmutableMap(value, method);
	} else {
		return ImmutableProxy.create(value);
	}
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
Source File: AutoInvoker.java    From Jupiter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@RuntimeType
public Object invoke(@Origin Method method, @AllArguments @RuntimeType Object[] args) throws Throwable {
    Class<?> returnType = method.getReturnType();

    if (isSyncInvoke(returnType)) {
        return doInvoke(method.getName(), args, returnType, true);
    }

    InvokeFuture<Object> inf = (InvokeFuture<Object>) doInvoke(method.getName(), args, returnType, false);

    if (returnType.isAssignableFrom(inf.getClass())) {
        return inf;
    }

    final CompletableFuture<Object> cf = newFuture((Class<CompletableFuture>) returnType);
    inf.whenComplete((result, throwable) -> {
        if (throwable == null) {
            cf.complete(result);
        } else {
            cf.completeExceptionally(throwable);
        }
    });

    return cf;
}
 
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: 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) {
    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 #14
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 #15
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, @RuntimeType @Argument(1) final ClassInitializer edgeType) {
    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, 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 #16
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 #17
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 #18
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 #19
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) {
    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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #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) {
    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 #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(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 #28
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 #29
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 #30
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());
}