本文整理汇总了Java中net.bytebuddy.description.NamedElement类的典型用法代码示例。如果您正苦于以下问题:Java NamedElement类的具体用法?Java NamedElement怎么用?Java NamedElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamedElement类属于net.bytebuddy.description包,在下文中一共展示了NamedElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAgentBuilder
import net.bytebuddy.description.NamedElement; //导入依赖的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;
}
示例2:
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
<T, B extends AnnotatedCodeElement & NamedElement.WithRuntimeName> ControllerInjectValueData<T> createValue
(int index, TypeDescription classType, TypeDescription.ForLoadedType.Generic type, B member, String name,
Map<Class<? extends Annotation>, ? extends Annotation> parentRawScopeAnnotations,
Map<Class<? extends Annotation>, ? extends Annotation> parentRawQualifierAnnotations)
{
Map<Class<? extends Annotation>, ? extends Annotation> scopeAnnotations;
{
Map<Class<? extends Annotation>, ? extends Annotation> memberRawScopeAnnotations = this.extractRawScopeAnnotations(member);
Map<Class<? extends Annotation>, Annotation> rawScopeAnnotations = new HashMap<>(parentRawScopeAnnotations);
rawScopeAnnotations.putAll(memberRawScopeAnnotations);
scopeAnnotations = this.transformAll(classType, name, member, rawScopeAnnotations);
}
Map<Class<? extends Annotation>, ? extends Annotation> qualifierAnnotations;
{
Map<Class<? extends Annotation>, ? extends Annotation> memberRawQualifierAnnotations = this.extractRawQualifierAnnotations(member);
Map<Class<? extends Annotation>, Annotation> rawQualifierAnnotations = new HashMap<>(parentRawQualifierAnnotations);
rawQualifierAnnotations.putAll(memberRawQualifierAnnotations);
qualifierAnnotations = this.transformAll(classType, name, member, rawQualifierAnnotations);
}
return new ControllerInjectValueData<>(index, name, type, scopeAnnotations, qualifierAnnotations);
}
示例3: buildMatch
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
public ElementMatcher<? super TypeDescription> buildMatch() {
ElementMatcher.Junction judge = new AbstractJunction<NamedElement>() {
@Override
public boolean matches(NamedElement target) {
return nameMatchDefine.containsKey(target.getActualName());
}
};
judge = judge.and(not(isInterface()));
for (AbstractClassEnhancePluginDefine define : signatureMatchDefine) {
ClassMatch match = define.enhanceClass();
if (match instanceof IndirectMatch) {
judge = judge.or(((IndirectMatch)match).buildJunction());
}
}
return new ProtectiveShieldMatcher(judge);
}
示例4: locate
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Override
public Resolution locate(String typeName) throws IOException {
int packageIndex = typeName.lastIndexOf('.');
ClassFileLocator classFileLocator = classFileLocators.get(packageIndex == -1
? NamedElement.EMPTY_NAME
: typeName.substring(0, packageIndex));
return classFileLocator == null
? new Resolution.Illegal(typeName)
: classFileLocator.locate(typeName);
}
示例5: testIsNamed
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test
public void testIsNamed() throws Exception {
NamedElement.WithOptionalName namedElement = mock(NamedElement.WithOptionalName.class);
assertThat(ElementMatchers.isNamed().matches(namedElement), is(false));
when(namedElement.isNamed()).thenReturn(true);
assertThat(ElementMatchers.isNamed().matches(namedElement), is(true));
}
示例6: testMatch
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test
public void testMatch() throws Exception {
when(nameMatcher.matches(FOO)).thenReturn(true);
assertThat(new NameMatcher<NamedElement>(nameMatcher).matches(namedElement), is(true));
verify(nameMatcher).matches(FOO);
verifyNoMoreInteractions(nameMatcher);
}
示例7: testNoMatch
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test
public void testNoMatch() throws Exception {
when(nameMatcher.matches(FOO)).thenReturn(false);
assertThat(new NameMatcher<NamedElement>(nameMatcher).matches(namedElement), is(false));
verify(nameMatcher).matches(FOO);
verifyNoMoreInteractions(nameMatcher);
}
示例8: setUp
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
when(foo.locate(FOO + "." + BAR)).thenReturn(fooResulution);
when(bar.locate(BAR)).thenReturn(barResolution);
Map<String, ClassFileLocator> map = new HashMap<String, ClassFileLocator>();
map.put(FOO, foo);
map.put(NamedElement.EMPTY_NAME, bar);
classFileLocator = new ClassFileLocator.PackageDiscriminating(map);
}
示例9: inPlugins
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
public <T extends NamedElement> ElementMatcher.Junction<T> inPlugins() {
return new NameMatcher(new PluginMathers(pluginManager));
}
示例10: geTypeMatchers
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
private static Junction<NamedElement> geTypeMatchers() {
// TODO: try that instead: type(any(), not(isBootstrapClassLoader()))
return not(nameStartsWith("java").or(nameStartsWith("sun")).or(nameStartsWith("javax"))
.or(nameStartsWith("com.sun")));
}
示例11: testMatch
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test
public void testMatch() throws Exception {
when(namedElement.isNamed()).thenReturn(true);
assertThat(new IsNamedMatcher<NamedElement.WithOptionalName>().matches(namedElement), is(true));
}
示例12: testPositiveToNegative
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test
public void testPositiveToNegative() throws Exception {
assertThat(new IsNamedMatcher<NamedElement.WithOptionalName>().matches(namedElement), is(false));
}
示例13: testTypeEmptyEndName
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testTypeEmptyEndName() throws Exception {
makePlainInstrumentedType().withName(NamedElement.EMPTY_NAME).validated();
}
示例14: isVariable
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
/**
* Matches a type variable with the given name.
*
* @param matcher A matcher for the type variable's name.
* @param <T> The type of the matched object.
* @return A matcher that matches type variables with the given name.
*/
public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(ElementMatcher<? super NamedElement> matcher) {
return new TypeSortMatcher<T>(anyOf(TypeDefinition.Sort.VARIABLE, TypeDefinition.Sort.VARIABLE_SYMBOLIC)).and(matcher);
}
示例15: named
import net.bytebuddy.description.NamedElement; //导入依赖的package包/类
/**
* Matches a {@link NamedElement} for its exact name.
*
* @param name The expected name.
* @param <T> The type of the matched object.
* @return An element matcher for a named element's exact name.
*/
public static <T extends NamedElement> ElementMatcher.Junction<T> named(String name) {
return new NameMatcher<T>(new StringMatcher(name, StringMatcher.Mode.EQUALS_FULLY));
}