本文整理了Java中com.sun.tools.javac.code.Types.elemtype()
方法的一些代码示例,展示了Types.elemtype()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.elemtype()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:elemtype
[英]The element type of an array.
[中]数组的元素类型。
代码示例来源:origin: google/error-prone
@Nullable
@Override
public Type visitNewArray(NewArrayTree node, Void aVoid) {
if (node.getDimensions().contains(current)) {
return state.getSymtab().intType;
}
if (node.getInitializers().contains(current)) {
return state.getTypes().elemtype(ASTHelpers.getType(node));
}
return null;
}
代码示例来源:origin: google/error-prone
/**
* Given an {@link ExpressionTree} that represents an argument of array type, rewrites it to wrap
* it in a call to either {@link java.util.Arrays#hashCode} if it is single dimensional, or {@link
* java.util.Arrays#deepHashCode} if it is multidimensional.
*/
private static String rewriteArrayArgument(ExpressionTree arg, VisitorState state) {
Types types = state.getTypes();
Type argType = ASTHelpers.getType(arg);
Preconditions.checkState(types.isArray(argType), "arg must be of array type");
if (types.isArray(types.elemtype(argType))) {
return "Arrays.deepHashCode(" + state.getSourceForNode(arg) + ")";
} else {
return "Arrays.hashCode(" + state.getSourceForNode(arg) + ")";
}
}
}
代码示例来源:origin: google/error-prone
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null
&& state.getTypes().isArray(type)
&& state.getTypes().elemtype(type).isPrimitive();
}
};
代码示例来源:origin: google/error-prone
@Nullable
private Type visitMethodInvocationOrNewClass(
List<? extends ExpressionTree> arguments, MethodSymbol sym, Type type) {
int idx = arguments.indexOf(current);
if (idx == -1) {
return null;
}
if (type.getParameterTypes().size() <= idx) {
if (!sym.isVarArgs()) {
if ((sym.flags() & Flags.HYPOTHETICAL) != 0) {
// HYPOTHETICAL is also used for signature-polymorphic methods
return null;
}
throw new IllegalStateException(
String.format(
"saw %d formal parameters and %d actual parameters on non-varargs method %s\n",
type.getParameterTypes().size(), arguments.size(), sym));
}
idx = type.getParameterTypes().size() - 1;
}
Type argType = type.getParameterTypes().get(idx);
if (sym.isVarArgs() && idx == type.getParameterTypes().size() - 1) {
argType = state.getTypes().elemtype(argType);
}
return argType;
}
代码示例来源:origin: google/error-prone
@Override
public Description matchMethodInvocation(
MethodInvocationTree methodInvocationTree, VisitorState visitorState) {
if (!TO_ARRAY_MATCHER.matches(methodInvocationTree, visitorState)) {
return NO_MATCH;
}
Types types = visitorState.getTypes();
Type variableType =
types.elemtype(getType(getOnlyElement(methodInvocationTree.getArguments())));
if (variableType == null) {
return NO_MATCH;
}
Type collectionType =
types.asSuper(
ASTHelpers.getReceiverType(methodInvocationTree),
visitorState.getSymbolFromString("java.util.Collection"));
List<Type> typeArguments = collectionType.getTypeArguments();
if (!typeArguments.isEmpty()
&& !types.isCastable(
types.erasure(variableType), types.erasure(getOnlyElement(typeArguments)))) {
return describeMatch(methodInvocationTree);
}
return NO_MATCH;
}
}
代码示例来源:origin: google/error-prone
String qualified =
SuggestedFixes.qualifyType(
state, fix, types.elemtype(getLast(sym.getParameters()).asType()));
Tree toFix = !trueIsArray ? cond.getTrueExpression() : cond.getFalseExpression();
fix.prefixWith(toFix, String.format("new %s[] {", qualified)).postfixWith(toFix, "}");
代码示例来源:origin: google/error-prone
state.getTypes().elemtype(ASTHelpers.getType(invocationTree.getArguments().get(0)));
Tree fillingArgument = Iterables.getLast(invocationTree.getArguments());
Type fillingObjectType = ASTHelpers.getType(fillingArgument);
代码示例来源:origin: google/error-prone
|| !types.elemtype(varargsArgumentType).isPrimitive()) {
return false;
代码示例来源:origin: google/error-prone
Type elemType = types.elemtype(ASTHelpers.getType(arg));
if (elemType.isPrimitive() || types.isArray(elemType)) {
fix = SuggestedFix.builder().replace(tree, rewriteArrayArgument(arg, state));
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* The number of dimensions of an array type.
*/
public int dimensions(Type t) {
int result = 0;
while (t.tag == ARRAY) {
result++;
t = elemtype(t);
}
return result;
}
// </editor-fold>
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Void visitArrayType(ArrayType source, Type target) throws AdaptFailure {
if (target.hasTag(ARRAY))
adaptRecursive(elemtype(source), elemtype(target));
return null;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Is type a type variable, or a (possibly multi-dimensional) array of
* type variables?
*/
boolean isTypeVar(Type t) {
return t.tag == TYPEVAR || t.tag == ARRAY && isTypeVar(types.elemtype(t));
}
代码示例来源:origin: sc.fiji/javac
boolean isAccessible(Env<AttrContext> env, Type t) {
return (t.tag == ARRAY)
? isAccessible(env, types.elemtype(t))
: isAccessible(env, t.tsym);
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Translate away the foreach loop. */
public void visitForeachLoop(JCEnhancedForLoop tree) {
if (types.elemtype(tree.expr.type) == null)
visitIterableForeachLoop(tree);
else
visitArrayForeachLoop(tree);
}
// where
代码示例来源:origin: sc.fiji/javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (t == s)
return true;
if (s.tag >= firstPartialTag)
return visit(s, t);
return s.tag == ARRAY
&& containsTypeEquivalent(t.elemtype, elemtype(s));
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
if (t == s)
return true;
if (s.isPartial())
return visit(s, t);
return s.hasTag(ARRAY)
&& containsTypeEquivalent(t.elemtype, elemtype(s));
}
代码示例来源:origin: com.google.errorprone/error_prone_check_api
@Override
public Type visitNewArray(NewArrayTree node, Void aVoid) {
if (node.getDimensions().contains(current)) {
return state.getSymtab().intType;
}
if (node.getInitializers().contains(current)) {
return state.getTypes().elemtype(ASTHelpers.getType(node));
}
return null;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public void visitForeachLoop(JCEnhancedForLoop tree) {
tree.var = translate(tree.var, null);
Type iterableType = tree.expr.type;
tree.expr = translate(tree.expr, erasure(tree.expr.type));
if (types.elemtype(tree.expr.type) == null)
tree.expr.type = iterableType; // preserve type for Lower
tree.body = translate(tree.body);
result = tree;
}
代码示例来源:origin: sc.fiji/javac
public void visitIndexed(JCArrayAccess tree) {
tree.indexed = translate(tree.indexed, erasure(tree.indexed.type));
tree.index = translate(tree.index, syms.intType);
// Insert casts of indexed expressions as needed.
result = retype(tree, types.elemtype(tree.indexed.type), pt);
}
代码示例来源:origin: com.google.errorprone/error_prone_check_api
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null
&& state.getTypes().isArray(type)
&& state.getTypes().elemtype(type).isPrimitive();
}
};
内容来源于网络,如有侵权,请联系作者删除!