本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}