org.aspectj.lang.Signature.getName()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(318)

本文整理了Java中org.aspectj.lang.Signature.getName()方法的一些代码示例,展示了Signature.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Signature.getName()方法的具体详情如下:
包路径:org.aspectj.lang.Signature
类名称:Signature
方法名:getName

Signature.getName介绍

[英]Returns the identifier part of this signature. For methods this will return the method name.
[中]返回此签名的标识符部分。对于方法,这将返回方法名称。

代码示例

代码示例来源:origin: hs-web/hsweb-framework

public static String getMethodBody(JoinPoint pjp) {
  StringBuilder methodName = new StringBuilder(pjp.getSignature().getName()).append("(");
  MethodSignature signature = (MethodSignature) pjp.getSignature();
  String[] names = signature.getParameterNames();
  Class[] args = signature.getParameterTypes();
  for (int i = 0, len = args.length; i < len; i++) {
    if (i != 0) {
      methodName.append(",");
    }
    methodName.append(args[i].getSimpleName()).append(" ").append(names[i]);
  }
  return methodName.append(")").toString();
}

代码示例来源:origin: spring-projects/spring-framework

@Before("execution(void *.additionalMethod(*))")
  public void log(JoinPoint jp) {
    System.out.println("Before " + jp.getSignature().getName());
  }
}

代码示例来源:origin: spring-projects/spring-framework

public int justJoinPoint(ProceedingJoinPoint pjp) throws Throwable {
  this.collaborator.justJoinPoint(pjp.getSignature().getName());
  return ((Integer) pjp.proceed()).intValue();
}

代码示例来源:origin: ZHENFENG13/My-Blog

@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
  // 接收到请求,记录请求内容
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  // 记录下请求内容
  LOGGER.info("URL : " + request.getRequestURL().toString() + ",IP : " + request.getRemoteAddr() + ",CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + ",ARGS : " + Arrays.toString(joinPoint.getArgs()));
}

代码示例来源:origin: ctripcorp/apollo

@Around("anyRepositoryMethod()")
 public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
  String name =
    joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature()
      .getName();
  Transaction catTransaction = Tracer.newTransaction("SQL", name);
  try {
   Object result = joinPoint.proceed();
   catTransaction.setStatus(Transaction.SUCCESS);
   return result;
  } catch (Throwable ex) {
   catTransaction.setStatus(ex);
   throw ex;
  } finally {
   catTransaction.complete();
  }
 }
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

@Around("execution (@org.springframework.scheduling.annotation.Scheduled  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
  if (this.skipPattern.matcher(pjp.getTarget().getClass().getName()).matches()) {
    return pjp.proceed();
  }
  String spanName = SpanNameUtil.toLowerHyphen(pjp.getSignature().getName());
  Span span = startOrContinueRenamedSpan(spanName);
  try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
    span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
    span.tag(METHOD_KEY, pjp.getSignature().getName());
    return pjp.proceed();
  }
  finally {
    span.finish();
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

String name(ProceedingJoinPoint pjp) {
  return this.spanNamer.name(getMethod(pjp, pjp.getTarget()),
      SpanNameUtil.toLowerHyphen(pjp.getSignature().getName()));
}

代码示例来源:origin: JakeWharton/hugo

private static void exitMethod(JoinPoint joinPoint, Object result, long lengthMillis) {
 if (!enabled) return;
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
  Trace.endSection();
 }
 Signature signature = joinPoint.getSignature();
 Class<?> cls = signature.getDeclaringType();
 String methodName = signature.getName();
 boolean hasReturnType = signature instanceof MethodSignature
   && ((MethodSignature) signature).getReturnType() != void.class;
 StringBuilder builder = new StringBuilder("\u21E0 ")
   .append(methodName)
   .append(" [")
   .append(lengthMillis)
   .append("ms]");
 if (hasReturnType) {
  builder.append(" = ");
  builder.append(Strings.toString(result));
 }
 Log.v(asTag(cls), builder.toString());
}

代码示例来源:origin: spring-projects/spring-framework

public void needsJoinPoint(JoinPoint tjp) {
  this.collaborator.needsJoinPoint(tjp.getSignature().getName());
}

代码示例来源:origin: spring-projects/spring-framework

public void needsJoinPointStaticPart(JoinPoint.StaticPart tjpsp) {
  this.collaborator.needsJoinPointStaticPart(tjpsp.getSignature().getName());
}

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

@Around("execution (@org.springframework.scheduling.annotation.Async  * *.*(..))")
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
  String spanName = name(pjp);
  Span span = this.tracer.currentSpan();
  if (span == null) {
    span = this.tracer.nextSpan();
  }
  span = span.name(spanName);
  try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
    span.tag(CLASS_KEY, pjp.getTarget().getClass().getSimpleName());
    span.tag(METHOD_KEY, pjp.getSignature().getName());
    return pjp.proceed();
  }
  finally {
    span.finish();
  }
}

代码示例来源:origin: changmingxie/tcc-transaction

private void enlistParticipant(ProceedingJoinPoint pjp) throws IllegalAccessException, InstantiationException {
  Method method = CompensableMethodUtils.getCompensableMethod(pjp);
  if (method == null) {
    throw new RuntimeException(String.format("join point not found method, point is : %s", pjp.getSignature().getName()));
  }
  Compensable compensable = method.getAnnotation(Compensable.class);
  String confirmMethodName = compensable.confirmMethod();
  String cancelMethodName = compensable.cancelMethod();
  Transaction transaction = transactionManager.getCurrentTransaction();
  TransactionXid xid = new TransactionXid(transaction.getXid().getGlobalTransactionId());
  if (FactoryBuilder.factoryOf(compensable.transactionContextEditor()).getInstance().get(pjp.getTarget(), method, pjp.getArgs()) == null) {
    FactoryBuilder.factoryOf(compensable.transactionContextEditor()).getInstance().set(new TransactionContext(xid, TransactionStatus.TRYING.getId()), pjp.getTarget(), ((MethodSignature) pjp.getSignature()).getMethod(), pjp.getArgs());
  }
  Class targetClass = ReflectionUtils.getDeclaringType(pjp.getTarget().getClass(), method.getName(), method.getParameterTypes());
  InvocationContext confirmInvocation = new InvocationContext(targetClass,
      confirmMethodName,
      method.getParameterTypes(), pjp.getArgs());
  InvocationContext cancelInvocation = new InvocationContext(targetClass,
      cancelMethodName,
      method.getParameterTypes(), pjp.getArgs());
  Participant participant =
      new Participant(
          xid,
          confirmInvocation,
          cancelInvocation,
          compensable.transactionContextEditor());
  transactionManager.enlistParticipant(participant);
}

代码示例来源:origin: weibocom/motan

@AfterReturning(value = "anyPublicOperation() && execCommandOperation()", returning = "result")
public void logAfter(JoinPoint joinPoint, boolean result) {
  Object[] args = joinPoint.getArgs();
  OperationRecord record = new OperationRecord();
  record.setOperator(getUsername());
  record.setType(joinPoint.getSignature().getName());
  record.setGroupName(args[0].toString());
  record.setCommand(JSON.toJSONString(args[1]));
  int status = result ? 1 : 0;
  record.setStatus((byte) status);
  if (recordMapper == null) {
    LoggerUtil.accessLog(JSON.toJSONString(record));
  } else {
    recordMapper.insertSelective(record);
  }
}

代码示例来源:origin: spring-projects/spring-security

MethodInvocationAdapter(JoinPoint jp) {
  this.jp = (ProceedingJoinPoint) jp;
  if (jp.getTarget() != null) {
    target = jp.getTarget();
  }
  else {
    // SEC-1295: target may be null if an ITD is in use
    target = jp.getSignature().getDeclaringType();
  }
  String targetMethodName = jp.getStaticPart().getSignature().getName();
  Class<?>[] types = ((CodeSignature) jp.getStaticPart().getSignature())
      .getParameterTypes();
  Class<?> declaringType = jp.getStaticPart().getSignature().getDeclaringType();
  method = findMethod(targetMethodName, declaringType, types);
  if (method == null) {
    throw new IllegalArgumentException(
        "Could not obtain target method from JoinPoint: '" + jp + "'");
  }
}

代码示例来源:origin: org.springframework.security/spring-security-core

MethodInvocationAdapter(JoinPoint jp) {
  this.jp = (ProceedingJoinPoint) jp;
  if (jp.getTarget() != null) {
    target = jp.getTarget();
  }
  else {
    // SEC-1295: target may be null if an ITD is in use
    target = jp.getSignature().getDeclaringType();
  }
  String targetMethodName = jp.getStaticPart().getSignature().getName();
  Class<?>[] types = ((CodeSignature) jp.getStaticPart().getSignature())
      .getParameterTypes();
  Class<?> declaringType = jp.getStaticPart().getSignature().getDeclaringType();
  method = findMethod(targetMethodName, declaringType, types);
  if (method == null) {
    throw new IllegalArgumentException(
        "Could not obtain target method from JoinPoint: '" + jp + "'");
  }
}

代码示例来源:origin: spring-projects/spring-framework

assertSame(target, raw);
assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());

代码示例来源:origin: nice-swa/my-site

@Before("webLog()")
public void doBefore(JoinPoint joinPoint){
  startTime.set(System.currentTimeMillis());
  //接收到请求,记录请求内容
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  HttpSession session = request.getSession();
  // 记录下请求内容
  LOGGER.info("URL : " + request.getRequestURL().toString());
  LOGGER.info("HTTP_METHOD : " + request.getMethod());
  LOGGER.info("IP : " + request.getRemoteAddr());
  LOGGER.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
  LOGGER.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
}

代码示例来源:origin: vector4wang/spring-boot-quick

@Before("logPointCut()")
  public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    loggger.info("请求地址 : " + request.getRequestURL().toString());
    loggger.info("HTTP METHOD : " + request.getMethod());
    loggger.info("IP : " + request.getRemoteAddr());
    loggger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
        + joinPoint.getSignature().getName());
    loggger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
//        loggger.info("参数 : " + joinPoint.getArgs());

  }

代码示例来源:origin: vector4wang/spring-boot-quick

@Before("logPointCut()")
  public void doBefore(JoinPoint joinPoint) throws Throwable {
    // 接收到请求,记录请求内容
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();

    // 记录下请求内容
    loggger.info("请求地址 : " + request.getRequestURL().toString());
    loggger.info("HTTP METHOD : " + request.getMethod());
    loggger.info("IP : " + request.getRemoteAddr());
    loggger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
        + joinPoint.getSignature().getName());
    loggger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
//        loggger.info("参数 : " + joinPoint.getArgs());

  }

代码示例来源:origin: zstackio/zstack

static void callConsumer(JoinPoint jp) {
    String name = String.format("%s.%s", jp.getSignature().getDeclaringType().getName(), jp.getSignature().getName());
    Consumer<JoinPoint> consumer = consumers.get(name);
    if (consumer != null) {
      consumer.accept(jp);
    }
  }
}

相关文章