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


Java Visibility类代码示例

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


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

示例1: createLazyClass

import net.bytebuddy.description.modifier.Visibility; //导入依赖的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: generateQueryResultClass

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
/**
 * Generates enhanced subclass of query result class. The enhanced subclass
 * does have a constructor for initializing all mapped fields.
 * 
 * @return the generated subclass
 */
private Class<?> generateQueryResultClass() {
	LOGGER.debug("Mapped fields of result: {}", mappedFields);
	Class<?>[] fieldTypes = mappedFields.stream().map(f -> f.getType()).collect(Collectors.toList())
			.toArray(new Class<?>[] {});

	Unloaded<T> unloadedSubClass;
	try {
		unloadedSubClass = new ByteBuddy().with(new NamingStrategy.SuffixingRandom("Query")).subclass(resultClazz)
				.defineConstructor(MethodArguments.VARARGS, Visibility.PUBLIC).withParameters(fieldTypes)
				.intercept(MethodCall.invoke(this.resultClazz.getDeclaredConstructor())
						.andThen(MethodDelegation.to(new ConstructorInitializer(mappedFields))))
				.make();
	} catch (NoSuchMethodException | SecurityException e) {
		throw new RuntimeException("Generation of subclass for " + resultClazz.getName() + " failed", e);
	}

	return unloadedSubClass
			.load(Thread.currentThread().getContextClassLoader(), ClassLoadingStrategy.Default.INJECTION)
			.getLoaded();
}
 
开发者ID:bbvch,项目名称:JpqlQueryBuilder,代码行数:27,代码来源:QueryResultEnhancer.java

示例3: testGenericReturnTypeClassMultipleEvolution

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testGenericReturnTypeClassMultipleEvolution() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericReturnClassBase.Intermediate.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription.SignatureToken token = typeDescription.getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asSignatureToken();
    MethodGraph.Node node = methodGraph.locate(token);
    MethodDescription.SignatureToken firstBridgeToken = typeDescription.getSuperClass().getDeclaredMethods()
            .filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asDefined().asSignatureToken();
    MethodDescription.SignatureToken secondBridgeToken = typeDescription.getSuperClass().getSuperClass().getDeclaredMethods()
            .filter(isMethod()).getOnly().asDefined().asSignatureToken();
    assertThat(node, is(methodGraph.locate(firstBridgeToken)));
    assertThat(node, is(methodGraph.locate(secondBridgeToken)));
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(3));
    assertThat(node.getMethodTypes().contains(token.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(firstBridgeToken.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(secondBridgeToken.asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodGraphCompilerDefaultTest.java

示例4: make

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Override
public DynamicType make(String auxiliaryTypeName,
                        ClassFileVersion classFileVersion,
                        MethodAccessorFactory methodAccessorFactory) {
    MethodDescription accessorMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    LinkedHashMap<String, TypeDescription> parameterFields = extractFields(accessorMethod);
    DynamicType.Builder<?> builder = new ByteBuddy(classFileVersion)
            .with(PrecomputedMethodGraph.INSTANCE)
            .subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS)
            .name(auxiliaryTypeName)
            .modifiers(DEFAULT_TYPE_MODIFIER)
            .implement(Runnable.class, Callable.class).intercept(new MethodCall(accessorMethod, assigner))
            .implement(serializableProxy ? new Class<?>[]{Serializable.class} : new Class<?>[0])
            .defineConstructor().withParameters(parameterFields.values())
            .intercept(ConstructorCall.INSTANCE);
    for (Map.Entry<String, TypeDescription> field : parameterFields.entrySet()) {
        builder = builder.defineField(field.getKey(), field.getValue(), Visibility.PRIVATE);
    }
    return builder.make();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodCallProxy.java

示例5: testAnnotationDefinition

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testAnnotationDefinition() throws Exception {
    Class<? extends Annotation> type = new ByteBuddy()
            .makeAnnotation()
            .defineMethod(FOO, int.class, Visibility.PUBLIC)
            .withoutCode()
            .defineMethod(BAR, String.class, Visibility.PUBLIC)
            .defaultValue(FOO, String.class)
            .defineMethod(QUX, SimpleEnum.class, Visibility.PUBLIC)
            .defaultValue(SimpleEnum.FIRST, SimpleEnum.class)
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredMethods().length, is(3));
    assertThat(type.getDeclaredMethod(FOO), notNullValue(Method.class));
    assertThat(type.getDeclaredMethod(BAR).getDefaultValue(), is((Object) FOO));
    assertThat(type.getDeclaredMethod(QUX).getDefaultValue(), is((Object) SimpleEnum.FIRST));
    assertThat(type.getDeclaredConstructors().length, is(0));
    assertThat(Annotation.class.isAssignableFrom(type), is(true));
    assertThat(type, not(CoreMatchers.<Class<?>>is(Annotation.class)));
    assertThat(type.isInterface(), is(true));
    assertThat(type.isAnnotation(), is(true));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:SubclassDynamicTypeBuilderTest.java

示例6: testGenericNonOverriddenInterfaceExtension

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testGenericNonOverriddenInterfaceExtension() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericNonOverriddenInterfaceBase.InnerClass.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription methodDescription = typeDescription.getInterfaces().getOnly().getDeclaredMethods().filter(isMethod()).getOnly();
    MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getRepresentative(), is(methodDescription));
    assertThat(node.getMethodTypes().size(), is(2));
    assertThat(node.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(methodDescription.asDefined().asTypeToken()), is(true));
    assertThat(node, is(methodGraph.getInterfaceGraph(new TypeDescription.ForLoadedType(GenericNonOverriddenInterfaceBase.class))
            .locate(methodDescription.asSignatureToken())));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodGraphCompilerDefaultTest.java

示例7: extendBy

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Override
public Entry<U> extendBy(MethodDescription methodDescription, Harmonizer<U> harmonizer) {
    Harmonized<U> key = this.key.extend(methodDescription.asDefined(), harmonizer);
    LinkedHashSet<MethodDescription> methodDescriptions = new LinkedHashSet<MethodDescription>(this.methodDescriptions.size() + 1);
    TypeDescription declaringType = methodDescription.getDeclaringType().asErasure();
    boolean bridge = methodDescription.isBridge();
    Visibility visibility = this.visibility;
    for (MethodDescription extendedMethod : this.methodDescriptions) {
        if (extendedMethod.getDeclaringType().asErasure().equals(declaringType)) {
            if (extendedMethod.isBridge() ^ bridge) {
                methodDescriptions.add(bridge ? extendedMethod : methodDescription);
            } else {
                methodDescriptions.add(methodDescription);
                methodDescriptions.add(extendedMethod);
            }
        }
        visibility = visibility.expandTo(extendedMethod.getVisibility());
    }
    if (methodDescriptions.isEmpty()) {
        return new Resolved<U>(key, methodDescription, visibility, bridge);
    } else if (methodDescriptions.size() == 1) {
        return new Resolved<U>(key, methodDescriptions.iterator().next(), visibility, Resolved.NOT_MADE_VISIBLE);
    } else {
        return new Ambiguous<U>(key, methodDescriptions, visibility);
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:27,代码来源:MethodGraph.java

示例8: testGenericInterfaceSingleEvolution

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testGenericInterfaceSingleEvolution() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericInterfaceBase.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription.SignatureToken token = typeDescription.getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asSignatureToken();
    MethodGraph.Node node = methodGraph.locate(token);
    MethodDescription.SignatureToken bridgeToken = typeDescription.getInterfaces().getOnly()
            .getDeclaredMethods().filter(isMethod()).getOnly().asDefined().asSignatureToken();
    assertThat(node, is(methodGraph.locate(bridgeToken)));
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(2));
    assertThat(node.getMethodTypes().contains(token.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(bridgeToken.asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodGraphCompilerDefaultTest.java

示例9: testGenericWithReturnTypeInterfaceMultipleEvolution

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testGenericWithReturnTypeInterfaceMultipleEvolution() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericWithReturnTypeInterfaceBase.Intermediate.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription.SignatureToken token = typeDescription.getDeclaredMethods().filter(ElementMatchers.not(isBridge())).getOnly().asSignatureToken();
    MethodGraph.Node node = methodGraph.locate(token);
    MethodDescription.SignatureToken firstBridgeToken = typeDescription.getInterfaces().getOnly()
            .getDeclaredMethods().filter(ElementMatchers.not(isBridge())).getOnly().asDefined().asSignatureToken();
    MethodDescription.SignatureToken secondBridgeToken = typeDescription.getInterfaces().getOnly().getInterfaces().getOnly()
            .getDeclaredMethods().getOnly().asDefined().asSignatureToken();
    assertThat(node, is(methodGraph.locate(firstBridgeToken)));
    assertThat(node, is(methodGraph.locate(secondBridgeToken)));
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(3));
    assertThat(node.getMethodTypes().contains(token.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(firstBridgeToken.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(secondBridgeToken.asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodGraphCompilerDefaultTest.java

示例10: testAdviceProcessesDeadCode

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testAdviceProcessesDeadCode() throws Exception {
    Class<?> type = new ByteBuddy(classFileVersion)
            .subclass(Object.class)
            .defineMethod(FOO, String.class, Visibility.PUBLIC)
            .intercept(new DeadStringAppender())
            .make()
            .load(null, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> redefined = new ByteBuddy()
            .redefine(type)
            .visit(Advice.to(ExitAdvice.class).on(named(FOO)))
            .make()
            .load(null, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(redefined.getDeclaredMethod(FOO).invoke(redefined.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:AdviceDeadCodeTest.java

示例11: testInconsistentStackSize

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testInconsistentStackSize() throws Exception {
    Class<?> atypical = new ByteBuddy()
            .subclass(Object.class)
            .defineMethod(FOO, type, Visibility.PUBLIC)
            .intercept(new InconsistentSizeAppender())
            .make()
            .load(null, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> adviced = new ByteBuddy()
            .redefine(atypical)
            .visit(Advice.withCustomMapping().bind(Value.class, replaced).to(ExitAdvice.class).on(named(FOO)))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(adviced.getDeclaredMethod(FOO).invoke(adviced.getDeclaredConstructor().newInstance()), is((Object) replaced));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:AdviceInconsistentStackSizeTest.java

示例12: testVisibilityBridgeForDefaultMethod

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testVisibilityBridgeForDefaultMethod() throws Exception {
    Class<?> defaultInterface = new ByteBuddy()
            .makeInterface()
            .merge(Visibility.PACKAGE_PRIVATE)
            .defineMethod(FOO, String.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(BAR))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER)
            .getLoaded();
    Class<?> type = new ByteBuddy()
            .subclass(defaultInterface)
            .modifiers(Visibility.PUBLIC)
            .make()
            .load(defaultInterface.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(1));
    Method foo = type.getDeclaredMethod(FOO);
    assertThat(foo.isBridge(), is(true));
    assertThat(foo.invoke(type.getDeclaredConstructor().newInstance()), is((Object) (BAR)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:SubclassDynamicTypeBuilderTest.java

示例13: testFrameTooShort

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
@JavaVersionRule.Enforce(7)
public void testFrameTooShort() throws Exception {
    Class<?> type = new ByteBuddy()
            .subclass(Object.class)
            .defineMethod(FOO, String.class, Visibility.PUBLIC)
            .intercept(new TooShortMethod())
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) BAR));
    new ByteBuddy()
            .redefine(type)
            .visit(Advice.to(TrivialAdvice.class).on(named(FOO)))
            .make();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:AdviceInconsistentFrameTest.java

示例14: testFrameInconsistentThisParameter

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
@JavaVersionRule.Enforce(7)
public void testFrameInconsistentThisParameter() throws Exception {
    Class<?> type = new ByteBuddy()
            .subclass(Object.class)
            .defineMethod(FOO, String.class, Visibility.PUBLIC)
            .intercept(new InconsistentThisReferenceMethod())
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) BAR));
    new ByteBuddy()
            .redefine(type)
            .visit(Advice.to(TrivialAdvice.class).on(named(FOO)))
            .make();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:AdviceInconsistentFrameTest.java

示例15: testInterfaceDefinition

import net.bytebuddy.description.modifier.Visibility; //导入依赖的package包/类
@Test
public void testInterfaceDefinition() throws Exception {
    Class<? extends SimpleInterface> type = new ByteBuddy()
            .makeInterface(SimpleInterface.class)
            .defineMethod(FOO, void.class, Visibility.PUBLIC).withParameters(Void.class)
            .withoutCode()
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(type.getDeclaredMethods().length, is(1));
    assertThat(type.getDeclaredMethod(FOO, Void.class), notNullValue(Method.class));
    assertThat(type.getDeclaredConstructors().length, is(0));
    assertThat(SimpleInterface.class.isAssignableFrom(type), is(true));
    assertThat(type, not(CoreMatchers.<Class<?>>is(SimpleInterface.class)));
    assertThat(type.isInterface(), is(true));
    assertThat(type.isAnnotation(), is(false));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:SubclassDynamicTypeBuilderTest.java


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