当前位置: 首页>>代码示例>>Java>>正文


Java ElementMatchers类代码示例

本文整理汇总了Java中net.bytebuddy.matcher.ElementMatchers的典型用法代码示例。如果您正苦于以下问题:Java ElementMatchers类的具体用法?Java ElementMatchers怎么用?Java ElementMatchers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ElementMatchers类属于net.bytebuddy.matcher包,在下文中一共展示了ElementMatchers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLazyClass

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Class<? extends T> createLazyClass(Class<T> type) {
	Class<? extends Element> lazyType = byteBuddy
			.subclass(AbstractElement.class)
			.implement(type)
			.defineField("handler", InvocationHandler.class, Visibility.PUBLIC)
			.implement(HandlerSetter.class)
			.intercept(FieldAccessor.ofField("handler"))
			.method(ElementMatchers.not(ElementMatchers.isDeclaredBy(HandlerSetter.class)))
			.intercept(InvocationHandlerAdapter.toField("handler"))
			.make()
			.load(type.getClassLoader())
			.getLoaded();
	lazyTypes.put(type, lazyType);
	return (Class<? extends T>) lazyType;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:17,代码来源:LazyLoader.java

示例2: transform

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
        final DynamicType.Builder<?> builder,
        final TypeDescription typeDescription,
        final ClassLoader classLoader,
        final JavaModule module) {

    final AsmVisitorWrapper methodsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceMethods.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isMethod()));

    final AsmVisitorWrapper constructorsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceConstructors.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isConstructor()));

    return builder.visit(methodsVisitor).visit(constructorsVisitor);
}
 
开发者ID:ivanyu,项目名称:java-agents-demo,代码行数:20,代码来源:MetricsCollectionByteBuddyAgent.java

示例3: getIncludes

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public ElementMatcher<MethodDescription> getIncludes() {
    return not(ElementMatchers.<MethodDescription>isPrivate()
            .or(ObjectMethodElementMatchers.INSTANCE)
            .or(named("close"))
            .or(named("getDB"))
            .or(named("getClient"))
            .or(named("connect"))
            .or(named("setDataSource"))
            .or(named("resetState"))
            .or(named("clusterSlots"))
            .or(named("isConnected"))
            .or(named("ping"))
            .or(named("quit"))
            .or(named("checkIsInMultiOrPipeline")));
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:18,代码来源:JaRedisMethodInclusion.java

示例4: matchAnyMethodIn

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
/**
 * Returns a byte buddy matcher matching any method contained in methodSignatures.
 */
public static ElementMatcher<MethodDescription> matchAnyMethodIn(Set<MethodSignature> methodSignatures) {
    ElementMatcher.Junction<MethodDescription> methodMatcher = ElementMatchers.none();
    for (MethodSignature methodSignature : methodSignatures) {
        ElementMatcher.Junction<MethodDescription> junction = ElementMatchers
                .named(methodSignature.getMethodName())
                .and(not(isAbstract()))
                .and(isPublic())
                .and(takesArguments(methodSignature.getParameterTypes().size()));
        for (int i = 0; i < methodSignature.getParameterTypes().size(); i++) {
            junction = junction.and(takesArgument(i, named(methodSignature.getParameterTypes().get(i))));
        }
        methodMatcher = methodMatcher.or(junction);
    }
    return methodMatcher;
}
 
开发者ID:fstab,项目名称:promagent,代码行数:19,代码来源:Promagent.java

示例5: result

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Override
public final Result<StackManipulation> result() {
    final TypeDescription declaringType = field.getDeclaringType().asErasure();
    final TypeDescription fieldType = field.getType().asErasure();
    if(new NaturalJavaAtom().matches(fieldType)) {
        return new SmtInvokeMethod(
            new TypeDescription.ForLoadedType(Object.class),
            ElementMatchers.named("equals")
        );
    } else {
        return new SmtInvokeMethod(
            declaringType,
            new ConjunctionMatcher<>(
                ElementMatchers.isSynthetic(),
                ElementMatchers.named("atom$equal")
            )
        );
    }
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:20,代码来源:SmtCompareAtomFields.java

示例6: ExtendingTest

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
public ExtendingTest() {
    super(
        new TestCase(
            "matches types inherited from atom", 
            new AssertThatTypeMatches(
                new TypeDescription.ForLoadedType(
                    Bar.class
                ), 
                new Extending(
                    ElementMatchers.anyOf(Foo.class)
                )
            )
        ),
        new TestCase(
            "mismatch atoms",
            new AssertThatTypeDoesNotMatch(
                new TypeDescription.ForLoadedType(
                    Foo.class
                ), 
                new Extending(
                    ElementMatchers.anyOf(Foo.class)
                )
            )
        )
    );
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:27,代码来源:ExtendingTest.java

示例7: createAgentBuilder

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
/**
 * Creates the AgentBuilder that will redefine the System class.
 * @param inst instrumentation instance.
 * @return an agent builder.
 */
private static AgentBuilder createAgentBuilder(Instrumentation inst) {

    // Find me a class called "java.lang.System"
    final ElementMatcher.Junction<NamedElement> systemType = ElementMatchers.named("java.lang.System");

    // And then find a method called setSecurityManager and tell MySystemInterceptor to
    // intercept it (the method binding is smart enough to take it from there)
    final AgentBuilder.Transformer transformer =
            (b, typeDescription) -> b.method(ElementMatchers.named("setSecurityManager"))
                    .intercept(MethodDelegation.to(MySystemInterceptor.class));

    // Disable a bunch of stuff and turn on redefine as the only option
    final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
    final AgentBuilder agentBuilder = new AgentBuilder.Default()
            .withByteBuddy(byteBuddy)
            .withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
            .withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.REDEFINITION)
            .withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE)
            .type(systemType)
            .transform(transformer);

    return agentBuilder;
}
 
开发者ID:wsargent,项目名称:securityfixer,代码行数:29,代码来源:SecurityFixerAgent.java

示例8: createMethodIdProxy

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
private static <C> C createMethodIdProxy(final Class<C> interfaceToProxy, final Optional<String> scopeNameOpt)
{
    final List<ConfigDescriptor> configDescList = ConfigSystem.descriptorFactory.buildDescriptors(interfaceToProxy, scopeNameOpt);

    DynamicType.Builder<C> typeBuilder = new ByteBuddy().subclass(interfaceToProxy);
    for (ConfigDescriptor desc : configDescList) {
        typeBuilder = typeBuilder.method(ElementMatchers.is(desc.getMethod())).intercept(InvocationHandlerAdapter.of((Object proxy, Method method1, Object[] args) -> {
            log.trace("BB InvocationHandler identifying method {} proxy {}, argCount {}", method1.getName(), proxy.toString(), args.length);
            lastIdentifiedMethodAndScope.set(new MethodAndScope(method1, scopeNameOpt));
            return defaultForType(desc.getMethod().getReturnType());
        }));
    }

    Class<? extends C> configImpl = typeBuilder.make()
        .load(interfaceToProxy.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
        .getLoaded();
    try {
        return configImpl.newInstance();
    }
    catch (InstantiationException | IllegalAccessException ex) {
        throw new ConfigException("Failed to instantiate identification implementation of Config {} scope {}",
            interfaceToProxy.getName(), scopeNameOpt.orElse("<empty>"), ex);
    }
}
 
开发者ID:kikinteractive,项目名称:ice,代码行数:25,代码来源:MethodIdProxyFactory.java

示例9: install

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
public static void install() {
    ByteBuddyAgent.install();

    ClassLoader targetClassLoader = File.class.getClassLoader();

    // interceptor class must be injected to the same classloader as the target class that is intercepted
    new ByteBuddy().redefine(CountFileSystemOperations.class)
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());

    new ByteBuddy().redefine(DirectoryFileTree.class)
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES)
                    .method(ElementMatchers.named("length"), Advice.to(CountFileSystemOperations.LengthMethod.class))
                    .method(ElementMatchers.named("isFile"), Advice.to(CountFileSystemOperations.IsFileMethod.class))
                    .method(ElementMatchers.named("isDirectory"), Advice.to(CountFileSystemOperations.IsDirectoryMethod.class))
                    .method(ElementMatchers.named("lastModified"), Advice.to(CountFileSystemOperations.LastModifiedMethod.class))
                    .method(ElementMatchers.named("exists"), Advice.to(CountFileSystemOperations.ExistsMethod.class))

            )
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());
}
 
开发者ID:lhotari,项目名称:gradle-profiling,代码行数:25,代码来源:FileSystemOperationsInterceptor.java

示例10: install

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
public static void install() {
    ByteBuddyAgent.install();

    ClassLoader targetClassLoader = DirectoryFileTree.class.getClassLoader();

    // interceptor class must be injected to the same classloader as the target class that is intercepted
    new ByteBuddy().redefine(CountDirectoryScans.class)
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());

    new ByteBuddy().redefine(DirectoryFileTree.class)
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES).method(ElementMatchers.named("visitFrom"), Advice.to(CountDirectoryScans.class)))
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());
}
 
开发者ID:lhotari,项目名称:gradle-profiling,代码行数:18,代码来源:DirectoryScanningInterceptor.java

示例11: getConstructorsInterceptPoints

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
    return new ConstructorInterceptPoint[] {
        new ConstructorInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getConstructorMatcher() {
                return ElementMatchers.takesArguments(1);
            }

            @Override
            public String getConstructorInterceptor() {
                return DO_CONSTRUCTOR_INTERCEPTOR;
            }
        }
    };
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:17,代码来源:AbstractNutzHttpInstrumentation.java

示例12: agent

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
private static synchronized void agent(final boolean shouldRedefine, final Instrumentation instrumentation)
{
    BufferAlignmentAgent.instrumentation = instrumentation;
    // all Int methods, and all String method other than
    // XXXStringWithoutLengthXXX or getStringXXX(int, int)
    final Junction<MethodDescription> intVerifierMatcher = nameContains("Int")
        .or(nameMatches(".*String[^W].*").and(not(ElementMatchers.takesArguments(int.class, int.class))));

    alignmentTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED))
        .with(LISTENER)
        .disableClassFormatChanges()
        .with(shouldRedefine ?
            AgentBuilder.RedefinitionStrategy.RETRANSFORMATION :
            AgentBuilder.RedefinitionStrategy.DISABLED)
        .type(isSubTypeOf(DirectBuffer.class).and(not(isInterface())))
        .transform((builder, typeDescription, classLoader, module) -> builder
            .visit(to(LongVerifier.class).on(nameContains("Long")))
            .visit(to(DoubleVerifier.class).on(nameContains("Double")))
            .visit(to(IntVerifier.class).on(intVerifierMatcher))
            .visit(to(FloatVerifier.class).on(nameContains("Float")))
            .visit(to(ShortVerifier.class).on(nameContains("Short")))
            .visit(to(CharVerifier.class).on(nameContains("Char"))))
        .installOn(instrumentation);
}
 
开发者ID:real-logic,项目名称:agrona,代码行数:25,代码来源:BufferAlignmentAgent.java

示例13: createStageClass

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
public <T> Class<? extends T> createStageClass( Class<T> stageClass ) {
    return new ByteBuddy()
        .subclass( stageClass, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING )
        .implement( StageInterceptorInternal.class )
        .defineField( INTERCEPTOR_FIELD_NAME, StepInterceptor.class )
        .method( named(SETTER_NAME) )
            .intercept(
                MethodDelegation.withDefaultConfiguration()
                    .withBinders( FieldProxy.Binder.install(
                            StepInterceptorGetterSetter.class ))
            .to(new StepInterceptorSetter() ))
        .method( not( named( SETTER_NAME )
                .or(ElementMatchers.isDeclaredBy(Object.class))))
        .intercept(
                MethodDelegation.withDefaultConfiguration()
                .withBinders(FieldProxy.Binder.install(
                        StepInterceptorGetterSetter.class ))
            .to( new ByteBuddyMethodInterceptor() ))
        .make()
        .load( getClassLoader( stageClass ),
            getClassLoadingStrategy( stageClass ) )
        .getLoaded();
}
 
开发者ID:TNG,项目名称:JGiven,代码行数:24,代码来源:ByteBuddyStageClassCreator.java

示例14: testRetrieveFromArray

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Test
public void testRetrieveFromArray() throws Exception {
    DynamicType.Unloaded<RetrieveFromArray> arr = new ByteBuddy().subclass(RetrieveFromArray.class)
                    .method(ElementMatchers.isDeclaredBy(RetrieveFromArray.class))
                    .intercept(new Implementation.Compound(new LoadReferenceParamImplementation(1),
                                    new RelativeRetrieveArrayImplementation(1),
                                    new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
                    .make();


    Class<?> dynamicType = arr.load(RetrieveFromArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                    .getLoaded();

    RetrieveFromArray test = (RetrieveFromArray) dynamicType.newInstance();
    int result = test.returnVal(0, 1);
    assertEquals(1, result);

}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:RelativeRetrieveTest.java

示例15: inPlaceSet

import net.bytebuddy.matcher.ElementMatchers; //导入依赖的package包/类
@Test
public void inPlaceSet() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val =
                    new ByteBuddy().subclass(SetValueInPlace.class)
                                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                                    MethodVariableAccess.INTEGER.loadOffset(2),
                                                    MethodVariableAccess.INTEGER.loadOffset(3),
                                                    ArrayStackManipulation.store(), MethodReturn.VOID)))
                                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 1);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:AssignImplementationTest.java


注:本文中的net.bytebuddy.matcher.ElementMatchers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。