Java Code Examples for net.bytebuddy.description.type.TypeDescription#getSuperClass()
The following examples show how to use
net.bytebuddy.description.type.TypeDescription#getSuperClass() .
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
Source File: MethodHierarchyMatcher.java From apm-agent-java with Apache License 2.0 | 6 votes |
private boolean declaresInHierarchy(MethodDescription targetMethod, TypeDescription type) { if (declaresMethod(named(targetMethod.getName()) .and(returns(targetMethod.getReturnType().asErasure())) .and(takesArguments(targetMethod.getParameters().asTypeList().asErasures())) .and(extraMethodMatcher)) .matches(type)) { return true; } for (TypeDescription interfaze : type.getInterfaces().asErasures()) { if (superClassMatcher.matches(interfaze)) { if (declaresInHierarchy(targetMethod, interfaze)) { return true; } } } final TypeDescription.Generic superClass = type.getSuperClass(); if (superClass != null && superClassMatcher.matches(superClass.asErasure())) { return declaresInHierarchy(targetMethod, superClass.asErasure()); } return false; }
Example 2
Source File: HierarchyMatch.java From skywalking with Apache License 2.0 | 6 votes |
@Override public boolean isMatch(TypeDescription typeDescription) { List<String> parentTypes = new ArrayList<String>(Arrays.asList(this.parentTypes)); TypeList.Generic implInterfaces = typeDescription.getInterfaces(); for (TypeDescription.Generic implInterface : implInterfaces) { matchHierarchyClass(implInterface, parentTypes); } if (typeDescription.getSuperClass() != null) { matchHierarchyClass(typeDescription.getSuperClass(), parentTypes); } return parentTypes.size() == 0; }
Example 3
Source File: HashCodeAndEqualsPlugin.java From byte-buddy with Apache License 2.0 | 6 votes |
@Override protected EqualsMethod equalsMethod(TypeDescription instrumentedType) { TypeDefinition typeDefinition = instrumentedType.getSuperClass(); while (typeDefinition != null && !typeDefinition.represents(Object.class)) { if (typeDefinition.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class)) { return EqualsMethod.requiringSuperClassEquality(); } MethodList<?> hashCode = typeDefinition.getDeclaredMethods().filter(isHashCode()); if (!hashCode.isEmpty()) { return hashCode.getOnly().isAbstract() ? EqualsMethod.isolated() : EqualsMethod.requiringSuperClassEquality(); } typeDefinition = typeDefinition.getSuperClass().asErasure(); } return EqualsMethod.isolated(); }
Example 4
Source File: TypeAttributeAppender.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void apply(ClassVisitor classVisitor, TypeDescription instrumentedType, AnnotationValueFilter annotationValueFilter) { AnnotationAppender annotationAppender = new AnnotationAppender.Default(new AnnotationAppender.Target.OnType(classVisitor)); annotationAppender = AnnotationAppender.ForTypeAnnotations.ofTypeVariable(annotationAppender, annotationValueFilter, AnnotationAppender.ForTypeAnnotations.VARIABLE_ON_TYPE, instrumentedType.getTypeVariables()); TypeDescription.Generic superClass = instrumentedType.getSuperClass(); if (superClass != null) { annotationAppender = superClass.accept(AnnotationAppender.ForTypeAnnotations.ofSuperClass(annotationAppender, annotationValueFilter)); } int interfaceIndex = 0; for (TypeDescription.Generic interfaceType : instrumentedType.getInterfaces()) { annotationAppender = interfaceType.accept(AnnotationAppender.ForTypeAnnotations.ofInterfaceType(annotationAppender, annotationValueFilter, interfaceIndex++)); } for (AnnotationDescription annotation : instrumentedType.getDeclaredAnnotations()) { annotationAppender = annotationAppender.append(annotation, annotationValueFilter); } }
Example 5
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public MethodRegistry inject(TypeDescription instrumentedType, MethodRegistry methodRegistry) { MethodList<?> candidates = instrumentedType.getSuperClass().getDeclaredMethods().filter(isConstructor().and(elementMatcher)); if (candidates.isEmpty()) { throw new IllegalStateException("No possible candidate for super constructor invocation in " + instrumentedType.getSuperClass()); } else if (!candidates.filter(takesArguments(0)).isEmpty()) { candidates = candidates.filter(takesArguments(0)); } else if (candidates.size() > 1) { throw new IllegalStateException("More than one possible super constructor for constructor delegation: " + candidates); } MethodCall methodCall = MethodCall.invoke(candidates.getOnly()); for (TypeDescription typeDescription : candidates.getOnly().getParameters().asTypeList().asErasures()) { methodCall = methodCall.with(typeDescription.getDefaultValue()); } return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor().and(takesArguments(0))), new MethodRegistry.Handler.ForImplementation(methodCall), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
Example 6
Source File: EitherInterfaceMatch.java From skywalking with Apache License 2.0 | 5 votes |
@Override public boolean isMatch(TypeDescription typeDescription) { MatchResult matchResult = new MatchResult(); for (TypeDescription.Generic generic : typeDescription.getInterfaces()) { matchHierarchyClazz(generic, matchResult); } if (typeDescription.getSuperClass() != null) { matchHierarchyClazz(typeDescription.getSuperClass(), matchResult); } return matchResult.result(); }
Example 7
Source File: HashCodeAndEqualsPlugin.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override protected EqualsMethod equalsMethod(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); return superClass != null && superClass.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class) ? EqualsMethod.requiringSuperClassEquality() : EqualsMethod.isolated(); }
Example 8
Source File: MethodCall.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public MethodInvoker make(TypeDescription instrumentedType) { if (instrumentedType.getSuperClass() == null) { throw new IllegalStateException("Cannot invoke super method for " + instrumentedType); } return new ForSuperMethodInvocation(instrumentedType); }
Example 9
Source File: HashCodeMethod.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public StackManipulation resolve(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); if (superClass == null) { throw new IllegalStateException(instrumentedType + " does not declare a super class"); } return new StackManipulation.Compound(MethodVariableAccess.loadThis(), MethodInvocation.invoke(HASH_CODE).special(superClass.asErasure())); }
Example 10
Source File: EqualsMethod.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override protected StackManipulation resolve(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); if (superClass == null) { throw new IllegalStateException(instrumentedType + " does not declare a super class"); } return new StackManipulation.Compound(MethodVariableAccess.loadThis(), MethodVariableAccess.REFERENCE.loadFrom(1), MethodInvocation.invoke(EQUALS).special(superClass.asErasure()), ConditionalReturn.onZeroInteger()); }
Example 11
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); MethodList<?> defaultConstructors = superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(takesArguments(0)).<MethodDescription>and(isVisibleTo(instrumentedType))); if (defaultConstructors.size() == 1) { return Collections.singletonList(new MethodDescription.Token(Opcodes.ACC_PUBLIC)); } else { throw new IllegalArgumentException(instrumentedType.getSuperClass() + " declares no constructor that is visible to " + instrumentedType); } }
Example 12
Source File: HashCodeAndEqualsPlugin.java From byte-buddy with Apache License 2.0 | 4 votes |
@Override protected HashCodeMethod hashCodeMethod(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); return superClass != null && superClass.asErasure().getDeclaredAnnotations().isAnnotationPresent(Enhance.class) ? HashCodeMethod.usingSuperClassOffset() : HashCodeMethod.usingDefaultOffset(); }
Example 13
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 2 votes |
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(isVisibleTo(instrumentedType)))).asTokenList(is(instrumentedType)); }
Example 14
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 2 votes |
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isPublic().and(isConstructor()))).asTokenList(is(instrumentedType)); }
Example 15
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 2 votes |
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(isVisibleTo(instrumentedType)))).asTokenList(is(instrumentedType)); }
Example 16
Source File: SubclassImplementationTarget.java From byte-buddy with Apache License 2.0 | 2 votes |
@Override protected TypeDefinition identify(TypeDescription typeDescription) { return typeDescription.getSuperClass(); }