Search in sources :

Example 51 with Member

use of java.lang.reflect.Member in project roboguice by roboguice.

the class GraphvizGrapher method newImplementationNode.

@Override
protected void newImplementationNode(ImplementationNode node) {
    NodeId nodeId = node.getId();
    GraphvizNode gnode = new GraphvizNode(nodeId);
    gnode.setStyle(NodeStyle.SOLID);
    gnode.setHeaderBackgroundColor("#000000");
    gnode.setHeaderTextColor("#ffffff");
    gnode.setTitle(nameFactory.getClassName(nodeId.getKey()));
    for (Member member : node.getMembers()) {
        gnode.addField(portIdFactory.getPortId(member), nameFactory.getMemberName(member));
    }
    addNode(gnode);
}
Also used : NodeId(com.google.inject.grapher.NodeId) Member(java.lang.reflect.Member)

Example 52 with Member

use of java.lang.reflect.Member in project yyl_example by Relucent.

the class JaqueExample method property.

public static <T> void property(Property<T, ?> propertyRef) {
    LambdaExpression<Function<T, ?>> parsed = LambdaExpression.parse(propertyRef);
    // Use parsed Expression Tree...
    Expression body = parsed.getBody();
    Expression methodCall = body;
    System.out.println("body:\n" + body);
    // remove casts
    while (methodCall instanceof UnaryExpression) {
        methodCall = ((UnaryExpression) methodCall).getFirst();
    }
    // checks are omitted for brevity
    MemberExpression invexp = (MemberExpression) ((InvocationExpression) methodCall).getTarget();
    Member member = invexp.getMember();
    System.out.println("member:\n" + member);
    System.out.println();
}
Also used : Function(java.util.function.Function) MemberExpression(com.trigersoft.jaque.expression.MemberExpression) Expression(com.trigersoft.jaque.expression.Expression) InvocationExpression(com.trigersoft.jaque.expression.InvocationExpression) MemberExpression(com.trigersoft.jaque.expression.MemberExpression) UnaryExpression(com.trigersoft.jaque.expression.UnaryExpression) LambdaExpression(com.trigersoft.jaque.expression.LambdaExpression) UnaryExpression(com.trigersoft.jaque.expression.UnaryExpression) Member(java.lang.reflect.Member)

Example 53 with Member

use of java.lang.reflect.Member in project groovy by apache.

the class Java9 method checkCanSetAccessible.

/**
 * This method may be used by a caller in class C to check whether to enable access to a member of declaring class D successfully
 * if {@link Java8#checkCanSetAccessible(java.lang.reflect.AccessibleObject, java.lang.Class)} returns true and any of the following hold:
 * <p>
 * 1) C and D are in the same module.
 * 2) The member is public and D is public in a package that the module containing D exports to at least the module containing C.
 * 3) The member is protected static, D is public in a package that the module containing D exports to at least the module containing C, and C is a subclass of D.
 * 4) D is in a package that the module containing D opens to at least the module containing C. All packages in unnamed and open modules are open to all modules and so this method always succeeds when D is in an unnamed or open module.
 *
 * @param accessibleObject the accessible object to check
 * @param callerClass      the class wishing to invoke {@code setAccessible}
 * @return the check result
 */
@Override
public boolean checkCanSetAccessible(final AccessibleObject accessibleObject, final Class<?> callerClass) {
    if (!super.checkCanSetAccessible(accessibleObject, callerClass))
        return false;
    if (callerClass == MethodHandle.class) {
        // should not happen
        throw new IllegalCallerException();
    }
    if (!(accessibleObject instanceof Member)) {
        // should not happen
        throw new IllegalArgumentException("accessibleObject should be a member of type: " + accessibleObject);
    }
    Member member = (Member) accessibleObject;
    Class<?> declaringClass = member.getDeclaringClass();
    Module declaringModule = declaringClass.getModule();
    Module callerModule = callerClass.getModule();
    if (!declaringModule.isNamed())
        return true;
    if (callerModule == declaringModule)
        return true;
    if (callerModule == Object.class.getModule())
        return true;
    return checkAccessible(callerClass, declaringClass, member.getModifiers(), true);
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) Member(java.lang.reflect.Member)

Example 54 with Member

use of java.lang.reflect.Member in project wildfly by wildfly.

the class WeldResourceInjectionServices method resolveResource.

public Object resolveResource(InjectionPoint injectionPoint) {
    final Member member = injectionPoint.getMember();
    AnnotatedMember<?> annotatedMember;
    if (injectionPoint.getAnnotated() instanceof AnnotatedField) {
        annotatedMember = (AnnotatedField<?>) injectionPoint.getAnnotated();
    } else {
        annotatedMember = ((AnnotatedParameter<?>) injectionPoint.getAnnotated()).getDeclaringCallable();
    }
    if (!annotatedMember.isAnnotationPresent(Resource.class)) {
        throw WeldLogger.ROOT_LOGGER.annotationNotFound(Resource.class, member);
    }
    if (member instanceof Method && ((Method) member).getParameterCount() != 1) {
        throw WeldLogger.ROOT_LOGGER.injectionPointNotAJavabean((Method) member);
    }
    String name = getResourceName(injectionPoint);
    for (ResourceInjectionResolver resolver : resourceResolvers) {
        Object result = resolver.resolve(name);
        if (result != null) {
            return result;
        }
    }
    try {
        return context.lookup(name);
    } catch (NamingException e) {
        throw WeldLogger.ROOT_LOGGER.couldNotFindResource(name, injectionPoint.getMember().toString(), e);
    }
}
Also used : Resource(javax.annotation.Resource) ResourceInjectionResolver(org.jboss.as.weld.spi.ResourceInjectionResolver) NamingException(javax.naming.NamingException) Method(java.lang.reflect.Method) AnnotatedField(javax.enterprise.inject.spi.AnnotatedField) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Member(java.lang.reflect.Member)

Example 55 with Member

use of java.lang.reflect.Member in project immutables by immutables.

the class ReflectionExtractor method extract.

@Override
@Nullable
public Object extract(Path path, Object instance) {
    Objects.requireNonNull(path, "path");
    Object result = instance;
    for (Member member : path.members()) {
        result = extractor.extract(member, result);
        if (result == null) {
            return null;
        }
    }
    return result;
}
Also used : Member(java.lang.reflect.Member) Nullable(javax.annotation.Nullable)

Aggregations

Member (java.lang.reflect.Member)135 Method (java.lang.reflect.Method)41 Field (java.lang.reflect.Field)30 ArrayList (java.util.ArrayList)13 AccessibleObject (java.lang.reflect.AccessibleObject)12 Type (java.lang.reflect.Type)12 Annotation (java.lang.annotation.Annotation)11 Constructor (java.lang.reflect.Constructor)10 TypeVariable (java.lang.reflect.TypeVariable)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ParameterizedType (java.lang.reflect.ParameterizedType)7 Map (java.util.Map)7 MetaInfo (org.qi4j.api.common.MetaInfo)7 InjectionPoint (com.google.inject.spi.InjectionPoint)6 AnnotatedElement (java.lang.reflect.AnnotatedElement)6 LinkedHashSet (java.util.LinkedHashSet)6 Optional (org.qi4j.api.common.Optional)6 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)6 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)6 HashSet (java.util.HashSet)5