com.sun.tools.javac.code.Types.findDescriptorType()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(177)

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

Types.findDescriptorType介绍

[英]Find the type of the method descriptor associated to this class symbol - if the symbol 'origin' is not a functional interface, an exception is thrown.
[中]查找与该类符号关联的方法描述符的类型-如果符号“origin”不是函数接口,则引发异常。

代码示例

代码示例来源:origin: google/error-prone

/**
 * Checks that the return value of a functional interface is void. Note, we do not use
 * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
 * void-returning functions silently ignore return values of any type.
 */
private static boolean functionalInterfaceReturnsExactlyVoid(
  Type interfaceType, VisitorState state) {
 return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind()
   == TypeKind.VOID;
}

代码示例来源:origin: google/error-prone

@Override
public Type visitLambdaExpression(LambdaExpressionTree lambdaExpressionTree, Void unused) {
 return state.getTypes().findDescriptorType(getType(lambdaExpressionTree)).getReturnType();
}

代码示例来源:origin: google/error-prone

@Override
public Type visitMemberReference(MemberReferenceTree node, Void aVoid) {
 return state.getTypes().findDescriptorType(getType(node)).getReturnType();
}

代码示例来源:origin: uber/AutoDispose

/**
 * Checks that the return value of a functional interface is void. Note, we do not use
 * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
 * void-returning functions silently ignore return values of any type.
 */
private static boolean functionalInterfaceReturnsExactlyVoid(Type interfaceType,
  VisitorState state) {
 return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind()
   == TypeKind.VOID;
}

代码示例来源:origin: google/error-prone

private static String functionalInterfaceSignature(VisitorState state, Type type) {
 Types types = state.getTypes();
 if (!maybeFunctionalInterface(type, types, state)) {
  return Signatures.descriptor(type, types);
 }
 Type descriptorType = types.findDescriptorType(type);
 List<Type> fiparams = descriptorType.getParameterTypes();
 // Implicitly typed block-statement-bodied lambdas are potentially compatible with
 // void-returning and value-returning functional interface types, so we don't consider return
 // types in general. The except is nullary functional interfaces, since the lambda parameters
 // will never be implicitly typed.
 String result =
   fiparams.isEmpty() ? Signatures.descriptor(descriptorType.getReturnType(), types) : "_";
 return String.format(
   "(%s)->%s",
   fiparams.stream().map(t -> Signatures.descriptor(t, types)).collect(joining(",")), result);
}

代码示例来源:origin: google/error-prone

/**
 * Checks that the return value of a functional interface is void. Note, we do not use
 * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
 * void-returning functions silently ignore return values of any type.
 */
private static boolean functionalInterfaceReturnsObject(Type interfaceType, VisitorState state) {
 Type objectType = state.getTypeFromString("java.lang.Object");
 return ASTHelpers.isSubtype(
   objectType,
   ASTHelpers.getUpperBound(
     state.getTypes().findDescriptorType(interfaceType).getReturnType(), state.getTypes()),
   state);
}

代码示例来源:origin: uber/AutoDispose

/**
 * Extracts the {@link Type} of the return value for {@link MethodInvocationTree} or {@link
 * MemberReferenceTree}, then checks it against {@link #capturedTypeAllowed(Type, VisitorState)}.
 */
private boolean isValidReturnValueType(ExpressionTree tree, VisitorState state) {
 Type returnType = null;
 if (tree instanceof MethodInvocationTree) {
  returnType = getReturnType(((JCMethodInvocation) tree).getMethodSelect());
 } else if (tree instanceof MemberReferenceTree) {
  // Get the return type of the target referenced interface
  returnType =
    state.getTypes().findDescriptorType(((JCMemberReference) tree).type).getReturnType();
 }
 if (returnType != null) {
  return capturedTypeAllowed(returnType, state);
 }
 return true;
}

代码示例来源:origin: google/error-prone

private static Type getMethodOrLambdaReturnType(VisitorState state) {
 for (Tree tree : state.getPath()) {
  switch (tree.getKind()) {
   case LAMBDA_EXPRESSION:
    return state.getTypes().findDescriptorType(ASTHelpers.getType(tree)).getReturnType();
   case METHOD:
    return ASTHelpers.getType(tree).getReturnType();
   case CLASS:
    return null;
   default: // fall out
  }
 }
 return null;
}

代码示例来源:origin: google/error-prone

@Override
public Description matchReturn(ReturnTree tree, VisitorState state) {
 if (tree.getExpression() == null) {
  return NO_MATCH;
 }
 Type type = null;
 outer:
 for (Tree parent : state.getPath()) {
  switch (parent.getKind()) {
   case METHOD:
    type = ASTHelpers.getType(((MethodTree) parent).getReturnType());
    break outer;
   case LAMBDA_EXPRESSION:
    type = state.getTypes().findDescriptorType(ASTHelpers.getType(parent)).getReturnType();
    break outer;
   default: // fall out
  }
 }
 if (type == null) {
  return NO_MATCH;
 }
 return check(type, tree.getExpression());
}

代码示例来源:origin: google/error-prone

static Type getTargetType(VisitorState state) {
 Tree parent = state.getPath().getParentPath().getLeaf();
 Type type;
 if (parent instanceof VariableTree || parent instanceof AssignmentTree) {
  type = ASTHelpers.getType(parent);
 } else if (parent instanceof ReturnTree || parent instanceof LambdaExpressionTree) {
  type = getMethodOrLambdaReturnType(state);
 } else if (parent instanceof MethodInvocationTree) {
  MethodInvocationTree tree = (MethodInvocationTree) parent;
  int idx = tree.getArguments().indexOf(state.getPath().getLeaf());
  if (idx == -1) {
   return null;
  }
  Type methodType = ASTHelpers.getType(tree.getMethodSelect());
  if (idx >= methodType.getParameterTypes().size()) {
   return null;
  }
  return methodType.getParameterTypes().get(idx);
 } else {
  return null;
 }
 Tree tree = state.getPath().getLeaf();
 if (tree instanceof MemberReferenceTree) {
  type = state.getTypes().findDescriptorType(ASTHelpers.getType(tree)).getReturnType();
 }
 return type;
}

代码示例来源:origin: konsoletyper/teavm-javac

public boolean isFunctionalInterface(Type site) {
  try {
    findDescriptorType(site);
    return true;
  } catch (FunctionDescriptorLookupError ex) {
    return false;
  }
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public boolean isFunctionalInterface(Type site) {
  try {
    findDescriptorType(site);
    return true;
  } catch (FunctionDescriptorLookupError ex) {
    return false;
  }
}

代码示例来源:origin: konsoletyper/teavm-javac

public Type getDescriptorType(Types types) {
    return targets.nonEmpty() ? types.findDescriptorType(targets.head) : types.createErrorType(null);
  }
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public Type getDescriptorType(Types types) {
    return targets.nonEmpty() ? types.findDescriptorType(targets.head) : types.createErrorType(null);
  }
}

代码示例来源:origin: com.google.errorprone/error_prone_core

/**
 * Checks that the return value of a functional interface is void. Note, we do not use
 * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
 * void-returning functions silently ignore return values of any type.
 */
private static boolean functionalInterfaceReturnsExactlyVoid(
  Type interfaceType, VisitorState state) {
 return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind()
   == TypeKind.VOID;
}

代码示例来源:origin: com.google.errorprone/error_prone_check_api

@Override
public Type visitLambdaExpression(LambdaExpressionTree lambdaExpressionTree, Void unused) {
 return state.getTypes().findDescriptorType(getType(lambdaExpressionTree)).getReturnType();
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

@Override
public void visitLambda(JCLambda tree) {
  if (inferenceContext.inferenceVars().contains(pt)) {
    stuckVars.add(pt);
  }
  if (!types.isFunctionalInterface(pt)) {
    return;
  }
  Type descType = types.findDescriptorType(pt);
  List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
  if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT &&
      freeArgVars.nonEmpty()) {
    stuckVars.addAll(freeArgVars);
    depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
  }
  scanLambdaBody(tree, descType.getReturnType());
}

代码示例来源:origin: konsoletyper/teavm-javac

@Override
public void visitLambda(JCLambda tree) {
  if (inferenceContext.inferenceVars().contains(pt)) {
    stuckVars.add(pt);
  }
  if (!types.isFunctionalInterface(pt)) {
    return;
  }
  Type descType = types.findDescriptorType(pt);
  List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
  if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT &&
      freeArgVars.nonEmpty()) {
    stuckVars.addAll(freeArgVars);
    depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
  }
  scanLambdaBody(tree, descType.getReturnType());
}

代码示例来源:origin: com.google.errorprone/error_prone_core

/**
 * Checks that the return value of a functional interface is void. Note, we do not use
 * ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
 * void-returning functions silently ignore return values of any type.
 */
private static boolean functionalInterfaceReturnsObject(Type interfaceType, VisitorState state) {
 Type objectType = state.getTypeFromString("java.lang.Object");
 return ASTHelpers.isSubtype(
   objectType,
   ASTHelpers.getUpperBound(
     state.getTypes().findDescriptorType(interfaceType).getReturnType(), state.getTypes()),
   state);
}

代码示例来源:origin: com.google.errorprone/error_prone_core

private static Type getMethodOrLambdaReturnType(VisitorState state) {
 for (Tree tree : state.getPath()) {
  switch (tree.getKind()) {
   case LAMBDA_EXPRESSION:
    return state.getTypes().findDescriptorType(ASTHelpers.getType(tree)).getReturnType();
   case METHOD:
    return ASTHelpers.getType(tree).getReturnType();
   case CLASS:
    return null;
   default: // fall out
  }
 }
 return null;
}

相关文章

Types类方法