当前位置: 首页>>代码示例>>Java>>正文


Java TypeSymbol.getKind方法代码示例

本文整理汇总了Java中com.sun.tools.javac.code.Symbol.TypeSymbol.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java TypeSymbol.getKind方法的具体用法?Java TypeSymbol.getKind怎么用?Java TypeSymbol.getKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.code.Symbol.TypeSymbol的用法示例。


在下文中一共展示了TypeSymbol.getKind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: enumValues

import com.sun.tools.javac.code.Symbol.TypeSymbol; //导入方法依赖的package包/类
/** @return all values of the given enum type, in declaration order. */
public static LinkedHashSet<String> enumValues(TypeSymbol enumType) {
  if (enumType.getKind() != ElementKind.ENUM) {
    throw new IllegalStateException();
  }
  Scope scope = enumType.members();
  Deque<String> values = new ArrayDeque<>();
  for (Symbol sym : scope.getSymbols()) {
    if (sym instanceof VarSymbol) {
      VarSymbol var = (VarSymbol) sym;
      if ((var.flags() & Flags.ENUM) != 0) {
        /**
         * Javac gives us the members backwards, apparently. It's worth making an effort to
         * preserve declaration order because it's useful for diagnostics (e.g. in {@link
         * MissingCasesInEnumSwitch}).
         */
        values.push(sym.name.toString());
      }
    }
  }
  return new LinkedHashSet<>(values);
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:ASTHelpers.java

示例2: matchClass

import com.sun.tools.javac.code.Symbol.TypeSymbol; //导入方法依赖的package包/类
@Override
public Description matchClass(ClassTree classTree, VisitorState state) {

  TypeSymbol symbol = ASTHelpers.getSymbol(classTree);
  if (symbol.getKind() != ElementKind.CLASS) {
    return Description.NO_MATCH;
  }

  MethodTree equals = null;
  for (Tree member : classTree.getMembers()) {
    if (!(member instanceof MethodTree)) {
      continue;
    }
    MethodTree methodTree = (MethodTree) member;
    if (EQUALS_MATCHER.matches(methodTree, state)) {
      equals = methodTree;
    }
  }
  if (equals == null || isSuppressed(equals)) {
    return Description.NO_MATCH;
  }

  MethodSymbol hashCodeSym =
      ASTHelpers.resolveExistingMethod(
          state,
          symbol,
          state.getName("hashCode"),
          ImmutableList.<Type>of(),
          ImmutableList.<Type>of());

  if (hashCodeSym.owner.equals(state.getSymtab().objectType.tsym)) {
    return describeMatch(equals);
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:36,代码来源:EqualsHashCode.java

示例3: isEnumIdentifier

import com.sun.tools.javac.code.Symbol.TypeSymbol; //导入方法依赖的package包/类
/** Returns true if this parameter is an enum identifier */
private static boolean isEnumIdentifier(Parameter parameter) {
  switch (parameter.kind()) {
    case IDENTIFIER:
    case MEMBER_SELECT:
      break;
    default:
      return false;
  }
  TypeSymbol typeSymbol = parameter.type().tsym;
  if (typeSymbol != null) {
    return typeSymbol.getKind() == ElementKind.ENUM;
  }
  return false;
}
 
开发者ID:google,项目名称:error-prone,代码行数:16,代码来源:AssertEqualsArgumentOrderChecker.java

示例4: matchClass

import com.sun.tools.javac.code.Symbol.TypeSymbol; //导入方法依赖的package包/类
@Override
public Description matchClass(ClassTree classTree, VisitorState state) {
  if (!IS_INPUT_STREAM.matches(classTree, state)) {
    return Description.NO_MATCH;
  }

  TypeSymbol thisClassSymbol = ASTHelpers.getSymbol(classTree);
  if (thisClassSymbol.getKind() != ElementKind.CLASS) {
    return Description.NO_MATCH;
  }

  // Find the method that overrides the single-byte read. It should also override the multibyte
  // read.
  MethodTree readByteMethod =
      classTree
          .getMembers()
          .stream()
          .filter(MethodTree.class::isInstance)
          .map(MethodTree.class::cast)
          .filter(m -> READ_INT_METHOD.matches(m, state))
          .findFirst()
          .orElse(null);

  if (readByteMethod == null) {
    return Description.NO_MATCH;
  }

  Type byteArrayType = state.arrayTypeForType(state.getSymtab().byteType);
  Type intType = state.getSymtab().intType;
  MethodSymbol multiByteReadMethod =
      ASTHelpers.resolveExistingMethod(
          state,
          thisClassSymbol,
          state.getName("read"),
          ImmutableList.of(byteArrayType, intType, intType),
          ImmutableList.of());

  return multiByteReadMethod.owner.equals(thisClassSymbol)
      ? Description.NO_MATCH
      : maybeMatchReadByte(readByteMethod, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:42,代码来源:InputStreamSlowMultibyteRead.java


注:本文中的com.sun.tools.javac.code.Symbol.TypeSymbol.getKind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。