/** * {@inheritDoc} */ public boolean isAccessibleTo(TypeDescription typeDescription) { return isPrimitive() || (isArray() ? getComponentType().isVisibleTo(typeDescription) : isPublic() || isSamePackage(typeDescription)/* || equals(typeDescription.asErasure()) */); }
@Override protected FieldDescription resolve(TypeDescription instrumentedType) { if (!fieldType.asErasure().isVisibleTo(instrumentedType)) { throw new IllegalStateException(fieldType + " is not visible to " + instrumentedType); } else { return instrumentedType.getDeclaredFields() .filter(named(fieldName).and(fieldType(fieldType.asErasure()))) .getOnly(); } } }
/** * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { return isPrimitive() || (isArray() ? getComponentType().isVisibleTo(typeDescription) : isPublic() || isProtected() || isSamePackage(typeDescription)/* || equals(typeDescription.asErasure()) */); }
/** * {@inheritDoc} */ public Compiled compile(TypeDescription instrumentedType) { FieldDescription fieldDescription = resolve(instrumentedType); if (!fieldDescription.getType().asErasure().isVisibleTo(instrumentedType)) { throw new IllegalStateException(fieldDescription + " is not visible to " + instrumentedType); } else { MethodList<?> candidates = methodGraphCompiler.compile(fieldDescription.getType(), instrumentedType) .listNodes() .asMethodList() .filter(matcher); List<MethodDelegationBinder.Record> records = new ArrayList<MethodDelegationBinder.Record>(candidates.size()); MethodDelegationBinder methodDelegationBinder = TargetMethodAnnotationDrivenBinder.of(parameterBinders); for (MethodDescription candidate : candidates) { records.add(methodDelegationBinder.compile(candidate)); } return new Compiled.ForField(fieldDescription, records); } }
} else if (!superClass.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on super class " + superClass + " for " + this); } else if (!superClass.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible super type " + superClass + " for " + this); } else if (!interfaceErasures.add(interfaceType.asErasure())) { throw new IllegalStateException("Already implemented interface " + interfaceType + " for " + this); } else if (!interfaceType.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible interface type " + interfaceType + " for " + this); } else if (!fieldType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on " + fieldType + " for " + this); } else if (!fieldDescription.isSynthetic() && !fieldType.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible field type " + fieldDescription.getType() + " for " + fieldDescription); } else if (!returnType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on return type " + returnType + " for " + methodDescription); } else if (!methodDescription.isSynthetic() && !methodDescription.getReturnType().asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible return type " + methodDescription.getReturnType() + " for " + methodDescription); } else if (!parameterType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on parameter " + parameterDescription + " for " + methodDescription); } else if (!methodDescription.isSynthetic() && !parameterType.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible parameter type of " + parameterDescription + " for " + methodDescription); } else if (!exceptionType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) { throw new IllegalStateException("Illegal type annotations on " + exceptionType + " for " + methodDescription); } else if (!methodDescription.isSynthetic() && !exceptionType.asErasure().isVisibleTo(this)) { throw new IllegalStateException("Invisible exception type " + exceptionType + " for " + methodDescription);
/** * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { return getDeclaringType().asErasure().isVisibleTo(typeDescription) && (isPublic() || typeDescription.equals(getDeclaringType().asErasure()) || (isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription)) || (!isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure()))); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { if (implementationContext.getClassFileVersion().isAtLeast(ClassFileVersion.JAVA_V5) && typeDescription.isVisibleTo(implementationContext.getInstrumentedType())) { methodVisitor.visitLdcInsn(Type.getType(typeDescription.getDescriptor())); } else { methodVisitor.visitLdcInsn(typeDescription.getName()); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false); } return SIZE; } }
/** * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription)) && (isPublic() || typeDescription.equals(getDeclaringType().asErasure()) || isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription) || !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())); }
/** * {@inheritDoc} */ public boolean isAccessibleTo(TypeDescription typeDescription) { return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription)) && (isPublic() || typeDescription.equals(getDeclaringType().asErasure()) || !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())) || isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure()); }
/** * {@inheritDoc} */ public Compiled compile(TypeDescription instrumentedType) { MethodList<?> targets = new MethodList.Explicit<MethodDescription>(CompoundList.<MethodDescription>of( instrumentedType.getDeclaredMethods().filter(isStatic().or(isPrivate())), methodGraphCompiler.compile(instrumentedType).listNodes().asMethodList()) ).filter(named(name).and(takesArguments(0)).and(not(returns(isPrimitive().or(isArray()))))); if (targets.size() != 1) { throw new IllegalStateException(instrumentedType + " does not define method without arguments with name " + name + ": " + targets); } else if (!targets.getOnly().getReturnType().asErasure().isVisibleTo(instrumentedType)) { throw new IllegalStateException(targets.getOnly() + " is not visible to " + instrumentedType); } else { MethodList<?> candidates = methodGraphCompiler.compile(targets.getOnly().getReturnType(), instrumentedType) .listNodes() .asMethodList() .filter(matcher); List<MethodDelegationBinder.Record> records = new ArrayList<MethodDelegationBinder.Record>(candidates.size()); MethodDelegationBinder methodDelegationBinder = TargetMethodAnnotationDrivenBinder.of(parameterBinders); for (MethodDescription candidate : candidates) { records.add(methodDelegationBinder.compile(candidate)); } return new Compiled.ForMethodReturn(targets.get(0), records); } }