Search in sources :

Example 31 with Member

use of java.lang.reflect.Member in project guice by google.

the class ShortNameFactoryTest method testGetSourceName_method.

/**
   * Tests the case where a provider method is the source of the
   *
   * @throws Exception
   */
public void testGetSourceName_method() throws Exception {
    Member method = Obj.class.getDeclaredMethod("method", String.class);
    assertEquals("Method should be identified by its file name and line number", "ShortNameFactoryTest.java:52", nameFactory.getSourceName(method));
}
Also used : Member(java.lang.reflect.Member)

Example 32 with Member

use of java.lang.reflect.Member in project guice by google.

the class ShortNameFactoryTest method testGetMemberName_constructor.

public void testGetMemberName_constructor() throws Exception {
    Member constructor = Obj.class.getDeclaredConstructor();
    assertEquals("<init>", nameFactory.getMemberName(constructor));
}
Also used : Member(java.lang.reflect.Member)

Example 33 with Member

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

the class CheckForbiddenMethodsUsage method testNoDefaultEncoding.

@Test
public void testNoDefaultEncoding() throws Exception {
    final Reflections reflections = new Reflections(new ConfigurationBuilder().useParallelExecutor(Runtime.getRuntime().availableProcessors()).addUrls(ClasspathHelper.forPackage("org.apache.flink")).addScanners(new MemberUsageScanner()));
    for (ForbiddenCall forbiddenCall : forbiddenCalls) {
        final Set<Member> methodUsages = forbiddenCall.getUsages(reflections);
        methodUsages.removeAll(forbiddenCall.getExclusions());
        assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size());
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) MemberUsageScanner(org.reflections.scanners.MemberUsageScanner) Member(java.lang.reflect.Member) Reflections(org.reflections.Reflections) Test(org.junit.Test) FieldParserTest(org.apache.flink.types.parser.FieldParserTest)

Example 34 with Member

use of java.lang.reflect.Member in project qi4j-sdk by Qi4j.

the class MetaInfoDeclaration method metaInfoFor.

@Override
public MetaInfo metaInfoFor(AccessibleObject accessor) {
    for (Map.Entry<Class<?>, InfoHolder<?>> entry : mixinPropertyDeclarations.entrySet()) {
        InfoHolder<?> holder = entry.getValue();
        MetaInfo metaInfo = holder.metaInfoFor(accessor);
        if (metaInfo != null) {
            Class<?> mixinType = entry.getKey();
            return metaInfo.withAnnotations(mixinType).withAnnotations(accessor).withAnnotations(accessor instanceof Method ? ((Method) accessor).getReturnType() : ((Field) accessor).getType());
        }
    }
    // TODO is this code reached at all??
    Class<?> declaringType = ((Member) accessor).getDeclaringClass();
    return new MetaInfo().withAnnotations(declaringType).withAnnotations(accessor).withAnnotations(accessor instanceof Method ? ((Method) accessor).getReturnType() : ((Field) accessor).getType());
}
Also used : Field(java.lang.reflect.Field) MetaInfo(org.qi4j.api.common.MetaInfo) Method(java.lang.reflect.Method) Map(java.util.Map) HashMap(java.util.HashMap) Member(java.lang.reflect.Member)

Example 35 with Member

use of java.lang.reflect.Member in project qi4j-sdk by Qi4j.

the class AssociationModel method bind.

@Override
public void bind(Resolution resolution) throws BindingException {
    builderInfo = new AssociationInfo() {

        @Override
        public boolean isImmutable() {
            return false;
        }

        @Override
        public QualifiedName qualifiedName() {
            return qualifiedName;
        }

        @Override
        public Type type() {
            return type;
        }

        @Override
        public void checkConstraints(Object value) throws ConstraintViolationException {
            AssociationModel.this.checkConstraints(value);
        }
    };
    if (type instanceof TypeVariable) {
        Class mainType = first(resolution.model().types());
        type = Classes.resolveTypeVariable((TypeVariable) type, ((Member) accessor).getDeclaringClass(), mainType);
    }
}
Also used : Type(java.lang.reflect.Type) GenericAssociationInfo(org.qi4j.api.association.GenericAssociationInfo) TypeVariable(java.lang.reflect.TypeVariable) QualifiedName(org.qi4j.api.common.QualifiedName) ConstraintViolationException(org.qi4j.api.constraint.ConstraintViolationException) AccessibleObject(java.lang.reflect.AccessibleObject) Member(java.lang.reflect.Member)

Aggregations

Member (java.lang.reflect.Member)59 Method (java.lang.reflect.Method)13 Annotation (java.lang.annotation.Annotation)8 AccessibleObject (java.lang.reflect.AccessibleObject)7 MetaInfo (org.qi4j.api.common.MetaInfo)7 Field (java.lang.reflect.Field)6 Optional (org.qi4j.api.common.Optional)6 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)6 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)6 TypeVariable (java.lang.reflect.TypeVariable)5 NodeId (com.google.inject.grapher.NodeId)4 Constructor (java.lang.reflect.Constructor)4 Type (java.lang.reflect.Type)4 ArrayList (java.util.ArrayList)4 ManyAssociation (org.qi4j.api.association.ManyAssociation)4 NamedAssociation (org.qi4j.api.association.NamedAssociation)4 QualifiedName (org.qi4j.api.common.QualifiedName)4 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)4 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)4 HashSet (java.util.HashSet)3