本文整理汇总了Java中com.sun.tools.javac.code.Types.isArray方法的典型用法代码示例。如果您正苦于以下问题:Java Types.isArray方法的具体用法?Java Types.isArray怎么用?Java Types.isArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.code.Types
的用法示例。
在下文中一共展示了Types.isArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewriteArrayArgument
import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
/**
* 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, Types types) {
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(" + arg + ")";
} else {
return "Arrays.hashCode(" + arg + ")";
}
}
示例2: matchMethodInvocation
import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
MethodSymbol sym = ASTHelpers.getSymbol(tree);
if (!sym.isVarArgs()) {
return NO_MATCH;
}
if (tree.getArguments().size() != sym.getParameters().size()) {
// explicit varargs call with more actuals than formals
return NO_MATCH;
}
Tree arg = getLast(tree.getArguments());
if (!(arg instanceof ConditionalExpressionTree)) {
return NO_MATCH;
}
Types types = state.getTypes();
if (types.isArray(getType(arg))) {
return NO_MATCH;
}
ConditionalExpressionTree cond = (ConditionalExpressionTree) arg;
boolean trueIsArray = types.isArray(getType(cond.getTrueExpression()));
if (!(trueIsArray ^ types.isArray(getType(cond.getFalseExpression())))) {
return NO_MATCH;
}
SuggestedFix.Builder fix = SuggestedFix.builder();
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, "}");
return describeMatch(tree, fix.build());
}
示例3: matches
import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
@Override
public boolean matches(MethodInvocationTree t, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(t);
if (!(symbol instanceof MethodSymbol)) {
return false;
}
MethodSymbol methodSymbol = (MethodSymbol) symbol;
// Bail out quickly if the method is not varargs
if (!methodSymbol.isVarArgs()) {
return false;
}
// Last param must be varags
List<VarSymbol> params = methodSymbol.getParameters();
int varargsPosition = params.length() - 1;
ArrayType varargsParamType = (ArrayType) params.last().type;
// Is the argument at the varargsPosition the only varargs argument and a primitive array?
JCMethodInvocation methodInvocation = (JCMethodInvocation) t;
List<JCExpression> arguments = methodInvocation.getArguments();
Types types = state.getTypes();
if (arguments.size() != params.length()) {
return false;
}
Type varargsArgumentType = arguments.get(varargsPosition).type;
if (!types.isArray(varargsArgumentType)
|| !types.elemtype(varargsArgumentType).isPrimitive()) {
return false;
}
// Do the param and argument types actually match? i.e. can boxing even happen?
return !(types.isSameType(varargsParamType, varargsArgumentType)
|| types.isSameType(varargsParamType.getComponentType(), varargsArgumentType));
}
示例4: matches
import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
@Override
public boolean matches(MethodInvocationTree t, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(t);
if (symbol == null || !(symbol instanceof MethodSymbol)) {
return false;
}
MethodSymbol methodSymbol = (MethodSymbol) symbol;
// Bail out quickly if the method is not varargs
if (!methodSymbol.isVarArgs()) {
return false;
}
// Last param must be varags
List<VarSymbol> params = methodSymbol.getParameters();
int varargsPosition = params.length() - 1;
ArrayType varargsParamType = (ArrayType) params.last().type;
// Is the argument at the varargsPosition the only varargs argument and a primitive array?
JCMethodInvocation methodInvocation = (JCMethodInvocation) t;
List<JCExpression> arguments = methodInvocation.getArguments();
Types types = state.getTypes();
if (arguments.size() != params.length()) {
return false;
}
Type varargsArgumentType = arguments.get(varargsPosition).type;
if (!types.isArray(varargsArgumentType)
|| !types.elemtype(varargsArgumentType).isPrimitive()) {
return false;
}
// Do the param and argument types actually match? i.e. can boxing even happen?
if (types.isSameType(varargsParamType, varargsArgumentType)
|| types.isSameType(varargsParamType.getComponentType(), varargsArgumentType)) {
return false;
}
return true;
}