Java Code Examples for org.gradle.internal.reflect.DirectInstantiator

The following examples show how to use org.gradle.internal.reflect.DirectInstantiator. These examples are extracted from open source projects. 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
public void invoke(MethodInvocation invocation) throws Throwable {
    if (current.get() != null) {
        // Already invoking a method on the mix-in
        return;
    }

    if (instance == null) {
        instance = new DirectInstantiator().newInstance(mixInClass, proxy);
    }
    MethodInvocation beanInvocation = new MethodInvocation(invocation.getName(), invocation.getReturnType(), invocation.getGenericReturnType(), invocation.getParameterTypes(), instance, invocation.getParameters());
    current.set(beanInvocation);
    try {
        next.invoke(beanInvocation);
    } finally {
        current.set(null);
    }
    if (beanInvocation.found()) {
        invocation.setResult(beanInvocation.getResult());
    }
}
 
Example 2
public void invoke(MethodInvocation invocation) throws Throwable {
    if (current.get() != null) {
        // Already invoking a method on the mix-in
        return;
    }

    if (instance == null) {
        instance = new DirectInstantiator().newInstance(mixInClass, proxy);
    }
    MethodInvocation beanInvocation = new MethodInvocation(invocation.getName(), invocation.getReturnType(), invocation.getGenericReturnType(), invocation.getParameterTypes(), instance, invocation.getParameters());
    current.set(beanInvocation);
    try {
        next.invoke(beanInvocation);
    } finally {
        current.set(null);
    }
    if (beanInvocation.found()) {
        invocation.setResult(beanInvocation.getResult());
    }
}
 
Example 3
private <T extends JvmLibraryArtifact> void addJvmLibraryArtifacts(Set<T> artifacts, Class<T> type, Class<? extends T> implType, ComponentMetaData component, ArtifactResolver artifactResolver) {
    ArtifactResolveContext context = new ArtifactTypeResolveContext(type);
    BuildableArtifactSetResolveResult artifactSetResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveModuleArtifacts(component, context, artifactSetResolveResult);

    Instantiator instantiator = new DirectInstantiator();
    for (ComponentArtifactMetaData artifactMetaData : artifactSetResolveResult.getArtifacts()) {
        BuildableArtifactResolveResult resolveResult = new DefaultBuildableArtifactResolveResult();
        artifactResolver.resolveArtifact(artifactMetaData, component.getSource(), resolveResult);
        if (resolveResult.getFailure() != null) {
            artifacts.add(instantiator.newInstance(implType, resolveResult.getFailure()));
        } else {
            artifacts.add(instantiator.newInstance(implType, resolveResult.getFile()));
        }
    }
}
 
Example 4
public void invoke(MethodInvocation invocation) throws Throwable {
    if (current.get() != null) {
        // Already invoking a method on the mix-in
        return;
    }

    if (instance == null) {
        instance = new DirectInstantiator().newInstance(mixInClass, proxy);
    }
    MethodInvocation beanInvocation = new MethodInvocation(invocation.getName(), invocation.getReturnType(), invocation.getGenericReturnType(), invocation.getParameterTypes(), instance, invocation.getParameters());
    current.set(beanInvocation);
    try {
        next.invoke(beanInvocation);
    } finally {
        current.set(null);
    }
    if (beanInvocation.found()) {
        invocation.setResult(beanInvocation.getResult());
    }
}
 
Example 5
public void invoke(MethodInvocation invocation) throws Throwable {
    if (current.get() != null) {
        // Already invoking a method on the mix-in
        return;
    }

    if (instance == null) {
        instance = new DirectInstantiator().newInstance(mixInClass, proxy);
    }
    MethodInvocation beanInvocation = new MethodInvocation(invocation.getName(), invocation.getReturnType(), invocation.getGenericReturnType(), invocation.getParameterTypes(), instance, invocation.getParameters());
    current.set(beanInvocation);
    try {
        next.invoke(beanInvocation);
    } finally {
        current.set(null);
    }
    if (beanInvocation.found()) {
        invocation.setResult(beanInvocation.getResult());
    }
}
 
Example 6
private <T extends JvmLibraryArtifact> void addJvmLibraryArtifacts(Set<T> artifacts, Class<T> type, Class<? extends T> implType, ComponentMetaData component, ArtifactResolver artifactResolver) {
    ArtifactResolveContext context = new ArtifactTypeResolveContext(type);
    BuildableArtifactSetResolveResult artifactSetResolveResult = new DefaultBuildableArtifactSetResolveResult();
    artifactResolver.resolveModuleArtifacts(component, context, artifactSetResolveResult);

    Instantiator instantiator = new DirectInstantiator();
    for (ComponentArtifactMetaData artifactMetaData : artifactSetResolveResult.getArtifacts()) {
        BuildableArtifactResolveResult resolveResult = new DefaultBuildableArtifactResolveResult();
        artifactResolver.resolveArtifact(artifactMetaData, component.getSource(), resolveResult);
        if (resolveResult.getFailure() != null) {
            artifacts.add(instantiator.newInstance(implType, resolveResult.getFailure()));
        } else {
            artifacts.add(instantiator.newInstance(implType, resolveResult.getFile()));
        }
    }
}
 
Example 7
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 8
public static Instantiator getOrCreate() {
    Instantiator instantiator = get();
    if (instantiator != null) {
        return instantiator;
    } else {
        return new ClassGeneratorBackedInstantiator(new AsmBackedClassGenerator(), new DirectInstantiator());
    }
}
 
Example 9
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 10
public static Instantiator getOrCreate() {
    Instantiator instantiator = get();
    if (instantiator != null) {
        return instantiator;
    } else {
        return new ClassGeneratorBackedInstantiator(new AsmBackedClassGenerator(), new DirectInstantiator());
    }
}
 
Example 11
public static <T extends LanguageSourceSet> T create(Class<? extends LanguageSourceSet> publicType, Class<T> implementationType, ComponentSpecIdentifier componentId, SourceDirectorySetFactory sourceDirectorySetFactory) {
    NEXT_SOURCE_SET_INFO.set(new SourceSetInfo(componentId, publicType, sourceDirectorySetFactory));
    try {
        try {
            return DirectInstantiator.INSTANCE.newInstance(implementationType);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create LanguageSourceSet of type %s", publicType.getSimpleName()), e.getCause());
        }
    } finally {
        NEXT_SOURCE_SET_INFO.set(null);
    }
}
 
Example 12
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 13
public static Instantiator getOrCreate() {
    Instantiator instantiator = get();
    if (instantiator != null) {
        return instantiator;
    } else {
        return new ClassGeneratorBackedInstantiator(new AsmBackedClassGenerator(), new DirectInstantiator());
    }
}
 
Example 14
public T newInstance(Object... params) {
    Instantiator instantiator = new DirectInstantiator();
    try {
        return instantiator.newInstance(implementationClass, params);
    } catch (ObjectInstantiationException t) {
        throw new RuntimeException(String.format("Could not create an implementation of service '%s'.", serviceType.getName()), t);
    }
}
 
Example 15
public static Instantiator getOrCreate() {
    Instantiator instantiator = get();
    if (instantiator != null) {
        return instantiator;
    } else {
        return new ClassGeneratorBackedInstantiator(new AsmBackedClassGenerator(), new DirectInstantiator());
    }
}
 
Example 16
public ComponentTypeRuleDefinitionHandler(final Instantiator instantiator) {
    super("component", ComponentType.class, ComponentSpec.class, BaseComponentSpec.class, ComponentTypeBuilder.class, JavaReflectionUtil.factory(new DirectInstantiator(), DefaultComponentTypeBuilder.class), new RegistrationAction(instantiator));
}
 
Example 17
public BinaryTypeRuleDefinitionHandler(final Instantiator instantiator) {
    super("binary", BinaryType.class, BinarySpec.class, BaseBinarySpec.class, BinaryTypeBuilder.class, JavaReflectionUtil.factory(new DirectInstantiator(), DefaultBinaryTypeBuilder.class), new RegistrationAction(instantiator));
}
 
Example 18
public ReflectiveNamedDomainObjectFactory(Class<? extends T> type, Object... extraArgs) {
    this(type, new DirectInstantiator(), extraArgs);
}
 
Example 19
public <T> T newInstance(Class<T> type, Object... parameters) {
    Instantiator instantiator = new DirectInstantiator();
    return instantiator.newInstance(generate(type), parameters);
}
 
Example 20
Instantiator createInstantiator(ClassGenerator classGenerator) {
    return new ClassGeneratorBackedInstantiator(classGenerator, new DirectInstantiator());
}
 
Example 21
Source Project: pushfish-android   Source File: WrapUtil.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Wraps the given items in a named domain object set.
 */
public static <T extends Named> NamedDomainObjectSet<T> toNamedDomainObjectSet(Class<T> type, T... items) {
    DefaultNamedDomainObjectSet<T> domainObjectSet = new DefaultNamedDomainObjectSet<T>(type, new DirectInstantiator());
    CollectionUtils.addAll(domainObjectSet, items);
    return domainObjectSet;
}
 
Example 22
public ReflectiveNamedDomainObjectFactory(Class<? extends T> type, Object... extraArgs) {
    this(type, new DirectInstantiator(), extraArgs);
}
 
Example 23
public <T> T newInstance(Class<T> type, Object... parameters) {
    Instantiator instantiator = new DirectInstantiator();
    return instantiator.newInstance(generate(type), parameters);
}
 
Example 24
Instantiator createInstantiator(ClassGenerator classGenerator) {
    return new ClassGeneratorBackedInstantiator(classGenerator, new DirectInstantiator());
}
 
Example 25
public ComponentTypeRuleDefinitionHandler(final Instantiator instantiator) {
    super("component", ComponentType.class, ComponentSpec.class, BaseComponentSpec.class, ComponentTypeBuilder.class, JavaReflectionUtil.factory(new DirectInstantiator(), DefaultComponentTypeBuilder.class), new RegistrationAction(instantiator));
}
 
Example 26
public BinaryTypeRuleDefinitionHandler(final Instantiator instantiator) {
    super("binary", BinaryType.class, BinarySpec.class, BaseBinarySpec.class, BinaryTypeBuilder.class, JavaReflectionUtil.factory(new DirectInstantiator(), DefaultBinaryTypeBuilder.class), new RegistrationAction(instantiator));
}
 
Example 27
public ReflectiveNamedDomainObjectFactory(Class<? extends T> type, Object... extraArgs) {
    this(type, new DirectInstantiator(), extraArgs);
}
 
Example 28
public <T> T newInstance(Class<T> type, Object... parameters) {
    Instantiator instantiator = new DirectInstantiator();
    return instantiator.newInstance(generate(type), parameters);
}
 
Example 29
Instantiator createInstantiator(ClassGenerator classGenerator) {
    return new ClassGeneratorBackedInstantiator(classGenerator, new DirectInstantiator());
}
 
Example 30
Source Project: Pushjet-Android   Source File: WrapUtil.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Wraps the given items in a named domain object set.
 */
public static <T extends Named> NamedDomainObjectSet<T> toNamedDomainObjectSet(Class<T> type, T... items) {
    DefaultNamedDomainObjectSet<T> domainObjectSet = new DefaultNamedDomainObjectSet<T>(type, new DirectInstantiator());
    CollectionUtils.addAll(domainObjectSet, items);
    return domainObjectSet;
}