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

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

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

Types.getRetention介绍

暂无

代码示例

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

@Override
 public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (!MATCHER.matches(tree, state)) {
   return NO_MATCH;
  }
  Type classType = getType(getOnlyElement(tree.getArguments()));
  if (classType == null || classType.getTypeArguments().isEmpty()) {
   return NO_MATCH;
  }
  Type type = getUpperBound(getOnlyElement(classType.getTypeArguments()), state.getTypes());
  if (isSameType(type, state.getSymtab().annotationType, state)) {
   return NO_MATCH;
  }
  RetentionPolicy retention = state.getTypes().getRetention(type.asElement());
  switch (retention) {
   case RUNTIME:
    break;
   case SOURCE:
   case CLASS:
    return buildDescription(tree)
      .setMessage(
        String.format(
          "%s; %s has %s retention",
          message(), type.asElement().getSimpleName(), retention))
      .build();
  }
  return NO_MATCH;
 }
}

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

public RetentionPolicy getRetention(Attribute.Compound a) {
  return getRetention(a.type.tsym);
}

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

public RetentionPolicy getRetention(Attribute.Compound a) {
  return getRetention(a.type.tsym);
}

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

private void validateRetention(Symbol container, Symbol contained, DiagnosticPosition pos) {
  Attribute.RetentionPolicy containerRetention = types.getRetention(container);
  Attribute.RetentionPolicy containedRetention = types.getRetention(contained);
  boolean error = false;
  switch (containedRetention) {
  case RUNTIME:
    if (containerRetention != Attribute.RetentionPolicy.RUNTIME) {
      error = true;
    }
    break;
  case CLASS:
    if (containerRetention == Attribute.RetentionPolicy.SOURCE)  {
      error = true;
    }
  }
  if (error ) {
    log.error(pos, "invalid.repeatable.annotation.retention",
         container, containerRetention,
         contained, containedRetention);
  }
}

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

private void validateRetention(Symbol container, Symbol contained, DiagnosticPosition pos) {
  Attribute.RetentionPolicy containerRetention = types.getRetention(container);
  Attribute.RetentionPolicy containedRetention = types.getRetention(contained);
  boolean error = false;
  switch (containedRetention) {
  case RUNTIME:
    if (containerRetention != Attribute.RetentionPolicy.RUNTIME) {
      error = true;
    }
    break;
  case CLASS:
    if (containerRetention == Attribute.RetentionPolicy.SOURCE)  {
      error = true;
    }
  }
  if (error ) {
    log.error(pos, "invalid.repeatable.annotation.retention",
         container, containerRetention,
         contained, containedRetention);
  }
}

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

private boolean needPackageInfoClass(JCCompilationUnit tree) {
  switch (pkginfoOpt) {
    case ALWAYS:
      return true;
    case LEGACY:
      return tree.packageAnnotations.nonEmpty();
    case NONEMPTY:
      for (Attribute.Compound a :
           tree.packge.getDeclarationAttributes()) {
        Attribute.RetentionPolicy p = types.getRetention(a);
        if (p != Attribute.RetentionPolicy.SOURCE)
          return true;
      }
      return false;
  }
  throw new AssertionError();
}

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

private boolean needPackageInfoClass(JCCompilationUnit tree) {
  switch (pkginfoOpt) {
    case ALWAYS:
      return true;
    case LEGACY:
      return tree.packageAnnotations.nonEmpty();
    case NONEMPTY:
      for (Attribute.Compound a :
           tree.packge.getDeclarationAttributes()) {
        Attribute.RetentionPolicy p = types.getRetention(a);
        if (p != Attribute.RetentionPolicy.SOURCE)
          return true;
      }
      return false;
  }
  throw new AssertionError();
}

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

@Override
 public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  if (!MATCHER.matches(tree, state)) {
   return NO_MATCH;
  }
  Type classType = getType(getOnlyElement(tree.getArguments()));
  if (classType == null || classType.getTypeArguments().isEmpty()) {
   return NO_MATCH;
  }
  Type type = getUpperBound(getOnlyElement(classType.getTypeArguments()), state.getTypes());
  if (isSameType(type, state.getSymtab().annotationType, state)) {
   return NO_MATCH;
  }
  RetentionPolicy retention = state.getTypes().getRetention(type.asElement());
  switch (retention) {
   case RUNTIME:
    break;
   case SOURCE:
   case CLASS:
    return buildDescription(tree)
      .setMessage(
        String.format(
          "%s; %s has %s retention",
          message(), type.asElement().getSimpleName(), retention))
      .build();
  }
  return NO_MATCH;
 }
}

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

for (VarSymbol s : m.params) {
  for (Attribute.Compound a : s.getRawAttributes()) {
    switch (types.getRetention(a)) {
    case SOURCE: break;
    case CLASS: hasInvisible = true; break;
  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
  for (Attribute.Compound a : s.getRawAttributes())
    if (types.getRetention(a) == RetentionPolicy.RUNTIME)
      buf.append(a);
  databuf.appendChar(buf.length());
  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
  for (Attribute.Compound a : s.getRawAttributes())
    if (types.getRetention(a) == RetentionPolicy.CLASS)
      buf.append(a);
  databuf.appendChar(buf.length());

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

for (VarSymbol s : m.params) {
  for (Attribute.Compound a : s.getRawAttributes()) {
    switch (types.getRetention(a)) {
    case SOURCE: break;
    case CLASS: hasInvisible = true; break;
  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
  for (Attribute.Compound a : s.getRawAttributes())
    if (types.getRetention(a) == RetentionPolicy.RUNTIME)
      buf.append(a);
  databuf.appendChar(buf.length());
  ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
  for (Attribute.Compound a : s.getRawAttributes())
    if (types.getRetention(a) == RetentionPolicy.CLASS)
      buf.append(a);
  databuf.appendChar(buf.length());

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

ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>();
for (Attribute.Compound a : attrs) {
  switch (types.getRetention(a)) {
  case SOURCE: break;
  case CLASS: invisibles.append(a); break;

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

if (!tc.position.emitToClassfile())
  continue;
switch (types.getRetention(tc)) {
case SOURCE: break;
case CLASS: invisibles.append(tc); break;

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

if (!tc.position.emitToClassfile())
  continue;
switch (types.getRetention(tc)) {
case SOURCE: break;
case CLASS: invisibles.append(tc); break;

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

ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>();
for (Attribute.Compound a : attrs) {
  switch (types.getRetention(a)) {
  case SOURCE: break;
  case CLASS: invisibles.append(a); break;

相关文章

Types类方法